Skip to content

rankun203/google-fonts-helper

 
 

Repository files navigation

google-fonts-helper

npm version npm downloads Github Actions CI Codecov License

Google Fonts Helper

📖 Release Notes

Install

Install using npm, yarn or pnpm:

npm install google-fonts-helper
# or
yarn add google-fonts-helper
# or
pnpm add google-fonts-helper

Import into your Node.js project:

const { constructURL, merge, isValidURL, parse, download } = require('google-fonts-helper')
// or
import { constructURL, merge, isValidURL, parse, download } from 'google-fonts-helper'

Usage

constructURL(): string

constructURL({ families: { Roboto: true } }) // https://fonts.googleapis.com/css2?family=Roboto
constructURL({ families: { Roboto: true, Lato: true } }) // https://fonts.googleapis.com/css2?family=Roboto&family=Lato

merge(...fonts: GoogleFonts[]): GoogleFonts

merge({ families: { Roboto: true } }, { families: { Lato: true } })  // { families: { Roboto: true, Lato: true } }
merge({ families: { Roboto: true } }, { families: { Roboto: [300, 400] } })  // { families: { Roboto: [300, 400] } }

isValidURL(url: string): boolean

isValidURL('https://fonts.googleapis.com/css2?family=Roboto') // true
isValidURL('https://foo.bar') // false

parse(url: string): GoogleFonts

parse('https://fonts.googleapis.com/css2?family=Roboto') // { families: { Roboto: true } }
parse('https://fonts.googleapis.com/css2?family=Roboto&family=Lato') // { families: { Roboto: true, Lato: true } }
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)
})

await downloader.execute()

License

MIT License

Copyright (c) Ricardo Gobbo de Souza

About

Google Fonts Helper fixed deepmerge import

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%