1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2025-02-04 01:53:43 +02:00

Reduce impact of path value on package size (#1521)

* Reduce package size by replacing JSON.stringify by custom stringify func

* Replace path data by getter

* Replace getter by Object.defineProperty

* Remove icon.path definition

* Revert 801c07d4

Apperantly getters have better support then Objct.defineProperty...
This commit is contained in:
Eric Cornelissen 2019-07-14 16:07:24 +01:00 committed by Johan Fagerberg
parent 80483e9597
commit 39b8fdfa85

View File

@ -15,18 +15,28 @@ const fs = require("fs");
const { titleToFilename } = require("./utils");
const icons = {};
// Local helper functions
function iconToKeyValue(icon) {
return `'${icon.title}':${iconToObject(icon)}`;
}
function iconToObject(icon) {
return `{title:'${icon.title}',svg:'${icon.svg}',get path(){return this.svg.match(/<path\\s+d="([^"]*)/)[1];},source:'${icon.source.replace(/'/g, "\\'")}',hex:'${icon.hex}'}`;
}
// 'main'
const icons = [];
data.icons.forEach(icon => {
const filename = titleToFilename(icon.title);
icon.svg = fs.readFileSync(`${iconsDir}/${filename}.svg`, "utf8");
icon.path = icon.svg.match(/<path\s+d="([^"]*)/)[1];
icons[icon.title] = icon;
icons.push(icon)
// write the static .js file for the icon
fs.writeFileSync(
`${iconsDir}/${filename}.js`,
`module.exports=${JSON.stringify(icon)};`
`module.exports=${iconToObject(icon)};`
);
});
// write our generic index.js
fs.writeFileSync(indexFile, `module.exports=${JSON.stringify(icons)};`);
const iconsString = icons.map(iconToKeyValue).join(',');
fs.writeFileSync(indexFile, `module.exports={${iconsString}};`);