0.0.2 • Published 9 years ago

merge-light v0.0.2

Weekly downloads
24
License
MIT
Repository
github
Last release
9 years ago

merge-light - npm

merge-light : merge objects into first argument object. thin merge copy.

PREPARE:

for node.js

$ npm install merge-light --save
var merge = require('merge-light');

or

for browsers

https://lightspeedworks.github.io/merge-light/merge-light.js

USAGE:

destination = merge(destination, source, ...)

EXAMPLES:

merge object into first object.

var merge = require('merge-light');

var a = {x:1};
var b = {y:2};

merge(a, b);
console.log(a);        // -> a = {x:1, y:2}
console.log(b);        // -> b = {y:2}

merge object into first object and return merged first object.

var merge = require('merge-light');

var a = {x:1};
var b = {y:2};

var c = merge(a, b);
console.log(a);        // -> a = {x:1, y:2}
console.log(b);        // -> b = {y:2}
console.log(c);        // -> c = {x:1, y:2}
console.log(a === c);  // -> true

create a new object and merge rest of arguments objects.

var merge = require('merge-light');

var a = {x:1};
var b = {y:2};
var c = {z:3};

var d = merge({}, a, b, c);
console.log(a);        // -> a = {x:1}
console.log(b);        // -> b = {y:2}
console.log(c);        // -> c = {z:3}
console.log(d);        // -> d = {x:1, y:2, z:3}

merge objects, if destination has same property already, then does not copied.

var merge = require('merge-light');

var a = {x:1, z:3};
var b = {y:22};
var c = {z:33};
var d = {w:44};

var e = merge({}, a, b, c, d);
console.log(a);        // -> a = {x:1, z:3}
console.log(b);        // -> b = {y:22}
console.log(c);        // -> c = {z:33}
console.log(d);        // -> d = {w:44}
console.log(e);        // -> d = {x:1, z:3, y:22, w:44}

LICENSE:

MIT