Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Do not throw error on invalid input
  • Loading branch information
BenjaminVanRyseghem authored and gwynjudd committed Mar 29, 2017
1 parent b71e47b commit 87b2dfe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
4 changes: 1 addition & 3 deletions numbro.js
Expand Up @@ -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));
Expand Down
18 changes: 9 additions & 9 deletions tests/numbro/format.js
Expand Up @@ -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();
}
};
11 changes: 10 additions & 1 deletion tests/numbro/misc.js
Expand Up @@ -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],
],
Expand All @@ -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);

Expand Down

0 comments on commit 87b2dfe

Please sign in to comment.