Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
google-font-installer
Advanced tools
Readme
Google Font Installer is written in NodeJS and let you Search, Donwload and Install any font offered by Google Web Fonts.
You can use it in two ways:
In Linux and OSX, the font will be installed in the user's font directory (~/.fonts for Linux, ~/Library/Fonts for OSX).
In Windows, due to the fact that font installation require some register modifications, I prefered to create a little WScript (a windows script that use ActiveX windows interface) and spawn a cscript
process to install the font in 'windows native way'.
First of all you have to install google-font-installer in your system
$ sudo npm install -g google-font-installer
If you are on a Windows Machine, you have to omit sudo
before npm
Now, from your terminal emulator, you can use the command gfi
$ gfi search [family_name]
The search is really permissive, so you can specify only few characters and view all the font families that contains these characters. Words order is also not important. For instance, search for Source Sans or Sans Source will produce the same result.
$ gfi download [family_name] [-d|--dest destination_folder] [-v|--variants comma_separeted_variants]
If family_name will match more than one family, nothing will be downloaded: a list of alternatives will help you better specify the font family name.
Download command accepts two options:
-d
or --dest
let you specify the folder where to download the fonts. If this option is omitted the fonts will be download in the folder in which the command was called (or in the home directory if this folder is not writable by the user)-v
or --variants
let you specify which variants of the font will be downloaded. You have to write each variant separated by the other with a comma. For exemple $ gfi download Source Sans Pro -v 300,400
. If omitted, all variants will be downloaded.$ gfi install [family_name] [-v|--variants comma_separeted_variants]
If family_name will match more than one family, nothing will be installed: a list of alternatives will help you better specify the font family name.
Install command accepts only one option:
-v
or --variants
let you specify which variants of the font will be installed. You have to write each variant separated by the other with a comma. For exemple $ gfi install Source Sans Pro -v 300,400
. If omitted, all variants will be downloaded.Search the source keyword:
$ gfi search source
Search reuslts for: "source"
* Source Code Pro
Category: monospace
Variants: 200, 300, regular, 500, 600, 700, 900
CSS Url: https://fonts.googleapis.com/css?family=Source+Code+Pro
* Source Sans Pro
Category: sans-serif
Variants: 200, 200italic, 300, 300italic, regular, italic, 600, 600italic, 700, 700italic, 900, 900italic
CSS Url: https://fonts.googleapis.com/css?family=Source+Sans+Pro
* Source Serif Pro
Category: serif
Variants: regular, 600, 700
CSS Url: https://fonts.googleapis.com/css?family=Source+Serif+Pro
Download Source Sans Pro 600 and 700italic:
$ gfi download source sans -v 600,700italic
Source Sans Pro variant 600 downloaded in /home/user/someFolder/SourceSansPro-600.ttf
Source Sans Pro variant 700italic downloaded in /home/user/someFolder/SourceSansPro-700italic.ttf
Install Lato 100
$ gfi install lato -v 100
Lato variant 100 downloaded in /home/user/.fonts/Lato-100.ttf
First of all you have to install the module in you NodeJS project:
$ npm install google-font-installer --save
And then you can require it in your code:
var GoogleFontList = require('google-font-installer');
To use this API is necessary to obtain a Browser Key enabled to Google Font API from the Google Developer Dashboard.
GoogleFontList is a class that can be instanced with the Google API Key as only argument.
var fontList = new GoogleFontList('API_KEY');
If you prefer you can also create an instance without the apiKey and call the methods .setApiKey('API_KEY')
and .downloadList()
in a second moment.
var fontList = new GoogleFontList();
fontList.setApiKey('API_KEY');
fontList.downloadList();
'success'
Emitted when the Font List is downloaded from Google and the data are converted, stored and processed. Callback contains only one argument for convenience: the object itself
'error'
Emitter if something go wrong in downloading, coverting or processing data. The Callback argument is the error object.
data
[Array]Array of GoogleFont instances, a class that extends the data provided by the Google APIs. Empty until 'success' event.
apiKey
[String]The Google APIs Key setted with the constructor or with setApiKey().
setApiKey('API_KEY')
Used to set the apiKey to download data from Google Web Font APIs.
downloadList()
Download the list from Google Web Font APIs.
parseRawData(rawData)
Parse raw data in valid JSON format. Used internally, but public for convenience if someone prefers to use the object without downloading the list (ex. cached data).
populate(jsonData)
Populate the object data
property with an array of GoogleFont instances, based on the data provided by Google Apis. Used internally, but public for convenience if someone prefers to use the object without downloading and parsing the list (ex. cached data).
clone()
Return a new instance of the object, with the same data
and apiKey
properties.
searchFont(term, field, callback)
Function with callback used to search a specific string inside a specific property of googleFont object.
searchFontByName(term, callback)
Same as searchFont, but specific for the Family property. (the font name)
searchFontByType(term, callback)
Same as searchFont, but specific for the Category property. (for instance serif, sans-serif, display, etc)
getFirst()
data
property, else return false.isSingle()
data
property, else return false.forEachFont(fn)
Execture fn foreach GoogleFOnt in GoogleFontList data
property. It's async.
Class that extends data structure provided by Google APIs.
It's instanced by the populate method of GoogleFontList, called internally by the constructor or by parseRawData method.
Every object inside the data
property of GoogleFontList is an instance of this class.
family
category
version
lastModified
[String]Inherits by Google Font API structure, respectively the font name, the font type (serif, sans-serif, etc), the version and the string rappresenting the last modification data.
subsets
[Array]Inherits by Google Font API structure, a list of the available subsest for that font.
variants
[Array]Inherits by Google Font API structure, a list of all available variants (weights) for that font.
files
[Object]Inherits by Google Font API structure, an object with key-value of variant and ttf remote file.
cssUrl
[String]Url of the css file containing the ready-to-use imports for the web about that specific font.
getFamily()
getCategory()
getVariants()
getSubsets()
getVersion()
getLastMod()
getFileList()
getCssUrl()
Method to access to the public properties: it's a better idea use them insteed the properties for a future-proof reason. Maybe someday google will decide to changhe his properties names.
All returns the type of the property, except GetLastMod()
that return a new Date instance.
hasVariant(variant)
getFiles(variants)
saveAt(variants, destFolder, callback)
Download specified variants of the font in the destination folder directory.
download(variants, callback)
Download specified variants of the font in the current directory (where the script is called).
install(variants, callback)
Install specified variants of the font. The destination folder depends on the platform used:
var GoogleFontlist = require('google-font-installer');
var fontList = new GoogleFontlist('VALID_API_KEY');
fontList.on('success', function(){
this.searchFontByName('Source Sans Pro', function(err, filteredList) {
if (err)
throw err;
filteredList.getFirst().download(['300', '400'], function(err, result){
if (err)
throw err;
result.forEach(function(el){
console.log('Variant %s of %s downloaded in %s', el.variant, el.family, el.path);
})
});
})
})
fontList.on('error', function(err){
throw err;
})
FAQs
Download and install Google Web Fonts on your local machine
The npm package google-font-installer receives a total of 1,113 weekly downloads. As such, google-font-installer popularity was classified as popular.
We found that google-font-installer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.