objecdiff
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

An object difference library for NodeJS

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

NPM version Downloads Minzipped Size Build Status Coverage Status Typings

Installation

$ npm install objecdiff

Usage

const objecdiff = require('objecdiff');

// Alternatively:
import { diff } from 'objecdiff';

API

diff(original, updated) Documentation

objecdiff.diff(objectA, objectB)

// Alternatively if using the `import` method shown above:
diff(objectA, objectB)
  • objectA - Object - The original or first object that you would like to compare.
  • objectB - Object - The updated or second object that you would like to compare the first against.

Example

import { diff } from 'objecdiff';

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

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

Tests

$ npm test

To see test coverage, please run:

$ npm run coverage

Features

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

Package Sidebar

Install

npm i objecdiff

Weekly Downloads

13

Version

2.0.0

License

MIT

Unpacked Size

4.99 kB

Total Files

4

Last publish

Collaborators

  • mrodrig