Skip to content

Latest commit

 

History

History
76 lines (51 loc) · 2.26 KB

README.md

File metadata and controls

76 lines (51 loc) · 2.26 KB

unifont

npm version npm downloads Github Actions Codecov

Framework agnostic tools for accessing data from font CDNs and providers

Usage

Install package:

# npm
npm install unifont
import { createUnifont, providers } from 'unifont'

const unifont = await createUnifont([
  providers.google(),
])

const fonts = await unifont.resolveFont('Poppins')

console.log(fonts)

In most environments, you will want to cache the results of font APIs to avoid unnecessary hits to them. By default unifont caches font data in memory.

For full control, unifont exposes a storage API which is compatible with unstorage. It simply needs to expose a getItem and setItem method.

import { createUnifont, providers } from 'unifont'

import { createStorage } from 'unstorage'
import fsDriver from 'unstorage/drivers/fs-lite'

const storage = createStorage({
  driver: fsDriver({ base: 'node_modules/.cache/unifont' }),
})

const cachedUnifont = await createUnifont([providers.google()], { storage })

console.log(await cachedUnifont.resolveFont('Poppins'))

// cached data is stored in `node_modules/.cache/unifont`

For more about the storage drivers exposed from unstorage, check out https://unstorage.unjs.io.

💻 Development

  • Clone this repository
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

License

Made with ❤️

Published under MIT License.