Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions accounting.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
* Tests whether supplied parameter is a true object
*/
function isObject(obj) {
return obj && toString.call(obj) === '[object Object]';
return !!(obj && toString.call(obj) === '[object Object]');
}

/**
Expand All @@ -85,7 +85,9 @@
for (key in defs) {
if (defs.hasOwnProperty(key)) {
// Replace values with defaults only if undefined (allow empty/zero values):
if (object[key] == null) object[key] = defs[key];
if (object[key] === undefined) {
object[key] = defs[key];
}
}
}
return object;
Expand Down Expand Up @@ -169,7 +171,7 @@
* Alias: `accounting.parse(string)`
*
* Decimal must be included in the regular expression to match floats (defaults to
* accounting.settings.number.decimal), so if the number uses a non-standard decimal
* accounting.settings.number.decimal), so if the number uses a non-standard decimal
* separator, provide it as the second argument.
*
* Also matches bracketed negatives (eg. "$ (1.99)" => -1.99)
Expand Down
9 changes: 9 additions & 0 deletions tests/jasmine/core/defaultsSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('defaults()', function(){

it('Defs paramter should not overwrite the value null of the object parameter', function() {

expect( defaults({flavour: null}, {flavor: "vanilla", sprinkles: "lots"}) ).toBe( {flavor: null, sprinkles: "lots"} );

});

});
1 change: 1 addition & 0 deletions tests/jasmine/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script src="core/formatNumberSpec.js"></script>
<script src="core/unformatSpec.js"></script>
<script src="core/formatMoneySpec.js"></script>
<script src="core/defaultsSpec.js"></script>
</head>
<body>
<script>
Expand Down