vweevers / bruce-millis

Convert various time formats to milliseconds.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Convert various time formats to milliseconds.

License:MIT License


Languages

Language:JavaScript 100.0%