JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bench remove unused May 2, 2017
src default to curr Date May 2, 2017
test add all tests May 1, 2017
.editorconfig first Apr 26, 2017
.gitignore first Apr 26, 2017
.travis.yml bump travis envs May 2, 2017
builder.js add gzip size logging May 1, 2017
license first Apr 26, 2017
package.json 1.0.0 May 2, 2017
readme.md Fix broken tinytime link May 4, 2017
yarn.lock add gzip size logging May 1, 2017

readme.md

tinydate Build Status

A tiny (337B) reusable date formatter. Extremely fast!

Demo

Inspired by tinytime, this module returns a "render" function that efficiently re-render your deconstructed template. This allows for incredibly performant results!

However, please notice that this only provides a limited subset of Date methods. If you need more, tinytime or date-fns are great alternatives!

Install

$ npm install --save tinydate

Usage

const tinydate = require('tinydate');
const fooDate = new Date('5/1/2017, 4:30:09 PM');

const stamp = tinydate('Current time: [{HH}:{mm}:{ss}]');

stamp(fooDate);
//=> Current time: [16:30:09]

stamp();
//=> Current time: [17:09:34]

API

tinydate(pattern)(date)

pattern

Type: string

The template pattern to be parsed.

date

Type: Date
Default: new Date()

The date from which to retrieve values. Defaults to current datetime.

Patterns

  • {YYYY}: full year; eg: 2017
  • {YY}: short year; eg: 17
  • {MM}: month; eg: 04
  • {DD}: day; eg: 01
  • {HH}: hours; eg: 06 (24h)
  • {mm}: minutes; eg: 59
  • {ss}: seconds; eg: 09

Benchmarks

tinydate
  --> 72,236,210 ops/sec ±0.89% (91 runs sampled)
tinytime
  --> 27,530,608 ops/sec ±0.92% (93 runs sampled)
time-stamp
  --> 569,692 ops/sec ±0.80% (90 runs sampled)

License

MIT © Luke Edwards