# @eslint-community/regexpp 中文文档

规范地址：https://npmcn.com/package/%40eslint-community/regexpp/

版本：4\.12\.2
npm 元数据更新时间：2025-10-22T11:56:01.280Z
中文译文更新时间：2026-11-05T01:35:29.911Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：474 kB，8 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：^12\.0\.0 \|\| ^14\.0\.0 \|\| \>=16\.0\.0
- 运行依赖：0 个
- 首次发布：2022-11-28T01:53:47.526Z
- 最新版本发布：2025-10-22T11:56:00.818Z
- 近 30 天下载量：537277116（2026-10-04 至 2026-11-02，npm 官方下载统计）
- 已发布版本数：27（近 12 个月 0 个）

## 中文简介

ECMAScript的正则表达式解析器。

## 安装

```sh
npm install @eslint-community/regexpp
```

也可以使用：`pnpm add @eslint-community/regexpp`、`yarn add @eslint-community/regexpp`、`bun add @eslint-community/regexpp`

## README

# @eslint-community / regexpp

[![npm version](https://img.shields.io/npm/v/@eslint-community/regexpp.svg)](https://www.npmjs.com/package/@eslint-community/regexpp) [![Downloads/month](https://img.shields.io/npm/dm/@eslint-community/regexpp.svg)](http://www.npmtrends.com/@eslint-community/regexpp) [![Build Status](https://github.com/eslint-community/regexpp/workflows/CI/badge.svg)](https://github.com/eslint-community/regexpp/actions) [![codecov](https://codecov.io/gh/eslint-community/regexpp/branch/main/graph/badge.svg)](https://codecov.io/gh/eslint-community/regexpp)

ECMAScript的正则表达式解析器。

## 💿安装

```bash
$ npm install @eslint-community/regexpp
```

-   要求节点@^12.0.0 || ^14.0.0 || >=16.0.0。

## 📖用法

```ts
import {
    AST,
    RegExpParser,
    RegExpValidator,
    RegExpVisitor,
    parseRegExpLiteral,
    validateRegExpLiteral,
    visitRegExpAST
} from "@eslint-community/regexpp"
```

### parseRegExpLiteral(来源、期权?)

解析给定的正则表达式文本，然后生成AST对象。

这个等价于 `new RegExpParser(options).parseLiteral(source)`。

-   **参数:**
    -   `source` （`string | RegExp`要解析的源代码。
    -   `options?` （[`RegExpParser.Options`](https://npmcn.com/package/%40eslint-community/regexpp/src/parser.ts#L743))要解析的选项。
-   **返回:**
    -   正则表达式的AST。

### validateRegExpLiteral(来源、期权?)

验证给定的正则表达式字面量。

这个等价于 `new RegExpValidator(options).validateLiteral(source)`。

-   **参数:**
    -   `source` （`string`)验证的源代码。
    -   `options?` （[`RegExpValidator.Options`](https://npmcn.com/package/%40eslint-community/regexpp/src/validator.ts#L220))验证的选项。

### 处理程序visitRegExpAST (ast)

访问给定AST的每个节点。

这个等价于 `new RegExpVisitor(handlers).visit(ast)`。

-   **参数:**
    -   `ast` （[`AST.Node`](https://npmcn.com/package/%40eslint-community/regexpp/src/ast.ts#L4)) AST访问。
    -   `handlers` （[`RegExpVisitor.Handlers`](https://npmcn.com/package/%40eslint-community/regexpp/src/visitor.ts#L291))回调。

### RegExpParser

#### 新RegExpParser(选择?)

-   **参数:**
    -   `options?` （[`RegExpParser.Options`](https://npmcn.com/package/%40eslint-community/regexpp/src/parser.ts#L743))要解析的选项。

#### 解析器。parseLiteral(来源,开始?结束?)

解析正则表达式字面量。

-   **参数:**
    -   `source` （`string`要解析的源代码。如。 `"/abc/g"`。
    -   `start?` （`number`)源代码中的起始索引。默认是 `0`。
    -   `end?` （`number`)源代码的结束索引。默认是 `source.length`。
-   **返回:**
    -   正则表达式的AST。

#### 解析器。parsePattern(来源,开始?,结束?、旗帜?)

解析正则表达式模式。

-   **参数:**
    -   `source` （`string`要解析的源代码。如。 `"abc"`。
    -   `start?` （`number`)源代码中的起始索引。默认是 `0`。
    -   `end?` （`number`)源代码的结束索引。默认是 `source.length`。
    -   `flags?` （`{ unicode?: boolean, unicodeSets?: boolean }`)启用Unicode模式和Unicode Set模式的标志。
-   **返回:**
    -   正则表达式模式的AST。

#### 解析器。parseFlags(来源,开始?结束?)

解析正则表达式标志。

-   **参数:**
    -   `source` （`string`要解析的源代码。如。 `"gim"`。
    -   `start?` （`number`)源代码中的起始索引。默认是 `0`。
    -   `end?` （`number`)源代码的结束索引。默认是 `source.length`。
-   **返回:**
    -   正则表达式标志的AST。

### RegExpValidator

#### 新RegExpValidator(选项)

-   **参数:**
    -   `options` （[`RegExpValidator.Options`](https://npmcn.com/package/%40eslint-community/regexpp/src/validator.ts#L220))验证的选项。

#### 验证器。validateLiteral（源，开始，结束）

验证正则表达式字面量。

-   **参数:**
    -   `source` （`string`)验证的源代码。
    -   `start?` （`number`)源代码中的起始索引。默认是 `0`。
    -   `end?` （`number`)源代码的结束索引。默认是 `source.length`。

#### 验证器。validatepatpattern（源、开始、结束、标志）

验证正则表达式模式。

-   **参数:**
    -   `source` （`string`)验证的源代码。
    -   `start?` （`number`)源代码中的起始索引。默认是 `0`。
    -   `end?` （`number`)源代码的结束索引。默认是 `source.length`。
    -   `flags?` （`{ unicode?: boolean, unicodeSets?: boolean }`)启用Unicode模式和Unicode Set模式的标志。

#### 验证器。validateFlags（source, start, end）

验证正则表达式标志。

-   **参数:**
    -   `source` （`string`)验证的源代码。
    -   `start?` （`number`)源代码中的起始索引。默认是 `0`。
    -   `end?` （`number`)源代码的结束索引。默认是 `source.length`。

### RegExpVisitor

#### 新RegExpVisitor(处理器)

-   **参数:**
    -   `handlers` （[`RegExpVisitor.Handlers`](https://npmcn.com/package/%40eslint-community/regexpp/src/visitor.ts#L291))回调。

#### visitor.visit (ast)

验证正则表达式字面量。

-   **参数:**
    -   `ast` （[`AST.Node`](https://npmcn.com/package/%40eslint-community/regexpp/src/ast.ts#L4)) AST访问。

## 📰更新日志

-   [GitHub版本](https://github.com/eslint-community/regexpp/releases)

## 🍻贡献

欢迎贡献!

请使用GitHub的问题/ pr。

### 开发工具

-   `npm test` 运行测试并度量覆盖率。
-   `npm run build` 将TypeScript源代码编译为 `index.js`， `index.js.map`, `index.d.ts`。
-   `npm run clean` 创建的临时文件 `npm test` 和 `npm run build`。
-   `npm run lint` ESLint运行。
-   `npm run update:test` 更新测试装置。
-   `npm run update:ids` 更新 `src/unicode/ids.ts`。
-   `npm run watch` 运行测试 `--watch` 选择。

## 常见问题

### @eslint-community/regexpp 是什么？

ECMAScript的正则表达式解析器。

### 如何安装 @eslint-community/regexpp？

在项目目录运行 npm install @eslint-community/regexpp，或使用 pnpm add / yarn add / bun add。

### @eslint-community/regexpp 支持 TypeScript 吗？

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

### @eslint-community/regexpp 支持 ESM 还是 CommonJS？

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

### @eslint-community/regexpp 需要什么版本的 Node\.js？

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

### @eslint-community/regexpp 可以商用吗？

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

### @eslint-community/regexpp 的下载量有多少？

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

### @eslint-community/regexpp 还在维护吗？

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

