Comparing version 0.7.3 to 1.0.0
75
index.js
@@ -5,7 +5,7 @@ /** | ||
var s = 1000 | ||
var m = s * 60 | ||
var h = m * 60 | ||
var d = h * 24 | ||
var y = d * 365.25 | ||
var s = 1000; | ||
var m = s * 60; | ||
var h = m * 60; | ||
var d = h * 24; | ||
var y = d * 365.25; | ||
@@ -26,14 +26,15 @@ /** | ||
module.exports = function (val, options) { | ||
options = options || {} | ||
var type = typeof val | ||
module.exports = function(val, options) { | ||
options = options || {}; | ||
var type = typeof val; | ||
if (type === 'string' && val.length > 0) { | ||
return parse(val) | ||
return parse(val); | ||
} else if (type === 'number' && isNaN(val) === false) { | ||
return options.long ? | ||
fmtLong(val) : | ||
fmtShort(val) | ||
return options.long ? fmtLong(val) : fmtShort(val); | ||
} | ||
throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val)) | ||
} | ||
throw new Error( | ||
'val is not a non-empty string or a valid number. val=' + | ||
JSON.stringify(val) | ||
); | ||
}; | ||
@@ -49,12 +50,14 @@ /** | ||
function parse(str) { | ||
str = String(str) | ||
str = String(str); | ||
if (str.length > 10000) { | ||
return | ||
return; | ||
} | ||
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str) | ||
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec( | ||
str | ||
); | ||
if (!match) { | ||
return | ||
return; | ||
} | ||
var n = parseFloat(match[1]) | ||
var type = (match[2] || 'ms').toLowerCase() | ||
var n = parseFloat(match[1]); | ||
var type = (match[2] || 'ms').toLowerCase(); | ||
switch (type) { | ||
@@ -66,7 +69,7 @@ case 'years': | ||
case 'y': | ||
return n * y | ||
return n * y; | ||
case 'days': | ||
case 'day': | ||
case 'd': | ||
return n * d | ||
return n * d; | ||
case 'hours': | ||
@@ -77,3 +80,3 @@ case 'hour': | ||
case 'h': | ||
return n * h | ||
return n * h; | ||
case 'minutes': | ||
@@ -84,3 +87,3 @@ case 'minute': | ||
case 'm': | ||
return n * m | ||
return n * m; | ||
case 'seconds': | ||
@@ -91,3 +94,3 @@ case 'second': | ||
case 's': | ||
return n * s | ||
return n * s; | ||
case 'milliseconds': | ||
@@ -98,5 +101,5 @@ case 'millisecond': | ||
case 'ms': | ||
return n | ||
return n; | ||
default: | ||
return undefined | ||
return undefined; | ||
} | ||
@@ -115,14 +118,14 @@ } | ||
if (ms >= d) { | ||
return Math.round(ms / d) + 'd' | ||
return Math.round(ms / d) + 'd'; | ||
} | ||
if (ms >= h) { | ||
return Math.round(ms / h) + 'h' | ||
return Math.round(ms / h) + 'h'; | ||
} | ||
if (ms >= m) { | ||
return Math.round(ms / m) + 'm' | ||
return Math.round(ms / m) + 'm'; | ||
} | ||
if (ms >= s) { | ||
return Math.round(ms / s) + 's' | ||
return Math.round(ms / s) + 's'; | ||
} | ||
return ms + 'ms' | ||
return ms + 'ms'; | ||
} | ||
@@ -143,3 +146,3 @@ | ||
plural(ms, s, 'second') || | ||
ms + ' ms' | ||
ms + ' ms'; | ||
} | ||
@@ -153,8 +156,8 @@ | ||
if (ms < n) { | ||
return | ||
return; | ||
} | ||
if (ms < n * 1.5) { | ||
return Math.floor(ms / n) + ' ' + name | ||
return Math.floor(ms / n) + ' ' + name; | ||
} | ||
return Math.ceil(ms / n) + ' ' + name + 's' | ||
return Math.ceil(ms / n) + ' ' + name + 's'; | ||
} |
{ | ||
"name": "ms", | ||
"version": "0.7.3", | ||
"version": "1.0.0", | ||
"description": "Tiny milisecond conversion utility", | ||
@@ -11,27 +11,28 @@ "repository": "zeit/ms", | ||
"scripts": { | ||
"test": "xo && mocha test/index.js", | ||
"test-browser": "serve ./test" | ||
"precommit": "lint-staged", | ||
"lint": "eslint lib/* bin/*", | ||
"test": "mocha tests.js" | ||
}, | ||
"eslintConfig": { | ||
"extends": "eslint:recommended", | ||
"env": { | ||
"node": true, | ||
"es6": true | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"npm run lint", | ||
"prettier --single-quote --write", | ||
"git add" | ||
] | ||
}, | ||
"license": "MIT", | ||
"devDependencies": { | ||
"eslint": "3.18.0", | ||
"expect.js": "0.3.1", | ||
"mocha": "3.0.2", | ||
"serve": "5.0.1", | ||
"xo": "0.17.0" | ||
}, | ||
"component": { | ||
"scripts": { | ||
"ms/index.js": "index.js" | ||
} | ||
}, | ||
"xo": { | ||
"space": true, | ||
"semicolon": false, | ||
"envs": [ | ||
"mocha" | ||
], | ||
"rules": { | ||
"complexity": 0 | ||
} | ||
"husky": "0.13.2", | ||
"lint-staged": "3.4.0", | ||
"mocha": "3.0.2" | ||
} | ||
} |
# ms | ||
[![Build Status](https://travis-ci.org/zeit/ms.svg?branch=master)](https://travis-ci.org/zeit/ms) | ||
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) | ||
[![Slack Channel](https://zeit-slackin.now.sh/badge.svg)](https://zeit.chat/) | ||
@@ -6,0 +5,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6269
141
1
5
52