Introduction
@opentf/obj-diff is the fast, accurate, and modern JavaScript Objects Diffing & Patching Library.
🚀 Features
🔍 Deep Objects Diffing: Detects changes at any depth.
✂️ Compact Array Diffs: Shortest edit scripts (Myers LCS) — inserting one element into a 10k array yields 1 op, not 10,001.
🩹 Efficient Patching: Apply diffs to recreate target objects.
🛠️ Extensible: Support for custom object types via
diffWith().📦 Modern Ecosystem: Built for Bun, Node.js, Deno, and Browser.
🟦 TypeScript Native: Full type safety and autocompletion.
⚡ High Performance: Optimized for speed and minimal memory footprint.
📦 Installation
Install @opentf/obj-diff using your preferred package manager:
sh
bun add @opentf/obj-diffsh
pnpm add @opentf/obj-diffsh
npm install @opentf/obj-diffsh
deno add @opentf/obj-diff🛠 Supported Types
The library natively handles the following, at any depth:
| Type | Note |
|---|---|
| Primitives | undefined, null, number, string, boolean, BigInt — compared with Object.is. |
| Plain objects | Own enumerable string keys (symbol keys are ignored). |
Array | Compact diffs via prefix/suffix trimming + Myers LCS. |
Date | Compared by timestamp. |
Map | Diffed by entries; the Map key itself appears in the path. |
Set | Compared positionally, by insertion order. |
TypedArray | Uint8Array, Float32Array, etc. — compared element-wise. |
ArrayBuffer / DataView | Compared by their underlying bytes. |
| Class instances | Same prototype → diffed by own enumerable properties; different classes → reported as replaced. |