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

digit-font

v0.0.2

Published

A tool to generate obfuscated digit fonts and encode/decode digit strings (maps 0-9 to custom digits)

Readme

digit-font

这是一个用于生成混淆数字字体(主要用于防爬虫/防数据抓取),并支持对数字字符串进行编码和解码的工具。通过配置映射规则,它可以将标准的数字(0-9)映射到其他字形上,从而在页面上显示正确的视觉效果,但在 HTML 源码或复制时得到的是混淆后的错误数据。

✨ 特性

  • 生成混淆字体:根据配置规则,从原字体中提取并重排数字字形,生成全新的混淆字体(支持 .ttf.otf 等)。
  • 编码 / 解码:提供将真实数字转换为混淆字符串(供页面渲染),以及将混淆字符串还原为真实数字的功能。
  • 本地预览服务:内置 Web 服务器,可快速在浏览器中预览生成的混淆字体和本地方案映射效果。
  • 双重形态:既可以作为 CLI 命令行工具独立运行,也可以作为 Node.js 模块集成在前端构建或后端服务中。

💻 CLI(命令行工具)使用指南

通过命令行可以快速生成字体、测试数据编解码以及启动预览服务。

安装

你可以全局安装它以便随时使用:

npm install -g digit-font

基本指令

本工具提供 obf-digitdigit-font 两个命令(指代完全相同)。

obf-digit [options] [command]

可用命令

  • gengenerate:读取配置并依据基础字体生成混淆后的新字体文件。
  • preview:启动本地 Web 服务器,快速预览已经生成好的混淆字体与映射效果。
  • encode <text>:使用当前加载的数字映射配置,对输入的十进制文本进行编码。
  • decode <text>:使用当前加载的数字映射配置,对遭混淆的文本进行解码。

可选参数

  • -c, --config <file>:指定配置文件路径(默认查找当前或相关目录的 .obf-digit.cfg)。
  • -i, --input <file>:输入的基础目标字体文件(例如 .ttf, .otf)。会覆盖配置里的设置。
  • -o, --output <file>:输出的混淆字体文件路径。会覆盖配置里的设置。
  • --preview:在执行 gen 生成字体成功后,自动一并启动预览服务器。
  • -p, --port <number>:预览服务器运行的指定端口号(默认:12337)。
  • -h, --help:显示帮助信息。
  • -v, --version:显示当前版本号。

配置文件示例 (.obf-digit.cfg)

工具默认执行时会自动在当前目录层级寻找配置文件,使用标准 INI 格式:

[general]
# 基础模板字体路径。可以直接写本地文件,或者工具内置自带的字体(例如 Roboto-Regular.ttf)
input = BirthdayDigits.ttf
# 生成的混淆字体输出路径
output = ./my-font.ttf

[numbermap]
# 解码映射规则 (看到的字形 = 实际底层存储的字符)
# 例如:当此处为 0=9 时,用户视觉上看到的是 "9",底层字符其实是 "0"
0=9
1=6
2=2
3=7
4=3
5=8
6=1
7=5
8=4
9=0

[preview]
enable = true
port = 12337

命令行常用用例

1. 一键生成混淆字体并启动预览:

obf-digit gen --preview

2. 借助一份自定义配置文件对金额进行混淆编码:

obf-digit encode "123" -c ./my-custom.cfg

🛠 Node.js API 使用指南

你可以将本工具直接引入你的 Node 项目或构建流水线(如 Webpack / Vite 插件内)来动态处理字体生成或对数据实施动态加密。

局部安装

npm install digit-font
# 或者
yarn add digit-font
pnpm add digit-font

引入和使用

import { 
  generateObfuscatedFont, 
  encodeDigits, 
  decodeDigits, 
  loadConfig 
} from 'digit-font';

API 详述

1. loadConfig(configPath?: string)

加载并解析本地配置。系统会自动将 decode 映射表进行反转,为你生出匹配的 encode 表。此举保证数据的双向转换不含糊。

示例:

const config = loadConfig('./.obf-digit.cfg');

// 查看解码映射字典
console.log(config.numberMap.decode); 
// { '0': '9', '1': '6', '2': '2', ... }

// 查看编码映射字典 (由系统自动反推生成)
console.log(config.numberMap.encode); 
// { '9': '0', '6': '1', '2': '2', ... }

2. generateObfuscatedFont(inputPath: string, outputPath: string, map: NumberMap)

根据上述生成的 NumberMap 规则表和提供的字体底包,生成一份打乱映射后新的混淆字体。

示例:

import path from 'path';

// 手动撰写映射表结构
const customMap = {
  decode: { '0': '9', '1': '2', '2': '1' }, // 用户敲下了 "1",实际看到视觉形变成了 "2" 的字样
  encode: { '9': '0', '2': '1', '1': '2' }
};

const inputFont = path.resolve(__dirname, 'Roboto.ttf');
const outputFont = path.resolve(__dirname, 'ObfuscatedRoboto.ttf');

try {
  generateObfuscatedFont(inputFont, outputFont, customMap);
  console.log('✅ 混淆字体生成完毕!');
} catch (error) {
  console.error('❌ 生成失败:', error);
}

3. encodeDigits(input: string | number, map: NumberMap)

用于后端接口吐出数据之前进行处理:将真实的数字字符串转换为符合当前字体映射的混淆字符。

示例:

const realData = "120"; // 这是系统内部的真实价格数据

// 把它转换为混淆版(由生成的混淆字体去配合显示视觉上依旧是 120 的效果)
const encodedText = encodeDigits(realData, config.numberMap);
console.log(encodedText); 

4. decodeDigits(input: string | number, map: NumberMap)

把从前台被混淆的数据(例如被爬虫强行复制粘贴抓回来的乱码数据),通过同一套规则正确解码还原为真实对应的数字字符体系。

示例:

const scrapedData = "629"; // 爬虫直接复制拿到的错误源码内容

// 一键还原真实面貌
const actualValue = decodeDigits(scrapedData, config.numberMap);
console.log(actualValue); 

📄 License协议

基于 MIT License 许可开源。