Socket
Socket
Sign inDemoInstall

is-svg

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-svg - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

index.d.ts

15

index.js
'use strict';
const htmlCommentRegex = require('html-comment-regex');
function isBinary(buf) {
const isBuf = Buffer.isBuffer(buf);
const isBinary = buffer => {
const isBuffer = Buffer.isBuffer(buffer);
for (let i = 0; i < 24; i++) {
const charCode = isBuf ? buf[i] : buf.charCodeAt(i);
const characterCode = isBuffer ? buffer[i] : buffer.charCodeAt(i);
if (charCode === 65533 || charCode <= 8) {
if (characterCode === 65533 || characterCode <= 8) {
return true;

@@ -16,6 +16,9 @@ }

return false;
}
};
const regex = /^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*\s*(?:\[?(?:\s*<![^>]*>\s*)*\]?)*[^>]*>\s*)?<svg[^>]*>[^]*<\/svg>\s*$/i;
module.exports = input => Boolean(input) && !isBinary(input) && regex.test(input.toString().replace(htmlCommentRegex, ''));
const isSvg = input => Boolean(input) && !isBinary(input) && regex.test(input.toString().replace(htmlCommentRegex, ''));
module.exports = isSvg;
module.exports.default = isSvg;
{
"name": "is-svg",
"version": "3.0.0",
"version": "4.0.0",
"description": "Check if a string or buffer is SVG",

@@ -13,9 +13,10 @@ "license": "MIT",

"engines": {
"node": ">=4"
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd-check"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],

@@ -42,5 +43,7 @@ "keywords": [

"devDependencies": {
"ava": "*",
"xo": "*"
"@types/node": "^11.10.4",
"ava": "^1.2.1",
"tsd-check": "^0.3.0",
"xo": "^0.24.0"
}
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc