Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svg-inline-loader

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-inline-loader - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

9

CHANGELOG.md
# Changelog
## 0.2.3
* Tag removal is fixed (`<defs />`, `<style />`, `<title />`, ...) and test
added
## 0.2.2
* Added unittest
## 0.2.1

@@ -4,0 +13,0 @@

46

index.js

@@ -20,7 +20,2 @@ var simpleHTMLTokenizer = require('simple-html-tokenizer');

// Non-displayed elements
[/<title>.*<\/title>/gi, ""],
[/<desc>.*<\/desc>/gi, ""],
[/<defs>.*<\/defs>/gi, ""],
// SVG XML -> HTML5

@@ -32,2 +27,13 @@ [/\<([A-Za-z]+)([^\>]*)\/\>/g, "<$1$2></$1>"], // convert self-closing XML SVG nodes to explicitly closed HTML5 SVG nodes

var removingTags = [
'title',
'desc',
'defs',
'style'
];
function isRemovingTag (tag) {
return removingTags.indexOf(tag.tagName) > -1;
}
function getExtractedSVG (svgStr) {

@@ -49,11 +55,27 @@ // Clean-up XML crusts like comments and doctype, etc.

// FIXME: Due to limtation of parser, we need to implement our
// very own little state machine to express tree structure
var removingTag = null;
// If the token is <svg> start-tag, then remove width and height attributes.
tokens.forEach(function(tag) {
if (isSVGToken(tag)) {
tag.attributes = tag.attributes.filter(hasNoWidthHeight);
return generate(tokens.map(function(tag) {
if (removingTag == null) {
// Reached start tag of a removing tag
if (isRemovingTag(tag)) {
removingTag = tag.tagName;
tag = null;
// Other stuffs that needs to be modified
} else if (isSVGToken(tag)) {
tag.attributes = tag.attributes.filter(hasNoWidthHeight);
}
} else {
// Reached end tag of a removing tag
if (tag.tagName === removingTag && tag.type === 'EndTag') {
removingTag = null;
}
tag = null;
}
});
// Finally, assemble tokens
return generate(tokens);
return tag;
})
.filter(function (nonNull) { return nonNull; }));
}

@@ -60,0 +82,0 @@

{
"name": "svg-inline-loader",
"version": "0.2.2",
"version": "0.2.3",
"description": "Cleans up and inlines your SVG files into Webpack module.",

@@ -35,4 +35,5 @@ "main": "index.js",

"karma-webpack": "^1.5.1",
"node-libs-browser": "^0.5.2"
"node-libs-browser": "^0.5.2",
"raw-loader": "^0.5.1"
}
}

Sorry, the diff of this file is not supported yet

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