Registry / http-networking / unifont

unifont

JSON →
library0.7.4jsnpmunverified

Unifont is a framework-agnostic JavaScript/TypeScript library designed to streamline access to font data from various Content Delivery Networks (CDNs) and font providers. It abstracts away the complexities of fetching and resolving fonts, supporting popular services like Google Fonts, Adobe Fonts, Bunny Fonts, Fontshare, and Fontsource. The library is currently at version 0.7.4 and maintains an active release cadence, frequently adding new provider features and addressing bug fixes, as seen in its recent updates like npm package resolution support and Adobe race condition handling. A key differentiator is its modular provider architecture, allowing users to integrate multiple font sources and even develop custom providers, simplifying font management and optimization across projects. It is an ESM-only package.

npm install unifont
INSTALL
IMPORT
SIG · UNIFONT
U
unifont
http-networkingjavascriptv0.7.4
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createUnifont
✓ import { createUnifont } from 'unifont';
✗ const { createUnifont } = require('unifont');
Unifont is an ESM-only package. CommonJS 'require' syntax will not work.
providers
✓ import { providers } from 'unifont';
✗ import providers from 'unifont';
The 'providers' object is a named export, not a default export.
providers.google
✓ import { providers } from 'unifont'; const googleProvider = providers.google();
✗ import { google } from 'unifont/providers';
Individual providers are accessed as properties of the 'providers' object.
InitializedProvider
✓ import type { InitializedProvider } from 'unifont';
Type imports for TypeScript users.
ResolveFontResult
✓ import type { ResolveFontResult } from 'unifont';
Type imports for TypeScript users, useful for destructuring results.

This quickstart demonstrates how to initialize Unifont with multiple providers, list available fonts, and resolve specific font families with optional configurations like variable axis settings for Google Fonts.

import { createUnifont, providers } from 'unifont'; async function main() { // Initialize Unifont with one or more providers. // The Google Fonts provider is initialized without specific options here. const unifont = await createUnifont([ providers.google(), providers.bunny(), // Adding another provider for a more robust example ]); // List all available fonts from the configured providers. console.log('Fetching available fonts...'); const availableFonts = await unifont.listFonts(); console.log('Available fonts:', availableFonts.slice(0, 5).map(f => f.name).join(', ') + '...'); // Log first 5 for brevity // Resolve a specific font family, e.g., 'Poppins'. // This will fetch the necessary font files and metadata. console.log('\nResolving "Poppins" font...'); const { fonts: poppinsFonts, metrics: poppinsMetrics } = await unifont.resolveFont('Poppins'); console.log('Resolved Poppins font files count:', poppinsFonts.length); // console.log('First Poppins font URL:', poppinsFonts[0]?.src); // Accessing the source URL for a resolved font // Example of resolving a font with specific options, like variable axis for Google Fonts // For Adobe Fonts, you would typically pass an ID: providers.adobe({ id: process.env.ADOBE_FONT_KIT_ID ?? '' }) const { fonts: robotoFonts } = await unifont.resolveFont('Roboto Flex', { options: { google: { experimental: { variableAxis: { wght: [['100', '900']], }, }, }, }, }); console.log('Resolved Roboto Flex (variable) font files count:', robotoFonts.length); } main().catch(console.error);
Debug
Known issues
breakingStarting from v0.4.0, Unifont only downloads variable font faces when explicitly necessary. This change was implemented for optimization, but users might need to adjust their configurations if they previously relied on all variable font faces being downloaded by default.
fix
Review font resolution configurations and explicitly request all desired variable font faces if they are not being loaded as expected.
affects: >=0.4.0
gotchaUnifont is an ESM-only package. Attempting to import it using CommonJS 'require()' syntax will result in runtime errors.
fix
Ensure your project is configured for ESM, typically by setting `"type": "module"` in `package.json` or using `.mjs` file extensions, and use `import` statements.
affects: >=0.1.0
gotchaThe Adobe Fonts provider requires a kit `id`. Failing to provide this `id` will lead to resolution errors. It is strongly recommended to load this ID from environment variables for security and flexibility.
fix
When initializing `providers.adobe()`, ensure you pass the `id` option, e.g., `providers.adobe({ id: process.env.ADOBE_KIT_ID ?? '' })`.
affects: >=0.1.0
gotchaWhile v0.7.4 includes a fix for race conditions with concurrent Adobe resolution, highly concurrent font fetching operations, especially with external providers, can still be prone to transient issues. Implement robust error handling and potentially introduce retries or rate limiting for critical paths.
fix
Upgrade to v0.7.4 or later. For very high-concurrency scenarios, consider implementing custom retry logic or rate limiting around `unifont.resolveFont()` calls.
affects: <0.7.4
Errors
Common errors & fixes
TypeError: (0 , unifont__WEBPACK_IMPORTED_MODULE_0__.createUnifont) is not a function
Attempting to use Unifont (an ESM package) within a CommonJS environment, or incorrect bundler configuration.
fix
Ensure your project uses ES Modules (ESM). For Node.js, set `"type": "module"` in `package.json`. For bundlers, verify that your configuration supports ESM imports. Also, check for incorrect named vs default imports.
Error: Adobe provider requires 'id' option.
The `providers.adobe()` function was called without the required `id` option.
fix
Pass the Adobe Fonts kit ID to the provider initialization: `providers.adobe({ id: 'your-adobe-kit-id' })`. It is recommended to load this from an environment variable.
Error: Provider 'unknownProvider' not found.
An invalid or unregistered provider name was passed to `createUnifont` or `unifont.resolveFont` options.
fix
Ensure you are using one of the built-in providers (e.g., `providers.google()`, `providers.adobe()`) or a correctly implemented custom provider.
Upgrade
Version history
0.7.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
unifont — npm install unifont · libregistry