Have ideas to improve npm?Join in the discussion! »

    utils.time

    0.2.0 • Public • Published


    header-image


    Build Status npm styled with prettier

    ⌚ Micro library to make working with milliseconds easier.


    If you have ever written something like this
    const ONE_DAY = 1000 * 60 * 60 * 24;

    ... then this micro library is made just for you.

    Install

    $ npm install --save utils.time
    

    Usage

    ES6+ way

    import { seconds } from 'utils.time';
     
    seconds(3);
    //=> 3000

    Pre-ES6 way

    const { seconds } = require('utils.time');
     
    seconds(3);
    //=> 3000

    Motivation

    Too often, I saw myself writing code that resembled something like this

    const ONE_SECOND = 1000;
    let twentyFourHours = ONE_SECOND * 60 * 60 * 24;
     
    const fn = () {
      // some code that runs every 24 hours
    };
     
    setInterval(fn, twentyFourHours);

    ... and not just in one place, but in several places. At some point, I would just extract all these constants either at the top-level of the module, or just create a small module itself. What you're seeing is the result of the small module I'd end up using in other projects.

    NOTE: I'm aware of the awesome library by zeit (ms), but I felt like it did way more than I needed it to, which is why I decided to publish my version of it. Once again, to reiterate, ms is great, but I just needed something smaller.

    Install

    npm i utils.time

    DownloadsWeekly Downloads

    2

    Version

    0.2.0

    License

    MIT

    Last publish

    Collaborators

    • avatar