Socket
Socket
Sign inDemoInstall

simple-dom

Package Overview
Dependencies
0
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.2.1

383

dist/simple-dom-test.js

@@ -17,2 +17,22 @@ (function() {

$$document$node$$Node.prototype._cloneNode = function() {
return new $$document$node$$Node(this.nodeType, this.nodeName, this.nodeValue);
};
$$document$node$$Node.prototype.cloneNode = function(deep) {
var node = this._cloneNode();
if (deep) {
var child = this.firstChild, nextChild = child;
while (nextChild) {
nextChild = child.nextSibling;
node.appendChild(child.cloneNode(true));
child = nextChild;
}
}
return node;
};
$$document$node$$Node.prototype.appendChild = function(node) {

@@ -151,2 +171,12 @@ if (node.nodeType === $$document$node$$Node.DOCUMENT_FRAGMENT_NODE) {

$$document$element$$Element.prototype._cloneNode = function() {
var node = new $$document$element$$Element(this.tagName);
node.attributes = this.attributes.map(function(attr) {
return { name: attr.name, value: attr.value, specified: attr.specified };
});
return node;
};
$$document$element$$Element.prototype.getAttribute = function(_name) {

@@ -200,2 +230,6 @@ var attributes = this.attributes;

$$document$text$$Text.prototype._cloneNode = function() {
return new $$document$text$$Text(this.nodeValue);
};
$$document$text$$Text.prototype = Object.create($$document$node$$default.prototype);

@@ -211,2 +245,6 @@ $$document$text$$Text.prototype.constructor = $$document$text$$Text;

$$document$comment$$Comment.prototype._cloneNode = function() {
return new $$document$comment$$Comment(this.nodeValue);
};
$$document$comment$$Comment.prototype = Object.create($$document$node$$default.prototype);

@@ -222,2 +260,6 @@ $$document$comment$$Comment.prototype.constructor = $$document$comment$$Comment;

$$document$document$fragment$$DocumentFragment.prototype._cloneNode = function() {
return new $$document$document$fragment$$DocumentFragment();
};
$$document$document$fragment$$DocumentFragment.prototype = Object.create($$document$node$$default.prototype);

@@ -258,3 +300,160 @@ $$document$document$fragment$$DocumentFragment.prototype.constructor = $$document$document$fragment$$DocumentFragment;

var simple$dom$document$$default = simple$dom$document$$Document;
function simple$dom$html$serializer$$HTMLSerializer(voidMap) {
this.voidMap = voidMap;
}
simple$dom$html$serializer$$HTMLSerializer.prototype.openTag = function(element) {
return '<' + element.nodeName.toLowerCase() + this.attributes(element.attributes) + '>';
};
simple$dom$html$serializer$$HTMLSerializer.prototype.closeTag = function(element) {
return '</' + element.nodeName.toLowerCase() + '>';
};
simple$dom$html$serializer$$HTMLSerializer.prototype.isVoid = function(element) {
return this.voidMap[element.nodeName] === true;
};
simple$dom$html$serializer$$HTMLSerializer.prototype.attributes = function(namedNodeMap) {
var buffer = '';
for (var i=0, l=namedNodeMap.length; i<l; i++) {
buffer += this.attr(namedNodeMap[i]);
}
return buffer;
};
simple$dom$html$serializer$$HTMLSerializer.prototype.escapeAttrValue = function(attrValue) {
return attrValue.replace(/[&"]/g, function(match) {
switch(match) {
case '&':
return '&amp;';
case '\"':
return '&quot;';
}
});
};
simple$dom$html$serializer$$HTMLSerializer.prototype.attr = function(attr) {
if (!attr.specified) {
return '';
}
if (attr.value) {
return ' ' + attr.name + '="' + this.escapeAttrValue(attr.value) + '"';
}
return ' ' + attr.name;
};
simple$dom$html$serializer$$HTMLSerializer.prototype.escapeText = function(textNodeValue) {
return textNodeValue.replace(/[&<>]/g, function(match) {
switch(match) {
case '&':
return '&amp;';
case '<':
return '&lt;';
case '>':
return '&gt;';
}
});
};
simple$dom$html$serializer$$HTMLSerializer.prototype.text = function(text) {
return this.escapeText(text.nodeValue);
};
simple$dom$html$serializer$$HTMLSerializer.prototype.comment = function(comment) {
return '<!--'+comment.nodeValue+'-->';
};
simple$dom$html$serializer$$HTMLSerializer.prototype.serialize = function(node) {
var buffer = '';
var next;
// open
switch (node.nodeType) {
case 1:
buffer += this.openTag(node);
break;
case 3:
buffer += this.text(node);
break;
case 8:
buffer += this.comment(node);
break;
default:
break;
}
next = node.firstChild;
if (next) {
buffer += this.serialize(next);
}
if (node.nodeType === 1 && !this.isVoid(node)) {
buffer += this.closeTag(node);
}
next = node.nextSibling;
if (next) {
buffer += this.serialize(next);
}
return buffer;
};
var simple$dom$html$serializer$$default = simple$dom$html$serializer$$HTMLSerializer;
var simple$dom$void$map$$default = {
AREA: true,
BASE: true,
BR: true,
COL: true,
COMMAND: true,
EMBED: true,
HR: true,
IMG: true,
INPUT: true,
KEYGEN: true,
LINK: true,
META: true,
PARAM: true,
SOURCE: true,
TRACK: true,
WBR: true
};
var $$support$$document = (function (root){
if (root.document) {
return root.document;
}
return new simple$dom$document$$default();
}(this));
function $$support$$element(tagName, attrs) {
var el = $$support$$document.createElement(tagName);
for (var key in attrs) {
el.setAttribute(key, attrs[key]);
}
for (var i=2; i<arguments.length; i++) {
el.appendChild(arguments[i]);
}
return el;
}
function $$support$$fragment() {
var frag = $$support$$document.createDocumentFragment();
for (var i=0; i<arguments.length; i++) {
frag.appendChild(arguments[i]);
}
return frag;
}
function $$support$$text(s) {
return $$support$$document.createTextNode(s);
}
function $$support$$comment(s) {
return $$support$$document.createComment(s);
}
QUnit.module('Element');

@@ -342,36 +541,39 @@

});
var $$support$$document = (function (root){
if (root.document) {
return root.document;
}
return new simple$dom$document$$default();
}(this));
QUnit.test("cloneNode(true) recursively clones nodes", function(assert) {
var parent = $$support$$element('div');
function $$support$$element(tagName, attrs) {
var el = $$support$$document.createElement(tagName);
for (var key in attrs) {
el.setAttribute(key, attrs[key]);
}
for (var i=2; i<arguments.length; i++) {
el.appendChild(arguments[i]);
}
return el;
}
var child1 = $$support$$element('p');
var child2 = $$support$$element('img', { src: "hamster.png" });
var child3 = $$support$$element('span');
function $$support$$fragment() {
var frag = $$support$$document.createDocumentFragment();
for (var i=0; i<arguments.length; i++) {
frag.appendChild(arguments[i]);
}
return frag;
}
parent.appendChild(child1);
parent.appendChild(child2);
parent.appendChild(child3);
function $$support$$text(s) {
return $$support$$document.createTextNode(s);
}
var child11 = $$support$$text('hello');
var child12 = $$support$$element('span');
child12.appendChild($$support$$text(' world'));
var child13 = $$support$$text('!');
function $$support$$comment(s) {
return $$support$$document.createComment(s);
}function simple$dom$html$parser$$HTMLParser(tokenize, document, voidMap) {
child1.appendChild(child11);
child1.appendChild(child12);
child1.appendChild(child13);
var clone = parent.cloneNode(true);
assert.notEqual(parent.firstChild, null);
assert.notStrictEqual(clone.firstChild, parent.firstChild);
var clone2 = parent.cloneNode(true);
assert.notEqual(parent.firstChild, null);
assert.notStrictEqual(clone2.firstChild, clone.firstChild);
assert.notStrictEqual(clone2.firstChild, parent.firstChild);
var actual = new simple$dom$html$serializer$$default(simple$dom$void$map$$default).serialize($$support$$fragment(clone));
assert.equal(actual, '<div><p>hello<span> world</span>!</p><img src="hamster.png"><span></span></div>');
});
function simple$dom$html$parser$$HTMLParser(tokenize, document, voidMap) {
this.tokenize = tokenize;

@@ -455,22 +657,2 @@ this.document = document;

var simple$dom$html$parser$$default = simple$dom$html$parser$$HTMLParser;
var simple$dom$void$map$$default = {
AREA: true,
BASE: true,
BR: true,
COL: true,
COMMAND: true,
EMBED: true,
HR: true,
IMG: true,
INPUT: true,
KEYGEN: true,
LINK: true,
META: true,
PARAM: true,
SOURCE: true,
TRACK: true,
WBR: true
};
function $$utils$$isSpace(char) {

@@ -1035,106 +1217,3 @@ return (/[\t\n\f ]/).test(char);

});
function simple$dom$html$serializer$$HTMLSerializer(voidMap) {
this.voidMap = voidMap;
}
simple$dom$html$serializer$$HTMLSerializer.prototype.openTag = function(element) {
return '<' + element.nodeName.toLowerCase() + this.attributes(element.attributes) + '>';
};
simple$dom$html$serializer$$HTMLSerializer.prototype.closeTag = function(element) {
return '</' + element.nodeName.toLowerCase() + '>';
};
simple$dom$html$serializer$$HTMLSerializer.prototype.isVoid = function(element) {
return this.voidMap[element.nodeName] === true;
};
simple$dom$html$serializer$$HTMLSerializer.prototype.attributes = function(namedNodeMap) {
var buffer = '';
for (var i=0, l=namedNodeMap.length; i<l; i++) {
buffer += this.attr(namedNodeMap[i]);
}
return buffer;
};
simple$dom$html$serializer$$HTMLSerializer.prototype.escapeAttrValue = function(attrValue) {
return attrValue.replace(/[&"]/g, function(match) {
switch(match) {
case '&':
return '&amp;';
case '\"':
return '&quot;';
}
});
};
simple$dom$html$serializer$$HTMLSerializer.prototype.attr = function(attr) {
if (!attr.specified) {
return '';
}
if (attr.value) {
return ' ' + attr.name + '="' + this.escapeAttrValue(attr.value) + '"';
}
return ' ' + attr.name;
};
simple$dom$html$serializer$$HTMLSerializer.prototype.escapeText = function(textNodeValue) {
return textNodeValue.replace(/[&<>]/g, function(match) {
switch(match) {
case '&':
return '&amp;';
case '<':
return '&lt;';
case '>':
return '&gt;';
}
});
};
simple$dom$html$serializer$$HTMLSerializer.prototype.text = function(text) {
return this.escapeText(text.nodeValue);
};
simple$dom$html$serializer$$HTMLSerializer.prototype.comment = function(comment) {
return '<!--'+comment.nodeValue+'-->';
};
simple$dom$html$serializer$$HTMLSerializer.prototype.serialize = function(node) {
var buffer = '';
var next;
// open
switch (node.nodeType) {
case 1:
buffer += this.openTag(node);
break;
case 3:
buffer += this.text(node);
break;
case 8:
buffer += this.comment(node);
break;
default:
break;
}
next = node.firstChild;
if (next) {
buffer += this.serialize(next);
}
if (node.nodeType === 1 && !this.isVoid(node)) {
buffer += this.closeTag(node);
}
next = node.nextSibling;
if (next) {
buffer += this.serialize(next);
}
return buffer;
};
var simple$dom$html$serializer$$default = simple$dom$html$serializer$$HTMLSerializer;
QUnit.module('Serializer', {

@@ -1141,0 +1220,0 @@ beforeEach: function() {

@@ -17,2 +17,22 @@ (function() {

$$document$node$$Node.prototype._cloneNode = function() {
return new $$document$node$$Node(this.nodeType, this.nodeName, this.nodeValue);
};
$$document$node$$Node.prototype.cloneNode = function(deep) {
var node = this._cloneNode();
if (deep) {
var child = this.firstChild, nextChild = child;
while (nextChild) {
nextChild = child.nextSibling;
node.appendChild(child.cloneNode(true));
child = nextChild;
}
}
return node;
};
$$document$node$$Node.prototype.appendChild = function(node) {

@@ -151,2 +171,12 @@ if (node.nodeType === $$document$node$$Node.DOCUMENT_FRAGMENT_NODE) {

$$document$element$$Element.prototype._cloneNode = function() {
var node = new $$document$element$$Element(this.tagName);
node.attributes = this.attributes.map(function(attr) {
return { name: attr.name, value: attr.value, specified: attr.specified };
});
return node;
};
$$document$element$$Element.prototype.getAttribute = function(_name) {

@@ -200,2 +230,6 @@ var attributes = this.attributes;

$$document$text$$Text.prototype._cloneNode = function() {
return new $$document$text$$Text(this.nodeValue);
};
$$document$text$$Text.prototype = Object.create($$document$node$$default.prototype);

@@ -211,2 +245,6 @@ $$document$text$$Text.prototype.constructor = $$document$text$$Text;

$$document$comment$$Comment.prototype._cloneNode = function() {
return new $$document$comment$$Comment(this.nodeValue);
};
$$document$comment$$Comment.prototype = Object.create($$document$node$$default.prototype);

@@ -222,2 +260,6 @@ $$document$comment$$Comment.prototype.constructor = $$document$comment$$Comment;

$$document$document$fragment$$DocumentFragment.prototype._cloneNode = function() {
return new $$document$document$fragment$$DocumentFragment();
};
$$document$document$fragment$$DocumentFragment.prototype = Object.create($$document$node$$default.prototype);

@@ -224,0 +266,0 @@ $$document$document$fragment$$DocumentFragment.prototype.constructor = $$document$document$fragment$$DocumentFragment;

@@ -7,2 +7,6 @@ import Node from './node';

Comment.prototype._cloneNode = function() {
return new Comment(this.nodeValue);
};
Comment.prototype = Object.create(Node.prototype);

@@ -12,2 +16,2 @@ Comment.prototype.constructor = Comment;

export default Comment;
export default Comment;

@@ -7,2 +7,6 @@ import Node from './node';

DocumentFragment.prototype._cloneNode = function() {
return new DocumentFragment();
};
DocumentFragment.prototype = Object.create(Node.prototype);

@@ -12,2 +16,2 @@ DocumentFragment.prototype.constructor = DocumentFragment;

export default DocumentFragment;
export default DocumentFragment;

@@ -15,2 +15,12 @@ import Node from './node';

Element.prototype._cloneNode = function() {
var node = new Element(this.tagName);
node.attributes = this.attributes.map(function(attr) {
return { name: attr.name, value: attr.value, specified: attr.specified };
});
return node;
};
Element.prototype.getAttribute = function(_name) {

@@ -17,0 +27,0 @@ var attributes = this.attributes;

@@ -15,2 +15,22 @@ function Node(nodeType, nodeName, nodeValue) {

Node.prototype._cloneNode = function() {
return new Node(this.nodeType, this.nodeName, this.nodeValue);
};
Node.prototype.cloneNode = function(deep) {
var node = this._cloneNode();
if (deep) {
var child = this.firstChild, nextChild = child;
while (nextChild) {
nextChild = child.nextSibling;
node.appendChild(child.cloneNode(true));
child = nextChild;
}
}
return node;
};
Node.prototype.appendChild = function(node) {

@@ -17,0 +37,0 @@ if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {

@@ -7,2 +7,6 @@ import Node from './node';

Text.prototype._cloneNode = function() {
return new Text(this.nodeValue);
};
Text.prototype = Object.create(Node.prototype);

@@ -12,2 +16,2 @@ Text.prototype.constructor = Text;

export default Text;
export default Text;
{
"name": "simple-dom",
"version": "0.2.0",
"version": "0.2.1",
"description": "A simple JS DOM.",

@@ -24,2 +24,3 @@ "main": "dist/simple-dom.js",

"es6-module-transpiler": "^0.9.6",
"qunit-extras": "^1.4.1",
"qunitjs": "^1.16.0",

@@ -26,0 +27,0 @@ "simple-html-tokenizer": "^0.1.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc