mirror of
				https://github.com/Mibew/simple-icons.git
				synced 2025-10-31 02:25:59 +03: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:
		
							parent
							
								
									80483e9597
								
							
						
					
					
						commit
						39b8fdfa85
					
				| @ -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}};`); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user