object-defaults

Like _.defaults, assigns properties of source objects to a target, without overriding existing ones.

Downloads
867
Stars
2
Committers
2

simulator npm travis

Like _.defaults, assigns properties of source objects to a target, without overriding existing ones.

Install

$ npm install --save object-defaults

Usage

var defaults = require('object-defaults')

// copies source to target
defaults({ foo: 0 }, { bar: 1 })
//=> { foo: 0, bar: 1 }

// multiple sources
defaults({ foo: 0 }, { bar: 1 }, { baz: 2 })
//=> { foo: 0, bar: 1, baz: 2 }

// does not override existing properties
defaults({ foo: 0 }, { foo: 1 }, { foo: 2 })
//=> { foo: 0 }

// ignores falsy sources
defaults({ foo: 0 }, null, '', { bar: 1 }, 0)
//=> { foo: 0, bar: 1 }

defaults(target, [source], [source, ...])

Assigns own enumerable properties of source objects to the target object and returns the target object. Existing properties are not overriden.

Related

License

MIT © Nicolas Gryman

Package Rankings
Top 8.15% on Npmjs.org
Badges
Extracted from project README
npm travis
Related Projects