google-fonts-helper
Google Fonts Helper
📖 Release Notes
Install
Install using npm, yarn or pnpm:
npm install google-fonts-helper
yarn add google-fonts-helper
pnpm add google-fonts-helper
Import into your Node.js project:
const {
constructURL,
merge,
isValidURL,
parse,
download,
} = require("google-fonts-helper");
import {
constructURL,
merge,
isValidURL,
parse,
download,
} from "google-fonts-helper";
Usage
constructURL(): string
constructURL({ families: { Roboto: true } });
constructURL({ families: { Roboto: true, Lato: true } });
constructURL({ families: { "Crimson Pro": { wght: "200..400" } } });
constructURL({
families: {
Roboto: true,
Lato: {
wght: 100,
},
Raleway: {
wght: [400],
ital: [100, 400],
},
},
});
merge(...fonts: GoogleFonts[]): GoogleFonts
merge({ families: { Roboto: true } }, { families: { Lato: true } });
merge({ families: { Roboto: true } }, { families: { Roboto: [300, 400] } });
isValidURL(url: string): boolean
isValidURL("https://fonts.googleapis.com/css2?family=Roboto");
isValidURL("https://foo.bar");
parse(url: string): GoogleFonts
parse("https://fonts.googleapis.com/css2?family=Roboto");
parse("https://fonts.googleapis.com/css2?family=Roboto&family=Lato");
parse("https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@200..400");
parse("https://foo.bar");
download(url: string, option?: DownloadOptions): Downloader
const downloader = download('https://fonts.googleapis.com/css2?family=Roboto', {
base64: false,
overwriting: false,
outputDir: './',
stylePath: 'fonts.css',
fontsDir: 'fonts',
fontsPath: './fonts'
})
downloader.hook('download-font:before', (font: FontInputOutput) {
console.log(font)
})
downloader.hook('download-font:done', (font: FontInputOutput) {
console.log(font)
})
downloader.hook('download:start', () => {
console.log('Downloading fonts...')
})
downloader.hook('download:complete', () => {
console.log('Download fonts completed.')
})
await downloader.execute()
License
MIT License
Copyright (c) Datalogix