Code Monkey home page Code Monkey logo

bruce-millis's Introduction

bruce-millis

Convert various time formats to milliseconds. Same as ms except it only does parsing, which gives us the opportunity to return a number input as-is. I frequently did:

const ms = require('ms')
const timeout = typeof n === 'number' ? n : ms(n)

npm status node Travis build status JavaScript Style Guide

Usage

const ms = require('bruce-millis')

ms(24)        // 24
ms('5s')      // 5000
ms('1m')      // 60000
ms('2h')      // 7200000
ms('2.5 hrs') // 9000000
ms('10h')     // 36000000
ms('1d')      // 86400000
ms('2 days')  // 172800000
ms('1y')      // 31557600000
ms('-3 days') // -259200000
ms('-1h')     // -3600000

API

ms(value)

The value argument is required and must be a string or a number (returned as-is). String values are parsed exactly like ms. If the input is invalid, NaN is returned. If you want an error to be thrown, see bruce-millis-option.

Install

With npm do:

npm install bruce-millis

License

MIT. Adapted from ms, please see license for details.

bruce-millis's People

Contributors

vweevers avatar

Stargazers

 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.