🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

nested-diff

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nested-diff

Calculating deep difference for JavaScript objects

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

nested-diff

Calculating deep difference for JavaScript objects. Inspired by https://github.com/flitbit/diff

Example Usage

var nestedDiff = require('nested-diff').nestedDiff;

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

var rhs = {
    name: 'updated object',
    hello: 'world',
    details: {
        it: 'has',
        an: 'what',
        with: ['elements', 'a', 'few', 'more', { than: 'before' }]
    }
};

nestedDiff(lhs, rhs);
[
    {
        "kind": "E",
        "key": "name",
        "lhs": "my object",
        "rhs": "updated object"
    },
    {
        "kind": "D",
        "key": "description",
        "lhs": "it's an object!"
    },
    {
        "kind": "E",
        "key": "details",
        "lhs": {
            "it": "has",
            "an": "array",
            "with": [
                "a",
                "few",
                "elements"
            ]
        },
        "rhs": {
            "it": "has",
            "an": "what",
            "with": [
                "elements",
                "a",
                "few",
                "more",
                {
                    "than": "before"
                }
            ]
        },
        "differences": [
            {
                "kind": "E",
                "key": "an",
                "lhs": "array",
                "rhs": "what"
            },
            {
                "kind": "A",
                "key": "with",
                "lhs": [
                    "a",
                    "few",
                    "elements"
                ],
                "rhs": [
                    "elements",
                    "a",
                    "few",
                    "more",
                    {
                        "than": "before"
                    }
                ],
                "differences": [
                    {
                        "kind": "E",
                        "key": 0,
                        "lhs": "a",
                        "rhs": "elements"
                    },
                    {
                        "kind": "E",
                        "key": 1,
                        "lhs": "few",
                        "rhs": "a"
                    },
                    {
                        "kind": "E",
                        "key": 2,
                        "lhs": "elements",
                        "rhs": "few"
                    },
                    {
                        "kind": "A",
                        "key": 3,
                        "lhs": "more"
                    },
                    {
                        "kind": "A",
                        "key": 4,
                        "lhs": {
                            "than": "before"
                        }
                    }
                ]
            }
        ]
    },
    {
        "kind": "N",
        "key": "hello",
        "rhs": "world"
    }
]
  • 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
  • key - the property name
  • 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')
  • differences - Nested differences

FAQs

Package last updated on 28 Feb 2016

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