font-awesome-svg-png
Version:
Font Awesome split to individual SVG and PNG files of different sizes along with Node.JS based generator
31 lines (27 loc) • 834 B
JavaScript
var Promise = require("bluebird"),
indexBy = require('lodash.indexby'),
readFile = Promise.promisify(require("fs").readFile),
parseXml = Promise.promisify(require("xml2js").parseString);
var SVG_FILE = require.resolve("font-awesome/fonts/fontawesome-webfont.svg");
function getFontData() {
return readFile(SVG_FILE)
.then(function (fontData) {
return fontData.toString("utf-8");
})
.then(parseXml)
.then(function (parsedXml) {
return parsedXml.svg.defs[0].font[0].glyph;
})
.map(function (xmlGlyph) {
if (xmlGlyph.$.unicode) {
return {
data: xmlGlyph.$,
unicodeDec: xmlGlyph.$.unicode.charCodeAt(0)
};
}
})
.then(function (fontData) {
return indexBy(fontData, "unicodeDec");
});
}
module.exports = getFontData;