A JavaScript library for diffing and patching plain objects and arrays, including nested structures. Current stable version is 0.6.0, released as an ES module with TypeScript type definitions. It uses LCS (Longest Common Subsequence) for smart array diffing, supports reverse deltas, unpatching, and optional output formatters. Optionally leverages google-diff-match-patch for long text diffs. Compared to similar libraries, diffpatch focuses on pure JSON delta format and low footprint (~16KB min+gzipped), and requires an objectHash function for object identity matching in arrays.
npm install diffpatchNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic diff, patch, and unpatch operations with primitive and array values using DiffPatcher.
Replace const { DiffPatcher } = require('diffpatch') with import { DiffPatcher } from 'diffpatch'.Use import { DiffPatcher } from 'diffpatch' instead of import DiffPatcher from 'diffpatch'.Use new DiffPatcher() instead of createPatcher().
const dp = new DiffPatcher({ objectHash: obj => obj.id })Use diffpatch both for producing and consuming deltas.
Upgrade to Node.js >= 8.
Run 'npm install diffpatch' and ensure import path is 'diffpatch' (not 'diffpatch-master' or similar).
Replace 'import DiffPatcher from "diffpatch"' with 'import { DiffPatcher } from "diffpatch"'.Ensure you have imported { DiffPatcher } and use 'new DiffPatcher()'.Verify you created an instance: const dp = new DiffPatcher();