An object difference library for NodeJS.


Keywords
object, diff, obj, difference
License
MIT
Install
npm install objecdiff@1.2.2

Documentation

An object difference library for NodeJS

This module can compares two objects and return the key that has changed along with the original and new values.

Dependencies Build Status Downloads NPM version Maintainability Known Vulnerabilities

Installation

$ npm install objecdiff

Usage

let objecdiff = require('objecdiff');

API

diff Documentation

objecdiff.diff(objectA, objectB)
  • objectA - Object - The original or first object that you would like to compare.
  • objectB - Object - The new or second object that you would like to compare the first against.

Example

let objecdiff = require('../lib/objecdiff.js');

let a = {
        firstName: 'Mike',
        lastName: 'R',
        city: 'Boston'
    },
    b = {
        firstName: 'Dan',
        name: 'Dan G',
        color: {
            favorite: 'blue'
        },
        city: 'Boston'
    };

console.log(objecdiff.diff(a, b));
// => [ { documentPath: 'firstName', original: 'Mike', new: 'Dan' },
// =>   { documentPath: 'lastName', original: 'R', new: undefined },
// =>   { documentPath: 'name', original: undefined, new: 'Dan G' },
// =>   { documentPath: 'color.favorite', original: null, new: 'blue' } ]

Tests

$ npm test

Note: This requires mocha, should, async, and underscore.

To see test coverage, please run:

$ npm run coverage

Current Coverage is:

<Tests coming soon.>

Features

  • Natively supports nested documents
  • Compares the objects and returns the key that has changed along with the original and new values