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

simplesvg

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

simplesvg - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

lib/compileTemplate.js

29

index.js
module.exports = svg;
svg.compile = require('./lib/compile');
var compileTemplate = svg.compileTemplate = require('./lib/compileTemplate');
var domEvents = require('add-event-listener');
var svgns = "http://www.w3.org/2000/svg";

@@ -16,2 +21,4 @@ var xlinkns = "http://www.w3.org/1999/xlink";

var compiledTempalte;
svgElement.simplesvg = true; // this is not good, since we are monkey patching svg

@@ -21,4 +28,26 @@ svgElement.attr = attr;

// add easy eventing
svgElement.on = on;
svgElement.off = off;
// data binding:
svgElement.dataSource = dataSource;
return svgElement;
function dataSource(model) {
if (!compiledTempalte) compiledTempalte = compileTemplate(svgElement);
compiledTempalte.link(model);
}
function on(name, cb, useCapture) {
domEvents.addEventListener(svgElement, name, cb, useCapture);
return svgElement;
}
function off(name, cb, useCapture) {
domEvents.removeEventListener(svgElement, name, cb, useCapture);
return svgElement;
}
function append(child) {

@@ -25,0 +54,0 @@ svgElement.appendChild(svg(child));

18

lib/compile.js

@@ -8,5 +8,4 @@ var parser = new DOMParser();

try {
return svg(parser.parseFromString(
'<g xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg">' +
svgText + '</g>', "text/xml").documentElement);
svgText = addNamespaces(svgText);
return svg(parser.parseFromString(svgText, "text/xml").documentElement);
} catch (e) {

@@ -16,1 +15,14 @@ throw e;

}
function addNamespaces(text) {
if (!text) return;
var namespaces = 'xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"';
var match = text.match(/^<\w+/);
if (match) {
var tagLength = match[0].length;
return text.substr(0, tagLength) + ' ' + namespaces + ' ' + text.substr(tagLength);
} else {
throw new Error('Cannot parse input text: invalid xml?');
}
}

5

package.json
{
"name": "simplesvg",
"version": "0.0.1",
"version": "0.0.2",
"description": "A very simple svg wrapper, inspired by original vivagraph",

@@ -18,3 +18,6 @@ "main": "index.js",

"url": "https://github.com/anvaka/simplesvg"
},
"dependencies": {
"add-event-listener": "0.0.1"
}
}
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