https://github.com/vweevers/bruce-millis-option
Convert various time formats to milliseconds and throw if result is NaN.
https://github.com/vweevers/bruce-millis-option
milliseconds ms nodejs npm-package time
Last synced: about 1 month ago
JSON representation
Convert various time formats to milliseconds and throw if result is NaN.
- Host: GitHub
- URL: https://github.com/vweevers/bruce-millis-option
- Owner: vweevers
- License: mit
- Created: 2020-07-25T08:08:33.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-25T08:10:38.000Z (almost 6 years ago)
- Last Synced: 2026-04-22T07:43:22.351Z (about 2 months ago)
- Topics: milliseconds, ms, nodejs, npm-package, time
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# bruce-millis-option
**Convert various time formats to milliseconds and throw if result is `NaN`. Like [`bruce-millis`](https://github.com/vweevers/bruce-millis) but dies harder.**
[](https://www.npmjs.org/package/bruce-millis-option)
[](https://www.npmjs.org/package/bruce-millis-option)
[](http://travis-ci.com/vweevers/bruce-millis-option)
[](https://standardjs.com)
## Usage
```js
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`](https://github.com/vweevers/bruce-millis), throws a TypeError if result is `NaN`. A `hint` may be provided to customize the error message:
```js
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. (/example/example.js:2:1)
at ..
```
## Install
With [npm](https://npmjs.org) do:
```
npm install bruce-millis-option
```
## License
[MIT](LICENSE.md) © 2020-present Vincent Weevers