From 4983f57d0f551fa70c4cb9643dddeea44e270a13 Mon Sep 17 00:00:00 2001 From: Greenkeeper Date: Sun, 15 Jan 2017 16:50:19 +0100 Subject: [PATCH 01/28] chore(package): update serve to version 2.4.1 (#74) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 58060aa..179d271 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "devDependencies": { "expect.js": "^0.3.1", "mocha": "^3.0.2", - "serve": "^1.4.0", + "serve": "^2.4.1", "xo": "^0.17.0" }, "component": { From 5260a41855ea27c8ae594ef71fec6a4ddbdc5e06 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Wed, 1 Feb 2017 15:48:24 +0100 Subject: [PATCH 02/28] chore(package): update serve to version 3.1.0 (#78) Closes #76 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 179d271..a940f0f 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "devDependencies": { "expect.js": "^0.3.1", "mocha": "^3.0.2", - "serve": "^2.4.1", + "serve": "^3.1.0", "xo": "^0.17.0" }, "component": { From 0f113ee1a753cb4b17fe33fe3f49394224dbf6e3 Mon Sep 17 00:00:00 2001 From: Dmitry Kirilyuk Date: Wed, 1 Feb 2017 17:49:16 +0300 Subject: [PATCH 03/28] Mark "options" param as optional in jsdoc (#77) --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 824b37e..e904c70 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,7 @@ var y = d * 365.25 * - `long` verbose formatting [false] * * @param {String|Number} val - * @param {Object} options + * @param {Object} [options] * @throws {Error} throw an error if val is not a non-empty string or a number * @return {String|Number} * @api public From 5f0653ab192a30301aed8668b4588a87975b41ab Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Fri, 24 Feb 2017 09:40:46 +0100 Subject: [PATCH 04/28] Lowercased text files --- LICENSE.md => license.md | 0 README.md => readme.md | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename LICENSE.md => license.md (100%) rename README.md => readme.md (100%) diff --git a/LICENSE.md b/license.md similarity index 100% rename from LICENSE.md rename to license.md diff --git a/README.md b/readme.md similarity index 100% rename from README.md rename to readme.md From 5bfb0a773a01f1d4f40578e0c8060aadb47fba14 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 1 Mar 2017 08:13:32 +0100 Subject: [PATCH 05/28] chore(package): update serve to version 4.0.0 (#79) https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a940f0f..529e957 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "devDependencies": { "expect.js": "^0.3.1", "mocha": "^3.0.2", - "serve": "^3.1.0", + "serve": "^4.0.0", "xo": "^0.17.0" }, "component": { From 2ee4afa1d66accdd4cfa1ff44cd69c54c9184d78 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 8 Mar 2017 17:55:32 +0100 Subject: [PATCH 06/28] chore(package): update serve to version 5.0.0 (#80) https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 529e957..ec83dd6 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "devDependencies": { "expect.js": "^0.3.1", "mocha": "^3.0.2", - "serve": "^4.0.0", + "serve": "^5.0.0", "xo": "^0.17.0" }, "component": { From 126d7f094a1836b991c8d0abfeb4d0ce09ac280f Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Wed, 8 Mar 2017 17:56:39 +0100 Subject: [PATCH 07/28] Pinned dependencies --- .npmrc | 1 + package.json | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..1dab4ed --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +save-exact = true diff --git a/package.json b/package.json index ec83dd6..1cf6451 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,10 @@ }, "license": "MIT", "devDependencies": { - "expect.js": "^0.3.1", - "mocha": "^3.0.2", - "serve": "^5.0.0", - "xo": "^0.17.0" + "expect.js": "0.3.1", + "mocha": "3.0.2", + "serve": "5.0.0", + "xo": "0.17.0" }, "component": { "scripts": { From 15a27b172f90bc9dfd9d0da7dd12521d022f0622 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 8 Mar 2017 22:46:48 +0100 Subject: [PATCH 08/28] chore(package): update serve to version 5.0.1 (#81) https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1cf6451..86d8fbd 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "devDependencies": { "expect.js": "0.3.1", "mocha": "3.0.2", - "serve": "5.0.0", + "serve": "5.0.1", "xo": "0.17.0" }, "component": { From 2006a7706041443fcf1f899b5752677bd7ae01a8 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Wed, 8 Mar 2017 22:58:30 +0100 Subject: [PATCH 09/28] 0.7.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 86d8fbd..1364a7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ms", - "version": "0.7.2", + "version": "0.7.3", "description": "Tiny milisecond conversion utility", "repository": "zeit/ms", "main": "./index", From 923eee11ba71cd9a8fe3bfc3b5397f5e2af2def1 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 9 Mar 2017 10:49:31 +0100 Subject: [PATCH 10/28] chore(package): update serve to version 5.0.2 (#82) https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1364a7a..b1ebbb3 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "devDependencies": { "expect.js": "0.3.1", "mocha": "3.0.2", - "serve": "5.0.1", + "serve": "5.0.2", "xo": "0.17.0" }, "component": { From d4a94b158ec618770671258627b925d00517f847 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Sun, 12 Mar 2017 13:42:12 +0100 Subject: [PATCH 11/28] chore(package): update serve to version 5.0.3 (#83) https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b1ebbb3..623e64c 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "devDependencies": { "expect.js": "0.3.1", "mocha": "3.0.2", - "serve": "5.0.2", + "serve": "5.0.3", "xo": "0.17.0" }, "component": { From bd49cec7751be4fdd92d11190d61e3deb719e6d2 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Sat, 18 Mar 2017 15:58:25 -0700 Subject: [PATCH 12/28] chore(package): update xo to version 0.18.0 (#84) https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 623e64c..8ee8309 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "expect.js": "0.3.1", "mocha": "3.0.2", "serve": "5.0.3", - "xo": "0.17.0" + "xo": "0.18.0" }, "component": { "scripts": { From 4b7f48f18b90c3849ae0d53649456b23e1e4711a Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Sun, 19 Mar 2017 22:25:19 +0100 Subject: [PATCH 13/28] chore(package): update serve to version 5.0.4 (#85) https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8ee8309..8a5e505 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "devDependencies": { "expect.js": "0.3.1", "mocha": "3.0.2", - "serve": "5.0.3", + "serve": "5.0.4", "xo": "0.18.0" }, "component": { From 94068ea6d518387670df277f740b1abada80ed48 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sun, 19 Mar 2017 22:26:09 +0100 Subject: [PATCH 14/28] Removed XO --- package.json | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/package.json b/package.json index 8a5e505..adee356 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "index.js" ], "scripts": { - "test": "xo && mocha test/index.js", + "test": "mocha test/index.js", "test-browser": "serve ./test" }, "license": "MIT", @@ -16,21 +16,10 @@ "expect.js": "0.3.1", "mocha": "3.0.2", "serve": "5.0.4", - "xo": "0.18.0" }, "component": { "scripts": { "ms/index.js": "index.js" } - }, - "xo": { - "space": true, - "semicolon": false, - "envs": [ - "mocha" - ], - "rules": { - "complexity": 0 - } } } From 57b3ef8e3423cae6254f94c5564a11b4492cff43 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sun, 19 Mar 2017 22:29:41 +0100 Subject: [PATCH 15/28] Use `prettier` and `eslint` --- index.js | 75 +++++++++++++++++++++++++++------------------------- package.json | 29 ++++++++++++++++---- 2 files changed, 63 insertions(+), 41 deletions(-) diff --git a/index.js b/index.js index e904c70..8d79c47 100644 --- a/index.js +++ b/index.js @@ -2,11 +2,11 @@ * Helpers. */ -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; /** * Parse or format the given `val`. @@ -22,18 +22,19 @@ var y = d * 365.25 * @api public */ -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) + ); +}; /** * Parse the given `str` and return milliseconds. @@ -44,53 +45,55 @@ module.exports = function (val, options) { */ 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) { case 'years': case 'year': case 'yrs': case 'yr': case 'y': - return n * y + return n * y; case 'days': case 'day': case 'd': - return n * d + return n * d; case 'hours': case 'hour': case 'hrs': case 'hr': case 'h': - return n * h + return n * h; case 'minutes': case 'minute': case 'mins': case 'min': case 'm': - return n * m + return n * m; case 'seconds': case 'second': case 'secs': case 'sec': case 's': - return n * s + return n * s; case 'milliseconds': case 'millisecond': case 'msecs': case 'msec': case 'ms': - return n + return n; default: - return undefined + return undefined; } } @@ -104,18 +107,18 @@ function parse(str) { function fmtShort(ms) { 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'; } /** @@ -131,7 +134,7 @@ function fmtLong(ms) { plural(ms, h, 'hour') || plural(ms, m, 'minute') || plural(ms, s, 'second') || - ms + ' ms' + ms + ' ms'; } /** @@ -140,10 +143,10 @@ function fmtLong(ms) { function plural(ms, n, name) { 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'; } diff --git a/package.json b/package.json index adee356..07aaccc 100644 --- a/package.json +++ b/package.json @@ -8,18 +8,37 @@ "index.js" ], "scripts": { + "precommit": "lint-staged", + "lint": "eslint lib/* bin/*", "test": "mocha test/index.js", "test-browser": "serve ./test" }, - "license": "MIT", - "devDependencies": { - "expect.js": "0.3.1", - "mocha": "3.0.2", - "serve": "5.0.4", + "eslintConfig": { + "extends": "eslint:recommended", + "env": { + "node": true, + "es6": true + } + }, + "lint-staged": { + "*.js": [ + "npm run lint", + "prettier --single-quote --write", + "git add" + ] }, "component": { "scripts": { "ms/index.js": "index.js" } + }, + "license": "MIT", + "devDependencies": { + "eslint": "3.18.0", + "expect.js": "0.3.1", + "husky": "0.13.2", + "lint-staged": "3.4.0", + "mocha": "3.0.2", + "serve": "5.0.4" } } From 1fbbe974cdcad96e592dcb65a7b2a8649f690420 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sun, 19 Mar 2017 22:30:06 +0100 Subject: [PATCH 16/28] Removed component specification People should use npm --- component.json | 15 --------------- package.json | 5 ----- 2 files changed, 20 deletions(-) delete mode 100644 component.json diff --git a/component.json b/component.json deleted file mode 100644 index 93e4d37..0000000 --- a/component.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "ms", - "repo": "zeit/ms", - "version": "0.7.1", - "description": "Tiny milisecond conversion utility", - "keywords": [ - "ms", - "parse", - "format" - ], - "scripts": [ - "index.js" - ], - "license": "MIT" -} diff --git a/package.json b/package.json index 07aaccc..8b508e3 100644 --- a/package.json +++ b/package.json @@ -27,11 +27,6 @@ "git add" ] }, - "component": { - "scripts": { - "ms/index.js": "index.js" - } - }, "license": "MIT", "devDependencies": { "eslint": "3.18.0", From 389840b329436117741b2ef13a172725082695b9 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sun, 19 Mar 2017 22:30:45 +0100 Subject: [PATCH 17/28] Badge for XO removed --- readme.md | 1 - 1 file changed, 1 deletion(-) diff --git a/readme.md b/readme.md index 5b47570..2f35b95 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,6 @@ # 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/) Use this package to easily convert various time formats to milliseconds. From c9b1fd319f0f9198d85ecf4ba83e46cc1216be04 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sun, 19 Mar 2017 22:31:18 +0100 Subject: [PATCH 18/28] Test on LTS version of Node --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b37faa2..ab0d211 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,7 @@ { "language": "node_js", - "node_js": "node" + "node_js": [ + "6", + "node" + ] } From e818c3581aca3119c00d81901bfe8fe653bcfda4 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sun, 19 Mar 2017 22:34:08 +0100 Subject: [PATCH 19/28] Removed browser testing --- package.json | 6 +- test.js | 221 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/index.js | 221 -------------------------------------------------- 3 files changed, 223 insertions(+), 225 deletions(-) create mode 100644 test.js delete mode 100644 test/index.js diff --git a/package.json b/package.json index 8b508e3..4d03b7a 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,7 @@ "scripts": { "precommit": "lint-staged", "lint": "eslint lib/* bin/*", - "test": "mocha test/index.js", - "test-browser": "serve ./test" + "test": "mocha test.js" }, "eslintConfig": { "extends": "eslint:recommended", @@ -33,7 +32,6 @@ "expect.js": "0.3.1", "husky": "0.13.2", "lint-staged": "3.4.0", - "mocha": "3.0.2", - "serve": "5.0.4" + "mocha": "3.0.2" } } diff --git a/test.js b/test.js new file mode 100644 index 0000000..9b437f4 --- /dev/null +++ b/test.js @@ -0,0 +1,221 @@ +/* eslint-disable no-undef */ +/** + * Dependencies. + */ + +if (typeof require !== 'undefined') { + expect = require('expect.js'); + ms = require('./'); +} + +// strings + +describe('ms(string)', function() { + it('should not throw an error', function() { + expect(function() { + ms('1m'); + }).to.not.throwError(); + }); + + it('should preserve ms', function() { + expect(ms('100')).to.be(100); + }); + + it('should convert from m to ms', function() { + expect(ms('1m')).to.be(60000); + }); + + it('should convert from h to ms', function() { + expect(ms('1h')).to.be(3600000); + }); + + it('should convert d to ms', function() { + expect(ms('2d')).to.be(172800000); + }); + + it('should convert s to ms', function() { + expect(ms('1s')).to.be(1000); + }); + + it('should convert ms to ms', function() { + expect(ms('100ms')).to.be(100); + }); + + it('should work with decimals', function() { + expect(ms('1.5h')).to.be(5400000); + }); + + it('should work with multiple spaces', function() { + expect(ms('1 s')).to.be(1000); + }); + + it('should return NaN if invalid', function() { + expect(isNaN(ms('☃'))).to.be(true); + }); + + it('should be case-insensitive', function() { + expect(ms('1.5H')).to.be(5400000); + }); + + it('should work with numbers starting with .', function() { + expect(ms('.5ms')).to.be(0.5); + }); +}); + +// long strings + +describe('ms(long string)', function() { + it('should not throw an error', function() { + expect(function() { + ms('53 milliseconds'); + }).to.not.throwError(); + }); + + it('should convert milliseconds to ms', function() { + expect(ms('53 milliseconds')).to.be(53); + }); + + it('should convert msecs to ms', function() { + expect(ms('17 msecs')).to.be(17); + }); + + it('should convert sec to ms', function() { + expect(ms('1 sec')).to.be(1000); + }); + + it('should convert from min to ms', function() { + expect(ms('1 min')).to.be(60000); + }); + + it('should convert from hr to ms', function() { + expect(ms('1 hr')).to.be(3600000); + }); + + it('should convert days to ms', function() { + expect(ms('2 days')).to.be(172800000); + }); + + it('should work with decimals', function() { + expect(ms('1.5 hours')).to.be(5400000); + }); +}); + +// numbers + +describe('ms(number, { long: true })', function() { + it('should not throw an error', function() { + expect(function() { + ms(500, { long: true }); + }).to.not.throwError(); + }); + + it('should support milliseconds', function() { + expect(ms(500, { long: true })).to.be('500 ms'); + }); + + it('should support seconds', function() { + expect(ms(1000, { long: true })).to.be('1 second'); + expect(ms(1200, { long: true })).to.be('1 second'); + expect(ms(10000, { long: true })).to.be('10 seconds'); + }); + + it('should support minutes', function() { + expect(ms(60 * 1000, { long: true })).to.be('1 minute'); + expect(ms(60 * 1200, { long: true })).to.be('1 minute'); + expect(ms(60 * 10000, { long: true })).to.be('10 minutes'); + }); + + it('should support hours', function() { + expect(ms(60 * 60 * 1000, { long: true })).to.be('1 hour'); + expect(ms(60 * 60 * 1200, { long: true })).to.be('1 hour'); + expect(ms(60 * 60 * 10000, { long: true })).to.be('10 hours'); + }); + + it('should support days', function() { + expect(ms(24 * 60 * 60 * 1000, { long: true })).to.be('1 day'); + expect(ms(24 * 60 * 60 * 1200, { long: true })).to.be('1 day'); + expect(ms(24 * 60 * 60 * 10000, { long: true })).to.be('10 days'); + }); + + it('should round', function() { + expect(ms(234234234, { long: true })).to.be('3 days'); + }); +}); + +// numbers + +describe('ms(number)', function() { + it('should not throw an error', function() { + expect(function() { + ms(500); + }).to.not.throwError(); + }); + + it('should support milliseconds', function() { + expect(ms(500)).to.be('500ms'); + }); + + it('should support seconds', function() { + expect(ms(1000)).to.be('1s'); + expect(ms(10000)).to.be('10s'); + }); + + it('should support minutes', function() { + expect(ms(60 * 1000)).to.be('1m'); + expect(ms(60 * 10000)).to.be('10m'); + }); + + it('should support hours', function() { + expect(ms(60 * 60 * 1000)).to.be('1h'); + expect(ms(60 * 60 * 10000)).to.be('10h'); + }); + + it('should support days', function() { + expect(ms(24 * 60 * 60 * 1000)).to.be('1d'); + expect(ms(24 * 60 * 60 * 10000)).to.be('10d'); + }); + + it('should round', function() { + expect(ms(234234234)).to.be('3d'); + }); +}); + +// invalid inputs + +describe('ms(invalid inputs)', function() { + it('should throw an error, when ms("")', function() { + expect(function() { + ms(''); + }).to.throwError(); + }); + + it('should throw an error, when ms(undefined)', function() { + expect(function() { + ms(undefined); + }).to.throwError(); + }); + + it('should throw an error, when ms(null)', function() { + expect(function() { + ms(null); + }).to.throwError(); + }); + + it('should throw an error, when ms([])', function() { + expect(function() { + ms([]); + }).to.throwError(); + }); + + it('should throw an error, when ms({})', function() { + expect(function() { + ms({}); + }).to.throwError(); + }); + + it('should throw an error, when ms(NaN)', function() { + expect(function() { + ms(NaN); + }).to.throwError(); + }); +}); diff --git a/test/index.js b/test/index.js deleted file mode 100644 index 31b23f9..0000000 --- a/test/index.js +++ /dev/null @@ -1,221 +0,0 @@ -/* eslint-disable no-undef */ -/** - * Dependencies. - */ - -if (typeof require !== 'undefined') { - expect = require('expect.js') - ms = require('../') -} - -// strings - -describe('ms(string)', function () { - it('should not throw an error', function () { - expect(function () { - ms('1m') - }).to.not.throwError() - }) - - it('should preserve ms', function () { - expect(ms('100')).to.be(100) - }) - - it('should convert from m to ms', function () { - expect(ms('1m')).to.be(60000) - }) - - it('should convert from h to ms', function () { - expect(ms('1h')).to.be(3600000) - }) - - it('should convert d to ms', function () { - expect(ms('2d')).to.be(172800000) - }) - - it('should convert s to ms', function () { - expect(ms('1s')).to.be(1000) - }) - - it('should convert ms to ms', function () { - expect(ms('100ms')).to.be(100) - }) - - it('should work with decimals', function () { - expect(ms('1.5h')).to.be(5400000) - }) - - it('should work with multiple spaces', function () { - expect(ms('1 s')).to.be(1000) - }) - - it('should return NaN if invalid', function () { - expect(isNaN(ms('☃'))).to.be(true) - }) - - it('should be case-insensitive', function () { - expect(ms('1.5H')).to.be(5400000) - }) - - it('should work with numbers starting with .', function () { - expect(ms('.5ms')).to.be(0.5) - }) -}) - -// long strings - -describe('ms(long string)', function () { - it('should not throw an error', function () { - expect(function () { - ms('53 milliseconds') - }).to.not.throwError() - }) - - it('should convert milliseconds to ms', function () { - expect(ms('53 milliseconds')).to.be(53) - }) - - it('should convert msecs to ms', function () { - expect(ms('17 msecs')).to.be(17) - }) - - it('should convert sec to ms', function () { - expect(ms('1 sec')).to.be(1000) - }) - - it('should convert from min to ms', function () { - expect(ms('1 min')).to.be(60000) - }) - - it('should convert from hr to ms', function () { - expect(ms('1 hr')).to.be(3600000) - }) - - it('should convert days to ms', function () { - expect(ms('2 days')).to.be(172800000) - }) - - it('should work with decimals', function () { - expect(ms('1.5 hours')).to.be(5400000) - }) -}) - -// numbers - -describe('ms(number, { long: true })', function () { - it('should not throw an error', function () { - expect(function () { - ms(500, {long: true}) - }).to.not.throwError() - }) - - it('should support milliseconds', function () { - expect(ms(500, {long: true})).to.be('500 ms') - }) - - it('should support seconds', function () { - expect(ms(1000, {long: true})).to.be('1 second') - expect(ms(1200, {long: true})).to.be('1 second') - expect(ms(10000, {long: true})).to.be('10 seconds') - }) - - it('should support minutes', function () { - expect(ms(60 * 1000, {long: true})).to.be('1 minute') - expect(ms(60 * 1200, {long: true})).to.be('1 minute') - expect(ms(60 * 10000, {long: true})).to.be('10 minutes') - }) - - it('should support hours', function () { - expect(ms(60 * 60 * 1000, {long: true})).to.be('1 hour') - expect(ms(60 * 60 * 1200, {long: true})).to.be('1 hour') - expect(ms(60 * 60 * 10000, {long: true})).to.be('10 hours') - }) - - it('should support days', function () { - expect(ms(24 * 60 * 60 * 1000, {long: true})).to.be('1 day') - expect(ms(24 * 60 * 60 * 1200, {long: true})).to.be('1 day') - expect(ms(24 * 60 * 60 * 10000, {long: true})).to.be('10 days') - }) - - it('should round', function () { - expect(ms(234234234, {long: true})).to.be('3 days') - }) -}) - -// numbers - -describe('ms(number)', function () { - it('should not throw an error', function () { - expect(function () { - ms(500) - }).to.not.throwError() - }) - - it('should support milliseconds', function () { - expect(ms(500)).to.be('500ms') - }) - - it('should support seconds', function () { - expect(ms(1000)).to.be('1s') - expect(ms(10000)).to.be('10s') - }) - - it('should support minutes', function () { - expect(ms(60 * 1000)).to.be('1m') - expect(ms(60 * 10000)).to.be('10m') - }) - - it('should support hours', function () { - expect(ms(60 * 60 * 1000)).to.be('1h') - expect(ms(60 * 60 * 10000)).to.be('10h') - }) - - it('should support days', function () { - expect(ms(24 * 60 * 60 * 1000)).to.be('1d') - expect(ms(24 * 60 * 60 * 10000)).to.be('10d') - }) - - it('should round', function () { - expect(ms(234234234)).to.be('3d') - }) -}) - -// invalid inputs - -describe('ms(invalid inputs)', function () { - it('should throw an error, when ms("")', function () { - expect(function () { - ms('') - }).to.throwError() - }) - - it('should throw an error, when ms(undefined)', function () { - expect(function () { - ms(undefined) - }).to.throwError() - }) - - it('should throw an error, when ms(null)', function () { - expect(function () { - ms(null) - }).to.throwError() - }) - - it('should throw an error, when ms([])', function () { - expect(function () { - ms([]) - }).to.throwError() - }) - - it('should throw an error, when ms({})', function () { - expect(function () { - ms({}) - }).to.throwError() - }) - - it('should throw an error, when ms(NaN)', function () { - expect(function () { - ms(NaN) - }).to.throwError() - }) -}) From ee91f307a8dc3581ebdad614ec0533ddb3d8bf56 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sun, 19 Mar 2017 22:34:59 +0100 Subject: [PATCH 20/28] More suitable name for file containing tests --- package.json | 2 +- test.js => tests.js | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename test.js => tests.js (100%) diff --git a/package.json b/package.json index 4d03b7a..a2db2c6 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "precommit": "lint-staged", "lint": "eslint lib/* bin/*", - "test": "mocha test.js" + "test": "mocha tests.js" }, "eslintConfig": { "extends": "eslint:recommended", diff --git a/test.js b/tests.js similarity index 100% rename from test.js rename to tests.js From 7daf984a9011e720cc3c165ed82c4506f3471b37 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sun, 19 Mar 2017 22:41:07 +0100 Subject: [PATCH 21/28] 1.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a2db2c6..a2aad78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ms", - "version": "0.7.3", + "version": "1.0.0", "description": "Tiny milisecond conversion utility", "repository": "zeit/ms", "main": "./index", From 3f2a4d71eda1b12bd5d625cce6777bd3604e8923 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Fri, 24 Mar 2017 16:36:26 +0100 Subject: [PATCH 22/28] chore(package): update husky to version 0.13.3 (#86) https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a2aad78..a99933b 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "devDependencies": { "eslint": "3.18.0", "expect.js": "0.3.1", - "husky": "0.13.2", + "husky": "0.13.3", "lint-staged": "3.4.0", "mocha": "3.0.2" } From b83b36d7266fb1bd779fd19a2f98bab17a04d999 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Fri, 31 Mar 2017 23:36:33 +0200 Subject: [PATCH 23/28] chore(package): update eslint to version 3.19.0 (#88) https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a99933b..6e294da 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ }, "license": "MIT", "devDependencies": { - "eslint": "3.18.0", + "eslint": "3.19.0", "expect.js": "0.3.1", "husky": "0.13.3", "lint-staged": "3.4.0", From caae2988ba2a37765d055c4eee63d383320ee662 Mon Sep 17 00:00:00 2001 From: Karen Yavine Date: Tue, 16 May 2017 12:08:29 +0300 Subject: [PATCH 24/28] Limit str to 100 to avoid ReDoS of 0.3s (#89) --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8d79c47..6a522b1 100644 --- a/index.js +++ b/index.js @@ -46,7 +46,7 @@ module.exports = function(val, options) { function parse(str) { str = String(str); - if (str.length > 10000) { + if (str.length > 100) { return; } var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec( From b1eaab752203e978492a4d540a7ae1d26e6306b1 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Tue, 16 May 2017 14:22:30 +0200 Subject: [PATCH 25/28] Ignored logs coming from npm --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 2a531ed..22f7aa0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ # dependencies node_modules + +# logs +npm-debug.log From bcf57157678fd5afc691383145a35e116f9704d0 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Tue, 16 May 2017 14:23:34 +0200 Subject: [PATCH 26/28] Bumped dependencies to the latest version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6e294da..6c1221f 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "eslint": "3.19.0", "expect.js": "0.3.1", "husky": "0.13.3", - "lint-staged": "3.4.0", - "mocha": "3.0.2" + "lint-staged": "3.4.1", + "mocha": "3.4.1" } } From 94b995c1d6d5d13ec976a0c6849a3cca9b277e6b Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Tue, 16 May 2017 14:25:00 +0200 Subject: [PATCH 27/28] Invalidated cache for slack badge --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 2f35b95..84a9974 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ # ms [![Build Status](https://travis-ci.org/zeit/ms.svg?branch=master)](https://travis-ci.org/zeit/ms) -[![Slack Channel](https://zeit-slackin.now.sh/badge.svg)](https://zeit.chat/) +[![Slack Channel](http://zeit-slackin.now.sh/badge.svg)](https://zeit.chat/) Use this package to easily convert various time formats to milliseconds. From 9b88d1568a52ec9bb67ecc8d2aa224fa38fd41f4 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Tue, 16 May 2017 14:25:19 +0200 Subject: [PATCH 28/28] 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6c1221f..6a31c81 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ms", - "version": "1.0.0", + "version": "2.0.0", "description": "Tiny milisecond conversion utility", "repository": "zeit/ms", "main": "./index",