# @github/issue-parser 中文文档

规范地址：https://npmcn.com/package/%40github/issue-parser/

版本：2\.0\.0
npm 元数据更新时间：2026-10-15T16:21:06.493Z
中文译文更新时间：2026-11-16T11:34:51.333Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40github/issue-parser
原文对照：https://npmcn.com/package/%40github/issue-parser/?lang=original
项目主页：https://github.com/github/issue-parser#readme
源码仓库：https://github.com/github/issue-parser

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

- 包体积（解压后）：904 kB，73 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- Node.js 要求：\>=20
- 运行依赖：1 个
- 首次发布：2024-11-05T15:46:08.974Z
- 最新版本发布：2025-02-13T19:43:08.006Z
- 近 30 天下载量：5189（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：4（近 12 个月 0 个）

## 中文简介

转换 JSON 的版本响应

## 安装

```sh
npm install @github/issue-parser
```

也可以使用：`pnpm add @github/issue-parser`、`yarn add @github/issue-parser`、`bun add @github/issue-parser`

## README

# 问题窗体解析器

![Check dist/](https://github.com/github/issue-parser/actions/workflows/check-dist.yml/badge.svg) ![Code Coverage](https://npmcn.com/package/%40github/issue-parser/badges/coverage.svg) ![CodeQL](https://github.com/github/issue-parser/actions/workflows/codeql.yml/badge.svg) ![Continuous Integration](https://github.com/github/issue-parser/actions/workflows/continuous-integration.yml/badge.svg) ![Continuous Delivery](https://github.com/github/issue-parser/actions/workflows/continuous-delivery.yml/badge.svg) ![Linter](https://github.com/github/issue-parser/actions/workflows/linter.yml/badge.svg)

转换 JSON 的版本响应

## 关于

此软件包可用于将 GitHub 问题解析为机器可读 JSON 处理。 特别是,它旨在与 [发行表格](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms) 使问题机构实现基本转变,从而实现一致性 JSON输出.

使用问题表格提交的问题采用结构化的Markdown格式. **再见 由于发行机构没有被用户大量修改,** 我们可以可靠地分析 问题体变成 JSON 对象.

## 安装

```bash
npm i @github/issue-parser
```

## 示例

以下是一个简单的例子,说明如何在您的工程中使用此软件包.

```typescript
import { parseIssue } from '@github/issue-parser'

const issue = parseIssue('<issue body>', '<template>')
```

假设问题和模板看起来像这些例子:

-   [示例问题标记](https://npmcn.com/package/%40github/issue-parser/__fixtures__/example/issue.md)
-   [示例模板 YAML](https://npmcn.com/package/%40github/issue-parser/__fixtures__/example/template.yml)

结果 `issue` 对象的外观如下:

```typescript
{
  name: 'this-thing',
  nickname: 'thing',
  color: ['blue'],
  shape: ['square'],
  sounds: ['re', 'mi'],
  topics: [],
  description: "This is a description.\n\nIt has multiple lines.\n\nIt's pretty cool!",
  notes: '- Note\n- Another note\n- Lots of notes',
  code: 'const thing = new Thing()\nthing.doThing()',
  'code-string': 'thing.toString()',
  'is-thing': {
    selected: ['Yes'],
    unselected: ['No']
  },
  'is-thing-useful': {
    selected: ['Sometimes'],
    unselected: ['Yes', 'No']
  },
  'read-team': 'IssueOps-Demo-Readers',
  'write-team': 'IssueOps-Demo-Writers'
}
```

## 使用量

### `parseIssue`

这是软件包的主要功能. 这需要两个论点:

-   `issue: string` - 要解析的问题的正文
-   `template: string` - (可选) 用于创建 问题
-   `options?: { slugify?: boolean }` - (备选)附加解析选项 处理问题主体时使用

如果 `template` 将尝试改变 以 `type` 财产的财产 模板中的特定字段。 如果 `template` 数值被省略,全部解析 值将作为字符串返回。 关于转型的信息 应用,参见 [转换](https://npmcn.com/package/%40github/issue-parser/#readme-transformations) 节.

#### 分析选项

-   `slugify: boolean` - 如果设置为 `true`,任何未在 问题表格模板(如果提供了)将转换为 [弹片](https://en.wikipedia.org/wiki/Clean_URL#Slug) 使用 [拼写](https://www.npmjs.com/package/slugify) 软件包。 否则 原始头值将作为对象键使用.

### `parseTemplate(template?: string)`

分析一个问题窗体模板并返回对象。 这个可以用来匹配 与字段一起在问题机构形成响应,以便您能够执行 额外验证.

当解析一个问题和相关的形式模板时,此软件包将 尝试将字段ID与响应值相匹配。 如果找到匹配的字段 ID将在解析对象密钥中使用(而不是来自 缩放反应)。 如果没有匹配,则以页眉文字作为对象 键.

例如,如果您有下列问题表模板:

```yaml
name: Example Request
description: Submit an example request
title: '[Request] Example'

body:
  - type: input
    id: name
    attributes:
      label: The Name of the Thing
      description: The name of the thing you want to create.
      placeholder: this-is-the-thing
    validations:
      required: true
```

以及以下议题机构:

```markdown
### The Name of the Thing

this-thing

### The Nickname of the Thing

thing
```

由此产生的问题将是:

```jsonc
{
  // Uses the ID value from the issue form template as the key
  "name": "this-thing",
  // Uses the original header value from the issue body
  "The Nickname of the Thing": "thing"
}
```

## 转换

以下变化将视 输入类型。 该类型取自发行表格模板. 供参考 每个特定类型,见 [GitHub 形式方案语法](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema)。 。 。 .

### 单行

[类型 : `input`](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema#input)

在此之前:

```plain
This is a response
```

之后( 无更改 ) :

```plain
This is a response
```

### 多线

[类型 : `textarea`](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema#textarea)

> \[注\]
> 
> 在多行响应中保留了空行.

在此之前:

```plain
First line :D

Third line!
```

之后:

```plain
First line :D\n\nThird line!
```

### 下拉选择

[类型 : `dropdown`](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema#dropdown)

在此之前:

```plain
red, blue, green
```

之后:

```json
["red", "blue", "green"]
```

### 复选框

[类型 : `checkboxes`](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema#checkboxes)

在此之前:

```plain
- [x] Pick me!
- [ ] Don't pick me D:
```

之后:

```json
{
  "selected": ["Pick me!"],
  "unselected": ["Don't pick me D:"]
}
```

## 输入

在以下情况下,产出JSON中将省去一个输入:

| 假设 | 示例 |
| --- | --- |
| 无效的标题 | `## This is invalid` |
| 空标题 | `###` |
|  | `This is a value` |
| 无值 | `### This is a heading` |
|  |  |
|  | `### This is another` |
|  | `This is a value` |

通常,如果提交表单时带有空字段,则将包含在 根据表格中的输入类型,将问题机构作为以下之一: 模板.

| 类型 | 无答复 |
| --- | --- |
| `dropdown` | `None` |
| `input` | `_No response_` |
| `textarea` | `_No response_` |

```markdown
### Dropdown Field

None

### Input or Textarea Field

_No response_

### Checkboxes Field

- [ ] Item A
- [ ] Item B
```

这些将按输入类型转换为以下之一 问题表格模板中指定的:

| 类型 | 产出 |
| --- | --- |
| `checkboxes` | `{ "selected": [], "unselected": []}` |
| `dropdown` | `[]` |
| `input` | `undefined` |
| `textarea` | `undefined` |

## 常见问题

### @github/issue-parser 是什么？

转换 JSON 的版本响应

### 如何安装 @github/issue-parser？

在项目目录运行 npm install @github/issue-parser，或使用 pnpm add / yarn add / bun add。

### @github/issue-parser 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/github\_\_issue-parser 是否存在。

### @github/issue-parser 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @github/issue-parser 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=20。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @github/issue-parser 可以商用吗？

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

### @github/issue-parser 的下载量有多少？

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

### @github/issue-parser 还在维护吗？

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

