@flow-scanner/regex-scanner

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

Generic regex-based scanning engine.

原始使用文档
文档目录8 节
  1. Installation
  2. Usage
  3. Built-in Rules
  4. Configuration
  5. Creating Custom Rules
  6. API
  7. Functions
  8. Models

@flow-scanner/regex-scanner

A generic regex-based scanning engine for metadata files. This package provides a lightweight, extensible framework for detecting patterns in metadata content.

Installation

npm install @flow-scanner/regex-scanner

Usage

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]);

Built-in Rules

All built-in rules apply to any metadata type by default.

Rule IDDescription
naming-conventionValidates file names match a configurable pattern
hardcoded-idDetects hardcoded Salesforce record IDs (15/18 char)
hardcoded-urlDetects hardcoded force.com URLs
hardcoded-secretDetects API keys, tokens, and credentials

Configuration

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);

Creating Custom Rules

Extend the RegexRule base class:

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

Functions

  • scanRegex(files, config?) - Scan multiple files, returns violations
  • scanFile(file, config?) - Scan a single file
  • getRegexRuleIds() - Get all available rule IDs
  • hasRegexRule(id) - Check if a rule exists

Models

  • MetadataFile - Input file representation
  • RegexViolation - Output violation with location info
  • RegexScanConfig - Configuration for scan behavior
  • RegexRule - Base class for rules

版本与发布记录

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

Generic regex-based scanning engine.

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