Socket
Socket
Sign inDemoInstall

svg-to-dataurl

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    svg-to-dataurl

😹 convert SVGs to DataURLs


Version published
Weekly downloads
7.6K
decreased by-5.09%
Maintainers
1
Install size
5.02 kB
Created
Weekly downloads
 

Readme

Source

svg-to-dataurl

😹 convert SVGs to DataURLs

Build Status Coverage Status NPM Version XO code style

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)
// data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%3Csvg%20version%3D%221.1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2240%22%20stroke%3D%22black%22%20stroke-width%3D%223%22%20fill%3D%22red%22%20%2F%3E%3C%2Fsvg%3E

Visual Confirmation

You can test the string works by pasting the output into the address bar of your web browser:

Browser Example

Keywords

FAQs

Last updated on 10 Apr 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc