spacegiant / svg-to-jsx

πŸŒ“ Transform SVG to valid JSX

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SVG to JSX πŸŒ“

Tiny module for transforming SVG to valid JSX

npm version

Install βš™

yarn add @balajmarius/svg-to-jsx --dev

Test β›±

yarn test

Use πŸ› 

const fs = require('fs')
const path = require('path')
const transform = require('@balajmarius/svg-to-jsx')

const filepath = path.resolve(__dirname, 'test.svg')

fs.readFile(filepath, 'utf8', (error, data) => {

  if (error) throw new Error('😞 Something went wrong')

  return transform(data)
    .then(transformedSVG => console.log(transformedSVG))
    .catch(error => console.log(error))

})

What it does βœ…

  • Convert attributes to valid JSX attributes
  • Convert CSS to Javascript
  • Convert CSS (fill, display, ..) to attributes
  • Remove useless attributes

TODO πŸ“

  • Single/double quotes option
  • Format option
  • React-native

About

πŸŒ“ Transform SVG to valid JSX


Languages

Language:JavaScript 100.0%