Skip to content

Commit

Permalink
Support error in case of Infinity (#116)
Browse files Browse the repository at this point in the history
* Support error in case of Infinity

* remove isNaN
  • Loading branch information
kaisugi authored and rauchg committed Feb 5, 2019
1 parent 2669f23 commit d95e17f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' && isFinite(val)) {
return options.long ? fmtLong(val) : fmtShort(val);
}
throw new Error(
Expand Down
12 changes: 12 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit d95e17f

Please sign in to comment.