3.6.0 • Published 7 days ago

google-fonts-helper v3.6.0

Weekly downloads
7,631
License
MIT
Repository
github
Last release
7 days ago

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

constructURL({ families: { "Crimson Pro": { wght: "200..400" } } });
// https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@200..400

constructURL({
  families: {
    Roboto: true,
    Lato: {
      wght: 100,
    },
    Raleway: {
      wght: [400],
      ital: [100, 400],
    },
  },
});
// https://fonts.googleapis.com/css2?family=Roboto&family=Lato:wght@100&family=Raleway:ital,wght@0,400;1,100;1,400

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://fonts.googleapis.com/css2?family=Crimson+Pro:wght@200..400");
// { families: { '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

3.6.0

7 days ago

3.5.0

2 months ago

3.4.1

5 months ago

3.4.0

6 months ago

3.3.3

6 months ago

3.3.2

6 months ago

3.3.1

10 months ago

3.3.0

1 year ago

3.2.4

1 year ago

3.2.3

1 year ago

3.2.2

1 year ago

3.2.1

2 years ago

3.2.0

2 years ago

3.1.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.5

4 years ago

1.0.2

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago