Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 24 days 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 (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-07-25T08:10:38.000Z (over 4 years ago)
- Last Synced: 2024-12-07T03:30:59.489Z (27 days 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.**
[![npm status](http://img.shields.io/npm/v/bruce-millis-option.svg)](https://www.npmjs.org/package/bruce-millis-option)
[![node](https://img.shields.io/node/v/bruce-millis-option.svg)](https://www.npmjs.org/package/bruce-millis-option)
[![Travis build status](https://img.shields.io/travis/com/vweevers/bruce-millis-option.svg?label=travis)](http://travis-ci.com/vweevers/bruce-millis-option)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](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') // -3600000ms('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