Gathering detailed insights and metrics for deep-object-diff-mod
Gathering detailed insights and metrics for deep-object-diff-mod
Gathering detailed insights and metrics for deep-object-diff-mod
Gathering detailed insights and metrics for deep-object-diff-mod
deep-object-diff
Deep diffs two objects, including nested structures of arrays and objects, and return the difference.
arr-diff
Returns an array with only the unique values from the first array, by excluding all values from additional arrays using strict equality for comparisons.
diff-match-patch
npm package for https://github.com/google/diff-match-patch
deep-diff
Javascript utility for calculating deep difference, capturing changes, and applying changes across objects; for nodejs and the browser.
npm install deep-object-diff-mod
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1 Stars
95 Commits
2 Watching
7 Branches
1 Contributors
Updated on 09 Jan 2019
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-56.5%
10
Compared to previous day
Last week
-58.4%
74
Compared to previous week
Last month
-12.3%
535
Compared to previous month
Last year
-33.6%
7,384
Compared to previous year
❄️
Deep diff two JavaScript Objects
A small library that can deep diff two JavaScript Objects, including nested structures of arrays and objects. This library is a slight mod of Matt Phillips' deep-object-diff package, the only difference being that it will return a 'REMOVED' string instead of undefined in place where objects have been removed from an updated object's array of objects. The use-case for this is for Mongo Database Logging - undefined key-values do not save, meaning logs don't show key-values that have been removed from an object. This solution remedies that issue.
yarn add deep-object-diff-mod
npm i --save deep-object-diff-mod
diff(originalObj, updatedObj)
returns the difference of the original and updated objects
addedDiff(original, updatedObj)
returns only the values added to the updated object
deletedDiff(original, updatedObj)
returns only the values deleted in the updated object
updatedDiff(original, updatedObj)
returns only the values that have been changed in the updated object
detailedDiff(original, updatedObj)
returns an object with the added, deleted and updated differences
ES6 / Babel:
1import { diff, addedDiff, deletedDiff, updatedDiff, detailedDiff } from 'deep-object-diff-mod';
ES5:
1const { diff, addedDiff, deletedDiff, detailedDiff, updatedDiff } = require("deep-object-diff-mod"); 2 3// OR 4 5const diff = require("deep-object-diff-mod").diff; 6const addedDiff = require("deep-object-diff-mod").addedDiff; 7const deletedDiff = require("deep-object-diff-mod").deletedDiff; 8const detailedDiff = require("deep-object-diff-mod").detailedDiff; 9const updatedDiff = require("deep-object-diff-mod").updatedDiff;
diff
:1const lhs = { 2 foo: { 3 bar: { 4 a: ['a', 'b'], 5 b: 2, 6 c: ['x', 'y'], 7 e: 100 // deleted 8 } 9 }, 10 buzz: 'world' 11}; 12 13const rhs = { 14 foo: { 15 bar: { 16 a: ['a'], // index 1 ('b') deleted 17 b: 2, // unchanged 18 c: ['x', 'y', 'z'], // 'z' added 19 d: 'Hello, world!' // added 20 } 21 }, 22 buzz: 'fizz' // updated 23}; 24 25console.log(diff(lhs, rhs)); // => 26/* 27{ 28 foo: { 29 bar: { 30 a: { 31 '1': 'REMOVED' 32 }, 33 c: { 34 '2': 'z' 35 }, 36 d: 'Hello, world!', 37 e: 'REMOVED' 38 } 39 }, 40 buzz: 'fizz' 41} 42*/
addedDiff
:1const lhs = { 2 foo: { 3 bar: { 4 a: ['a', 'b'], 5 b: 2, 6 c: ['x', 'y'], 7 e: 100 // deleted 8 } 9 }, 10 buzz: 'world' 11}; 12 13const rhs = { 14 foo: { 15 bar: { 16 a: ['a'], // index 1 ('b') deleted 17 b: 2, // unchanged 18 c: ['x', 'y', 'z'], // 'z' added 19 d: 'Hello, world!' // added 20 } 21 }, 22 buzz: 'fizz' // updated 23}; 24 25console.log(addedDiff(lhs, rhs)); 26 27/* 28{ 29 foo: { 30 bar: { 31 c: { 32 '2': 'z' 33 }, 34 d: 'Hello, world!' 35 } 36 } 37} 38*/
deletedDiff
:1const lhs = { 2 foo: { 3 bar: { 4 a: ['a', 'b'], 5 b: 2, 6 c: ['x', 'y'], 7 e: 100 // deleted 8 } 9 }, 10 buzz: 'world' 11}; 12 13const rhs = { 14 foo: { 15 bar: { 16 a: ['a'], // index 1 ('b') deleted 17 b: 2, // unchanged 18 c: ['x', 'y', 'z'], // 'z' added 19 d: 'Hello, world!' // added 20 } 21 }, 22 buzz: 'fizz' // updated 23}; 24 25console.log(deletedDiff(lhs, rhs)); 26 27/* 28{ 29 foo: { 30 bar: { 31 a: { 32 '1': 'REMOVED' 33 }, 34 e: 'REMOVED' 35 } 36 } 37} 38*/
updatedDiff
:1const lhs = { 2 foo: { 3 bar: { 4 a: ['a', 'b'], 5 b: 2, 6 c: ['x', 'y'], 7 e: 100 // deleted 8 } 9 }, 10 buzz: 'world' 11}; 12 13const rhs = { 14 foo: { 15 bar: { 16 a: ['a'], // index 1 ('b') deleted 17 b: 2, // unchanged 18 c: ['x', 'y', 'z'], // 'z' added 19 d: 'Hello, world!' // added 20 } 21 }, 22 buzz: 'fizz' // updated 23}; 24 25console.log(updatedDiff(lhs, rhs)); 26 27/* 28{ 29 buzz: 'fizz' 30} 31*/
detailedDiff
:1const lhs = { 2 foo: { 3 bar: { 4 a: ['a', 'b'], 5 b: 2, 6 c: ['x', 'y'], 7 e: 100 // deleted 8 } 9 }, 10 buzz: 'world' 11}; 12 13const rhs = { 14 foo: { 15 bar: { 16 a: ['a'], // index 1 ('b') deleted 17 b: 2, // unchanged 18 c: ['x', 'y', 'z'], // 'z' added 19 d: 'Hello, world!' // added 20 } 21 }, 22 buzz: 'fizz' // updated 23}; 24 25console.log(detailedDiff(lhs, rhs)); 26 27/* 28{ 29 added: { 30 foo: { 31 bar: { 32 c: { 33 '2': 'z' 34 }, 35 d: 'Hello, world!' 36 } 37 } 38 }, 39 deleted: { 40 foo: { 41 bar: { 42 a: { 43 '1': 'REMOVED' 44 }, 45 e: 'REMOVED' 46 } 47 } 48 }, 49 updated: { 50 buzz: 'fizz' 51 } 52} 53*/
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
77 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More