# @flow-scanner/regex-scanner 中文文档

规范地址：https://npmcn.com/package/%40flow-scanner/regex-scanner/

版本：1\.1\.1
npm 元数据更新时间：2026-04-05T11:51:54.333Z
中文译文更新时间：2026-11-15T00:08:02.581Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：49.5 kB，25 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：^18 \|\| ^20 \|\| ^22 \|\| ^23 \|\| ^24
- 运行依赖：0 个
- 首次发布：2026-01-14T14:15:19.511Z
- 最新版本发布：2026-04-05T11:51:54.216Z
- 近 30 天下载量：21797（2026-10-15 至 2026-11-13，npm 官方下载统计）
- 已发布版本数：3（近 12 个月 3 个）

## 中文简介

基于regex的通用扫描引擎.

## 安装

```sh
npm install @flow-scanner/regex-scanner
```

也可以使用：`pnpm add @flow-scanner/regex-scanner`、`yarn add @flow-scanner/regex-scanner`、`bun add @flow-scanner/regex-scanner`

## README

# @ flow-scanner/ regex-scanner (英语)

一个通用的基于regex的元数据文件扫描引擎. 这个包提供了一个轻量级,可扩展的框架来检测元数据内容中的规律.

## 安装

```bash
npm install @flow-scanner/regex-scanner
```

## 使用量

```typescript
import { scanRegex, MetadataFile } from "@flow-scanner/regex-scanner";

const file: MetadataFile = {
  name: "My_Flow",
  fileName: "My_Flow.flow-meta.xml",
  metadataType: "Flow",
  content: "<Flow>...</Flow>",
};

// Works with any Salesforce metadata type
const prompt: MetadataFile = {
  name: "My_Prompt",
  fileName: "My_Prompt.aiPromptTemplate-meta.xml",
  metadataType: "AiPromptTemplate",
  content: "<AiPromptTemplate>...</AiPromptTemplate>",
};

const violations = scanRegex([file]);
```

## 内部规则

所有内置规则默认适用于任何元数据类型.

| 规则ID | 说明 |
| --- | --- |
| `naming-convention` | 校验符合可配置模式的文件名 |
| `hardcoded-id` | 检测出硬码的销售力量记录 ID (15/18 char) |
| `hardcoded-url` | 检测出硬码力量.com URL |
| `hardcoded-secret` | 检测 API 密钥、 令牌和证书 |

## 配置

```typescript
import { scanRegex, RegexScanConfig } from "@flow-scanner/regex-scanner";

const config: RegexScanConfig = {
  rules: {
    "naming-convention": {
      enabled: true,
      expression: "[A-Z][a-z]+_[A-Z][a-z]+", // Custom pattern
      severity: "warning",
    },
    "hardcoded-id": {
      enabled: false, // Disable this rule
    },
  },
};

const violations = scanRegex(files, config);
```

## 创建自定义规则

扩展 `RegexRule` 基准类 :

```typescript
import { RegexRule, MetadataFile, RegexViolation } from "@flow-scanner/regex-scanner";

export class MyCustomRule extends RegexRule {
  constructor() {
    super({
      ruleId: "my-custom-rule",
      name: "MyCustomRule",
      label: "My Custom Rule",
      description: "Detects something specific",
      summary: "Short summary",
      severity: "warning",
      supportedTypes: ["*"], // or specific types like ["Flow", "ApexClass"]
      isConfigurable: false,
    });
  }

  protected check(file: MetadataFile): RegexViolation[] {
    const violations: RegexViolation[] = [];
    // Your regex logic here
    return violations;
  }
}
```

## API 密码

### 职能

-   `scanRegex(files, config?)` - 扫描多份文件,返回违规情况
-   `scanFile(file, config?)` - 扫描一个文件
-   `getRegexRuleIds()` - 获取所有可用的规则标识
-   `hasRegexRule(id)` - 检查是否有规则

### 模型

-   `MetadataFile` - 输入文件说明
-   `RegexViolation` - 输出违反地点信息
-   `RegexScanConfig` - 扫描行为配置
-   `RegexRule` - 规则基础课

## 常见问题

### @flow-scanner/regex-scanner 是什么？

基于regex的通用扫描引擎\.

### 如何安装 @flow-scanner/regex-scanner？

在项目目录运行 npm install @flow-scanner/regex-scanner，或使用 pnpm add / yarn add / bun add。

### @flow-scanner/regex-scanner 支持 TypeScript 吗？

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

### @flow-scanner/regex-scanner 支持 ESM 还是 CommonJS？

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

### @flow-scanner/regex-scanner 需要什么版本的 Node\.js？

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

### @flow-scanner/regex-scanner 可以商用吗？

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

### @flow-scanner/regex-scanner 的下载量有多少？

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

### @flow-scanner/regex-scanner 还在维护吗？

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

