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

0.1.6 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i unifont

Weekly Downloads

21,370

Version

0.1.6

License

MIT

Unpacked Size

31.4 kB

Total Files

5

Last publish

Collaborators

  • danielroe