gfscoute is a npm tool designed for effortless fonts fetching & downloading from Google Fonts.
- Download By Name: GFScoute makes it easy to search & download the font by its name.
- Multiple Extensions Support: The tool will download the font file locally in its original type [.tff, .woff2, etc...].
To install gfscoute, use npm:
npm install gfscoute
or yarn:
yarn add gfscoute
To use gfscoute, import or require the DownloadFont
from the package:
import DownloadFont from "gfscoute";
const DownloadFont = require("gfscoute");
Example of calling the function /test/:
DownloadFont("Georgia")
.then(console.log("Success"))
.catch((error) => {
console.log(error);
});
The ScoutFont function can be called to search the font, and return a Boolean
response:
import { ScouteFont } from "gfscoute";
const fontName = "Roboto";
ScouteFont(fontName)
.then((resp) => {
if (resp) {
// Font found. Perform action...
});
} else {
// Font could not be found.
}
})
.catch((error) => {
// Handle error
});
Complete example:
"use client";
import { useState } from "react";
import DownloadFont from "gfscoute";
export default function Fonts() {
const [fontName, setFontName] = useState("");
const hadnleDownload = (name: string) => {
DownloadFont(name)
.then(() => console.log("Success"));
.catch((error: Error) => {
throw error;
});
};
return (
<>
<h1>Type font's name</h1>
<input
id="fontName"
value={fontName}
=> setFontName(e.target.value)}
/>
<button => hadnleDownload(fontName)}>
{" "}
Download Font
</button>
</>
);
}