safe-assign
Extend your object without breaking its structure.
Installtion
$ npm i safe-assign
Usage
// commonJsconst safeAssign = // or using esmodule// import safeAssign from 'safe-assign' // works like Object.assignObject//=> {foo: 0, bar: 1}//=> {foo: 0, bar: 1} Object//=> {foo: 2}//=> {foo: 2} // DifferenceObject//=> {foo: null} /* oops, foo is changed to another type *///=> {foo: 1} /* values whose type is different with original one will be omitted */ // Deep-copyconst target = foo: 0const source = bar: baz: 1//=> JSON.stringify(target) === '{foo: 0, bar: {baz: 1}}'sourcebarbaz = 2//=> JSON.stringify(target) === '{foo: 0, bar: {baz: 1}}'
API
safeAssign(target, [source, ...])