Skip to content

Commit

Permalink
fix: isNumberValue should not crash on non-coercible values
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Aug 11, 2017
1 parent fe5b55a commit 0db765e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion object/is-number-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
var isValue = require("./is-value");

module.exports = function (value) {
return isValue(value) && !isNaN(value);
if (!isValue(value)) return false;
try {
return !isNaN(value);
} catch (e) {
return false;
}
};
3 changes: 3 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"globals": {
"Symbol": true
},
"rules": {
"consistent-this": "off",
"id-length": "off",
Expand Down
3 changes: 3 additions & 0 deletions test/object/is-number-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ module.exports = function (t, a) {
a(t(new Number(2)), true, "Number object");
a(t("asdfaf"), false, "String");
a(t(""), true, "Empty String");
if (typeof Symbol === "function") {
a(t(Symbol("test")), false, "Symbol");
}
};

0 comments on commit 0db765e

Please sign in to comment.