Comparing version 1.1.1 to 2.0.0
'use strict'; | ||
var htmlCommentRegex = require('html-comment-regex'); | ||
@@ -18,3 +19,3 @@ function isBinary(buf) { | ||
module.exports = function (buf) { | ||
return !isBinary(buf) && /<svg[^>]*>[^]*<\/svg>\s*$/.test(buf); | ||
return !isBinary(buf) && /^\s*(?:<\?xml[^>]*>)?(?:<!doctype svg[^>]*>)?<svg[^>]*>[^]*<\/svg>\s*$/i.test(buf.toString().replace(htmlCommentRegex, '')); | ||
}; |
{ | ||
"name": "is-svg", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"description": "Check if a String/Buffer is SVG", | ||
@@ -10,3 +10,3 @@ "license": "MIT", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "http://sindresorhus.com" | ||
"url": "sindresorhus.com" | ||
}, | ||
@@ -17,3 +17,3 @@ "engines": { | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "xo && ava" | ||
}, | ||
@@ -39,5 +39,9 @@ "files": [ | ||
], | ||
"dependencies": { | ||
"html-comment-regex": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*" | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
} |
@@ -8,3 +8,3 @@ # is-svg [![Build Status](https://travis-ci.org/sindresorhus/is-svg.svg?branch=master)](https://travis-ci.org/sindresorhus/is-svg) | ||
```sh | ||
``` | ||
$ npm install --save is-svg | ||
@@ -17,2 +17,4 @@ ``` | ||
```js | ||
const isSvg = require('is-svg'); | ||
isSvg('<svg xmlns="http://www.w3.org/2000/svg"><path fill="#00CD9F"/></svg>'); | ||
@@ -22,5 +24,13 @@ //=> true | ||
## Edge cases | ||
This module performs a quick-and-dirty check. It's fast, but in certain cases it'll 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](https://github.com/polotek/libxmljs). | ||
## License | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3143
15
34
1
2
+ Addedhtml-comment-regex@^1.1.0
+ Addedhtml-comment-regex@1.1.2(transitive)