millis

Because code is read by humans.

  • millis

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
millis
102.2.27 years ago9 years agoMinified + gzip package size for millis in KB

Readme

millis

Convert different measures (minutes, hours, etc..) to milliseconds.

<a href="https://www.npmjs.com/package/millis">
  <img src="https://img.shields.io/npm/v/millis.svg" alt="npm version">
</a>
<a href="https://travis-ci.org/Moeriki/node-millis">
  <img src="https://travis-ci.org/Moeriki/node-millis.svg?branch=master" alt="Build Status"></img>
</a>
<a href="https://coveralls.io/github/Moeriki/node-millis?branch=master">
  <img src="https://coveralls.io/repos/github/Moeriki/node-millis/badge.svg?branch=master" alt="Coverage Status"></img>
</a>
<a href="https://david-dm.org/moeriki/node-millis">
  <img src="https://david-dm.org/moeriki/node-millis/status.svg" alt="dependencies Status"></img>
</a>


Because code is read by humans we don't like this.
const CACHE_TIMEOUT = 30 * 24 * 60 * 60 * 1000;

const COOKIE_EXPIRE = Date.now() + 1209600000;

But we do like this.
import { days } from 'millis'

const CACHE_TIMEOUT = days(30)

const COOKIE_EXPIRE = Date.now() + 14 * days();

Install

npm install --save millis

Import

const seconds = require('millis/seconds');
const minutes = require('millis/minutes');
const hours = require('millis/hours');
const days = require('millis/days');
const weeks = require('millis/weeks');
const months = require('millis/months');
const years = require('millis/years');

ES Modules
import { seconds, minutes, hours, days, weeks, months, years } from 'millis';

Usage

const THIRTY_SECONDS = seconds(30);
const SIX_HOURS = 6 * hours();
const TWO_DAYS_AND_TWO_HOURS = 2 * days() + 2 * hours();

All methods are available in singular and plural.
const year = require('millis/year');
const ONE_YEAR = year();

In seconds

Because often timestamps are in unix format. You might need your duration in seconds instead of milliseconds.
const hours = require('millis/hours');
const unix = require('millis/unix');
const ONE_YEAR = 2 * unix() * hours();

Extending Number prototype

If you don't understand the implication of extending a native prototype \[1\ \[2\, don't use this.
require('millis/register');

const TWO_DAYS = (2).days();
const SIX_HOURS = (6).unix().hours();