proxy-merge
Merge one or more objects using Proxy. Flatten a proxy-merged object to remove the proxy.
npm install -S proxy-merge
Examples
const proxyMerge = ;
Merge two (or more...) objects.
const input0 = foo: 'bar' ;const input1 = age: 5 ;const obj = ;objfoo; // => 'bar'objage; // => 5
Only keys from the first input are listed with Object.keys(obj)...
Object; // => ['foo']
...but, the first input is not the output object.
input0 === obj; // => false
Changes made to the input after merging will be reflected by the proxy-merged object.
input0change0 = 0;input1change1 = 1;objchange0; // => 0objchange1; // => 1
If you need a vanilla Object
, use .flatten(obj)
.
const flat = proxyMerge;Object; // ['age', 'change0', 'change1', 'foo']flatage; // => 5
Changes made to the inputs are not reflected in the flattened object.
input0change2 = 2;objchange2; // => 2flatchange2; // => undefined