Skip to content

Convert various time formats to milliseconds and throw if result is NaN.

License

Notifications You must be signed in to change notification settings

vweevers/bruce-millis-option

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bruce-millis-option

Convert various time formats to milliseconds and throw if result is NaN. Like bruce-millis but dies harder.

npm status node Travis build status JavaScript Style Guide

Usage

const ms = require('bruce-millis-option')

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

ms('invalid') // throws TypeError

API

ms(value[, hint])

Parses value with bruce-millis, throws a TypeError if result is NaN. A hint may be provided to customize the error message:

ms(options.timeout, 'The timeout option')
$ node example.js
/example/node_modules/bruce-millis-option/index.js:11
    throw new TypeError(
    ^

TypeError: The timeout option must be a number in milliseconds or a string with unit (e.g. '5m')
    at module.exports (/example/node_modules/bruce-millis-option/index.js:11:11)
    at Object.<anonymous> (/example/example.js:2:1)
    at ..

Install

With npm do:

npm install bruce-millis-option

License

MIT © 2020-present Vincent Weevers

About

Convert various time formats to milliseconds and throw if result is NaN.

Topics

Resources

License

Stars

Watchers

Forks