Skip to content

nanowizard/default-assign

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

default-assign

ES6 Object.assign() like functionality, but does not replace existing properties, and is recursive.

Usage

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}

API

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

Assigns enumerable own properties of source objects recursively to the target object if undefined and returns the target object.

Resources

Based off of the ES6 Object.assign polyfill by MDN

Licence

MIT

About

ES6 Object.assign() like functionality, but does not replace existing properties, and is recursive.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published