New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

deep-diff-ts

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-diff-ts

Fast deep object diff with full TypeScript types — zero dependencies

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

deep-diff-ts — Fast Deep Object Diff for TypeScript

npm version npm downloads license CI

Fast deep object diff and patch with full TypeScript types. Compare nested objects, arrays, dates, and regexps. Zero dependencies, ~1.4KB.

deep-diff-ts demo — comparing two objects and showing CREATE, UPDATE, DELETE changes

Install

npm install deep-diff-ts

Usage

import { diff } from "deep-diff-ts";

const oldObj = {
  name: "Alice",
  age: 30,
  tags: ["admin"],
  config: { theme: "dark" },
};

const newObj = {
  name: "Alice",
  age: 31,
  tags: ["admin", "editor"],
  config: { theme: "light" },
};

const changes = diff(oldObj, newObj);
// [
//   { type: "UPDATE", path: ["age"], oldValue: 30, value: 31 },
//   { type: "CREATE", path: ["tags", 1], value: "editor" },
//   { type: "UPDATE", path: ["config", "theme"], oldValue: "dark", value: "light" }
// ]

Apply Diffs

import { diff, applyDiff } from "deep-diff-ts";

const changes = diff(oldObj, newObj);
const result = applyDiff(oldObj, changes);
// result deeply equals newObj
// oldObj is not mutated

Diff Types

Each difference has a type and path:

TypeFieldsDescription
CREATEpath, valueProperty was added
UPDATEpath, oldValue, valueProperty value changed
DELETEpath, oldValueProperty was removed

path is an array of keys/indices: ["users", 0, "name"]

Supported Types

  • Objects (deep recursive)
  • Arrays (element-by-element)
  • Dates (compared by time value)
  • RegExps (compared by string representation)
  • Primitives (string, number, boolean, null, undefined)
  • NaN (correctly handled via Object.is)

API

diff(oldObj, newObj)

Returns Difference[] describing all changes from oldObj to newObj.

applyDiff(target, diffs)

Returns a new object with all diffs applied. Does not mutate the original.

Other Projects

Author

Ofer Shapira

LinkedIn GitHub

License

MIT

Keywords

diff

FAQs

Package last updated on 19 Feb 2026

Did you know?

Socket

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.

Install

Related posts