@eslint-community/regexpp

中文文档
4.12.2发布于 2025/10/22MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 5.4亿

ECMAScript的正则表达式解析器。

中文使用文档
文档目录11 节
  1. 💿安装
  2. 📖用法
  3. parseRegExpLiteral(来源、期权?)
  4. validateRegExpLiteral(来源、期权?)
  5. 处理程序visitRegExpAST (ast)
  6. RegExpParser
  7. RegExpValidator
  8. RegExpVisitor
  9. 📰更新日志
  10. 🍻贡献
  11. 开发工具

@eslint-community / regexpp

npm version Downloads/month Build Status codecov

ECMAScript的正则表达式解析器。

💿安装

$ npm install @eslint-community/regexpp
  • 要求节点@^12.0.0 || ^14.0.0 || >=16.0.0。

📖用法

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)要解析的选项。
  • 返回:
    • 正则表达式的AST。

validateRegExpLiteral(来源、期权?)

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

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

处理程序visitRegExpAST (ast)

访问给定AST的每个节点。

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

RegExpParser

新RegExpParser(选择?)

解析器。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(选项)

验证器。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(处理器)

visitor.visit (ast)

验证正则表达式字面量。

📰更新日志

🍻贡献

欢迎贡献!

请使用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 共发布 27 个版本,首次发布于 2022/11/28;过去 12 个月发布了 0 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.12.2latest2025/10/221 年前
4.12.12024/10/282 年前
4.12.02024/10/272 年前
4.11.22024/10/262 年前
4.11.12024/09/152 年前
4.11.02024/06/282 年前

关于 @eslint-community/regexpp 的常见问题

@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 和提交记录判断。