# @capsizecss/unpack

> Unpack capsize font metrics from fonts

Latest version **4.0.1** (published 2026-06-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @capsizecss/unpack
pnpm add @capsizecss/unpack
yarn add @capsizecss/unpack
bun add @capsizecss/unpack
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2026-06-12 |
| First published | 2021-09-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 1 |
| Unpacked size | 18.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1719 |
| Author | Michael Taranto |
| Maintainers | mjt01, seek-oss-ci |
| Keywords | capsize, leading trim, white space, baseline, basekick, cap height, typography, line gap, leading |

## Links

- npm: https://www.npmjs.com/package/@capsizecss/unpack
- Repository: https://github.com/seek-oss/capsize
- Homepage: https://github.com/seek-oss/capsize#readme
- Issues: https://github.com/seek-oss/capsize/issues
- npm.io page: https://npm.io/package/@capsizecss/unpack

## Dependencies (1)

- [fontkitten](https://npm.io/package/fontkitten.md) ^1.0.3

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 4.0.1 (latest) — 2026-06-12
- 0.0.0-test-20251006235016 (test) — 2025-10-06
- 0.0.0-add-weight-italic-support-20240507015549 (add-weight-italic-support) — 2024-05-07
- 0.0.0-metrics-xwidthavg-inc-space-20240305000813 (metrics-xwidthavg-inc-space) — 2024-03-05
- 0.0.0-add-subset-support-20240304225850 (add-subset-support) — 2024-03-04
- 0.0.0-metrics-frequency-data-20240215031405 (metrics-frequency-data) — 2024-02-15
- 0.0.0-master-20240214212615 (master) — 2024-02-14
- 0.0.0-crackle-20240208083429 (crackle) — 2024-02-08
- 0.0.0-add-language-support-v2-20231129052138 (add-language-support-v2) — 2023-11-29
- 0.0.0-add-language-support-20231121023926 (add-language-support) — 2023-11-21
- 0.0.0-x-width-avg-20230123213508 (x-width-avg) — 2023-01-23
- 0.0.0-x-avg-char-width-20221118004523 (x-avg-char-width) — 2022-11-18
- 0.0.0-createfontstack-20221110224822 (createfontstack) — 2022-11-10
- 4.0.0 — 2025-12-18
- 3.0.1 — 2025-11-12
- … 23 more at https://npm.io/package/@capsizecss/unpack/versions

## README

<img src="https://raw.githubusercontent.com/seek-oss/capsize/HEAD/images/capsize-header.png" alt="Capsize" title="Capsize" width="443px" />
<br/>

# @capsizecss/unpack

Unpack the capsize font metrics directly from a font file.

```bash
npm install @capsizecss/unpack
```

- [Usage](#usage)
  - [fromBuffer](#frombuffer)
  - [fromBlob](#fromblob)
  - [fromUrl](#fromurl)
  - [fromFile](#fromfile)
- [Options](#options)
  - [postscriptName](#postscriptname)
- [Font Metrics](#font-metrics)

## Usage

### `fromBuffer`

Takes a buffer and returns the resolved [font metrics](#font-metrics).

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

const metrics = await fromBuffer(buffer);
```

### `fromBlob`

Takes a file blob and returns the resolved [font metrics](#font-metrics).

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

const metrics = await fromBlob(file);
```

### `fromUrl`

Takes a url string and returns the resolved [font metrics](#font-metrics).

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

const metrics = await fromUrl(url);
```

### `fromFile`

Takes a file path string and returns the resolved [font metrics](#font-metrics).

```ts
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`.

```ts
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:

| Property       | Type                                        | Description                                                                                                                                                                                                       |
| -------------- | ------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| familyName     | string                                      | The font’s family name as authored by font creator                                                                                                                                                                |
| fullName       | string                                      | The font’s full name as authored by font creator                                                                                                                                                                  |
| postscriptName | string                                      | The font’s unique PostScript name as authored by font creator                                                                                                                                                     |
| category       | string                                      | The style of the font: serif, sans-serif, monospace, display, or handwriting.                                                                                                                                     |
| capHeight      | number                                      | The height of capital letters above the baseline                                                                                                                                                                  |
| ascent         | number                                      | The height of the ascenders above baseline                                                                                                                                                                        |
| descent        | number                                      | The descent of the descenders below baseline                                                                                                                                                                      |
| lineGap        | number                                      | The amount of space included between lines                                                                                                                                                                        |
| unitsPerEm     | number                                      | The size of the font’s internal coordinate grid                                                                                                                                                                   |
| xHeight        | number                                      | The height of the main body of lower case letters above baseline                                                                                                                                                  |
| xWidthAvg      | number                                      | The 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        | {<br/>[subset]: { xWidthAvg: number }<br/>} | A lookup of the `xWidthAvg` metric by subset (see [supported subsets])                                                                                                                                            |

[based on character frequencies in written text]: ../metrics/README.md#how-xwidthavg-is-calculated
[supported subsets]: ../metrics/README.md#subsets

## Thanks

- [Devon Govett](https://github.com/devongovett) for creating [Fontkit](https://github.com/foliojs/fontkit). A [fork of Fontkit](https://github.com/delucis/fontkitten) does all the heavy lifting of extracting the font metrics under the covers.
- [SEEK](https://au.seek.com) for giving us the space to do interesting work.

## License

MIT.

---
_Source: https://npm.io/package/@capsizecss/unpack · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
