Socket
Socket
Sign inDemoInstall

shallow-diff

Package Overview
Dependencies
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    shallow-diff

compare two objects or arrays and return the diff (add/updated/removed/unchanged)


Version published
Weekly downloads
1.6K
decreased by-7.35%
Maintainers
1
Install size
11.5 kB
Created
Weekly downloads
 

Readme

Source

Shallow diff

Make a shallow diff between two objects/arrays to get what has been updated/deleted/added or remains unchanged. It will not traverse the whole structure, only the top level items/property.

Installation

npm install shallow-diff

How to use

Require shallow-diff:

var diff = require("shallow-diff");

Get the diff between two objects:

var base = {a:1, b:2, c:3, d:4, f:6};
var compared = {a:1, b:20, d: 4, e: 5};

diff(base, compared);
// returns
// {
//    unchanged: ["a", "d"],
//    updated: ["b"],
//    deleted: ["f"],
//    added: ["e"]
// }

Get the diff between two arrays:

var base = [10, 20, 30]
var compared = [15, 20]

diff(base, compared);
// returns:
// {
//    unchanged: [1],
//    updated: [0],
//    deleted: [2],
//    added: []
// }

CHANGELOG

0.0.5 - 9 JUN 2015

  • Also update to simple loop 0.0.4 to remove its dependency on assert. Thanks to @markdalgleish.

0.0.4 - 7 MAY 2015

  • Remove dependency on assert and replace with own function. Saves 17kb in the end after browserfication. Thanks to @tomekwi.

0.0.3 - 8 APR 2015

  • Fix a bug where undefined values would appear in the diff as added and deleted. See #1. Thanks to @sverrejoh

LICENSE

MIT

Keywords

FAQs

Last updated on 09 Jun 2015

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc