Skip to content

Commit

Permalink
override undefined options from defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Feb 27, 2019
1 parent f089323 commit a8e2e8b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ with defaults set as specified.

* When `options` contains an unknown property, [TypeError] is thrown: `Option "name" is not supported.`

* When a property in `options` is missing or `undefined`, its value is set from the `defaults`.

* When `options` is not `null`/`undefined`, it is expected to be of type `object`, or else [TypeError]
is thrown: `Invalid "options" parameter.`

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "assert-options",
"version": "0.0.5",
"version": "0.0.6",
"description": "Generic options handling",
"main": "src/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
if (!isArray) {
for (const d in defaults) {
if (!(d in options)) {
if (options[d] === undefined) {
options[d] = defaults[d];
}
}
Expand Down
1 change: 1 addition & 0 deletions test/mainSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('positive', () => {
expect(assert({}, {one: 1})).toEqual({one: 1});
expect(assert(null, {one: 1})).toEqual({one: 1});
expect(assert({one: 1}, {one: 111, two: 222})).toEqual({one: 1, two: 222});
expect(assert({one: undefined, two: 2}, {one: 111, two: 222})).toEqual({one: 111, two: 2});
});

it('must not set defaults for arrays', () => {
Expand Down

0 comments on commit a8e2e8b

Please sign in to comment.