Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nalchevanidze/svg-json-parser

Convert SVG to JSON Format. it is useful for React SVG icons.
https://github.com/nalchevanidze/svg-json-parser

Last synced: 14 days ago
JSON representation

Convert SVG to JSON Format. it is useful for React SVG icons.

Awesome Lists containing this project

README

        

# svg-json-parser

this App Converts SVG Element to JSON.

```html

npm install svg-json-parser;

var svgParser = require("svg-json-parser");

app.json.lib('lib.svg','Output file path Without .json');
```

converted Object

```html

{
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.

```html

// 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:

```html

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 ();}
}
}

```