ES6 Object.assign() like functionality, but does not replace existing properties, and is recursive.
var defaultAssign = require('default-assign');
// does not overwrite equal keys
defaultAssign({foo: 0, bar: 1}, {bar: 2, baz: 2});
//=> {foo: 0, bar: 1, baz: 2}
// multiple sources
defaultAssign({foo: 0, bar: 1}, {bar: 2}, {baz: 3});
//=> {foo: 0, bar: 1, baz: 3}
// recursive
defaultAssign({foo: 0, bar: {barA: 1, barB: 2}}, {bar: {barA: 2, barC: 3}});
//=> {foo: 0, bar: {barA: 1, barB: 2, barC: 3}}
// ignores null and undefined sources
defaultAssign({foo: 0, bar: 1}, null, {bar: 2, baz: 2}, undefined);
//=> {foo: 0, bar: 1, baz: 2}
Assigns enumerable own properties of source
objects recursively to the target
object if undefined and returns the target
object.
Based off of the ES6 Object.assign polyfill by MDN
MIT