1.0.8 • Published 1 year ago

@thewisker/formatterjs v1.0.8

Weekly downloads
-
License
GNU
Repository
github
Last release
1 year ago
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.

FormatterConstructorDescription
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.

FunctionParametersDefaultDescription
format(date: Date())new Date()Formats the date object
FormatTypeDescriptionExample
%%Escape SequenceEscapes the % character%
FormatTypeDescriptionExample
%YYearThe year2022
%yYearThe short year22 or 022
%JYearThe day of the year364
%MMonthThe month number02
%mMonthThe month number2
%BMonthThe month nameFebruary
%bMonthThe month short nameFeb
%DDayThe day of the month08
%dDayThe day of the month8
%AWeekdayThe name of the dayMonday
%aWeekdayThe name of the dayMon
%WWeekdayThe day of the week1
FormatTypeDescriptionExample
%HHourThe hour in 24 format20
%hHourThe hour in 24 format20
%IHourThe hour in 12 format08
%iHourThe hour in 12 format08
%KMinutesThe minutes06
%kMinutesThe minutes6
%SSecondsThe seconds04
%sSecondsThe seconds4
%LDecisecondThe decisecond2
%QCentisecondThe centiseconds02
%qCentisecondThe centiseconds2
%FMilisecondThe miliszeconds06
%fMilisecondThe miliszeconds6
%PTimestampThe timestampAM
%pTimestampThe timestampam
%fTimezone OffsetThe timezone offset+02
%fTimezone OffsetThe 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.

FunctionParametersDefaultDescription
format(date: Date(), format: string, utc: boolean)No defaultsFormats the date object
1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago