A TypeScript WOFF2 decoder
npm install woff2-decodeimport { decode } from 'woff2-decode'
const woff2Data = await fetch('/font.woff2').then(r => r.arrayBuffer())
const ttfData = await decode(woff2Data)
// ttfData is a Uint8Array containing the decoded TTF/OTFBenchmarks on an M2 Max, Node 22. Native Brotli is used in Node (via zlib) and browsers that support DecompressionStream('brotli') (Firefox 113+, Safari 16.4+). Chrome falls back to pure JS
| File | Size | Native | Pure JS |
|---|---|---|---|
| enc-otf.woff2 (CFF) | 107 KB | 1.6 ms | 5.3 ms |
| enc-ttf.woff2 | 98 KB | 2.4 ms | 5.5 ms |
| enc-var-ttf.woff2 | 318 KB | 5.2 ms | 14.4 ms |
function decode(data: ArrayBuffer | Uint8Array): Promise<Uint8Array>MIT, maintained by @jpt