Socket
Socket
Sign inDemoInstall

undom

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

undom - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

67

dist/undom.js

@@ -15,6 +15,2 @@ (function (global, factory) {

function createAttributeFilter(ns, name) {
return function (o) { return o.ns===ns && o.name===toLower(name); };
}
function splice(arr, item, add, byValueOnly) {

@@ -32,2 +28,6 @@ var i = arr ? findWhere(arr, item, true, byValueOnly) : -1;

function createAttributeFilter(ns, name) {
return function (o) { return o.ns===ns && toLower(o.name)===toLower(name); };
}
/*

@@ -51,2 +51,7 @@ const NODE_TYPES = {

function undom() {
function isElement(node) {
return node.nodeType===1;
}
var Node = function Node(nodeType, nodeName) {

@@ -57,16 +62,26 @@ this.nodeType = nodeType;

};
var prototypeAccessors = { nextSibling: {},previousSibling: {},firstChild: {},lastChild: {} };
prototypeAccessors.nextSibling.get = function () {
var p = this.parentNode;
if (p) return p.childNodes[findWhere(p.childNodes, this, true) + 1];
};
prototypeAccessors.previousSibling.get = function () {
var p = this.parentNode;
if (p) return p.childNodes[findWhere(p.childNodes, this, true) - 1];
};
prototypeAccessors.firstChild.get = function () {
return this.childNodes[0];
};
prototypeAccessors.lastChild.get = function () {
return this.childNodes[this.childNodes.length-1];
};
Node.prototype.appendChild = function appendChild (child) {
child.remove();
child.parentNode = this;
this.childNodes.push(child);
if (this.children && child.nodeType===1) this.children.push(child);
this.insertBefore(child);
};
Node.prototype.insertBefore = function insertBefore (child, ref) {
child.remove();
var i = splice(this.childNodes, ref, child);
if (!ref) this.appendChild(child);
else if (~i && child.nodeType===1) {
while (i<this.childNodes.length && (ref = this.childNodes[i]).nodeType!==1 || ref===child) i++;
if (ref) splice(this.children, ref, child);
}
child.parentNode = this;
if (!ref) this.childNodes.push(child);
else splice(this.childNodes, ref, child);
};

@@ -81,3 +96,2 @@ Node.prototype.replaceChild = function replaceChild (child, ref) {

splice(this.childNodes, child);
if (child.nodeType===1) splice(this.children, child);
};

@@ -88,7 +102,9 @@ Node.prototype.remove = function remove () {

Object.defineProperties( Node.prototype, prototypeAccessors );
var Text = (function (Node) {
function Text(text) {
Node.call(this, 3, '#text'); // TEXT_NODE
this.textContent = this.nodeValue = text;
this.nodeValue = text;
}

@@ -100,2 +116,12 @@

var prototypeAccessors$1 = { textContent: {} };
prototypeAccessors$1.textContent.set = function (text) {
this.nodeValue = text;
};
prototypeAccessors$1.textContent.get = function () {
return this.nodeValue;
};
Object.defineProperties( Text.prototype, prototypeAccessors$1 );
return Text;

@@ -109,3 +135,2 @@ }(Node));

this.attributes = [];
this.children = [];
this.__handlers = {};

@@ -118,2 +143,8 @@ }

var prototypeAccessors$2 = { children: {} };
prototypeAccessors$2.children.get = function () {
return this.childNodes.filter(isElement);
};
Element.prototype.setAttribute = function setAttribute (key, value) {

@@ -161,2 +192,4 @@ this.setAttributeNS(null, key, value);

Object.defineProperties( Element.prototype, prototypeAccessors$2 );
return Element;

@@ -163,0 +196,0 @@ }(Node));

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.undom=e()}(this,function(){function t(t,e){for(var n in e)t[n]=e[n]}function e(t){return String(t).toLowerCase()}function n(t,n){return function(o){return o.ns===t&&o.name===e(n)}}function o(t,e,n,o){var i=t?r(t,e,!0,o):-1;return~i&&(n?t.splice(i,0,n):t.splice(i,1)),i}function r(t,e,n,o){for(var r=t.length;r--&&("function"!=typeof e||o?t[r]!==e:!e(t[r])););return n?r:t[r]}function i(){function i(t){return new d(null,String(t).toUpperCase())}function u(t,e){var n=i(e);return n.namespace=t,n}function p(t){return new h(t)}function s(){var e=new a;return t(e,e.defaultView={document:e,Document:a,Node:c,Text:h,Element:d,Event:l}),t(e,{documentElement:e,createElement:i,createElementNS:u,createTextNode:p}),e.appendChild(e.body=i("body")),e}var c=function(t,e){this.nodeType=t,this.nodeName=e,this.childNodes=[]};c.prototype.appendChild=function(t){t.remove(),t.parentNode=this,this.childNodes.push(t),this.children&&1===t.nodeType&&this.children.push(t)},c.prototype.insertBefore=function(t,e){t.remove();var n=o(this.childNodes,e,t);if(e){if(~n&&1===t.nodeType){for(;n<this.childNodes.length&&1!==(e=this.childNodes[n]).nodeType||e===t;)n++;e&&o(this.children,e,t)}}else this.appendChild(t)},c.prototype.replaceChild=function(t,e){e.parentNode===this&&(this.insertBefore(t,e),e.remove())},c.prototype.removeChild=function(t){o(this.childNodes,t),1===t.nodeType&&o(this.children,t)},c.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)};var h=function(t){function e(e){t.call(this,3,"#text"),this.textContent=this.nodeValue=e}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(c),d=function(t){function i(e,n){t.call(this,e||1,n),this.attributes=[],this.children=[],this.__handlers={}}return t&&(i.__proto__=t),i.prototype=Object.create(t&&t.prototype),i.prototype.constructor=i,i.prototype.setAttribute=function(t,e){this.setAttributeNS(null,t,e)},i.prototype.getAttribute=function(t){return this.getAttributeNS(null,t)},i.prototype.removeAttribute=function(t){this.removeAttributeNS(null,t)},i.prototype.setAttributeNS=function(t,e,o){var i=r(this.attributes,n(t,e));i||this.attributes.push(i={ns:t,name:e}),i.value=String(o)},i.prototype.getAttributeNS=function(t,e){var o=r(this.attributes,n(t,e));return o&&o.value},i.prototype.removeAttributeNS=function(t,e){o(this.attributes,n(t,e))},i.prototype.addEventListener=function(t,n){(this.__handlers[e(t)]||(this.__handlers[e(t)]=[])).push(n)},i.prototype.removeEventListener=function(t,n){o(this.__handlers[e(t)],n,0,!0)},i.prototype.dispatchEvent=function(t){var n,o,r=t.currentTarget=this,i=t.cancelable;do if(n=r.__handlers[e(t.type)])for(o=n.length;o--&&(n[o](t)!==!1&&!t._end||!i););while(t.bubbles&&(!i||!t._stop)&&(t.target=r=r.parentNode));return!t.defaultPrevented},i}(c),a=function(t){function e(){t.call(this,9,"#document")}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(d),l=function(t,e){this.type=t,this.bubbles=!!e.bubbles,this.cancelable=!!e.cancelable};return l.prototype.stopPropagation=function(){this._stop=!0},l.prototype.stopImmediatePropagation=function(){this._end=this._stop=!0},l.prototype.preventDefault=function(){this.defaultPrevented=!0},s()}return i});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.undom=e()}(this,function(){function t(t,e){for(var n in e)t[n]=e[n]}function e(t){return String(t).toLowerCase()}function n(t,e,n,r){var i=t?o(t,e,!0,r):-1;return~i&&(n?t.splice(i,0,n):t.splice(i,1)),i}function o(t,e,n,o){for(var r=t.length;r--&&("function"!=typeof e||o?t[r]!==e:!e(t[r])););return n?r:t[r]}function r(t,n){return function(o){return o.ns===t&&e(o.name)===e(n)}}function i(){function i(t){return 1===t.nodeType}function u(t){return new a(null,String(t).toUpperCase())}function s(t,e){var n=u(e);return n.namespace=t,n}function p(t){return new l(t)}function c(){var e=new f;return t(e,e.defaultView={document:e,Document:f,Node:d,Text:l,Element:a,Event:b}),t(e,{documentElement:e,createElement:u,createElementNS:s,createTextNode:p}),e.appendChild(e.body=u("body")),e}var d=function(t,e){this.nodeType=t,this.nodeName=e,this.childNodes=[]},h={nextSibling:{},previousSibling:{},firstChild:{},lastChild:{}};h.nextSibling.get=function(){var t=this.parentNode;if(t)return t.childNodes[o(t.childNodes,this,!0)+1]},h.previousSibling.get=function(){var t=this.parentNode;if(t)return t.childNodes[o(t.childNodes,this,!0)-1]},h.firstChild.get=function(){return this.childNodes[0]},h.lastChild.get=function(){return this.childNodes[this.childNodes.length-1]},d.prototype.appendChild=function(t){this.insertBefore(t)},d.prototype.insertBefore=function(t,e){t.remove(),t.parentNode=this,e?n(this.childNodes,e,t):this.childNodes.push(t)},d.prototype.replaceChild=function(t,e){e.parentNode===this&&(this.insertBefore(t,e),e.remove())},d.prototype.removeChild=function(t){n(this.childNodes,t)},d.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)},Object.defineProperties(d.prototype,h);var l=function(t){function e(e){t.call(this,3,"#text"),this.nodeValue=e}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var n={textContent:{}};return n.textContent.set=function(t){this.nodeValue=t},n.textContent.get=function(){return this.nodeValue},Object.defineProperties(e.prototype,n),e}(d),a=function(t){function u(e,n){t.call(this,e||1,n),this.attributes=[],this.__handlers={}}t&&(u.__proto__=t),u.prototype=Object.create(t&&t.prototype),u.prototype.constructor=u;var s={children:{}};return s.children.get=function(){return this.childNodes.filter(i)},u.prototype.setAttribute=function(t,e){this.setAttributeNS(null,t,e)},u.prototype.getAttribute=function(t){return this.getAttributeNS(null,t)},u.prototype.removeAttribute=function(t){this.removeAttributeNS(null,t)},u.prototype.setAttributeNS=function(t,e,n){var i=o(this.attributes,r(t,e));i||this.attributes.push(i={ns:t,name:e}),i.value=String(n)},u.prototype.getAttributeNS=function(t,e){var n=o(this.attributes,r(t,e));return n&&n.value},u.prototype.removeAttributeNS=function(t,e){n(this.attributes,r(t,e))},u.prototype.addEventListener=function(t,n){(this.__handlers[e(t)]||(this.__handlers[e(t)]=[])).push(n)},u.prototype.removeEventListener=function(t,o){n(this.__handlers[e(t)],o,0,!0)},u.prototype.dispatchEvent=function(t){var n,o,r=t.currentTarget=this,i=t.cancelable;do if(n=r.__handlers[e(t.type)])for(o=n.length;o--&&(n[o](t)!==!1&&!t._end||!i););while(t.bubbles&&(!i||!t._stop)&&(t.target=r=r.parentNode));return!t.defaultPrevented},Object.defineProperties(u.prototype,s),u}(d),f=function(t){function e(){t.call(this,9,"#document")}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(a),b=function(t,e){this.type=t,this.bubbles=!!e.bubbles,this.cancelable=!!e.cancelable};return b.prototype.stopPropagation=function(){this._stop=!0},b.prototype.stopImmediatePropagation=function(){this._end=this._stop=!0},b.prototype.preventDefault=function(){this.defaultPrevented=!0},c()}return i});
//# sourceMappingURL=undom.min.js.map
{
"name": "undom",
"amdName": "undom",
"version": "0.2.1",
"version": "0.3.0",
"description": "Minimally viable DOM Document implementation.",

@@ -6,0 +6,0 @@ "main": "dist/undom.js",

@@ -13,2 +13,5 @@ # undom

[**JSFiddle Demo:**](https://jsfiddle.net/developit/4qv3v6r3/) Rendering [preact](https://github.com/developit/preact/) components into an undom Document.
---

@@ -15,0 +18,0 @@

@@ -27,2 +27,7 @@ import {

export default function undom() {
function isElement(node) {
return node.nodeType===1;
}
class Node {

@@ -34,16 +39,24 @@ constructor(nodeType, nodeName) {

}
get nextSibling() {
let p = this.parentNode;
if (p) return p.childNodes[findWhere(p.childNodes, this, true) + 1];
}
get previousSibling() {
let p = this.parentNode;
if (p) return p.childNodes[findWhere(p.childNodes, this, true) - 1];
}
get firstChild() {
return this.childNodes[0];
}
get lastChild() {
return this.childNodes[this.childNodes.length-1];
}
appendChild(child) {
child.remove();
child.parentNode = this;
this.childNodes.push(child);
if (this.children && child.nodeType===1) this.children.push(child);
this.insertBefore(child);
}
insertBefore(child, ref) {
child.remove();
let i = splice(this.childNodes, ref, child);
if (!ref) this.appendChild(child);
else if (~i && child.nodeType===1) {
while (i<this.childNodes.length && (ref = this.childNodes[i]).nodeType!==1 || ref===child) i++;
if (ref) splice(this.children, ref, child);
}
child.parentNode = this;
if (!ref) this.childNodes.push(child);
else splice(this.childNodes, ref, child);
}

@@ -58,3 +71,2 @@ replaceChild(child, ref) {

splice(this.childNodes, child);
if (child.nodeType===1) splice(this.children, child);
}

@@ -70,4 +82,10 @@ remove() {

super(3, '#text'); // TEXT_NODE
this.textContent = this.nodeValue = text;
this.nodeValue = text;
}
set textContent(text) {
this.nodeValue = text;
}
get textContent() {
return this.nodeValue;
}
}

@@ -80,6 +98,9 @@

this.attributes = [];
this.children = [];
this.__handlers = {};
}
get children() {
return this.childNodes.filter(isElement);
}
setAttribute(key, value) {

@@ -86,0 +107,0 @@ this.setAttributeNS(null, key, value);

@@ -9,6 +9,2 @@ export function assign(obj, props) {

export function createAttributeFilter(ns, name) {
return o => o.ns===ns && o.name===toLower(name);
}
export function splice(arr, item, add, byValueOnly) {

@@ -25,1 +21,5 @@ let i = arr ? findWhere(arr, item, true, byValueOnly) : -1;

}
export function createAttributeFilter(ns, name) {
return o => o.ns===ns && toLower(o.name)===toLower(name);
}

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc