New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

diff-immutability-helper

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

diff-immutability-helper

Creates a diff between 2 javascript objects / variables, in a format that is compatible with immutability-helper

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
89
increased by61.82%
Maintainers
1
Weekly downloads
 
Created
Source

diff-immutability-helper

Creates a diff between 2 JavaScript objects, allowing you to mutate one object to another using immutability-helper.

npm package Build Status Coverage Status

Overview

diff-immutability-helper creates an immutability-helper compatible diff object between 2 JavaScript variables.

This diff object would then allow you to mutate the base object to the target object.

Example

  import diff from 'diff-immutability-helper';

  const base = {
    a: [1, 2, {b: 1}],
    b: 'test',
    c: 'prev'
  };

  const target = {
    a: [1, 2, {b: 2}, 4],
    b: 'test 2',
    d: 'new'
  };

  const change = diff(base, target);

will give a result of:

  const change = {
    a: {
      '2': {
        b: {$set: 2}
      },
      '3': {$set: 4}
    },
    b: {$set: 'test 2'},
    $apply: (v) => omit(v, ['c']),
    $merge: {
      d: 'new'
    }
  }

as such, we can achieve

  import update from 'immutability-helper';
  update(base, change); // to match target

Installation

Install the library:

npm install diff-immutability-helper --save

// or

yarn add diff-immutability-helper

License

diff-immutability-helper is MIT licensed

FAQs

Package last updated on 18 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

  • 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