scan-zh
v0.1.3
Published
扫描目录下文件中的简体中文字符工具
Readme
扫描简体中文工具 (scan-zh)
功能特性
- 🔍 递归扫描指定目录下的所有文件
- 📝 支持多种文件格式 (txt, html, js, ts, md, json 等, 目前仅支持:html)
- 🚫 自动过滤简繁体相同的字符 (可配置)
- 📊 提供详细的统计信息
- 💾 支持结果导出到文件
- ⚙️ 灵活的配置选项
安装依赖
npm install scan-zh -g使用方法
基本用法
Usage: scan-zh [options] [command] <directory>
扫描目录下文件中的简体中文字符工具
Arguments:
directory 要扫描的目录路径
Options:
-V, --version output the version number
-s, --statistics 显示统计信息 (default: true)
-o, --output <file> 将结果保存到文件
-v, --verbose 显示详细信息
-c, --config <file> 指定配置文件路径
-h, --help 显示帮助信息
Commands:
init 在当前目录生成默认配置文件
config [options] 查看当前配置
用法示例:
scan-zh <目录路径> [选项]
选项说明:
-s, --statistics 显示统计信息(如字符频率、文件数量等), default "true"
-o, --output <file> 将扫描结果保存到指定文件
-v, --verbose 显示详细扫描结果
--config <file> 指定自定义配置文件路径
子命令:
init 在当前目录生成默认配置文件
config 查看当前工具的扫描配置
示例:
scan-zh ./src
scan-zh ./src -s -o result.txt
scan-zh init
scan-zh config配置文件
工具支持 JSON 格式的配置文件,配置文件查找顺序:
- 用户通过
--config参数指定的配置文件 - 当前工作目录下的
config.json(推荐通过scan-zh init生成) - 工具默认配置
配置文件格式示例
{
"sameSimplifiedTraditional": [
"一", "二", "三", "人", "大", "小", "中", "文"
],
"supportedExtensions": [
".html", ".htm", ".js", ".ts", ".md"
],
"excludedDirs": [
"node_modules", ".git", "dist", "build"
],
"simplifiedChineseRegex": "[\\u4e00-\\u9fff]"
}查看配置
# 查看当前配置
scan-zh config
# 查看指定配置文件
scan-zh config -f ./my-config.json初始化配置文件
# 在当前目录生成一份默认配置文件 config.json
scan-zh init
# 之后可直接运行扫描命令,工具会优先使用当前目录下的配置
scan-zh ./src输出格式
找到 X 个简体中文字符:
path/to/file.txt 22行 33列 包含简体字 "国"
上下文: Hello [国] world
path/to/file.html 15行 8列 包含简体字 "语"
上下文: 这是[语]言测试内置排除的目录
- node_modules
- .git, .svn, .hg
- dist, build, coverage
- tmp, temp, .cache
