@eslint-community/regexpp

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

Regular expression parser for ECMAScript.

原始使用文档
文档目录11 节
  1. 💿 Installation
  2. 📖 Usage
  3. parseRegExpLiteral(source, options?)
  4. validateRegExpLiteral(source, options?)
  5. visitRegExpAST(ast, handlers)
  6. RegExpParser
  7. RegExpValidator
  8. RegExpVisitor
  9. 📰 Changelog
  10. 🍻 Contributing
  11. Development Tools

@eslint-community/regexpp

npm version Downloads/month Build Status codecov

A regular expression parser for ECMAScript.

💿 Installation

$ npm install @eslint-community/regexpp
  • require Node@^12.0.0 || ^14.0.0 || >=16.0.0.

📖 Usage

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

parseRegExpLiteral(source, options?)

Parse a given regular expression literal then make AST object.

This is equivalent to new RegExpParser(options).parseLiteral(source).

  • Parameters:
    • source (string | RegExp) The source code to parse.
    • options? (RegExpParser.Options) The options to parse.
  • Return:
    • The AST of the regular expression.

validateRegExpLiteral(source, options?)

Validate a given regular expression literal.

This is equivalent to new RegExpValidator(options).validateLiteral(source).

  • Parameters:

visitRegExpAST(ast, handlers)

Visit each node of a given AST.

This is equivalent to new RegExpVisitor(handlers).visit(ast).

RegExpParser

new RegExpParser(options?)

parser.parseLiteral(source, start?, end?)

Parse a regular expression literal.

  • Parameters:
    • source (string) The source code to parse. E.g. "/abc/g".
    • start? (number) The start index in the source code. Default is 0.
    • end? (number) The end index in the source code. Default is source.length.
  • Return:
    • The AST of the regular expression.

parser.parsePattern(source, start?, end?, flags?)

Parse a regular expression pattern.

  • Parameters:
    • source (string) The source code to parse. E.g. "abc".
    • start? (number) The start index in the source code. Default is 0.
    • end? (number) The end index in the source code. Default is source.length.
    • flags? ({ unicode?: boolean, unicodeSets?: boolean }) The flags to enable Unicode mode, and Unicode Set mode.
  • Return:
    • The AST of the regular expression pattern.

parser.parseFlags(source, start?, end?)

Parse a regular expression flags.

  • Parameters:
    • source (string) The source code to parse. E.g. "gim".
    • start? (number) The start index in the source code. Default is 0.
    • end? (number) The end index in the source code. Default is source.length.
  • Return:
    • The AST of the regular expression flags.

RegExpValidator

new RegExpValidator(options)

validator.validateLiteral(source, start, end)

Validate a regular expression literal.

  • Parameters:
    • source (string) The source code to validate.
    • start? (number) The start index in the source code. Default is 0.
    • end? (number) The end index in the source code. Default is source.length.

validator.validatePattern(source, start, end, flags)

Validate a regular expression pattern.

  • Parameters:
    • source (string) The source code to validate.
    • start? (number) The start index in the source code. Default is 0.
    • end? (number) The end index in the source code. Default is source.length.
    • flags? ({ unicode?: boolean, unicodeSets?: boolean }) The flags to enable Unicode mode, and Unicode Set mode.

validator.validateFlags(source, start, end)

Validate a regular expression flags.

  • Parameters:
    • source (string) The source code to validate.
    • start? (number) The start index in the source code. Default is 0.
    • end? (number) The end index in the source code. Default is source.length.

RegExpVisitor

new RegExpVisitor(handlers)

visitor.visit(ast)

Validate a regular expression literal.

  • Parameters:

📰 Changelog

🍻 Contributing

Welcome contributing!

Please use GitHub's Issues/PRs.

Development Tools

  • npm test runs tests and measures coverage.
  • npm run build compiles TypeScript source code to index.js, index.js.map, and index.d.ts.
  • npm run clean removes the temporary files which are created by npm test and npm run build.
  • npm run lint runs ESLint.
  • npm run update:test updates test fixtures.
  • npm run update:ids updates src/unicode/ids.ts.
  • npm run watch runs tests with --watch option.

版本与发布记录

@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 是什么?

Regular expression parser for 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 和提交记录判断。