1.0.0 • Published 8 years ago
proxy-merge v1.0.0
proxy-merge
Merge one or more objects using Proxy. Flatten a proxy-merged object to remove the proxy.
npm install -S proxy-mergeExamples
const proxyMerge = require('proxy-merge');Merge two (or more...) objects.
const input0 = { foo: 'bar' };
const input1 = { age: 5 };
const obj = proxyMerge(input0, input1);
obj.foo; // => 'bar'
obj.age; // => 5Only keys from the first input are listed with Object.keys(obj)...
Object.keys(obj); // => ['foo']...but, the first input is not the output object.
input0 === obj; // => falseChanges made to the input after merging will be reflected by the proxy-merged object.
input0.change0 = 0;
input1.change1 = 1;
obj.change0; // => 0
obj.change1; // => 1If you need a vanilla Object, use .flatten(obj).
const flat = proxyMerge.flatten(obj);
Object.keys(flat).sort(); // ['age', 'change0', 'change1', 'foo']
flat.age; // => 5Changes made to the inputs are not reflected in the flattened object.
input0.change2 = 2;
obj.change2; // => 2
flat.change2; // => undefined1.0.0
8 years ago