feat(@vates/parse-duration): 0.1.0
This commit is contained in:
parent
3fc16cb414
commit
27f53f262b
47
@vates/parse-duration/README.md
Normal file
47
@vates/parse-duration/README.md
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
|
||||||
|
|
||||||
|
# @vates/parse-duration
|
||||||
|
|
||||||
|
[](https://npmjs.org/package/@vates/parse-duration)  [](https://bundlephobia.com/result?p=@vates/parse-duration) [](https://npmjs.org/package/@vates/parse-duration)
|
||||||
|
|
||||||
|
> Small wrapper around ms to parse a duration
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
Installation of the [npm package](https://npmjs.org/package/@vates/parse-duration):
|
||||||
|
|
||||||
|
```
|
||||||
|
> npm install --save @vates/parse-duration
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
`ms` without magic: always parse a duration and throws if invalid.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { parseDuration } from '@vates/parse-duration'
|
||||||
|
|
||||||
|
parseDuration('2 days')
|
||||||
|
// 172800000
|
||||||
|
|
||||||
|
parseDuration(172800000)
|
||||||
|
// 172800000
|
||||||
|
|
||||||
|
parseDuration(undefined)
|
||||||
|
// throws TypeError('not a valid duration: undefined')
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contributions
|
||||||
|
|
||||||
|
Contributions are _very_ welcomed, either on the documentation or on
|
||||||
|
the code.
|
||||||
|
|
||||||
|
You may:
|
||||||
|
|
||||||
|
- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
|
||||||
|
you've encountered;
|
||||||
|
- fork and create a pull request.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
[AGPL-3.0-or-later](https://spdx.org/licenses/AGPL-3.0-or-later) © [Vates SAS](https://vates.fr)
|
14
@vates/parse-duration/USAGE.md
Normal file
14
@vates/parse-duration/USAGE.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
`ms` without magic: always parse a duration and throws if invalid.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { parseDuration } from '@vates/parse-duration'
|
||||||
|
|
||||||
|
parseDuration('2 days')
|
||||||
|
// 172800000
|
||||||
|
|
||||||
|
parseDuration(172800000)
|
||||||
|
// 172800000
|
||||||
|
|
||||||
|
parseDuration(undefined)
|
||||||
|
// throws TypeError('not a valid duration: undefined')
|
||||||
|
```
|
12
@vates/parse-duration/index.js
Normal file
12
@vates/parse-duration/index.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
const ms = require('ms')
|
||||||
|
|
||||||
|
exports.parseDuration = value => {
|
||||||
|
if (typeof value === 'number') {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
const duration = ms(value)
|
||||||
|
if (duration === undefined) {
|
||||||
|
throw new TypeError(`not a valid duration: ${duration}`)
|
||||||
|
}
|
||||||
|
return duration
|
||||||
|
}
|
32
@vates/parse-duration/package.json
Normal file
32
@vates/parse-duration/package.json
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"private": false,
|
||||||
|
"name": "@vates/parse-duration",
|
||||||
|
"description": "Small wrapper around ms to parse a duration",
|
||||||
|
"keywords": [
|
||||||
|
"duration",
|
||||||
|
"ms",
|
||||||
|
"parse"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@vates/parse-duration",
|
||||||
|
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
|
||||||
|
"repository": {
|
||||||
|
"directory": "@vates/parse-duration",
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/vatesfr/xen-orchestra.git"
|
||||||
|
},
|
||||||
|
"author": {
|
||||||
|
"name": "Vates SAS",
|
||||||
|
"url": "https://vates.fr"
|
||||||
|
},
|
||||||
|
"license": "AGPL-3.0-or-later",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8.10"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"ms": "^2.1.2"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"postversion": "npm publish --access public"
|
||||||
|
}
|
||||||
|
}
|
@ -12445,7 +12445,7 @@ ms@2.1.1:
|
|||||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a"
|
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a"
|
||||||
integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==
|
integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==
|
||||||
|
|
||||||
ms@^2.1.1:
|
ms@^2.1.1, ms@^2.1.2:
|
||||||
version "2.1.2"
|
version "2.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
|
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
|
||||||
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
|
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
|
||||||
|
Loading…
Reference in New Issue
Block a user