npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

zh-scanner-ola

v1.0.2

Published

扫描js,ts代码中的汉字字符串, 多语言自动替换

Readme

zh-scanner

扫描 js(x),ts(x) 代码中的汉字到指定文件

usage

1.安装

$ npm i zh-scanner --save-dev

2.配置 npm 脚本

--files 选项指定你要扫描的目录, 支持 glob 匹配, --out 选项指定扫描结果要存放的位置

{
  "scripts": {
    "scanner": "zh-scanner --files '**/*.{tsx,ts,jsx,js}' --out ./zh-CN.json"
  }
}

3.执行

# 扫描出的汉字以 json 的形式存储, json key 为扫描出的汉字语句的 md5 值的前 6 位, json value 为扫描出的汉字
$ npm run scanner

配合附带的babel插件 babel-plugin-zh-replacer 做多语言自动替换

1.将提取出的 zh-CN.json 上传到翻译网站, 如 crowdin, 翻译完成后, 下载对应的各语言 json, 并根据语言重命名如: en.json, ar.json, jp.json

2.根据用户语言后引入对应语言的 json 并挂载到 window 对象上, 参考代码:

import(`someDir/${lan}.json`).then((module) => {
  window.locale = module.default;
});

3.将 babel-plugin-zh-replacer 插件添加到项目的 babel 配置文件中, 如

// babel.config.js
const { babelPluginZhReplacer } = require("@den9yon9/zh-scanner");

module.export = {
  plugins: [babelPluginZhReplacer],
};

Q&A

Q. 某个文件想排除掉不被扫描怎么办?

A. 在文件起始位置添加字符串指令 "skip scanner", 即可跳过这个文件

Q. 我想排除某一句汉语, 使其不被扫描和翻译要怎样处理?

A. 使用模板字符串, 模板字符串中的汉语不会被扫描和翻译

Q. 我想扫描并翻译某一句非汉语, 要怎样处理?

A. 使用模板字符串, 模板字符串中非汉语会被扫描并翻译

Q. 为什么含有表达式的模板字符串没有被处理?

A. 含有表达式的模板字符串无法扫描出完整的文案语义, 所以无法处理, 你可以这样:

"xx位好友向你发送了xx条消息".replace("xx", "2").replace("xx", "100")