diff-match-patch

A battle-tested JavaScript port of Google's diff-match-patch engine for computing, applying, and fuzzy-matching text differences.

Library
npm
v1.0.5
271 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
38 /100 Needs Attention
Development Activity 0
Maintenance 20
Community 52
Maturity 60
Momentum 20

Technical Analysis

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

diff-match-patch is the npm-packaged JavaScript port of Google’s original diff-match-patch library, an algorithm engine for comparing, matching, and patching plain text. It computes diffs between two strings, offers cleanup passes that turn raw character-level diffs into human-readable or storage-efficient results, locates approximate substring matches using a bitap-based fuzzy search, and generates and applies GNU-diff-style patches even against text that has since changed.

The library exposes a single diff_match_patch constructor with three families of prototype methods: diff_* for computing and formatting differences, match_* for approximate substring location, and patch_* for creating, serializing, and applying patch sets. It has no runtime dependencies, ships as a single file, and is used as a building block inside editors, sync engines, and other tools that need to compute and reconcile text changes.

What You Get

  • Text diffing via diff_main with a configurable timeout and line-mode preprocessing for large documents
  • Diff cleanup functions (diff_cleanupSemantic, diff_cleanupEfficiency) that turn raw character-level diffs into human-readable or storage-efficient results
  • Fuzzy substring matching via match_main using a bitap algorithm with tunable distance/threshold parameters
  • Patch creation, serialization (patch_toText/patch_fromText), and fault-tolerant application (patch_apply) against modified text

Common Use Cases

  • Collaborative text editors computing and merging concurrent edits between two versions of a document
  • Version-control or diff viewers rendering human-readable diffs between two revisions of a text file
  • Sync engines applying patches generated against an older version of text even after the target has drifted
  • Wiki and CMS platforms needing lightweight text-level diffing without a full diff/merge toolchain

Under The Hood

Architecture diff-match-patch ships as a single ~2200-line file exposing one diff_match_patch constructor with prototype methods, rather than a modular multi-file architecture; state (Diff_Timeout, Match_Threshold, Match_Distance, Patch_DeleteThreshold, Patch_Margin) lives entirely on instance properties set in the constructor and read by every prototype method. The three functional groups — diff_, match_, patch_* — are separated purely by naming convention and file section rather than by module boundary, and diffs flow between functions as plain [op, text] tuple arrays with no wrapping abstraction, so changing that core representation would ripple through nearly every method in the file. This mirrors the structure of Google’s original Java/Python/C++ implementations that the library is ported from, favoring a direct algorithmic port over idiomatic modern JavaScript module design.

Tech Stack The package has zero runtime dependencies and a single devDependency, the lightweight testit test runner. It ships as plain, pre-ES6 JavaScript (var, function expressions, no classes, no let/const) for maximum compatibility across Node and browser environments, requires no build or bundling step, and is consumed directly via CommonJS require. Continuous integration runs through a GitHub Actions workflow (.github/workflows/test.yml) that installs on Node 16 and runs npm test on every push and pull request.

Code Quality A dedicated test suite (test/index.js, over 1,000 lines) exercises diff, match, and patch behavior using custom equivalence-assertion helpers built on Node’s assert module, and is wired into CI. There is no TypeScript and no visible linter/formatter configuration, so type safety and style consistency rely entirely on convention and code review rather than tooling. Error handling follows the ported algorithm’s original design — functions return sentinel values (e.g. -1 for match_main) rather than throwing — and naming is consistent throughout (public diff_/match_/patch_ methods vs. trailing-underscore private helpers).

What Makes It Unique This package doesn’t introduce a novel algorithm — it’s a direct, well-established port of Google’s public diff-match-patch engine (Myers-style diffing, bitap fuzzy matching, and drift-tolerant patch application), the same algorithm many other language ports and consuming tools rely on. Its value is as a stable, dependency-free, long-lived reference implementation of that algorithm for JavaScript environments rather than any implementation innovation of its own.

Used by 9 apps in this directory

TypeScript
94%
AGPL 3.0

Element Web

Collaboration · Team Chat

13,518

A polished, self-hostable Matrix client for secure, decentralized messaging and collaboration that puts your organization in full control of its data.

View details
96
Repo Health
83
Technical
65
Dependency
Built with
TypeScript 94%
Updated 6 days ago
Rust
65%
Other

GitButler

AI Development · Developer Tools · Devops

21,726

Git, but better — a modern version control client with stacked branches, parallel workflows, unlimited undo, and first-class support for AI-powered development.

View details
89
Repo Health
84
Technical
66
Dependency
Built with
Rust 65%
TypeScript 22%
Svelte 10%
Updated 5 days ago
TypeScript
83%
Apache 2.0

Grist

Databases · No Code Platforms

11,875

A modern relational spreadsheet that combines Python-powered formulas, drag-and-drop dashboards, and granular access controls in a self-hostable, SQLite-backed data platform.

View details
91
Repo Health
93
Technical
66
Dependency
Built with
TypeScript 83%
Python 11%
Updated 6 days ago
TypeScript
77%
Other

Joplin

Note Taking

56,513

The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.

View details
93
Repo Health
87
Technical
60
Dependency
Built with
TypeScript 77%
JavaScript 14%
Updated 6 days ago
Clojure
70%
AGPL 3.0

Logseq

Knowledge Management · Note Taking

45,069

A privacy-first, open-source knowledge graph platform combining Markdown, Org-mode, bidirectional linking, and local-first storage for building your second brain.

View details
92
Repo Health
82
Technical
68
Dependency
Built with
Clojure 70%
OCaml 12%
Updated 5 days ago
JavaScript
55%
Other

Lokus

Knowledge Management · Note Taking

802

Local-first note-taking with graph view, canvas & AI plugins—your Markdown files, zero telemetry, blazing-fast Rust performance.

View details
78
Repo Health
75
Technical
65
Dependency
Built with
JavaScript 55%
HTML 21%
Rust 12%
Updated 1 months ago
JavaScript
26%
AGPL 3.0

Omnivore

Bookmarks Archiving · Knowledge Management · Note Taking

16,265

Self-hosted read-it-later platform with highlights, newsletters, PDFs, and seamless Obsidian and Logseq integration.

View details
90
Repo Health
74
Technical
65
Dependency
Built with
JavaScript 26%
TypeScript 25%
HTML 19%
Updated 6 days ago
TypeScript
97%
GPL 3.0

OpenKnowledge

Code Editors · Knowledge Management · Note Taking

4,337

A beautiful, local-first markdown IDE that turns any git repo into a live collaborative workspace for humans and AI coding agents like Claude, Codex, and OpenCode.

View details
79
Repo Health
89
Technical
64
Dependency
Built with
TypeScript 97%
Updated 5 days ago
JavaScript
86%
AGPL 3.0

SillyTavern

AI Assistants

33,853

The power-user LLM frontend that unifies dozens of AI backends with a rich scripting engine, immersive Visual Novel mode, and a thriving extension ecosystem.

View details
91
Repo Health
71
Technical
67
Dependency
Built with
JavaScript 86%
Updated 1 weeks 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