svg-to-dataurl
😹 convert SVGs to DataURLs
Install
$ yarn add svg-to-dataurl
Usage
Where svgStr
is a string of SVG content, like this:
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
</svg>
You can convert the string to a DataURL with svgToDataURL()
:
const svgToDataURL = require('svg-to-dataurl')
const dataUrl = svgToDataURL(svgStr)
console.log(dataUrl)
Visual Confirmation
You can test the string works by pasting the output into the address bar of your web browser: