Skip to content

Commit d95e17f

Browse files
kaisugirauchg
authored andcommitted
Support error in case of Infinity (#116)
* Support error in case of Infinity * remove isNaN
1 parent 2669f23 commit d95e17f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = function(val, options) {
2828
var type = typeof val;
2929
if (type === 'string' && val.length > 0) {
3030
return parse(val);
31-
} else if (type === 'number' && isNaN(val) === false) {
31+
} else if (type === 'number' && isFinite(val)) {
3232
return options.long ? fmtLong(val) : fmtShort(val);
3333
}
3434
throw new Error(

tests.js

+12
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,16 @@ describe('ms(invalid inputs)', function() {
283283
ms(NaN);
284284
}).to.throwError();
285285
});
286+
287+
it('should throw an error, when ms(Infinity)', function() {
288+
expect(function() {
289+
ms(Infinity);
290+
}).to.throwError();
291+
});
292+
293+
it('should throw an error, when ms(-Infinity)', function() {
294+
expect(function() {
295+
ms(-Infinity);
296+
}).to.throwError();
297+
});
286298
});

0 commit comments

Comments
 (0)