Added some tests
This commit is contained in:
47
tests/node_modules/pretty-ms/index.js
generated
vendored
Normal file
47
tests/node_modules/pretty-ms/index.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
var parseMs = require('parse-ms');
|
||||
var plur = require('plur');
|
||||
var isFinitePonyfill = require('is-finite');
|
||||
|
||||
module.exports = function (ms, opts) {
|
||||
if (!isFinitePonyfill(ms)) {
|
||||
throw new TypeError('Expected a finite number');
|
||||
}
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
if (ms < 1000) {
|
||||
var msDecimalDigits = typeof opts.msDecimalDigits === 'number' ? opts.msDecimalDigits : 0;
|
||||
return (msDecimalDigits ? ms.toFixed(msDecimalDigits) : Math.ceil(ms)) + (opts.verbose ? ' ' + plur('millisecond', Math.ceil(ms)) : 'ms');
|
||||
}
|
||||
|
||||
var ret = [];
|
||||
|
||||
var add = function (val, long, short, valStr) {
|
||||
if (val === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var postfix = opts.verbose ? ' ' + plur(long, val) : short;
|
||||
|
||||
ret.push((valStr || val) + postfix);
|
||||
};
|
||||
|
||||
var parsed = parseMs(ms);
|
||||
|
||||
add(parsed.days, 'day', 'd');
|
||||
add(parsed.hours, 'hour', 'h');
|
||||
add(parsed.minutes, 'minute', 'm');
|
||||
|
||||
if (opts.compact) {
|
||||
add(parsed.seconds, 'second', 's');
|
||||
return '~' + ret[0];
|
||||
}
|
||||
|
||||
var sec = ms / 1000 % 60;
|
||||
var secDecimalDigits = typeof opts.secDecimalDigits === 'number' ? opts.secDecimalDigits : 1;
|
||||
var secStr = sec.toFixed(secDecimalDigits).replace(/\.0$/, '');
|
||||
add(sec, 'second', 's', secStr);
|
||||
|
||||
return ret.join(' ');
|
||||
};
|
||||
21
tests/node_modules/pretty-ms/license
generated
vendored
Normal file
21
tests/node_modules/pretty-ms/license
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
80
tests/node_modules/pretty-ms/package.json
generated
vendored
Normal file
80
tests/node_modules/pretty-ms/package.json
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"_from": "pretty-ms@^2.1.0",
|
||||
"_id": "pretty-ms@2.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-QlfCVt8/sLRR1q/6qwIYhBJpgdw=",
|
||||
"_location": "/pretty-ms",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "pretty-ms@^2.1.0",
|
||||
"name": "pretty-ms",
|
||||
"escapedName": "pretty-ms",
|
||||
"rawSpec": "^2.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/tap-spec"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-2.1.0.tgz",
|
||||
"_shasum": "4257c256df3fb0b451d6affaab021884126981dc",
|
||||
"_spec": "pretty-ms@^2.1.0",
|
||||
"_where": "/home/lilleman/go/src/gitlab.larvit.se/power-plan/auth/tests/node_modules/tap-spec",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/pretty-ms/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"is-finite": "^1.0.1",
|
||||
"parse-ms": "^1.0.0",
|
||||
"plur": "^1.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Convert milliseconds to a human readable string: 1337000000 → 15d 11h 23m 20s",
|
||||
"devDependencies": {
|
||||
"mocha": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/sindresorhus/pretty-ms#readme",
|
||||
"keywords": [
|
||||
"pretty",
|
||||
"prettify",
|
||||
"human",
|
||||
"humanize",
|
||||
"humanized",
|
||||
"readable",
|
||||
"time",
|
||||
"ms",
|
||||
"milliseconds",
|
||||
"duration",
|
||||
"period",
|
||||
"range",
|
||||
"text",
|
||||
"string",
|
||||
"str",
|
||||
"number",
|
||||
"hrtime"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "pretty-ms",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sindresorhus/pretty-ms.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"version": "2.1.0"
|
||||
}
|
||||
89
tests/node_modules/pretty-ms/readme.md
generated
vendored
Normal file
89
tests/node_modules/pretty-ms/readme.md
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
# pretty-ms [](https://travis-ci.org/sindresorhus/pretty-ms)
|
||||
|
||||
> Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
$ npm install --save pretty-ms
|
||||
```
|
||||
|
||||
```js
|
||||
var prettyMs = require('pretty-ms');
|
||||
|
||||
prettyMs(1337000000);
|
||||
//=> '15d 11h 23m 20s'
|
||||
|
||||
prettyMs(1337);
|
||||
//=> '1.3s'
|
||||
|
||||
prettyMs(133);
|
||||
//=> '133ms'
|
||||
|
||||
// compact option
|
||||
prettyMs(1337, {compact: true});
|
||||
//=> '~1s'
|
||||
|
||||
// verbose option
|
||||
prettyMs(1335669000, {verbose: true});
|
||||
//=> '15 days 11 hours 1 minute 9 seconds'
|
||||
|
||||
// can be useful for time durations
|
||||
prettyMs(new Date(2014, 0, 1, 10, 40) - new Date(2014, 0, 1, 10, 5))
|
||||
//=> '35m'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### prettyMs(milliseconds, [options])
|
||||
|
||||
#### milliseconds
|
||||
|
||||
*Required*
|
||||
Type: `number`
|
||||
|
||||
Milliseconds to humanize.
|
||||
|
||||
#### options
|
||||
|
||||
##### secDecimalDigits
|
||||
|
||||
Type: `number`
|
||||
Default: `1`
|
||||
|
||||
Number of digits to appear after the seconds decimal point.
|
||||
|
||||
##### msDecimalDigits
|
||||
|
||||
Type: `number`
|
||||
Default: `0`
|
||||
|
||||
Number of digits to appear after the milliseconds decimal point.
|
||||
|
||||
Useful in combination with [`process.hrtime()`](https://nodejs.org/api/process.html#process_process_hrtime).
|
||||
|
||||
##### compact
|
||||
|
||||
Type: `boolean`
|
||||
Default: `false`
|
||||
|
||||
Only show the first unit: `1h 10m` → `~1h`.
|
||||
|
||||
##### verbose
|
||||
|
||||
Type: `boolean`
|
||||
Default: `false`
|
||||
|
||||
Use full-length units: `5h 1m 45s` → `5 hours 1 minute 45 seconds`
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [pretty-ms-cli](https://github.com/sindresorhus/pretty-ms-cli) - CLI for this module
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](http://sindresorhus.com)
|
||||
Reference in New Issue
Block a user