百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

diff-match-patch-es

> 编程语言
开源

ESM 和 TypeScript 重写了 Google 的 diff-match-patch 程序,适用于 JavaScript

196 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

ESM 和 TypeScript 重写了 Google 的 diff-match-patch 程序,适用于 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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptdff-match-patchdiffesmjavascript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

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