google-fonts-complete
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -0,1 +1,7 @@ | ||
## 2.1.0 (2019-11-13) | ||
- Added: support of Material Icons font | ||
- Updated: Google Fonts base to the latest version | ||
## 2.0.0 (2019-11-07) | ||
@@ -2,0 +8,0 @@ |
@@ -1,9 +0,9 @@ | ||
var URL = 'https://www.googleapis.com/webfonts/v1/webfonts?fields=items(category%2Cfamily%2ClastModified%2Csubsets%2Cvariants%2Cversion)&key='; | ||
const URL = 'https://www.googleapis.com/webfonts/v1/webfonts?fields=items(category%2Cfamily%2ClastModified%2Csubsets%2Cvariants%2Cversion)&key='; | ||
var fs = require('fs'); | ||
var https = require('https'); | ||
const fs = require('fs'); | ||
const https = require('https'); | ||
function fetchGoogleFontsList(url, key) { | ||
return new Promise(function (resolve, reject) { | ||
var req = https.get(url + key, function(res) { | ||
const fetchGoogleFontsList = url => { | ||
return new Promise((resolve, reject) => { | ||
const req = https.get(url, res => { | ||
if (res.statusCode < 200 || res.statusCode > 299) { | ||
@@ -13,9 +13,9 @@ reject(new Error('Failed to load list, status code: ' + res.statusCode)); | ||
var rawData = ''; | ||
let rawData = ''; | ||
res.setEncoding('utf8'); | ||
res.on('data', function(chunk) { return rawData += chunk; }); | ||
res.on('data', chunk => rawData += chunk ); | ||
res.on('end', function() { | ||
try { | ||
var list = JSON.parse(rawData); | ||
const list = JSON.parse(rawData); | ||
resolve(list.items); | ||
@@ -29,7 +29,7 @@ } catch (e) { | ||
// handle connection errors of the request | ||
req.on('error', function(err) { return reject(err); }); | ||
req.on('error', err => reject(err) ); | ||
}) | ||
} | ||
var key = process.argv[2]; | ||
const key = process.argv[2]; | ||
@@ -41,4 +41,4 @@ if (key === undefined) { | ||
fetchGoogleFontsList(URL, key) | ||
.then(function(list) { | ||
fetchGoogleFontsList(URL + key) | ||
.then(list => { | ||
fs.writeFile('api-response.json', JSON.stringify(list, null, '\t'), function () { | ||
@@ -45,0 +45,0 @@ console.log('Operation complete.'); |
@@ -29,7 +29,2 @@ // api-response.json retrieved from: https://www.googleapis.com/webfonts/v1/webfonts?fields=items(category%2Cfamily%2ClastModified%2Csubsets%2Cvariants%2Cversion)&key={YOUR_API_KEY} | ||
const fontToPath = (family, variant) => { | ||
return `/css?subset=latin-ext&family=${family.replace(/\s/g, '+')}:${variant}`; | ||
}; | ||
const fetch = options => { | ||
@@ -122,3 +117,3 @@ return new Promise((resolve, reject) => { | ||
const getFetchOptions = ({ family, variants, format }) => { | ||
const getFetchOptions = ({ family, variants, format, pathCb }) => { | ||
const userAgent = userAgents[format]; | ||
@@ -130,17 +125,13 @@ | ||
return variantsList.map(variant => { | ||
const path = fontToPath(family, variant); | ||
return { | ||
host: 'fonts.googleapis.com', | ||
path: encodeURI(path), | ||
headers: { | ||
'User-Agent': userAgent | ||
} | ||
}; | ||
}); | ||
return variantsList.map(variant => ({ | ||
host: 'fonts.googleapis.com', | ||
path: encodeURI(pathCb({ family, variant })), | ||
headers: { | ||
'User-Agent': userAgent | ||
} | ||
})); | ||
} | ||
const convertFontsOptions = async (fonts) => { | ||
const convertFontsOptions = async (fonts, pathCb) => { | ||
let results = {}; | ||
@@ -160,3 +151,3 @@ | ||
for(const format of agents) { | ||
const optionsList = getFetchOptions({ family, variants, format }); | ||
const optionsList = getFetchOptions({ family, variants, format, pathCb }); | ||
for (const options of optionsList) { | ||
@@ -173,6 +164,36 @@ convertedFont = await convertFont({ convertedFont, family, format }, options); | ||
console.time('convert'); | ||
convertFontsOptions(fonts).then(results => { | ||
Promise.all([ | ||
convertFontsOptions( | ||
fonts, | ||
({ family, variant }) => { | ||
return `/css?subset=latin-ext&family=${family.replace(/\s/g, '+')}:${variant}`; | ||
} | ||
), | ||
convertFontsOptions( | ||
[ | ||
{ | ||
"family": "Material Icons", | ||
"category": "icon", | ||
"variants": [ | ||
"regular", | ||
], | ||
"subsets": [ | ||
"latin" | ||
], | ||
} | ||
], | ||
() => { | ||
return '/icon?family=Material+Icons'; | ||
} | ||
) | ||
]) | ||
.then(results => { | ||
const combinedResults = { | ||
...results[0], | ||
...results[1] | ||
} | ||
fs.writeFile( | ||
'google-fonts.json', | ||
JSON.stringify(getSortedObject(results), null, '\t'), | ||
JSON.stringify(getSortedObject(combinedResults), null, '\t'), | ||
function() { | ||
@@ -179,0 +200,0 @@ console.timeEnd('convert'); |
{ | ||
"name": "google-fonts-complete", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "A complete list of Google Fonts and their sources", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5046792
15832