
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
nested-object-diff
Advanced tools
A lightweight javascript diff library for comparing two javascript object nested with supporting matching by value of the object's choosen key name in array.
A lightweight javascript diff library for comparing two javascript object nested with supporting matching by value of the object's choosen key name in array.
npm i --save nested-object-diff
NodeJs / ES5:
var diff = require('nested-object-diff').diff;
ES6 / Babel:
import diff from 'nested-object-diff';
var diff = require('./dist/index').diff;
var lhs = {
shop: {
products: [{ id: 1, name: 'a' }, { id: 2, name: 'b' }, { id: 3, name: 'c' }]
},
name: 'foo'
};
var rhs = {
shop: {
products: [
{ id: 1, name: 'a' },
{ id: 2, name: 'bb' },
{ id: 4, name: 'd' },
{ id: 3, name: 'cc' }
]
},
name: 'baz'
};
var differences = diff(lhs, rhs, { matchKey: 'id' });
The code snippet above would result in the following structure describing the differences:
[
{ type: 'E', path: 'shop.products.1.name', lhs: 'b', rhs: 'bb' },
{ type: 'E', path: 'shop.products.3.name', lhs: 'c', rhs: 'cc' },
{ type: 'A', path: 'shop.products.2', rhs: { id: 4, name: 'd' } },
{ type: 'E', path: 'name', lhs: 'foo', rhs: 'baz' }
]
lhs
- the left-hand operand; the origin object.rhs
- the right-hand operand; the object being compared structurally with the origin object.options
- A configuration object that can have the following properties:
matchKey
: used to match objects when diffing arrays, by default only === operator is usedDifferences are reported as one or more change records. Change records have the following structure:
type
- indicates the kind of change; will be one of the following:
A
- indicates a newly added propertyD
- indicates a property was deletedE
- indicates a property was editedpath
- the property pathlhs
- the value on the left-hand-side of the comparison (undefined if kind === 'A')rhs
- the value on the right-hand-side of the comparison (undefined if kind === 'D')You discovered a bug or have an idea for a new feature? Great, why don't you send me a PR or open an issue so everyone can benefit from it?
If you decide to send PR please run the unit tests before submitting your PR: npm test
. Hopefully your PR includes additional unit tests to illustrate your changemodification!
MIT
FAQs
A lightweight javascript diff library for comparing two javascript object nested with supporting matching by value of the object's choosen key name in array.
The npm package nested-object-diff receives a total of 7,580 weekly downloads. As such, nested-object-diff popularity was classified as popular.
We found that nested-object-diff demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.