A TypeScript WOFF2 decoder
npm install woff2-decodeimport { decode } from 'woff2-decode'
const woff2Data = await fetch('/font.woff2').then(r => r.arrayBuffer())
const ttfData = decode(woff2Data)
// ttfData is a Uint8Array containing the decoded TTF/OTFBenchmarks on an M1 Mac, Node 22. In Node, native Brotli (via zlib) is used; browsers use 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): Uint8ArrayMIT, maintained by @jpt