Giter VIP home page Giter VIP logo

format-date's Introduction

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

ย  Token Output
Year YY 70, 71, ... 19, 20.
YYYY 1970, 1971, ... 2019, 2020.
Month M 1, 2, ... 11, 12.
MM 01, 02, ... 11, 12.
Day of Month D 1, 2, ... 30, 31.
DD 01, 02, ... 30, 31.
Hour H 1, 2, ... , 22,23.
HH 01, 02, ... , 22,23.
Minute m 1, 2, ... , 58,59.
mm 01, 02, ... , 58,59.
Second s 1, 2, ... , 58,59.
ss 01, 02, ... , 58,59.
AM/PM A AM, PM.
a am, pm.
Escape [*] ย 

License

Released under MIT License.

format-date's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.