svg-json-parser
this App Converts SVG Element to JSON.
npm install svg-json-parser; var svgParser = require("svg-json-parser"); app.json.lib('lib.svg','Output file path Without .json');
converted Object
{ node:"svg", id:"svglib", children:[ {"node":"g",id:apple,children:[{node:"path",attr:{d:"M10..",fill="red"}},.....]}, {"node":"path",id:orange,attr:{fill="#FF3456"}}, ..... ]}
lib method
returns SVG elements as the properties of the object, will be included only elements with ID attribute; only direct children need id Attributes. and can be passed only: SVG or SVG "defs" element.
// it not, no id ....... var svglib = svgParser.json.lib();{ work:{ node:"g", id:"work", children:[ {"node":"path",attr{"d":"M0..."}}, {"node":"path",attr{"d":"M0..."}} ] }, gmail:{ node:"path", id:"gmail", attr{"d":"M0..."}} },.....}
you can use lib object in react:
class Icon extends React.Component { render(){ var s = svglib[this.props.id]; if(s.node=="g"){return ({sv.children.map((e,i)=>)});} else if(s.node=="path"){return ();} }}