1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-11-16 00:59:07 +02:00

Reduce package size by replacing JSON.stringify (#1519)

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

* Escape icon's title and SVG value

... as pointed out by @birjolaxew, if they contain a "'" it will break 
the resulting object.
This commit is contained in:
Eric Cornelissen 2019-07-14 20:15:26 +01:00 committed by Johan Fagerberg
parent c6a9346985
commit 7672bfb2db

View File

@ -20,11 +20,14 @@ const data = require(dataFile);
const { titleToFilename } = require("./utils");
// Local helper functions
function escape(value) {
return value.replace(/'/g, "\\'");
}
function iconToKeyValue(icon) {
return `'${icon.title}':${iconToObject(icon)}`;
}
function iconToObject(icon) {
return `{title:'${icon.title}',slug:'${icon.slug}',svg:'${icon.svg}',get path(){return this.svg.match(/<path\\s+d="([^"]*)/)[1];},source:'${icon.source.replace(/'/g, "\\'")}',hex:'${icon.hex}'}`;
return `{title:'${escape(icon.title)}',slug:'${escape(icon.slug)}',svg:'${escape(icon.svg)}',get path(){return this.svg.match(/<path\\s+d="([^"]*)/)[1];},source:'${escape(icon.source)}',hex:'${icon.hex}'}`;
}
// 'main'