Check if a string or buffer is SVG
JavaScript
Latest commit f681396 Nov 4, 2016 @sindresorhus 2.1.0
Permalink
Failed to load latest commit information.
fixtures 💄 (#4) Apr 21, 2016
.editorconfig meta tweaks Nov 4, 2016
.gitattributes meta tweaks Nov 4, 2016
.gitignore init Apr 21, 2014
.travis.yml meta tweaks Nov 4, 2016
index.js Update Regex to handle DTD markup declarations (#9) Nov 4, 2016
license init Apr 21, 2014
package.json 2.1.0 Nov 4, 2016
readme.md meta tweaks Nov 4, 2016
test.js Update Regex to handle DTD markup declarations (#9) Nov 4, 2016

readme.md

is-svg Build Status

Check if a string or buffer is SVG

Install

$ npm install --save is-svg

Usage

const isSvg = require('is-svg');

isSvg('<svg xmlns="http://www.w3.org/2000/svg"><path fill="#00CD9F"/></svg>');
//=> true

Edge cases

This module performs a quick-and-dirty check. It's fast, but in certain cases it will give incorrect results.

  • Returns true for an SVG-like string that isn't well-formed or valid: <svg><div></svg>

If you want to make certain that your SVG is valid, try parsing it with libxmljs.

License

MIT © Sindre Sorhus