@capsizecss/unpack

中文文档
4.0.1发布于 2026/06/12MITTypeScriptES Module构建来源已验证近 30 天下载 3660.7万

Unpack capsize font metrics from fonts

原始使用文档
文档目录9 节
  1. Usage
  2. fromBuffer
  3. fromBlob
  4. fromUrl
  5. fromFile
  6. Options
  7. Font metrics
  8. Thanks
  9. License
Capsize

@capsizecss/unpack

Unpack the capsize font metrics directly from a font file.

npm install @capsizecss/unpack

Usage

fromBuffer

Takes a buffer and returns the resolved font metrics.

import { fromBuffer } from '@capsizecss/unpack';

const metrics = await fromBuffer(buffer);

fromBlob

Takes a file blob and returns the resolved font metrics.

import { fromBlob } from '@capsizecss/unpack';

const metrics = await fromBlob(file);

fromUrl

Takes a url string and returns the resolved font metrics.

import { fromUrl } from '@capsizecss/unpack';

const metrics = await fromUrl(url);

fromFile

Takes a file path string and returns the resolved font metrics.

import { fromFile } from '@capsizecss/unpack/fs';

const metrics = await fromFile(filePath);

Options

All of the above APIs accept an optional second parameter with the following options:

postscriptName

Capsize can extract the metrics for a single font from a TrueType Collection (TTC) file by providing the postscriptName.

import { fromFile } from '@capsizecss/unpack';

const metrics = await fromFile('AvenirNext.ttc', {
  postscriptName: 'AvenirNext-Bold',
});

Font metrics

The font metrics object returned contains the following properties:

PropertyTypeDescription
familyNamestringThe font’s family name as authored by font creator
fullNamestringThe font’s full name as authored by font creator
postscriptNamestringThe font’s unique PostScript name as authored by font creator
categorystringThe style of the font: serif, sans-serif, monospace, display, or handwriting.
capHeightnumberThe height of capital letters above the baseline
ascentnumberThe height of the ascenders above baseline
descentnumberThe descent of the descenders below baseline
lineGapnumberThe amount of space included between lines
unitsPerEmnumberThe size of the font’s internal coordinate grid
xHeightnumberThe height of the main body of lower case letters above baseline
xWidthAvgnumberThe average width of character glyphs in the font for the selected unicode subset. Calculated based on character frequencies in written text, falling back to the built in xAvgCharWidth from the OS/2 table.
subsets{
[subset]: { xWidthAvg: number }
}
A lookup of the xWidthAvg metric by subset (see supported subsets)

Thanks

License

MIT.

版本与发布记录

@capsizecss/unpack 共发布 38 个版本,首次发布于 2021/09/24;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.0.1latest2026/06/124 个月前
4.0.02025/12/1910 个月前
3.0.12025/11/1211 个月前
0.0.0-test-202510062350162025/10/071.1 年前
3.0.02025/07/011.4 年前
2.4.02025/03/311.6 年前

其他发布通道:createfontstack → 0.0.0-createfontstack-20221110224822,x-avg-char-width → 0.0.0-x-avg-char-width-20221118004523,x-width-avg → 0.0.0-x-width-avg-20230123213508,add-language-support → 0.0.0-add-language-support-20231121023926,add-language-support-v2 → 0.0.0-add-language-support-v2-20231129052138,crackle → 0.0.0-crackle-20240208083429。

关于 @capsizecss/unpack 的常见问题

@capsizecss/unpack 是什么?

Unpack capsize font metrics from fonts

如何安装 @capsizecss/unpack?

在项目目录运行 npm install @capsizecss/unpack,或使用 pnpm add / yarn add / bun add。

@capsizecss/unpack 支持 TypeScript 吗?

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

@capsizecss/unpack 支持 ESM 还是 CommonJS?

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

@capsizecss/unpack 需要什么版本的 Node.js?

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

@capsizecss/unpack 可以商用吗?

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

@capsizecss/unpack 的下载量有多少?

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

@capsizecss/unpack 还在维护吗?

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