mirror of
https://github.com/Mibew/simple-icons.git
synced 2024-11-16 02:14:12 +03: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:
parent
c6a9346985
commit
7672bfb2db
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user