Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@broofa/merge

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@broofa/merge

Merge immutable JSON data structures to allow for identity (===) comparisons on deeply-equal subtrees

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

merge

Merge immutable JSON data structures to allow for identity (===) comparisons on deeply-equal subtrees.

Installation

npm i @broofa/merge

Example

const assert = require('assert');
const merge = require('@broofa/merge');

const obj0 = {
  a: 'hello',
  b: 123,
  c: {
    ca: 'zig',
    cb: [{a:1}, {b:2}]
  },
};

const obj1 = {
  a: 'world',
  c: {
    ca: {a: 1},
    cb: [{a:99}, {b:2}]
  },
};

const result = merge(obj0, obj1);

// Result will always be deepEqual to right-most argument
assert.deepEqual(obj1, result);

// root.c has changed, so is not identical
result.c === obj0.c; // ⇨ false

// ... same goes for root.c.ca and root.c.cb and root.c.cb[0]
result.c.ca === obj0.c.ca; // ⇨ false
result.c.cb === obj0.c.cb; // ⇨ false
result.c.cb[0] === obj0.c.cb[0]; // ⇨ false

// 'But root.c.cb[1] hasn't, so `===` works!
result.c.cb[1] === obj0.c.cb[1]; // ⇨ true


Markdown generated from src/README_js.md by RunMD Logo

Keywords

FAQs

Package last updated on 18 Oct 2018

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc