modern-fontmin
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

modern-fontmin

Minzip Version Downloads Issues License

Install

npm i modern-fontmin

# peerDependencies
npm i pako

Usage

import { minify, arrayBufferToDataUrl } from 'modern-fontmin'

window.fetch('./font.woff')
  .then(rep => rep.arrayBuffer())
  .then(font => {
    const min = minify(font, 'You want a subset of the text')
    console.log('raw size', font.byteLength / 1024, 'kb')
    console.log('min size', min.byteLength / 1024, 'kb')
    const dataUrl = arrayBufferToDataUrl(min, 'font/woff')
    const style = document.createElement('style')
    style.appendChild(
      document.createTextNode(`
@font-face {
  font-family: "CustomFont";
  src: url(${ dataUrl }) format("woff");
}
`),
    )
    document.head.append(style)
  })

Package Sidebar

Install

npm i modern-fontmin

Weekly Downloads

3

Version

0.0.1

License

MIT

Unpacked Size

209 kB

Total Files

14

Last publish

Collaborators

  • wengxiangmin