Permalink
Browse files

Do not throw error on invalid input

  • Loading branch information...
BenjaminVanRyseghem authored and gwynjudd committed Mar 28, 2017
1 parent 279cb44 commit 3d41e70a9a456fb3acc082e493eb3347708b0b90
Showing with 20 additions and 13 deletions.
  1. +1 −3 numbro.js
  2. +9 −9 tests/numbro/format.js
  3. +10 −1 tests/numbro/misc.js
@@ -719,12 +719,10 @@
numbro = function(input) {
if (numbro.isNumbro(input)) {
input = input.value();
} else if (input === 0 || typeof input === 'undefined') {
input = 0;
} else if (typeof input === 'string' || typeof input === 'number') {
input = numbro.fn.unformat(input);
} else {
throw new Error('Invalid input');
input = NaN;
}
return new Numbro(Number(input));
@@ -726,16 +726,16 @@ exports.format = {
test.done();
},
regression261: function(test) {
// Setup
var currentCulture = numbro.culture();
regression261: function(test) {
// Setup
var currentCulture = numbro.culture();
numbro.culture("de-DE");
var result = numbro("100.000").format();
test.strictEqual(result, "100.000");
numbro.culture("de-DE");
var result = numbro("100.000").format();
test.strictEqual(result, "100.000");
//Teardown
numbro.culture(currentCulture);
test.done();
//Teardown
numbro.culture(currentCulture);
test.done();
}
};
@@ -10,7 +10,7 @@ exports.misc = {
var tests = [
[1000, 1000],
[0.5, 0.5],
[undefined, 0],
[undefined, NaN],
['1,000', 1000],
['not a number', NaN],
],
@@ -28,6 +28,15 @@ exports.misc = {
test.done();
},
regression265: function(test) {
// Setup
var result = numbro(null).format();
test.strictEqual(result, "NaN");
//Teardown
test.done();
},
set: function (test) {
test.expect(2);

0 comments on commit 3d41e70

Please sign in to comment.