time-chainer
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

Time Chainer

Create your milliseconds declaratively!

CircleCI Known Vulnerabilities Maintainability codecov

npm

Install

npm install --save time-chainer

or

yarn add time-chainer

Example

import Time from 'time-chainer';

// Do something after 5 seconds
setTimeout(() => {
  doSomething();

}, +Time.seconds(5));

// 3 Days and 12 hours later from now
new Date(
  new Date() + (
    Time
      .days(3)
      .hours(12)
  )
);

// 1 week + 15 days + 12 hours + 30 minutes + 30 seconds + 500 milliseconds
Time
  .milliseconds(500)
  .seconds(30)
  .minutes(30)
  .hours(12)
  .days(15)
  .weeks(1)
; // 1,945,830,500

TimeChainer extends Number

Time Chainer extends Number object. In cases where a primitive number is strictly required, you will need to explicitly convert it to a primitive number by appending a + operator like this:

jest.advanceTimersByTime(+Time.days(30));

See details:

Time.seconds(5) instanceof Number // true
typeof Time.seconds(5) // "object"
typeof +Time.seconds(5) // "number"

Package Sidebar

Install

npm i time-chainer

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

18.1 kB

Total Files

10

Last publish

Collaborators

  • amoshydra