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.3.3 to 0.4.0

34

dist/undom.js

@@ -77,2 +77,3 @@ (function (global, factory) {

this.insertBefore(child);
return child;
};

@@ -82,4 +83,4 @@ Node.prototype.insertBefore = function insertBefore (child, ref) {

child.parentNode = this;
if (!ref) this.childNodes.push(child);
else splice(this.childNodes, ref, child);
!ref ? this.childNodes.push(child) : splice(this.childNodes, ref, child);
return child;
};

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

ref.remove();
return ref;
}

@@ -95,2 +97,3 @@ };

splice(this.childNodes, child);
return child;
};

@@ -186,12 +189,15 @@ Node.prototype.remove = function remove () {

Element.prototype.dispatchEvent = function dispatchEvent (event) {
var t = event.currentTarget = this,
var t = event.target = this,
c = event.cancelable,
l, i;
do {
event.currentTarget = t;
l = t.__handlers && t.__handlers[toLower(event.type)];
if (l) for (i=l.length; i--; ) {
if ((l[i].call(t, event)===false || event._end) && c) break;
if ((l[i].call(t, event) === false || event._end) && c) {
event.defaultPrevented = true;
}
}
} while (event.bubbles && !(c && event._stop) && (event.target=t=t.parentNode));
return !event.defaultPrevented;
} while (event.bubbles && !(c && event._stop) && (t=t.parentNode));
return l!=null;
};

@@ -220,4 +226,4 @@

this.type = type;
this.bubbles = !!opts.bubbles;
this.cancelable = !!opts.cancelable;
this.bubbles = !!(opts && opts.bubbles);
this.cancelable = !!(opts && opts.cancelable);
};

@@ -255,4 +261,12 @@ Event.prototype.stopPropagation = function stopPropagation () {

assign(document, document.defaultView = { document: document, Document: Document, Node: Node, Text: Text, Element: Element, SVGElement:Element, Event: Event });
assign(document, { documentElement:document, createElement: createElement, createElementNS: createElementNS, createTextNode: createTextNode });
document.appendChild(document.body = createElement('body'));
assign(document, { createElement: createElement, createElementNS: createElementNS, createTextNode: createTextNode });
document.appendChild(
document.documentElement = createElement('html')
);
document.documentElement.appendChild(
document.head = createElement('head')
);
document.documentElement.appendChild(
document.body = createElement('body')
);
return document;

@@ -259,0 +273,0 @@ }

@@ -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,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 s(t){return new a(null,String(t).toUpperCase())}function u(t,e){var n=s(e);return n.namespace=t,n}function c(t){return new h(t)}function p(){var e=new f;return t(e,e.defaultView={document:e,Document:f,Node:l,Text:h,Element:a,SVGElement:a,Event:b}),t(e,{documentElement:e,createElement:s,createElementNS:u,createTextNode:c}),e.appendChild(e.body=s("body")),e}var l=function(t,e){this.nodeType=t,this.nodeName=e,this.childNodes=[]},d={nextSibling:{},previousSibling:{},firstChild:{},lastChild:{}};d.nextSibling.get=function(){var t=this.parentNode;if(t)return t.childNodes[o(t.childNodes,this,!0)+1]},d.previousSibling.get=function(){var t=this.parentNode;if(t)return t.childNodes[o(t.childNodes,this,!0)-1]},d.firstChild.get=function(){return this.childNodes[0]},d.lastChild.get=function(){return this.childNodes[this.childNodes.length-1]},l.prototype.appendChild=function(t){this.insertBefore(t)},l.prototype.insertBefore=function(t,e){t.remove(),t.parentNode=this,e?n(this.childNodes,e,t):this.childNodes.push(t)},l.prototype.replaceChild=function(t,e){e.parentNode===this&&(this.insertBefore(t,e),e.remove())},l.prototype.removeChild=function(t){n(this.childNodes,t)},l.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)},Object.defineProperties(l.prototype,d);var h=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}(l),a=function(t){function s(e,n){var o=this;t.call(this,e||1,n),this.attributes=[],this.__handlers={},this.style={},Object.defineProperty(this,"className",{set:function(t){o.setAttribute("class",t)},get:function(){return o.getAttribute("class")}}),Object.defineProperty(this.style,"cssText",{set:function(t){o.setAttribute("style",t)},get:function(){return o.getAttribute("style")}})}t&&(s.__proto__=t),s.prototype=Object.create(t&&t.prototype),s.prototype.constructor=s;var u={children:{}};return u.children.get=function(){return this.childNodes.filter(i)},s.prototype.setAttribute=function(t,e){this.setAttributeNS(null,t,e)},s.prototype.getAttribute=function(t){return this.getAttributeNS(null,t)},s.prototype.removeAttribute=function(t){this.removeAttributeNS(null,t)},s.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)},s.prototype.getAttributeNS=function(t,e){var n=o(this.attributes,r(t,e));return n&&n.value},s.prototype.removeAttributeNS=function(t,e){n(this.attributes,r(t,e))},s.prototype.addEventListener=function(t,n){(this.__handlers[e(t)]||(this.__handlers[e(t)]=[])).push(n)},s.prototype.removeEventListener=function(t,o){n(this.__handlers[e(t)],o,0,!0)},s.prototype.dispatchEvent=function(t){var n,o,r=t.currentTarget=this,i=t.cancelable;do if(n=r.__handlers&&r.__handlers[e(t.type)])for(o=n.length;o--&&(n[o].call(r,t)!==!1&&!t._end||!i););while(t.bubbles&&(!i||!t._stop)&&(t.target=r=r.parentNode));return!t.defaultPrevented},Object.defineProperties(s.prototype,u),s}(l),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},p()}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 h(null,String(t).toUpperCase())}function s(t,e){var n=u(e);return n.namespace=t,n}function c(t){return new d(t)}var p=function(t,e){this.nodeType=t,this.nodeName=e,this.childNodes=[]},l={nextSibling:{},previousSibling:{},firstChild:{},lastChild:{}};l.nextSibling.get=function(){var t=this.parentNode;if(t)return t.childNodes[o(t.childNodes,this,!0)+1]},l.previousSibling.get=function(){var t=this.parentNode;if(t)return t.childNodes[o(t.childNodes,this,!0)-1]},l.firstChild.get=function(){return this.childNodes[0]},l.lastChild.get=function(){return this.childNodes[this.childNodes.length-1]},p.prototype.appendChild=function(t){return this.insertBefore(t),t},p.prototype.insertBefore=function(t,e){return t.remove(),t.parentNode=this,e?n(this.childNodes,e,t):this.childNodes.push(t),t},p.prototype.replaceChild=function(t,e){if(e.parentNode===this)return this.insertBefore(t,e),e.remove(),e},p.prototype.removeChild=function(t){return n(this.childNodes,t),t},p.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)},Object.defineProperties(p.prototype,l);var d=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}(p),h=function(t){function u(e,n){var o=this;t.call(this,e||1,n),this.attributes=[],this.__handlers={},this.style={},Object.defineProperty(this,"className",{set:function(t){o.setAttribute("class",t)},get:function(){return o.getAttribute("class")}}),Object.defineProperty(this.style,"cssText",{set:function(t){o.setAttribute("style",t)},get:function(){return o.getAttribute("style")}})}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.target=this,i=t.cancelable;do{if(t.currentTarget=r,n=r.__handlers&&r.__handlers[e(t.type)])for(o=n.length;o--;)(!1===n[o].call(r,t)||t._end)&&i&&(t.defaultPrevented=!0)}while(t.bubbles&&(!i||!t._stop)&&(r=r.parentNode));return null!=n},Object.defineProperties(u.prototype,s),u}(p),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}(h),f=function(t,e){this.type=t,this.bubbles=!(!e||!e.bubbles),this.cancelable=!(!e||!e.cancelable)};return f.prototype.stopPropagation=function(){this._stop=!0},f.prototype.stopImmediatePropagation=function(){this._end=this._stop=!0},f.prototype.preventDefault=function(){this.defaultPrevented=!0},function(){var e=new a;return t(e,e.defaultView={document:e,Document:a,Node:p,Text:d,Element:h,SVGElement:h,Event:f}),t(e,{createElement:u,createElementNS:s,createTextNode:c}),e.appendChild(e.documentElement=u("html")),e.documentElement.appendChild(e.head=u("head")),e.documentElement.appendChild(e.body=u("body")),e}()}return i});
//# sourceMappingURL=undom.min.js.map
{
"name": "undom",
"amdName": "undom",
"version": "0.3.3",
"version": "0.4.0",
"description": "Minimally viable DOM Document implementation.",

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

@@ -17,3 +17,2 @@ # undom

---

@@ -20,0 +19,0 @@

@@ -54,2 +54,3 @@ import {

this.insertBefore(child);
return child;
}

@@ -59,4 +60,4 @@ insertBefore(child, ref) {

child.parentNode = this;
if (!ref) this.childNodes.push(child);
else splice(this.childNodes, ref, child);
!ref ? this.childNodes.push(child) : splice(this.childNodes, ref, child);
return child;
}

@@ -67,2 +68,3 @@ replaceChild(child, ref) {

ref.remove();
return ref;
}

@@ -72,2 +74,3 @@ }

splice(this.childNodes, child);
return child;
}

@@ -144,12 +147,15 @@ remove() {

dispatchEvent(event) {
let t = event.currentTarget = this,
let t = event.target = this,
c = event.cancelable,
l, i;
do {
event.currentTarget = t;
l = t.__handlers && t.__handlers[toLower(event.type)];
if (l) for (i=l.length; i--; ) {
if ((l[i].call(t, event)===false || event._end) && c) break;
if ((l[i].call(t, event) === false || event._end) && c) {
event.defaultPrevented = true;
}
}
} while (event.bubbles && !(c && event._stop) && (event.target=t=t.parentNode));
return !event.defaultPrevented;
} while (event.bubbles && !(c && event._stop) && (t=t.parentNode));
return l!=null;
}

@@ -169,4 +175,4 @@ }

this.type = type;
this.bubbles = !!opts.bubbles;
this.cancelable = !!opts.cancelable;
this.bubbles = !!(opts && opts.bubbles);
this.cancelable = !!(opts && opts.cancelable);
}

@@ -205,4 +211,12 @@ stopPropagation() {

assign(document, document.defaultView = { document, Document, Node, Text, Element, SVGElement:Element, Event });
assign(document, { documentElement:document, createElement, createElementNS, createTextNode });
document.appendChild(document.body = createElement('body'));
assign(document, { createElement, createElementNS, createTextNode });
document.appendChild(
document.documentElement = createElement('html')
);
document.documentElement.appendChild(
document.head = createElement('head')
);
document.documentElement.appendChild(
document.body = createElement('body')
);
return document;

@@ -209,0 +223,0 @@ }

@@ -13,2 +13,18 @@ import undom from '../src/undom';

it('should create a valid Document tree', () => {
let document = undom();
let html = document.documentElement;
expect(html).to.be.an.instanceOf(document.Element);
expect(html).to.have.property('nodeName', 'HTML');
expect(document.head).to.be.an.instanceOf(document.Element);
expect(document.head).to.have.property('nodeName', 'HEAD');
expect(document.head).to.have.property('parentNode', html);
expect(document.body).to.be.an.instanceOf(document.Element);
expect(document.body).to.have.property('nodeName', 'BODY');
expect(document.body).to.have.property('parentNode', html);
});
describe('createElement()', () => {

@@ -228,3 +244,3 @@ let document = undom();

it('should bubble if enabled', () => {
let event = { type:'foo', cancelable:true, bubbles:true };
let event = new document.defaultView.Event('foo', { cancelable:true, bubbles:true });
let child = document.createElement('div');

@@ -253,4 +269,30 @@ let parent = document.createElement('div');

});
it('should return `found`', () => {
let el = document.createElement('div');
let el2 = document.createElement('div');
el.addEventListener('foo', () => {});
expect(el.dispatchEvent(new document.defaultView.Event('foo'))).to.equal(true);
expect(el2.dispatchEvent(new document.defaultView.Event('foo'))).to.equal(false);
});
it('preventDefault() should set defaultPrevented', () => {
let event = new document.defaultView.Event('foo', { cancelable: true, bubbles: true });
let el = document.createElement('div');
let parent = document.createElement('div');
parent.appendChild(el);
let fn = spy(e => { e.preventDefault(); });
let parentFn = spy(e => { e.preventDefault(); });
el.addEventListener('foo', fn);
parent.addEventListener('foo', parentFn);
el.dispatchEvent(event);
expect(fn).to.have.been.calledOnce;
expect(parentFn).to.have.been.calledOnce;
expect(parentFn.firstCall.args[0]).to.have.property('defaultPrevented', true);
});
});
});
});

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