@benedicte/html-diff

中文文档
0.1.0发布于 2025/05/08MITTypeScriptESM + CJS零依赖近 30 天下载 9783

A lightweight JavaScript library to highlight changes between two HTML strings. It wraps inserted content with <ins> tags and deleted content with <del> tags, making it ideal for visualizing diffs in rich text content.

原始使用文档
文档目录7 节
  1. 🚀 Features
  2. 🌐 Demo
  3. 📦 Installation
  4. 🛠️ API
  5. 💡 Examples
  6. 🔒 License
  7. 🤝 Contributing

html-diff

A lightweight JavaScript library to highlight changes between two HTML strings. It wraps inserted content with <ins> tags and deleted content with <del> tags, making it ideal for visualizing diffs in rich text content.


🚀 Features

  • 🔍 Detects and highlights changes between two HTML strings
  • 🧩 Wraps insertions in <ins> and deletions in <del>
  • ⚡ No external dependencies
  • ✅ Works in both browser and Node.js environments

🌐 Demo

You can see a live demo of html-diff in action here: Demo

📦 Installation

Install via npm:

npm install @benedicte/html-diff

🛠️ API

htmlDiff(htmlBefore: string, htmlAfter: string): string

Parameters:

  • htmlBefore (required) – Original HTML string
  • htmlAfter (required) – Updated HTML string

Returns the resulting HTML string with:

  • Inserted content is wrapped in tags
  • Deleted content is wrapped in tags

💡 Examples

import { htmlDiff } from '@benedicte/html-diff';

const before = '<p>Hello world!</p>';
const after = '<p>Hello brave new world</p>';
const result = htmlDiff(before, after);

console.log(result);
// Output: <p>Hello <ins>brave new </ins>world<del>!</del></p>

🔒 License

MIT

🤝 Contributing

Contributions, bug reports, and feature requests are welcome! Feel free to open an issue or submit a pull request.

版本与发布记录

@benedicte/html-diff 共发布 2 个版本,首次发布于 2025/05/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.0latest2025/05/081.5 年前
0.1.0-rc12025/05/081.5 年前

关于 @benedicte/html-diff 的常见问题

@benedicte/html-diff 是什么?

A lightweight JavaScript library to highlight changes between two HTML strings. It wraps inserted content with <ins> tags and deleted content with <del> tags, making it ideal for visualizing diffs in rich text content.

如何安装 @benedicte/html-diff?

在项目目录运行 npm install @benedicte/html-diff,或使用 pnpm add / yarn add / bun add。

@benedicte/html-diff 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@benedicte/html-diff 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@benedicte/html-diff 可以商用吗?

@benedicte/html-diff 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@benedicte/html-diff 的下载量有多少?

根据 npm 官方下载统计,@benedicte/html-diff 在 2026/10/08 – 2026/11/06 这 30 天内被下载 9,783 次,日均约 326 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@benedicte/html-diff 还在维护吗?

最新版本 0.1.0 发布于 2025/05/08(1.5 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/05/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。