← 返回首页
GitHub - mattphillips/deep-object-diff: Deep diffs two objects, including nested structures of arrays and objects, and returns the difference. ❄️ · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

mattphillips/deep-object-diff

Go to file
Code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

114 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
View all files

Repository files navigation

More items

deep-object-diff

❄️

Deep diff two JavaScript Objects

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

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

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

About

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

Topics

Resources

License

Stars

1.1k stars

Watchers

9 watching

Forks

Sponsor this project

 
Sponsor

Packages

 
 
 

Contributors

Footer

© 2026 GitHub, Inc.