Socket
Book a DemoInstallSign in
Socket

ddiff

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

ddiff

Calculate differences between two data structures

0.1.3
latest
Source
npmnpm
Version published
Weekly downloads
9
28.57%
Maintainers
1
Weekly downloads
 
Created
Source

ddiff

npm (scoped) Travis Coveralls

Calculate differences between two data structures

Table of Contents

Install

This project uses node and npm. Go check them out if you don't have them locally installed.

$ npm install --save ddiff

The UMD build is also available on jsdelivr:

<script src="https://cdn.jsdelivr.net/npm/ddiff/dist/ddiff.umd.js"></script>

You can find the library on window.ddiff.

Usage

import {diff} from 'ddiff';

const lhs = {
  name: 'my object',
  description: 'it\'s an object!',
  details: {
    it: 'has',
    an: 'array',
    with: ['a', 'few', 'elements']
  }
};

const rhs = {
  name: 'updated object',
  description: 'it\'s an object!',
  details: {
    it: 'has',
    an: 'array',
    with: ['a', 'few', 'more', 'elements', { than: 'before' }]
};

diff(lhs, rhs);
// [ { kind: 'E',
//     path: [ 'name' ],
//     lhs: 'my object',
//     rhs: 'updated object' },
//   { kind: 'A',
//     path: [ 'details', 'with' ],
//     index: 2,
//     item: { kind: 'E', path: [], lhs: 'elements', rhs: 'more' } },
//   { kind: 'A',
//     path: [ 'details', 'with' ],
//     index: 3,
//     item: { kind: 'N', rhs: 'elements' } },
//   { kind: 'A',
//     path: [ 'details', 'with' ],
//     index: 4,
//     item: { kind: 'N', rhs: { than: 'before' } } } ]

Changes

Change records have the following structure:

  • kind - indicates the kind of change; will be one of the following:
    • N - indicates a newly added property/element
    • D - indicates a property/element was deleted
    • E - indicates a property/element was edited
    • A - indicates a change occurred within an array
  • path - the property path (from the left-hand-side root)
  • lhs - the value on the left-hand-side of the comparison (undefined if kind === 'N')
  • rhs - the value on the right-hand-side of the comparison (undefined if kind === 'D')
  • index - when kind === 'A', indicates the array index where the change occurred
  • item - when kind === 'A', contains a nested change record indicating the change that occurred at the array index

Credits

The test suite is adapted from deep-diff. @flitbit Thanks for your amazing work.

Contributing

See the contributing file.

License

Apache License, Version 2.0 © Thiago Santos

Keywords

diff

FAQs

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

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.