Skip to content

Commit

Permalink
Require Node.js 6
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 25, 2018
1 parent d31878e commit b5a583d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 62 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- '10'
- '8'
- '6'
- '4'
24 changes: 11 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
'use strict';
const parseMs = require('parse-ms');

const plur = (word, count) => count === 1 ? word : word + 's';
const pluralize = (word, count) => count === 1 ? word : word + 's';

module.exports = (ms, opts) => {
module.exports = (ms, options = {}) => {
if (!Number.isFinite(ms)) {
throw new TypeError('Expected a finite number');
}

opts = opts || {};

if (ms < 1000) {
const msDecimalDigits = typeof opts.msDecimalDigits === 'number' ? opts.msDecimalDigits : 0;
return (msDecimalDigits ? ms.toFixed(msDecimalDigits) : Math.ceil(ms)) + (opts.verbose ? ' ' + plur('millisecond', Math.ceil(ms)) : 'ms');
const msDecimalDigits = typeof options.msDecimalDigits === 'number' ? options.msDecimalDigits : 0;
return (msDecimalDigits ? ms.toFixed(msDecimalDigits) : Math.ceil(ms)) + (options.verbose ? ' ' + pluralize('millisecond', Math.ceil(ms)) : 'ms');
}

const ret = [];

const add = (val, long, short, valStr) => {
if (val === 0) {
const add = (value, long, short, valueString) => {
if (value === 0) {
return;
}

const postfix = opts.verbose ? ' ' + plur(long, val) : short;
const postfix = options.verbose ? ' ' + pluralize(long, value) : short;

ret.push((valStr || val) + postfix);
ret.push((valueString || value) + postfix);
};

const parsed = parseMs(ms);
Expand All @@ -34,15 +32,15 @@ module.exports = (ms, opts) => {
add(parsed.hours, 'hour', 'h');
add(parsed.minutes, 'minute', 'm');

if (opts.compact) {
if (options.compact) {
add(parsed.seconds, 'second', 's');
return '~' + ret[0];
}

const sec = ms / 1000 % 60;
const secDecimalDigits = typeof opts.secDecimalDigits === 'number' ? opts.secDecimalDigits : 1;
const secDecimalDigits = typeof options.secDecimalDigits === 'number' ? options.secDecimalDigits : 1;
const secFixed = sec.toFixed(secDecimalDigits);
const secStr = opts.keepDecimalsOnWholeSeconds ? secFixed : secFixed.replace(/\.0+$/, '');
const secStr = options.keepDecimalsOnWholeSeconds ? secFixed : secFixed.replace(/\.0+$/, '');
add(sec, 'second', 's', secStr);

return ret.join(' ');
Expand Down
90 changes: 45 additions & 45 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
{
"name": "pretty-ms",
"version": "3.2.0",
"description": "Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`",
"license": "MIT",
"repository": "sindresorhus/pretty-ms",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"pretty",
"prettify",
"human",
"humanize",
"humanized",
"readable",
"time",
"ms",
"milliseconds",
"duration",
"period",
"range",
"text",
"string",
"str",
"number",
"hrtime"
],
"dependencies": {
"parse-ms": "^1.0.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
}
"name": "pretty-ms",
"version": "3.2.0",
"description": "Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`",
"license": "MIT",
"repository": "sindresorhus/pretty-ms",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"pretty",
"prettify",
"human",
"humanize",
"humanized",
"readable",
"time",
"ms",
"milliseconds",
"duration",
"period",
"range",
"text",
"string",
"str",
"number",
"hrtime"
],
"dependencies": {
"parse-ms": "^1.0.1"
},
"devDependencies": {
"ava": "*",
"xo": "*"
}
}
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
> Convert milliseconds to a human readable string: `1337000000``15d 11h 23m 20s`

## Usage
## Install

```
$ npm install pretty-ms
```


## Usage

```js
const prettyMs = require('pretty-ms');

Expand Down

0 comments on commit b5a583d

Please sign in to comment.