2.0.0 • Published 1 year ago

objecdiff v2.0.0

Weekly downloads
15
License
MIT
Repository
github
Last release
1 year ago

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
2.0.0

1 year ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.1

8 years ago