npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@thewisker/formatterjs

v1.0.8

Published

A javascript time and date formatter!

Downloads

5

Readme

git clone https://github.com/TheWisker/FormatterJS
cd FormatterJS
cp -a ./out/ES5/classes/. ../destination/
cd ..
rm -fr FormatterJS

Node.js:

npm i @thewisker/formatterjs

Manually:

git clone https://github.com/TheWisker/FormatterJS
cd FormatterJS
cp -a ./out/ES6/module/. ../destination/
cd ..
rm -fr FormatterJS

This series of commands install the module to the destination folder. Use one or another depending on the ES version (5 or 6) with wich it will be executed.

Note: · The ES6 version is up to 2 times faster. · All installation scripts are located under the /scripts folder.

Just add a script tag refering to the Formatter file before any script tag that depends on it.

<script type="text/javascript" src="/destination/Formatter.js"></script>
<script type="text/javascript" src="/YourScript.js"></script>

With Node.js:

import {UniversalFormatter, DateFormatter, TimeFormatter} from "@thewisker/formatterjs";

Note: To run it with node.js name the file with the .mjs extension or add "type" : "module" to the package.json.

Or manually, just add a import statement targeting the Formatter file with the classes to import between the brackets.

import {UniversalFormatter, DateFormatter, TimeFormatter} from "/destination/Formatter.js";

Note: All import examples are located under the /examples folder.

|Formatter|Constructor|Description| |:-------:|:---------:|:----------| |UniversalFormatter|(Format: string, UTC: boolean)|Formats date and time altogether| |DateFormatter|(Format: string, UTC: boolean)|Formats only date| |TimeFormatter|(Format: string, UTC: boolean)|Formats only time|

Then call the format function on the object and pass an optional date parameter.

|Function|Parameters|Default|Description| |:------:|:--------:|:------|:----------| |format|(date: Date())|new Date()|Formats the date object|

|Format|Type|Description|Example| |:----:|:--:|:----------:|:----:| |%%|Escape Sequence|Escapes the % character|%|

|Format|Type|Description|Example| |:----:|:--:|:----------:|:----:| |%Y|Year|The year|2022| |%y|Year|The short year|22 or 022| |%J|Year|The day of the year|364| |%M|Month|The month number|02| |%m|Month|The month number|2| |%B|Month|The month name|February| |%b|Month|The month short name|Feb| |%D|Day|The day of the month|08| |%d|Day|The day of the month|8| |%A|Weekday|The name of the day|Monday| |%a|Weekday|The name of the day|Mon| |%W|Weekday|The day of the week|1|

|Format|Type|Description|Example| |:----:|:--:|:----------:|:----:| |%H|Hour|The hour in 24 format|20| |%h|Hour|The hour in 24 format|20| |%I|Hour|The hour in 12 format|08| |%i|Hour|The hour in 12 format|08| |%K|Minutes|The minutes|06| |%k|Minutes|The minutes|6| |%S|Seconds|The seconds|04| |%s|Seconds|The seconds|4| |%L|Decisecond|The decisecond|2| |%Q|Centisecond|The centiseconds|02| |%q|Centisecond|The centiseconds|2| |%F|Milisecond|The miliszeconds|06| |%f|Milisecond|The miliszeconds|6| |%P|Timestamp|The timestamp|AM| |%p|Timestamp|The timestamp|am| |%f|Timezone Offset|The timezone offset|+02| |%f|Timezone Offset|The timezone offset|+2|

var Formatter = new UniversalFormatter("%Y %H"); //Formats the year and hour.
console.log(Formatter.format()); //Prints to console the format for the current Date() object.

Output: 2020 12

var Formatter = new DateFormatter("%Y_%B"); //Formats the year and month.
console.log(Formatter.format(new Date("December 17, 1995 03:24:00"))); //Prints to console the format for the passed Date() object.

Output: 1995_December

var Formatter = new TimeFormatter("(%H-%S)"); //Formats the hour and second.
console.log(Formatter.format(new Date("November 20, 1998 03:25:00"))); //Prints to console the format for the passed Date() object.

Output: (03-25)

Note: All examples are located under the /examples folder.

Under the /out/{ES5, ES6}/function folders a Formatter.js files is located containing a single function format() that can be used when compatibility issues arise when using classes.

|Function|Parameters|Default|Description| |:------:|:--------:|:------|:----------| |format|(date: Date(), format: string, utc: boolean)|No defaults|Formats the date object|