gd

get-diff

Javascript object diff tool

Showing:

Popularity

Downloads/wk

1

GitHub Stars

0

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

0

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

get-diff

Build Status

Installation

npm install get-diff --save

Syntax

getDiff(variableA, variableB)

Usage

Diff a shallow object
import getDiff from 'get-diff';

const userA = {username: 'Max'};
const userB = {username: 'Jane'};

getDiff(userA, userB)
//  [
//    {
//      keyPath: 'username',
//      diff: [
//        ['String','Max'],
//        ['String','Jane']
//      ]
//    }
//  ]

Diff a deep object
import getDiff from 'get-diff';

const userA = {
  work: {
    'title': 'Developer'
  }
};

const userB = {
  work: {}
};

getDiff(userA, userB)
//  [
//    {
//      keyPath: 'work.title',
//      diff: [
//        ['String','Developer'],
//        ['Undefined', undefined]
//      ]
//    }
//  ]

Diff everything...
import getDiff from 'get-diff';

const genderFemale = Symbol('female');

const userA = {
  userId: 1,
  firstname: 'Maxine',
  surname: 'Mustermann',
  age: 20,
  sex: genderFemale,
  level: Symbol('admin'),
  hobbies: ['golf', 'tennis'],
  music: ['Blur'],
  work: {
    title: 'Developer',
    senior: 'yes'
  },
  cool: false,
  happy: true,
  birthDath: new Date('1984-01-01'),
  recentLogin: new Date('2015-01-01')
};

const userB = {
  userId: 2,
  firstname: 'Maxine',
  surname: 'Johansson',
  age: 20,
  sex: genderFemale,
  level: Symbol('admin'),
  hobbies: ['golf', 'tennis'],
  music: ['Pulp'],
  work: {
    title: 'Developer',
    senior: 'no'
  },
  cool: false,
  happy: true,
  birthDath: new Date('1984-01-01'),
  recentLogin: new Date('2015-01-02')
};


getDiff(userA, userB)
//  [
//    { keyPath: 'userId',
//      diff: [
//        [ 'Number', 1 ],
//        [ 'Number', 2 ]
//      ]
//    },
//    { keyPath: 'surname',
//      diff: [
//        [ 'String', 'Mustermann' ],
//        [ 'String', 'Johansson' ]
//      ]
//    },
//    { keyPath: 'level',
//      diff: [
//        [ 'Symbol', {} ],
//        [ 'Symbol', {} ]
//      ]
//    },
//    { keyPath: 'music.0',
//      diff: [
//        [ 'String', 'Blur' ],
//        [ 'String', 'Pulp' ]
//      ]
//    },
//    { keyPath: 'work.senior',
//      diff: [
//        [ 'String', 'yes' ],
//        [ 'String', 'no' ]
//      ]
//    },
//    { keyPath: 'recentLogin',
//      diff: [
//        [ 'Date', Thu Jan 01 2015 01:00:00 GMT+0100 (CET) ],
//        [ 'Date', Fri Jan 02 2015 01:00:00 GMT+0100 (CET) ]
//      ]
//    }
//  ] 

Gotchas

Different Symbol instances will render this message
//  diff: [
//    [ 'Symbol', {} ],
//    [ 'Symbol', {} ]
//  ]

Tests

npm test

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

Release History

  • 0.0.3 Fixed date bug
  • 0.0.2 Date support
  • 0.0.1 Initial alpha release

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial