Gathering detailed insights and metrics for recursive-diff
Gathering detailed insights and metrics for recursive-diff
Gathering detailed insights and metrics for recursive-diff
Gathering detailed insights and metrics for recursive-diff
pixel-buffer-diff-folders
Pbd-folders ( Pixel Buffer Diff folders ) recursively diff folders of images using pixel buffer diff
@cbmrham/recursive-diff
A library that creates a diff object by comparing two objects recursively.
@aminzer/dir-diff
Utility for recursive directory iteration and comparison
recursive-diff.js
This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.
A JavaScript library to find diff between two JavaScript Objects. Support for Array, Number, Date and other primitive data types.
npm install recursive-diff
Typescript
Module System
Node Version
NPM Version
99.1
Supply Chain
100
Quality
76.1
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
4,331,104
Last Day
1,553
Last Week
31,205
Last Month
136,815
Last Year
1,632,556
MIT License
152 Stars
139 Commits
21 Forks
1 Watchers
3 Branches
4 Contributors
Updated on Jun 16, 2025
Minified
Minified + Gzipped
Latest Version
1.0.9
Package Id
recursive-diff@1.0.9
Unpacked Size
29.67 kB
Size
8.78 kB
File Count
9
NPM Version
9.3.1
Node Version
18.14.1
Published on
Feb 19, 2023
Cumulative downloads
Total Downloads
This library can be used to get diff between two JS Objects/Arrays(or other primitive values). Diff are returned in the form of Array where each ARRAY item represents a change in the original Object/Array. A diff item can have following three properties:
path
: An array representation of nested pathop
: Can be any one of the following - add, update or deleteval
: New value after change1const rdiff = require('recursive-diff'); 2const initialVal = { 3 a: { 4 b: 1, 5 c: 2, 6 d: [1] 7 } 8} 9const changedVal = { 10 a: { 11 b: 2, 12 d: [1, 2], 13 }, 14}; 15 16const diff = rdiff.getDiff(initialVal, changedVal); 17/*** 18Diff of initialVal and changedVal is: [ 19 { 20 "path": [ 21 "a", 22 "b" 23 ], 24 "op": "update", 25 "val": 2 26 }, 27 { 28 "path": [ 29 "a", 30 "c" 31 ], 32 "op": "delete" 33 }, 34 { 35 "path": [ 36 "a", 37 "d", 38 1 39 ], 40 "op": "add", 41 "val": 2 42 } 43] 44**/ 45 46const c = rdiff.applyDiff(initialVal, diff); 47assert.deepEqual(c, changedVal); 48
getDiff(oldVal, newVal, keepOldVal?)
: getDiff
takes following parameters
oldVal (required)
: initial value, can be Array/Object or even primitive type such as number, boolean or stringnewVal (required)
: changed value ( required ), can be Array/Object or even primitive type such as number, boolean or stringkeepOldValueInDiff (optional)
: boolean parameter which if set to true, every diff value will have an additional property oldValue
which will denote the old value before mutationapplyDiff (oldVal, diff, visitorCallbackFn?)
applyDiff
takes three arguments:
oldVal (required)
: original value,diff (required)
: diff returned by getDiff
APIvisitorCallbackFn (optional)
: This callback function is called at each depth level while applying the diff. It can be used to mark the mutation path with some meta properties eg: { isMutated: true }
. For more details, please check the examples directory of this repo.npm install recursive-diff
1const diff = require('recursive-diff'); 2const oldVal = {a:1}; 3const newVal = {a:2}; 4const delta = diff.getDiff(oldVal, newVal); 5const ob3 = diff.applyDiff(oldVal, delta); 6assert.deepEqual(ob3, newVal);
'dist/recursive-diff.min.js'
can be directly injected into a HTML page using the URL https://unpkg.com/recursive-diff@latest/dist/recursive-diff.min.js
. Once it is included into the HTML file, diff API is accessible using window.recursiveDiff
. Example given below.
1<script type="text" src="https://unpkg.com/recursive-diff@latest/dist/recursive-diff.min.js"/> 2<script type="text/javascript"> 3 const oldVal = { a: 1 }; 4 const newVal = { a: 2 }; 5 const delta = recursiveDiff.getDiff(oldVal, newVal); 6 const ob3 = recursiveDiff.applyDiff(oldVal, delta); //expect ob3 is deep equal to newVal 7</script>
1import { getDiff, applyDiff, rdiffResult } from 'recursive-diff'; 2 3const oldVal = [1, 2]; 4const newVal = [2, 3, 4]; 5const diff:rdiffResult[] = getDiff(oldVal, newVal); 6console.log('diff', diff); 7const final = applyDiff(oldVal, diff); 8console.log('applydiff', final); // final should deep equal to newVal
Unit test can be run using the command npm test
. This repo has more than 99% code coverage.
You can find more examples in the example folder of this repo. Few of the examples are listed below.
1/* eslint-disable no-param-reassign */ 2/* eslint-disable no-console */ 3import { getDiff, applyDiff } from '../dist/recursive-diff'; 4 5let [a, b, c, delta] = []; 6// testing primitive data type 7a = 3; 8b = 10; 9delta = getDiff(a, b); 10console.log(delta); 11// Output: [{path: [], op: 'update', val: 10}] 12c = applyDiff(a, delta); 13console.log(c); // Output: 10 14 15// testing array 16a = [1, 2]; 17b = [1, 30, 40]; 18delta = getDiff(a, b, true); // third parameter : keepOldValInDiff, see output below 19console.log(delta); 20/** * 21Output: 22[ 23 { path: [1], op: 'update', val: 30, oldVal: 2 }, 24 { path: [2], op: 'add', val: 40 }, 25] 26* */ 27c = applyDiff(a, delta); 28console.log(c); // Output: [1,30,40] 29 30// testing objects 31a = { 32 a: '10', 33 b: '20', 34 c: '30', 35}; 36b = { 37 a: '10', 38 b: '40', 39}; 40delta = getDiff(a, b); 41console.log(delta); 42/** * Output: 43[ 44 { path: ['b'], op: 'update', val: 40 }, 45 { path: ['c'], op: 'delete', val: undefined }, 46] 47* */ 48c = applyDiff(a, delta); 49console.log(c); // Output: {a:'10', 'b':40} 50 51// testing complex deep object 52a = { 53 b: [1, 2, [3, 4]], 54 c: { 55 c1: 20, 56 c2: { 57 c21: 'hello', 58 }, 59 c3: 'India', 60 }, 61}; 62b = { 63 b: [1, 2, [4]], 64 c: { 65 c1: 20, 66 c2: { 67 c21: 'hi', 68 c22: 'welcome', 69 }, 70 c3: 'cosmic', 71 }, 72}; 73 74delta = getDiff(a, b); 75console.log(delta); 76/** 77Output: 78[ 79 { path: ['b', 2, 0], op: 'update', val: 4 }, 80 { path: ['b', 2, 1], op: 'delete', val: undefined }, 81 { path: ['c', 'c2', 'c21'], op: 'update', val: 'hi' }, 82 { path: ['c', 'c2', 'c22'], op: 'add', val: 'welcome' }, 83 { path: ['c', 'c3'], op: 'update', val: 'cosmic' }, 84] 85* */ 86c = applyDiff(a, delta); 87console.log(c); 88/** *Output 89 { 90 b: [1,2,[4]], 91 c: { 92 c1 : 20, 93 c2 : { 94 c21: 'hi', 95 c22: 'welcome' 96 }, 97 c3: 'cosmic' 98 } 99} 100* */ 101
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 1/4 approved changesets -- score normalized to 2
Reason
9 existing vulnerabilities detected
Details
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
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
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 MoreLast Day
-5%
1,553
Compared to previous day
Last Week
-13.5%
31,205
Compared to previous week
Last Month
-1.1%
136,815
Compared to previous month
Last Year
41.7%
1,632,556
Compared to previous year