Update code to ES6
* var -> let / const
* [].forEach -> for (... of ...)
* '...' + var -> template strings `...${var}`
* function -> arrow functions `=>`
* use === and !== instead of == and !=
This commit is contained in:
+23
-28
@@ -1,66 +1,61 @@
|
||||
'use strict';
|
||||
|
||||
var clone = require('clone'),
|
||||
express = require('express'),
|
||||
fs = require('fs'),
|
||||
path = require('path');
|
||||
const clone = require('clone');
|
||||
const express = require('express');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
var utils = require('./utils');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = function(options, allowedFonts) {
|
||||
var app = express().disable('x-powered-by');
|
||||
module.exports = (options, allowedFonts) => {
|
||||
const app = express().disable('x-powered-by');
|
||||
|
||||
var lastModified = new Date().toUTCString();
|
||||
const lastModified = new Date().toUTCString();
|
||||
|
||||
var fontPath = options.paths.fonts;
|
||||
const fontPath = options.paths.fonts;
|
||||
|
||||
var existingFonts = {};
|
||||
var fontListingPromise = new Promise(function(resolve, reject) {
|
||||
fs.readdir(options.paths.fonts, function(err, files) {
|
||||
const existingFonts = {};
|
||||
const fontListingPromise = new Promise((resolve, reject) => {
|
||||
fs.readdir(options.paths.fonts, (err, files) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
files.forEach(function(file) {
|
||||
fs.stat(path.join(fontPath, file), function(err, stats) {
|
||||
for (const file of files) {
|
||||
fs.stat(path.join(fontPath, file), (err, stats) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
if (stats.isDirectory() &&
|
||||
fs.existsSync(path.join(fontPath, file, '0-255.pbf'))) {
|
||||
fs.existsSync(path.join(fontPath, file, '0-255.pbf'))) {
|
||||
existingFonts[path.basename(file)] = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/fonts/:fontstack/:range([\\d]+-[\\d]+).pbf',
|
||||
function(req, res, next) {
|
||||
var fontstack = decodeURI(req.params.fontstack);
|
||||
var range = req.params.range;
|
||||
app.get('/fonts/:fontstack/:range([\\d]+-[\\d]+).pbf', (req, res, next) => {
|
||||
const fontstack = decodeURI(req.params.fontstack);
|
||||
const range = req.params.range;
|
||||
|
||||
utils.getFontsPbf(options.serveAllFonts ? null : allowedFonts,
|
||||
fontPath, fontstack, range, existingFonts).then(function(concated) {
|
||||
fontPath, fontstack, range, existingFonts).then(concated => {
|
||||
res.header('Content-type', 'application/x-protobuf');
|
||||
res.header('Last-Modified', lastModified);
|
||||
return res.send(concated);
|
||||
}, function(err) {
|
||||
return res.status(400).send(err);
|
||||
}
|
||||
}, err => res.status(400).send(err)
|
||||
);
|
||||
});
|
||||
|
||||
app.get('/fonts.json', function(req, res, next) {
|
||||
app.get('/fonts.json', (req, res, next) => {
|
||||
res.header('Content-type', 'application/json');
|
||||
return res.send(
|
||||
Object.keys(options.serveAllFonts ? existingFonts : allowedFonts).sort()
|
||||
);
|
||||
});
|
||||
|
||||
return fontListingPromise.then(function() {
|
||||
return app;
|
||||
});
|
||||
return fontListingPromise.then(() => app);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user