Assigns enumerable properties from the default object to destination object for all properties that resolve to undefined.
JavaScript
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.jshintrc
.travis.yml
History.md
Makefile
Readme.md
component.json
index.js
package.json

Readme.md

Build Status

defaults

Assigns enumerable properties of the default object(s) to the destination object for all destination properties that resolve to undefined.

Installation

npm:

$ npm install stluafed

or component:

$ component install avetisk/defaults

API

simple: defaults(obj1, obj2)

defaults(
  {
    'x': 1,
    'z': {
      'a': 11
    }
  },
  {
    'x': 2,
    'y': 2,
    'z': {
      'b': 22
    }
  }
);
// > {'x': 1, 'y': 2, 'z': {'a': 11}}

recursive: defaults(obj1, obj2, true)

defaults(
  {
    'x': 1,
    'z': {
      'a': 11
    }
  },
  {
    'x': 2,
    'y': 2,
    'z': {
      'b': 22
    }
  },
  true
);
// > {'x': 1, 'y': 2, 'z': {'a': 11, 'b': 22}}

License

MIT