Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@broofa/merge
Advanced tools
Merge immutable JSON data structures to allow for identity (===) comparisons on deeply-equal subtrees
Merge immutable model state (or any data structure, really), preserving references to unchanged nodes. This
allows for ===
operation to determine where state has changed. (Useful when
dealing with immutable data models such as React+Redux, where ===
is used for
exactly this purpose.)
In practical terms, where state = merge(before, after)
the returned state
object has the following properties:
assert.deepEqual(state, after)
will always be truestate[X] === before[X]
will be true where deepEqual(before[X], after[X])
state[X] === after[X]
will be true where after[X]
replaces all before[X]
statenpm i @broofa/merge
const assert = require('assert');
const merge = require('@broofa/merge');
const before = {
a: 'hello',
b: 123,
c: {ca: ['zig'], cb: [{a:1}, {b:2}]},
};
const after = {
a: 'world',
b: 123,
c: {ca: ['zig'], cb: [{a:99}, {b:2}]},
};
const state = merge(before, after);
assert.deepEqual(after, state); // Always true
// Where state HAS changed
state === before; // ⇨ false
state.c === before.c; // ⇨ false
state.c.cb === before.c.cb; // ⇨ false
state.c.cb[0] === before.c.cb[0]; // ⇨ false
// Where state HAS NOT changed
state.c.ca === before.c.ca; // ⇨ true
state.c.cb[1] === before.c.cb[1]; // ⇨ true
Markdown generated from src/README_js.md by
FAQs
Merge immutable JSON data structures to allow for identity (===) comparisons on deeply-equal subtrees
The npm package @broofa/merge receives a total of 1 weekly downloads. As such, @broofa/merge popularity was classified as not popular.
We found that @broofa/merge demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.