A Google Fonts library specifically designed for the v2 API and variable fonts, which helps to load them in the browser.
- Google Fonts v2 API
- Variable fonts
- Promise that await for a font to be fully loaded
- List loaded fonts
- Unloading fonts
- Type safe/Typescript support
npm install google-fonts-loader-v2
# or
yarn add google-fonts-loader-v2
# or
pnpm add google-fonts-loader-v2
# or
bun add google-fonts-loader-v2
import {loadAwait, list, unload} from "google-fonts-loader-v2";
console.log("Loading Open Sans…");
await loadAwait({
family: "Open Sans",
axisTupleList: [
[
{tag: "ital", value: 0},
{tag: "wght", value: 500},
],
[
{tag: "ital", value: 1},
{tag: "wght", value: 500},
],
],
}, {
display: "swap",
});
console.log("Open Sans loaded!");
console.log(`${list().length} fonts loaded!`);
console.log("Unloading Open Sans…");
unload({
family: "Open Sans",
});
console.log("Open Sans unloaded!");
load(font: Font, options?: Options): void
Just load the given font in the curent page.
loadAwait(font: Font, options?: Options): Promise<void>
Load the given font and return a promise that resolve when the font is fully loaded.
list(): Font[]
List the currently loaded fonts.
unload(font: Font): void
Unload the given font family.
unloadAll(): void
Unload all the previously loaded fonts.
- https://fonts.googleapis.com/css2?family=Nabla:EHLT@5;12&display=swap seems to return 400 code while this query should be valid