@omerdev/tiny-diff
v1.0.1
Published
Ultra-fast zero-dependency structural diff, patch, deep equality, and delta utility for objects and arrays (<1.5KB)
Maintainers
Readme
🔍 @omerdev/tiny-diff
Ultra-fast zero-dependency structural diff, patch, deep equality, and delta utility for objects and arrays (<1.5KB).
⚡ Why tiny-diff?
- Zero Dependencies: Less than 1.5KB gzipped footprint.
- Deep Equality: Checks nested objects, arrays, Dates, RegExps, Sets, Maps, and handles circular references safely.
- Structural Diffing: Produces minimal atomic change sets (
add,remove,replace) with full path segments. - Patch Engine: Re-applies diffs immutably or mutably to bring objects up-to-date.
- Deep Clone: Fast and reliable deep cloning across standard JavaScript built-ins.
- Flatten & Unflatten: Convert nested hierarchies into dot-notated objects and back.
📦 Installation
npm install @omerdev/tiny-diff
# or
pnpm add @omerdev/tiny-diff
# or
bun add @omerdev/tiny-diff💡 Quick Start
1. Deep Equality
import { deepEqual } from "@omerdev/tiny-diff";
deepEqual({ a: [1, 2], date: new Date(2025, 0, 1) }, { a: [1, 2], date: new Date(2025, 0, 1) });
// => true2. Computing Diffs
import { diff } from "@omerdev/tiny-diff";
const oldUser = { name: "Alice", age: 30, tags: ["admin"] };
const newUser = { name: "Alice", age: 31, tags: ["admin", "editor"] };
const changes = diff(oldUser, newUser);
/*
[
{ type: "replace", path: ["age"], oldValue: 30, value: 31 },
{ type: "add", path: ["tags", 1], value: "editor" }
]
*/3. Patching Objects
import { patch } from "@omerdev/tiny-diff";
const updated = patch(oldUser, changes);
// returns brand new object matching newUser4. Flatten & Unflatten
import { flatten, unflatten } from "@omerdev/tiny-diff";
const flat = flatten({ user: { profile: { name: "Bob" } } });
// { "user.profile.name": "Bob" }
const nested = unflatten(flat);
// { user: { profile: { name: "Bob" } } }👤 Author
omerdev
📄 License
MIT
