UNPKG

1.36 kBMarkdownView Raw
1# @svgr/core
2
3[![Build Status][build-badge]][build]
4[![version][version-badge]][package]
5[![MIT License][license-badge]][license]
6
7Node API of SVGR.
8
9```
10npm install @svgr/core
11```
12
13## Usage
14
15```js
16import { transform } from '@svgr/core'
17
18const svgCode = `
19<svg xmlns="http://www.w3.org/2000/svg"
20 xmlns:xlink="http://www.w3.org/1999/xlink">
21 <rect x="10" y="10" height="100" width="100"
22 style="stroke:#ff0000; fill: #0000ff"/>
23</svg>
24`
25
26transform(svgCode, { icon: true }, { componentName: 'MyComponent' }).then(
27 (jsCode) => {
28 console.log(jsCode)
29 },
30)
31```
32
33Use `svgr.sync(code, config, state)` if you would like to use sync version.
34
35### Plugins
36
37By default `@svgr/core` doesn't include any plugin, if you want them, you have to install them and include them in config.
38
39```js
40svgr(svgCode, {
41 plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx', '@svgr/plugin-prettier'],
42}).then((jsCode) => {
43 console.log(jsCode)
44})
45```
46
47## License
48
49MIT
50
51[build-badge]: https://img.shields.io/travis/smooth-code/svgr.svg?style=flat-square
52[build]: https://travis-ci.org/smooth-code/svgr
53[version-badge]: https://img.shields.io/npm/v/@svgr/core.svg?style=flat-square
54[package]: https://www.npmjs.com/package/@svgr/core
55[license-badge]: https://img.shields.io/npm/l/@svgr/core.svg?style=flat-square
56[license]: https://github.com/smooth-code/svgr/blob/master/LICENSE