0.0.1 • Published 5 months ago

modern-fontmin v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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)
  })