microdiff

A tiny, zero-dependency library for deep diffing objects and arrays with full TypeScript support.

Library
npm
v1.6.0
3,874 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
54 /100 Fair
Development Activity 36
Maintenance 36
Community 48
Maturity 56
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
63 /100 Good
Architecture 72
Code Quality 65
Innovation 70
Learning Curve 45

Microdiff is a sub-1kb JavaScript library that computes the difference between two objects or arrays, returning a flat list of CREATE, REMOVE, and CHANGE operations along with the path to each changed property. It has zero runtime dependencies, ships full TypeScript type definitions, and runs identically across Node, Deno, Bun, browsers, and service workers.

Under the hood, Microdiff walks both objects in a single recursive pass, using strict equality augmented with special-cased handling for Date, RegExp, String/Number wrapper objects, and Temporal types. An optional cycle-detection stack (enabled by default) lets it safely diff self-referential structures without infinite recursion, and it can be disabled via the cyclesFix: false option for a speed boost when inputs are known to be cycle-free, such as parsed JSON.

What You Get

  • A single diff(oldObj, newObj, options) function that returns an array of typed difference records
  • TypeScript type definitions for Difference, DifferenceCreate, DifferenceRemove, and DifferenceChange out of the box
  • Built-in cycle detection for self-referential objects, toggleable via the cyclesFix option
  • Special-case handling for Date, RegExp, and Temporal values so semantically equal instances aren’t reported as changed
  • Zero runtime dependencies and a sub-1kb minified/gzipped footprint

Common Use Cases

  • Detecting which fields changed between two versions of a form or a Redux/Zustand-style state snapshot
  • Building undo/redo or audit-log systems that need a precise path to each mutation
  • Comparing API response payloads in tests to assert only expected fields changed
  • Powering real-time sync engines that need to ship minimal changesets over the wire

Under The Hood

Architecture The entire library is one recursive diff() function exported from index.ts: it iterates the keys of the old value looking for removed or changed entries, recurses into nested objects/arrays that share a compatible shape, then does a second pass over the new value’s keys to find additions. There’s no internal layering because the problem doesn’t need one — recursion handles nesting, and a _stack array (not part of the public options) threads cycle-detection state through recursive calls without a class or external state container. This keeps the implementation compact, though the dense conditional logic mixing type detection, rich-type comparison, and recursion in one function block makes it slightly harder to extend without touching several branches at once.

Tech Stack The TypeScript source is compiled twice by the same tsc invocation — once targeting CommonJS, once targeting ES2020 — with shx renaming the CJS build’s output extensions to .cjs/.d.cts so npm’s exports map can serve both module systems from a single source file. The package depends on zero runtime packages; devDependencies are limited to prettier for formatting, terser for measuring minified/gzipped size, and mitata for benchmarking against competing diff libraries (deep-diff, deep-object-diff, diff) in bench.js.

Code Quality Tests run on Node’s built-in node:test runner with assert.deepStrictEqual — no external test framework — split into dedicated files per concern (basic.js, arrays.js, dates.js, regex.js, cycles.js, nan.js, class-primitives.js, temporal.js) that cover edge cases like null-prototype objects, self-referential cycles, NaN equality, and the newer Temporal API. There is no GitHub Actions CI workflow in .github/ (only issue templates), so this test suite isn’t automatically enforced on push or PR. TypeScript’s declaration: true output gives consumers full type coverage, and the single-file source keeps naming consistent, though there’s no explicit input validation — the function assumes well-formed object/array arguments.

API Design The public surface is one default export, diff(oldObj, newObj, options), so getting started requires a single import and a single call with no configuration. The only knob exposed is cyclesFix, a clear opt-out for trading safety against speed when inputs are known to be cycle-free. Output is more granular than most competing diff libraries — each change carries a path array pinpointing exactly where it occurred rather than just a whole-value comparison — and the README backs its speed claims with its own benchmark numbers against deep-diff, deep-object-diff, and jsDiff.

Used by 5 apps in this directory

TypeScript
68%
Apache 2.0

Appsmith

Automation · Developer Tools · No Code Platforms

40,959

Open-source low-code platform to build admin panels, dashboards, and internal tools connected to any database or API.

View details
93
Repo Health
79
Technical
66
Dependency
Built with
TypeScript 68%
Java 21%
Updated 1 weeks ago
TypeScript
51%
MIT

Ghost

Blogging · CMS

55,450

Open source headless Node.js CMS for professional publishing, paid memberships, and newsletters with a fully owned audience.

View details
96
Repo Health
85
Technical
67
Dependency
Built with
TypeScript 51%
JavaScript 44%
Updated 5 days ago
TypeScript
55%
Other

OpenReplay

Analytics

12,911

Self-hosted session replay and product analytics suite that lets you see exactly what users do on your web app — without sending data to third parties.

View details
90
Repo Health
77
Technical
66
Dependency
Built with
TypeScript 55%
Go 13%
Updated 1 weeks ago
TypeScript
65%
MIT

Scalar

Developer Tools

16,198

Beautiful, interactive OpenAPI documentation with a built-in offline-first API client and multi-language code generation — all in one open-source platform.

View details
90
Repo Health
89
Technical
65
Dependency
Built with
TypeScript 65%
Vue 30%
Updated 5 days ago
TypeScript
82%
Other

twenty

CRM

57,585

The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.

View details
92
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 82%
MDX 15%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers