All Projects → mattphillips → Deep Object Diff

mattphillips / Deep Object Diff

Licence: mit
Deep diffs two objects, including nested structures of arrays and objects, and returns the difference. ❄️

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Deep Object Diff

js-deep-sort-object
Simple module to sort objects recursively by its keys
Stars: ✭ 19 (-96.31%)
Mutual labels:  object, array, deep
php-helpers
An extensive set of PHP helper functions and classes.
Stars: ✭ 27 (-94.76%)
Mutual labels:  object, array
js-explorer
Find the method you need without digging through the docs, directly on the command line!
Stars: ✭ 287 (-44.27%)
Mutual labels:  object, array
prototyped.js
Some common Typescript prototypes
Stars: ✭ 22 (-95.73%)
Mutual labels:  object, array
Kibana Object Format
A Kibana plugin for displaying objects and arrays of objects.
Stars: ✭ 100 (-80.58%)
Mutual labels:  array, object
What The Filter
A visual playground to JavaScript array & object transformations.
Stars: ✭ 128 (-75.15%)
Mutual labels:  array, object
CarND-VehicleDetection
vehicle detection with deep learning
Stars: ✭ 34 (-93.4%)
Mutual labels:  object, deep
Get Value
Use property paths (`a.b.c`) get a nested value from an object.
Stars: ✭ 194 (-62.33%)
Mutual labels:  object, deep
ss-search
The most basic, yet powerful text search.
Stars: ✭ 41 (-92.04%)
Mutual labels:  object, array
get
🚚 A really small and type-safe (requires TypeScript >= 4.1.3) function, that gets a nested value from an object using a path string (like "a.b[0].d"). If value is 'undefined' or unreachable returns the placeholder instead.
Stars: ✭ 13 (-97.48%)
Mutual labels:  object, deep
array-diff-multidimensional
Compare the difference between two multidimensional arrays in PHP
Stars: ✭ 60 (-88.35%)
Mutual labels:  diff, array
Shallow Clone
Make a shallow clone of an object, array or primitive.
Stars: ✭ 23 (-95.53%)
Mutual labels:  array, object
Moses
Utility library for functional programming in Lua
Stars: ✭ 541 (+5.05%)
Mutual labels:  array, object
Kind Of
Get the native JavaScript type of a value, fast. Used by superstruct, micromatch and many others!
Stars: ✭ 268 (-47.96%)
Mutual labels:  array, object
Clone Deep
Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives. Used by superstruct, merge-deep, and many others!
Stars: ✭ 229 (-55.53%)
Mutual labels:  object, deep
Differentia.js
No longer being supported or maintained. A Graph Theory & Data Structure Library for JavaScript.
Stars: ✭ 13 (-97.48%)
Mutual labels:  diff, deep
Trdis
The most known way to travel in space and time
Stars: ✭ 83 (-83.88%)
Mutual labels:  object, diff
utils.js
👷 🔧 zero dependencies vanilla JavaScript utils.
Stars: ✭ 14 (-97.28%)
Mutual labels:  object, array
underscore.haz
🔍 _.haz() is like _.has() but this underscore and/or lodash mixin lets you do deep object key existence checking with a dot denoted string, for example 'a.b.c'
Stars: ✭ 13 (-97.48%)
Mutual labels:  object, deep
Morphism
⚡ Type-safe data transformer for JavaScript, TypeScript & Node.js.
Stars: ✭ 336 (-34.76%)
Mutual labels:  array, object

deep-object-diff

❄️

Deep diff two JavaScript Objects


Build Status Code Coverage version downloads MIT License PRs Welcome

A small library that can deep diff two JavaScript Objects, including nested structures of arrays and objects.

Installation

yarn add deep-object-diff

npm i --save deep-object-diff

Functions available:

Importing

ES6 / Babel:

import { diff, addedDiff, deletedDiff, updatedDiff, detailedDiff } from 'deep-object-diff';

ES5:

const { diff, addedDiff, deletedDiff, detailedDiff, updatedDiff } = require("deep-object-diff");

// OR

const diff = require("deep-object-diff").diff;
const addedDiff = require("deep-object-diff").addedDiff;
const deletedDiff = require("deep-object-diff").deletedDiff;
const detailedDiff = require("deep-object-diff").detailedDiff;
const updatedDiff = require("deep-object-diff").updatedDiff;

Usage:

diff:

const lhs = {
  foo: {
    bar: {
      a: ['a', 'b'],
      b: 2,
      c: ['x', 'y'],
      e: 100 // deleted
    }
  },
  buzz: 'world'
};

const rhs = {
  foo: {
    bar: {
      a: ['a'], // index 1 ('b')  deleted
      b: 2, // unchanged
      c: ['x', 'y', 'z'], // 'z' added
      d: 'Hello, world!' // added
    }
  },
  buzz: 'fizz' // updated
};

console.log(diff(lhs, rhs)); // =>
/*
{
  foo: {
    bar: {
      a: {
        '1': undefined
      },
      c: {
        '2': 'z'
      },
      d: 'Hello, world!',
      e: undefined
    }
  },
  buzz: 'fizz'
}
*/

addedDiff:

const lhs = {
  foo: {
    bar: {
      a: ['a', 'b'],
      b: 2,
      c: ['x', 'y'],
      e: 100 // deleted
    }
  },
  buzz: 'world'
};

const rhs = {
  foo: {
    bar: {
      a: ['a'], // index 1 ('b')  deleted
      b: 2, // unchanged
      c: ['x', 'y', 'z'], // 'z' added
      d: 'Hello, world!' // added
    }
  },
  buzz: 'fizz' // updated
};

console.log(addedDiff(lhs, rhs));

/*
{
  foo: {
    bar: {
      c: {
        '2': 'z'
      },
      d: 'Hello, world!'
    }
  }
}
*/

deletedDiff:

const lhs = {
  foo: {
    bar: {
      a: ['a', 'b'],
      b: 2,
      c: ['x', 'y'],
      e: 100 // deleted
    }
  },
  buzz: 'world'
};

const rhs = {
  foo: {
    bar: {
      a: ['a'], // index 1 ('b')  deleted
      b: 2, // unchanged
      c: ['x', 'y', 'z'], // 'z' added
      d: 'Hello, world!' // added
    }
  },
  buzz: 'fizz' // updated
};

console.log(deletedDiff(lhs, rhs));

/*
{
  foo: {
    bar: {
      a: {
        '1': undefined
      },
      e: undefined
    }
  }
}
*/

updatedDiff:

const lhs = {
  foo: {
    bar: {
      a: ['a', 'b'],
      b: 2,
      c: ['x', 'y'],
      e: 100 // deleted
    }
  },
  buzz: 'world'
};

const rhs = {
  foo: {
    bar: {
      a: ['a'], // index 1 ('b')  deleted
      b: 2, // unchanged
      c: ['x', 'y', 'z'], // 'z' added
      d: 'Hello, world!' // added
    }
  },
  buzz: 'fizz' // updated
};

console.log(updatedDiff(lhs, rhs));

/*
{
  buzz: 'fizz'
}
*/

detailedDiff:

const lhs = {
  foo: {
    bar: {
      a: ['a', 'b'],
      b: 2,
      c: ['x', 'y'],
      e: 100 // deleted
    }
  },
  buzz: 'world'
};

const rhs = {
  foo: {
    bar: {
      a: ['a'], // index 1 ('b')  deleted
      b: 2, // unchanged
      c: ['x', 'y', 'z'], // 'z' added
      d: 'Hello, world!' // added
    }
  },
  buzz: 'fizz' // updated
};

console.log(detailedDiff(lhs, rhs));

/*
{
  added: {
    foo: {
      bar: {
        c: {
          '2': 'z'
        },
        d: 'Hello, world!'
      }
    }
  },
  deleted: {
    foo: {
      bar: {
        a: {
          '1': undefined
        },
        e: undefined
      }
    }
  },
  updated: {
    buzz: 'fizz'
  }
}
*/

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].