# @asyncapi/diff 中文文档

规范地址：https://npmcn.com/package/%40asyncapi/diff/

版本：0\.6\.1
npm 元数据更新时间：2026-11-02T08:25:24.970Z
中文译文更新时间：2026-11-07T01:37:37.747Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40asyncapi/diff
原文对照：https://npmcn.com/package/%40asyncapi/diff/?lang=original
项目主页：https://github.com/asyncapi/cli/tree/master/packages/diff#readme
源码仓库：https://github.com/asyncapi/cli

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：168 kB，60 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：3 个
- 首次发布：2021-06-08T08:46:12.291Z
- 最新版本发布：2026-11-02T08:25:24.609Z
- 近 30 天下载量：312621（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：12（近 12 个月 4 个）

## 中文简介

比较两个 AsyncAPI 文件和报告破损,不破损,以及未分类的更改的库.

## 安装

```sh
npm install @asyncapi/diff
```

也可以使用：`pnpm add @asyncapi/diff`、`yarn add @asyncapi/diff`、`bun add @asyncapi/diff`

## README

[![AsyncAPI Diff](https://npmcn.com/assets/logo.png)](https://www.asyncapi.com/)

AsyncDiff是一个比较了两个AsyncAPI文件的库,通过明确指出像突破更改一样的信息来提供差异信息.

> **这个包裹现在生活在 [`asyncapi/cli`](https://github.com/asyncapi/cli) 单相** 下级 `packages/diff/` 从那里释放(同一个 npm 名称) `@asyncapi/diff`) (中文(简体) ). 比较规则不变. `AsyncAPIDiff` 从软件包条目导出,而两个 输入错误为 `TypeError` 有稳定的子类 `.code`。参见规格 : [`docs/diff/spec.md`](https://github.com/asyncapi/cli/blob/master/docs/diff/spec.md)。 。 。 .

![npm](https://img.shields.io/npm/v/@asyncapi/diff?style=for-the-badge) ![npm](https://img.shields.io/npm/dt/@asyncapi/diff?style=for-the-badge)

-   [特征](https://npmcn.com/package/%40asyncapi/diff/#readme-features)
-   [安装](https://npmcn.com/package/%40asyncapi/diff/#readme-installation)
-   [使用量](https://npmcn.com/package/%40asyncapi/diff/#readme-usage)
-   [标准对象](https://npmcn.com/package/%40asyncapi/diff/#readme-standard-object)
    -   [超越标准](https://npmcn.com/package/%40asyncapi/diff/#readme-overriding-the-standard)
-   [示例](https://npmcn.com/package/%40asyncapi/diff/#readme-example)
-   [产出](https://npmcn.com/package/%40asyncapi/diff/#readme-output)
-   [API 密码](https://npmcn.com/package/%40asyncapi/diff/#readme-api)
-   [开发](https://npmcn.com/package/%40asyncapi/diff/#readme-develop)
-   [捐款](https://npmcn.com/package/%40asyncapi/diff/#readme-contributing)
-   [贡献者](https://npmcn.com/package/%40asyncapi/diff/#readme-contributors)

## 特征

-   获取关于您对 AsyncAPI 文件所做的更改的清晰信息, 如破解、 未破解和未解密的更改 .
-   JSON,YAML和Markdown等不同类型的输出.

## 安装

```
npm install @asyncapi/diff
```

## 使用量

**注:** 库中没有内置的解析器来解析给定的AsyncAPI文档. 因此,您必须确保它们作为输入提供有效的AsyncAPI文档。 你可以用这个 [AsyncAPI 解析器](https://github.com/asyncapi/parser-js) 首先分析并验证 AsyncAPI 文件。 你可以使用其他的工具,但你 **必须** 确保文档是有效的,并进行调试.

```js
import { diff } from "@asyncapi/diff"; // const { diff } = require('@asyncapi/diff');

const output = diff(firstDocument, secondDocument, {
  override: {
    // object to override the standard
  },
});
```

## 标准对象

此库有一个预设的标准,标记为 `breaking`, (中文(简体) ), `non-breaking` 或者说 `unclassified`本标准数据作为对象存储于 [`standard.ts`](https://github.com/asyncapi/cli/blob/master/packages/diff/src/standard.ts) 文档.

此标准对象的格式解释如下: [这个](https://npmcn.com/package/%40asyncapi/diff/standard-format.md) 文档.

### 超越标准

要了解压倒性对象的格式,请看 [这个](https://npmcn.com/package/%40asyncapi/diff/standard-format.md) 文档.

覆盖对象必须以下列格式传递:

```
{
    [jsonPointer]: {
        add: 'breaking' | 'non-breaking' | 'unclassified'
        remove: 'breaking' | 'non-breaking' | 'unclassified'
        edit: 'breaking' | 'non-breaking' | 'unclassified'
    }
}
```

## 示例

见 [指数](https://npmcn.com/package/%40asyncapi/diff/docs/modules/index.md) 文档以获取此库提供的所有帮助方法.

1.  没有任何覆盖

```js
const output = diff(firstDocument, secondDocument);

output.getOutput(); // the whole output data
output.breaking(); // the breaking changes
output.nonBreaking(); // the non-breaking changes
output.unclassified(); // the unclassified changes
```

2.  带有超音速

```js
const output = diff(firstDocument, secondDocument, {
  override: {
    "/servers/*/protocol": {
      add: "non-breaking",
      remove: "breaking",
      edit: "unclassified",
    },
  },
});
```

## 产出

该库支持以下产出:

-   贾森: `json`
-   亚马逊: `yaml` 或者说 `yml`
-   标记下 : `markdown` 或者说 `md`

```js
const jsonOutput = diff(firstDocument, secondDocument, {
  outputType: "json",
});

const yamlOutput = diff(firstDocument, secondDocument, {
  outputType: "yaml" | "yml",
});

const markdownOutput = diff(firstDocument, secondDocument, {
  outputType: "markdown" | "md",
});
```

降标输出后,您也可以选择更改的子类型为 JSON ()`json`) 或 YAML( 或 YAML ()`yaml` 或者说 `yml`) (中文(简体) ).

```js
const markdownOutput = diff(firstDocument, secondDocument, {
  outputType: "markdown" | "md",
  markdownSubtype: "json" | "yaml" | "yml",
});
```

## API 密码

检查 [指数](https://npmcn.com/package/%40asyncapi/diff/docs/modules/index.md) 文档来查看此库提供的所有 API .

## 开发

1.  密码和测试
2.  确保所有测试通过 `npm run test`
3.  确保代码格式良好且安全 `npm run lint`

## 捐款

帮助我们使这个图书馆更加坚固. 读取 [捐款](https://github.com/asyncapi/.github/blob/master/CONTRIBUTING.md) 引导并开始贡献.

## 贡献者

感谢这些伟大的人[emoji 密钥](https://allcontributors.org/docs/en/emoji-key):

<table><tbody><tr><td align="center"><a href="https://aayushsahu.com/" rel="nofollow noopener noreferrer"><img alt="" src="https://avatars.githubusercontent.com/u/54525741?v=4?s=100" width="100px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>阿尤什·库马尔·萨胡</b></sub></a><br><a href="https://github.com/aayushmau5/diff/commits?author=aayushmau5" title="Code" rel="nofollow noopener noreferrer">💻</a> <a href="https://github.com/aayushmau5/diff/commits?author=aayushmau5" title="Documentation" rel="nofollow noopener noreferrer">📖</a> <a href="https://npmcn.com/package/%40asyncapi/diff/#readme-maintenance-aayushmau5" title="Maintenance" rel="nofollow noopener noreferrer">🚧</a> <a href="https://npmcn.com/package/%40asyncapi/diff/#readme-ideas-aayushmau5" title="Ideas, Planning, &amp; Feedback" rel="nofollow noopener noreferrer">🤔</a> <a href="https://github.com/aayushmau5/diff/pulls?q=is%3Apr+reviewed-by%3Aaayushmau5" title="Reviewed Pull Requests" rel="nofollow noopener noreferrer">👀</a> <a href="https://github.com/aayushmau5/diff/commits?author=aayushmau5" title="Tests" rel="nofollow noopener noreferrer">⚠️</a></td><td align="center"><a href="https://www.brainfart.dev/" rel="nofollow noopener noreferrer"><img alt="" src="https://avatars.githubusercontent.com/u/6995927?v=4?s=100" width="100px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>卢卡斯·戈尔尼茨基</b></sub></a><br><a href="https://npmcn.com/package/%40asyncapi/diff/#readme-ideas-derberg" title="Ideas, Planning, &amp; Feedback" rel="nofollow noopener noreferrer">🤔</a> <a href="https://github.com/aayushmau5/diff/pulls?q=is%3Apr+reviewed-by%3Aderberg" title="Reviewed Pull Requests" rel="nofollow noopener noreferrer">👀</a> <a href="https://npmcn.com/package/%40asyncapi/diff/#readme-maintenance-derberg" title="Maintenance" rel="nofollow noopener noreferrer">🚧</a></td><td align="center"><a href="https://github.com/magicmatatjahu" rel="nofollow noopener noreferrer"><img alt="" src="https://avatars.githubusercontent.com/u/20404945?v=4?s=100" width="100px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>马西杰·乌尔班奇克</b></sub></a><br><a href="https://github.com/aayushmau5/diff/pulls?q=is%3Apr+reviewed-by%3Amagicmatatjahu" title="Reviewed Pull Requests" rel="nofollow noopener noreferrer">👀</a></td><td align="center"><a href="https://github.com/jonaslagoni" rel="nofollow noopener noreferrer"><img alt="" src="https://avatars.githubusercontent.com/u/13396189?v=4?s=100" width="100px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>乔纳斯·拉戈尼</b></sub></a><br><a href="https://github.com/aayushmau5/diff/pulls?q=is%3Apr+reviewed-by%3Ajonaslagoni" title="Reviewed Pull Requests" rel="nofollow noopener noreferrer">👀</a></td><td align="center"><a href="https://github.com/vinitshahdeo" rel="nofollow noopener noreferrer"><img alt="" src="https://avatars.githubusercontent.com/u/20594326?v=4?s=100" width="100px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>维尼特·沙德奥</b></sub></a><br><a href="https://github.com/aayushmau5/diff/pulls?q=is%3Apr+reviewed-by%3Avinitshahdeo" title="Reviewed Pull Requests" rel="nofollow noopener noreferrer">👀</a></td><td align="center"><a href="https://www.linkedin.com/in/anubhav-vats-0688b5187/" rel="nofollow noopener noreferrer"><img alt="" src="https://avatars.githubusercontent.com/u/46771418?v=4?s=100" width="100px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>阿努比哈夫·瓦兹</b></sub></a><br><a href="https://github.com/aayushmau5/diff/pulls?q=is%3Apr+reviewed-by%3Aonbit-uchenik" title="Reviewed Pull Requests" rel="nofollow noopener noreferrer">👀</a></td></tr><tr><td align="center"><a href="https://github.com/shivensinha4" rel="nofollow noopener noreferrer"><img alt="" src="https://avatars.githubusercontent.com/u/19777714?v=4?s=100" width="100px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>谢文·辛哈</b></sub></a><br><a href="https://github.com/aayushmau5/diff/commits?author=shivensinha4" title="Code" rel="nofollow noopener noreferrer">💻</a> <a href="https://github.com/aayushmau5/diff/commits?author=shivensinha4" title="Tests" rel="nofollow noopener noreferrer">⚠️</a></td><td align="center"><a href="https://github.com/ron-debajyoti" rel="nofollow noopener noreferrer"><img alt="" src="https://avatars.githubusercontent.com/u/22571664?v=4?s=100" width="100px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>德巴吉奥蒂·哈尔德</b></sub></a><br><a href="https://github.com/aayushmau5/diff/commits?author=ron-debajyoti" title="Documentation" rel="nofollow noopener noreferrer">📖</a></td></tr></tbody></table>

本项目遵循 [全部贡献者](https://github.com/all-contributors/all-contributors) 规格。 任何捐款都欢迎!

## 常见问题

### @asyncapi/diff 是什么？

比较两个 AsyncAPI 文件和报告破损,不破损,以及未分类的更改的库\.

### 如何安装 @asyncapi/diff？

在项目目录运行 npm install @asyncapi/diff，或使用 pnpm add / yarn add / bun add。

### @asyncapi/diff 支持 TypeScript 吗？

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

### @asyncapi/diff 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @asyncapi/diff 可以商用吗？

@asyncapi/diff 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @asyncapi/diff 的下载量有多少？

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

### @asyncapi/diff 还在维护吗？

最新版本 0\.6\.1 发布于 2026/11/02（5 天前）；至今共发布 12 个版本，其中过去 12 个月发布了 4 个；首次发布于 2021/06/08。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

