@flow-scanner/regex-scanner

中文文档
1.1.1发布于 2026/04/05MITTypeScriptESM + CJS零依赖近 30 天下载 2.2万

基于regex的通用扫描引擎.

中文使用文档
文档目录8 节
  1. 安装
  2. 使用量
  3. 内部规则
  4. 配置
  5. 创建自定义规则
  6. API 密码
  7. 职能
  8. 模型

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

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

安装

npm install @flow-scanner/regex-scanner

使用量

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 密钥、 令牌和证书

配置

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 基准类 :

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 共发布 3 个版本,首次发布于 2026/01/14;过去 12 个月发布了 3 个版本。

版本发布日期距今
1.1.1latest2026/04/057 个月前
1.1.02026/02/039 个月前
1.0.02026/01/1410 个月前

关于 @flow-scanner/regex-scanner 的常见问题

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