Skip to content

Instantly share code, notes, and snippets.

@lgk-bsw
Created July 17, 2020 09:50
Show Gist options
  • Save lgk-bsw/d6bf964d73c6ec7789c9ce7b2dabc5bd to your computer and use it in GitHub Desktop.
Save lgk-bsw/d6bf964d73c6ec7789c9ce7b2dabc5bd to your computer and use it in GitHub Desktop.
SVG to React generator
const fs = require("fs");
const path = require("path");
const svgToJsx = require("svg-to-jsx");
const parser = require("fast-xml-parser");
let componentCodes = [];
function main() {
const dir = fs.readdirSync(".");
dir.forEach(file => {
const extension = path.extname(file);
console.log(extension);
if (extension.toLowerCase() === ".svg") {
const svg = fs.readFileSync(file, "utf-8");
svgToJsx(svg, (error, jsx) => {
if (error) console.error(error);
console.log(jsx);
const jsonObj = parser.parse(svg);
console.log(jsonObj);
componentCodes.push(``);
});
}
});
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment