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-diff
sh
pnpm add @opentf/obj-diff
sh
npm install @opentf/obj-diff
sh
deno add @opentf/obj-diff

🛠 Supported Types

The library natively handles the following, at any depth:

TypeNote
Primitivesundefined, null, number, string, boolean, BigInt — compared with Object.is.
Plain objectsOwn enumerable string keys (symbol keys are ignored).
ArrayCompact diffs via prefix/suffix trimming + Myers LCS.
DateCompared by timestamp.
MapDiffed by entries; the Map key itself appears in the path.
SetCompared positionally, by insertion order.
TypedArrayUint8Array, Float32Array, etc. — compared element-wise.
ArrayBuffer / DataViewCompared by their underlying bytes.
Class instancesSame prototype → diffed by own enumerable properties; different classes → reported as replaced.
Last updated on
Edit this page