Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

diff-match-patch-es

> 编程语言
Open source

ESM and TypeScript rewrite of Google's diff-match-patch for JavaScript

196 stars0 likes1 views
WebsiteGitHub

About

ESM and TypeScript rewrite of Google's diff-match-patch for JavaScript

diff-match-patch-es

npm version npm downloads bundle JSDocs License

ESM and TypeScript rewrite of Google's diff-match-patch (for JavaScript).

Features

  • Rewritten in ESM and TypeScript, ships with type declarations
  • Published as pure ESM
  • Refactor all to pure functions, fully tree-shakable

Migration

Migration from diff-match-patch npm package

  • Default export and the class constructor has been removed
  • Function name has been unified to camelCase
  • Previous options like Diff_Timeout and Diff_EditCost are now passed as an options object in the arguments if needed
javascript
// before
import DiffMatchPatch from 'diff-match-patch'

const dmp = new DiffMatchPatch()
dmp.Diff_Timeout = 1
const result = dmp.diff_main('hello', 'world')
javascript
// after
import { diff } from 'diff-match-patch-es'

const result = diff('hello', 'world', { diffTimeout: 1 })

Why?

Well, the code source repo from Google hasn't been updated for 5 years, and the npm package diff-match-patch hasn't been published for 4 years. And the code is not ESM nor tree-shakable. While this library is a composition of diff patch and match functions, sometimes you don't need all of them but since all functions were bound to a single class, all the code has to be included in the bundle. It's probably not a big deal as this whole library is still relatively small, but it's a bit annoying to me when you know something wasn't optimal. So I took an afternoon porting and rewriting the library to ESM and TypeScript. Helpfully it will lead to better maintainability and help the community to move forward with the modern JavaScript ecosystem.

Note for Developers

Releases are published from CI using npm Trusted Publisher (OIDC), so no long-lived npm token is needed. Run pnpm run release to bump the version and push the tag — the Release GitHub Actions workflow takes care of building and publishing.

Sponsors

License

Apache-2.0 License

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptdff-match-patchdiffesmjavascript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言