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
271stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
38/100Needs Attention
Development Activity0
Maintenance20
Community52
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
58/100Fair
Architecture70
Code Quality65
Innovation30
Learning Curve65

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 8 apps in this directory

TypeScript
94%
AGPL 3.0

Element Web

Team Chat · Collaboration

13,437

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
TypeScript94%
Updated yesterday
Rust
67%
Other

GitButler

Developer Tools · Devops · AI Development

21,624

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
67
Dependency
Built with
Rust67%
TypeScript20%
Svelte11%
Updated yesterday
TypeScript
83%
Apache 2.0

Grist

Databases · No Code Platforms

11,726

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
TypeScript83%
Python11%
Updated yesterday
TypeScript
76%
Other

Joplin

Note Taking

56,257

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
61
Dependency
Built with
TypeScript76%
JavaScript14%
Updated yesterday
Clojure
70%
AGPL 3.0

Logseq

Note Taking · Knowledge Management

44,800

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
Clojure70%
OCaml12%
Updated yesterday
JavaScript
55%
Other

Lokus

Note Taking · Knowledge Management

788

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

View details
77
Repo Health
75
Technical
65
Dependency
Built with
JavaScript55%
HTML21%
Rust12%
Updated 1 weeks ago
JavaScript
26%
AGPL 3.0

Omnivore

Knowledge Management · Bookmarks Archiving · Note Taking

16,228

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

View details
88
Repo Health
74
Technical
65
Dependency
Built with
JavaScript26%
TypeScript25%
HTML19%
Updated 2 days ago
JavaScript
86%
AGPL 3.0

SillyTavern

AI Assistants

33,071

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
68
Repo Health
71
Technical
67
Dependency
Built with
JavaScript86%
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

Search