Comparing version 0.1.2 to 0.2.0
@@ -0,1 +1,5 @@ | ||
# 0.2.0 (2014-11-25) | ||
* become NaN when not a number | ||
# 0.1.2 (2014-06-29) | ||
@@ -2,0 +6,0 @@ |
16
int.js
@@ -17,2 +17,5 @@ | ||
// default value 0 | ||
num = num || 0; | ||
// sign | ||
@@ -24,5 +27,14 @@ self._s = ((num += '').charAt(0) === '-') ? 1 : 0; | ||
num = num.replace(/^[+-]/, ''); | ||
var orig = num; | ||
// remove any leading - or + as well as other invalid characters | ||
num = num.replace(/[^\d]/g, ''); | ||
// detect if value is not a number | ||
if (orig !== num) { | ||
self._nan = true; | ||
return; | ||
} | ||
// _d is the array of single digits making up the number | ||
@@ -375,2 +387,6 @@ var ln = num.length; | ||
if (self._nan) { | ||
return NaN; | ||
} | ||
if (!radix || radix === 10) { | ||
@@ -377,0 +393,0 @@ return (self._s && self._d.length ? '-' : '') + ((self._d.length) ? self._d.join('') : '0'); |
@@ -5,3 +5,3 @@ { | ||
"description": "arbitrary precision integer and library in javascript", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"repository": { | ||
@@ -19,4 +19,4 @@ "type": "git", | ||
"devDependencies": { | ||
"zuul": "~1.7.0", | ||
"mocha": "~1.8.0" | ||
"zuul": "~1.13.1", | ||
"mocha": "~2.0.1" | ||
}, | ||
@@ -23,0 +23,0 @@ "license": "MIT", |
@@ -1,2 +0,1 @@ | ||
var assert = require('assert'); | ||
@@ -22,1 +21,9 @@ var int = require('../'); | ||
}); | ||
test('should become NaN with invalid values', function() { | ||
var n1 = int('asd'); | ||
var n2 = int('1'); | ||
assert(!isNaN(n2)); | ||
assert(isNaN(n1)); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20741
576