WOFF2 font converter

wawoff2 for Edge Scripting for bunny.net 🐰

NPM Version

Introduction

WOFF2 is a compressed web font format.

Imports

There are three ways to import this package:

  • import { initCompress } from 'https://cdn.jsdelivr.net/npm/bunny-woff2@0.0.2/dist/compress.js'
  • import { initDecompress } from 'https://cdn.jsdelivr.net/npm/bunny-woff2@0.0.2/dist/decompress.js'
  • import { initCompress, initDecompress } from 'https://cdn.jsdelivr.net/npm/bunny-woff2@0.0.2/dist/index.js'

If you are only performing a one-way conversion, you can save significant file size and loading time by only importing the function you need.

Example

import * as BunnySDK from 'https://esm.sh/@bunny.net/edgescript-sdk@0.11.2'import { initCompress } from 'https://cdn.jsdelivr.net/npm/bunny-woff2@0.0.2/dist/compress.js'let compressBunnySDK.net.http.serve(async (request: Request): Promise<Response> => {  // keep script startup time under 500ms  if (!compress) {    compress = await initCompress()  }  // fetch font  const fontResponse = await fetch(    'https://cdn.jsdelivr.net/gh/google/fonts@main/ofl/bungeetint/BungeeTint-Regular.ttf',  )  const fontBytes = await fontResponse.bytes()  // convert font  const fontWoff2 = compress(fontBytes)  // return font response  return new Response(fontWoff2, {    headers: {      'Content-Type': 'font/woff2',    },  })})