defaults-shallow

0.1.0 • Public • Published

defaults-shallow NPM version

Extend an object with the properties of other objects, but only if they don't already exist.

How is this different than extend or assign?

  • [extend][] and assign: "last one wins" - properties are updated or overwritten by new values.
  • defaults: "first one wins" - only new properties are filled in.

Install

Install with npm

$ npm i defaults-shallow --save

Usage

var defaults = require('defaults-shallow');
 
defaults({a: 'b'}, {c: 'd'});
//=> {a: 'b', c: 'd'}
 
defaults({a: 'b'}, {a: 'c'});
//=> {a: 'b'}

To shallow clone you can use an empty object as the first argument:

var options = defaults({}, {a: 'b'}, {c: 'd'}, {a: 'f'});
//=> {a: 'b', c: 'd'}

Related projects

  • defaults-deep: Like extend but recursively copies only the missing properties/values to the target object. | homepage
  • extend-shallow: Extend an object with the properties of additional objects. node.js/javascript util. | homepage
  • merge-deep: Recursively merge values in a javascript object. | homepage
  • mixin-deep: Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone. | homepage

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on October 04, 2015.

Package Sidebar

Install

npm i defaults-shallow

Weekly Downloads

3

Version

0.1.0

License

MIT

Last publish

Collaborators

  • jonschlinkert