From 8c2768ffb162d19a29917191cbcbde1ae14de435 Mon Sep 17 00:00:00 2001 From: 7ma7X <7X.rusk@gmail.com> Date: Fri, 14 Dec 2018 01:22:44 +0900 Subject: [PATCH 1/2] Support error in case of Infinity --- index.js | 2 +- tests.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a1d2ea4..7ac4bad 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ module.exports = function(val, options) { var type = typeof val; if (type === 'string' && val.length > 0) { return parse(val); - } else if (type === 'number' && isNaN(val) === false) { + } else if (type === 'number' && isNaN(val) === false && isFinite(val)) { return options.long ? fmtLong(val) : fmtShort(val); } throw new Error( diff --git a/tests.js b/tests.js index 9427390..6a44931 100644 --- a/tests.js +++ b/tests.js @@ -283,4 +283,16 @@ describe('ms(invalid inputs)', function() { ms(NaN); }).to.throwError(); }); + + it('should throw an error, when ms(Infinity)', function() { + expect(function() { + ms(Infinity); + }).to.throwError(); + }); + + it('should throw an error, when ms(-Infinity)', function() { + expect(function() { + ms(-Infinity); + }).to.throwError(); + }); }); From e35de3162c8acc04e0492aedc3b6aa4ce29b5795 Mon Sep 17 00:00:00 2001 From: 7ma7X <7X.rusk@gmail.com> Date: Fri, 14 Dec 2018 09:00:06 +0900 Subject: [PATCH 2/2] remove isNaN --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7ac4bad..8b3455a 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ module.exports = function(val, options) { var type = typeof val; if (type === 'string' && val.length > 0) { return parse(val); - } else if (type === 'number' && isNaN(val) === false && isFinite(val)) { + } else if (type === 'number' && isFinite(val)) { return options.long ? fmtLong(val) : fmtShort(val); } throw new Error(