Socket
Book a DemoInstallSign in
Socket

proxy-merge

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proxy-merge

Merge one or more objects using Proxy

1.0.0
latest
npmnpm
Version published
Weekly downloads
87
7.41%
Maintainers
1
Weekly downloads
 
Created
Source

proxy-merge

npm version license CircleCI

Merge one or more objects using Proxy. Flatten a proxy-merged object to remove the proxy.

npm install -S proxy-merge

Examples

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; // => 5

Only 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; // => false

Changes 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; // => 1

If you need a vanilla Object, use .flatten(obj).

const flat = proxyMerge.flatten(obj);
Object.keys(flat).sort(); // ['age', 'change0', 'change1', 'foo']
flat.age; // => 5

Changes made to the inputs are not reflected in the flattened object.

input0.change2 = 2;
obj.change2; // => 2
flat.change2; // => undefined

Keywords

es6

FAQs

Package last updated on 08 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.