1.4.0 • Published 2 years ago

@bitty/format-date v1.4.0

Weekly downloads
25
License
MIT
Repository
github
Last release
2 years ago

@bitty/format-date

Bundle minified size Bundle minified and gzipped size

@bitty/format-date is a small library (around 400 B when gziped & minified) to format JavaScript Date object using same tokens as moment.

  • 📦 Distributions in ESM, CommonJS, UMD and UMD minified formats.

  • ⚡ Lightweight:

    • Weighs around 0.4KB (min + gzip).
  • 🔋 Bateries included:

    • No dependencies.
    • Its not based on newer browser's APIs or es2015+ features.
  • 🏷 Safe:

    • JSDocs and type declarations for IDEs and editor's autocomplete/intellisense.
    • Made with TypeScript as strict as possible.
    • Unit tests with AVA.

Installation

This library is published in the NPM registry and can be installed using any compatible package manager.

npm install @bitty/format-date --save

# For Yarn, use the command below.
yarn add @bitty/format-date

Installation from CDN

This module has a UMD bundle available through JSDelivr and Unpkg CDNs.

<!-- For UNPKG use the code below. -->
<script src="https://unpkg.com/@bitty/format-date"></script>

<!-- For JSDelivr use the code below. -->
<script src="https://cdn.jsdelivr.net/npm/@bitty/format-date"></script>

<script>
  // UMD module is exposed through the "isNullish" global function.
  console.log(formatDate);
  //=> "[Function: formatDate]"

  console.log(formatDate(new Date(), 'YYYY-MM-DD'));
  //=> "2020-06-14"
</script>

Usage

@bitty/format-date exports a function to format JavaScript Date object using moment tokens.

import formatDate from '@bitty/format-date';

formatDate(new Date(), 'DD/MM/YYYY HH [hours] [and] mm [minutes].');
// I'm escaping "hours", "and" and "minutes" using same syntax as Moment.js.

Tokens

Right now this lib supports the tokens below.

 TokenOutput
YearYY70, 71, ... 19, 20.
YYYY1970, 1971, ... 2019, 2020.
MonthM1, 2, ... 11, 12.
MM01, 02, ... 11, 12.
Day of MonthD1, 2, ... 30, 31.
DD01, 02, ... 30, 31.
HourH1, 2, ... , 22,23.
HH01, 02, ... , 22,23.
Minutem1, 2, ... , 58,59.
mm01, 02, ... , 58,59.
Seconds1, 2, ... , 58,59.
ss01, 02, ... , 58,59.
AM/PMAAM, PM.
aam, pm.
Escape[*] 

License

Released under MIT License.

1.4.0

2 years ago

1.3.0

2 years ago

1.2.1

3 years ago

1.2.0

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago