Skip to content
/ unifont Public

Framework agnostic tools for accessing data from font CDNs and providers

License

Notifications You must be signed in to change notification settings

unjs/unifont

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a3957cb · Apr 22, 2025
Mar 19, 2025
Mar 3, 2025
Apr 21, 2025
Apr 21, 2025
Apr 26, 2024
Apr 26, 2024
Oct 1, 2024
Apr 26, 2024
Apr 26, 2024
Apr 21, 2025
Apr 26, 2024
Oct 3, 2024
Apr 22, 2025
Apr 21, 2025
Apr 9, 2025
Apr 26, 2024
Oct 3, 2024
Apr 26, 2024

Repository files navigation

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)

const availableFonts = await unifont.listFonts()

console.log(availableFonts)

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.