@ctrl/ts-base32

中文文档
4.2.2发布于 2026/02/17MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 2.7万

Base32 encoder/decoder with support for multiple variants

原始使用文档
文档目录4 节
  1. Install
  2. Use
  3. Benchmarks
  4. See Also

ts-base32 npm bundlesize

Base32 encode and decode in typescript exported as both commonjs and tree shakeable modules. Support for RFC4648, RFC4648_HEX, and CROCKFORD base32 encoding. Mostly directly taken from LinusU's packages.

Demo: https://ts-base32.ep.workers.dev

Install

npm install @ctrl/ts-base32

Use

import { base32Encode, base32Decode } from '@ctrl/ts-base32';
import { stringToUint8Array, uint8ArrayToString } from 'uint8array-extras';

console.log(base32Encode(stringToUint8Array('a')));
// 'ME======'

console.log(base32Encode(stringToUint8Array('a'), { padding: false }));
// 'ME'

console.log(base32Decode('ME======'));
// Uint8Array

console.log(uint8ArrayToString(base32Decode('ME======'))
// 'a'

Benchmarks

64KB payload, Node.js, ops/s (higher is better): @exodus/bytes uses nodejs Buffer, but is very fast.

Benchmark@ctrl/ts-base32@exodus/bytesbase32-encode/decode@scure/base
encode RFC46488,50031,2002,600283
encode Crockford8,500——332
decode RFC46486,5009,900755333
decode Crockford6,700——387

Run pnpm bench to reproduce.

See Also

base32-encode - https://github.com/LinusU/base32-encode
base32-decode - https://github.com/LinusU/base32-decode
uint8array-extras - https://github.com/sindresorhus/uint8array-extras

版本与发布记录

@ctrl/ts-base32 共发布 32 个版本,首次发布于 2018/12/27;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.2.2latest2026/02/178 个月前
4.2.12026/02/168 个月前
4.2.02025/09/291.1 年前
4.1.02025/09/161.1 年前
4.0.22025/09/161.2 年前
4.0.12025/09/161.2 年前

关于 @ctrl/ts-base32 的常见问题

@ctrl/ts-base32 是什么?

Base32 encoder/decoder with support for multiple variants

如何安装 @ctrl/ts-base32?

在项目目录运行 npm install @ctrl/ts-base32,或使用 pnpm add / yarn add / bun add。

@ctrl/ts-base32 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ctrl/ts-base32 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@ctrl/ts-base32 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ctrl/ts-base32 可以商用吗?

@ctrl/ts-base32 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ctrl/ts-base32 的下载量有多少?

根据 npm 官方下载统计,@ctrl/ts-base32 在 2026/10/11 – 2026/11/09 这 30 天内被下载 27,380 次,日均约 913 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ctrl/ts-base32 还在维护吗?

最新版本 4.2.2 发布于 2026/02/17(8 个月前);至今共发布 32 个版本,其中过去 12 个月发布了 2 个;首次发布于 2018/12/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。