Fast deep object diff with full TypeScript types. Zero dependencies. ~1.4KB.
npm install deep-diff-tsimport { 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" }
// ]import { diff, applyDiff } from "deep-diff-ts";
const changes = diff(oldObj, newObj);
const result = applyDiff(oldObj, changes);
// result deeply equals newObj
// oldObj is not mutatedEach difference has a type and path:
| Type | Fields | Description |
|---|---|---|
CREATE |
path, value |
Property was added |
UPDATE |
path, oldValue, value |
Property value changed |
DELETE |
path, oldValue |
Property was removed |
path is an array of keys/indices: ["users", 0, "name"]
- 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)
Returns Difference[] describing all changes from oldObj to newObj.
Returns a new object with all diffs applied. Does not mutate the original.
- ts-result — Rust-style Result<T, E> for TypeScript
- ts-nano-event — Typed event emitter in <200 bytes
- hover-effects — Canvas-based hover effects for images
MIT
