Commit ca692819 authored by Roy Revelt's avatar Roy Revelt

chore: setup refresh

parent ef39ee9b
This diff is collapsed.
......@@ -32,7 +32,7 @@
"test": "FORCE_COLOR=1 lerna run ci_test && npm run readme:generate && npm run info",
"test:full": "FORCE_COLOR=1 lerna run test --stream --concurrency 1 && npm run readme:generate && npm run info",
"test:only": "FORCE_COLOR=1 lerna run unittest --stream --concurrency 1 && npm run readme:generate && npm run info",
"wipe": "rm -rf node_modules && FORCE_COLOR=1 npx lerna clean -y"
"wipe": "rm package-lock.json && rm -rf node_modules && FORCE_COLOR=1 npx lerna clean -y"
},
"husky": {
"hooks": {
......
......@@ -261,7 +261,7 @@
"tap": "^14.10.7",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-cleanup": "^3.1.1",
"rollup-plugin-banner": "^0.2.1",
......
......@@ -138,7 +138,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -141,7 +141,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -136,7 +136,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -139,7 +139,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -133,7 +133,7 @@
"array-shuffle": "^1.0.1",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -138,7 +138,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -128,7 +128,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -140,7 +140,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -138,7 +138,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -142,7 +142,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -137,7 +137,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -140,7 +140,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -144,7 +144,7 @@
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"object-path": "^0.11.4",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -139,7 +139,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -136,7 +136,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -143,7 +143,7 @@
"lect": "^0.13.2",
"lodash.isequal": "^4.5.0",
"object-path": "^0.11.4",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -143,7 +143,7 @@
"lect": "^0.13.2",
"lodash.isequal": "^4.5.0",
"object-path": "^0.11.4",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -143,7 +143,7 @@
"lect": "^0.13.2",
"lodash.isequal": "^4.5.0",
"object-path": "^0.11.4",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -144,7 +144,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -148,7 +148,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -138,7 +138,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -141,7 +141,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -151,7 +151,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -144,7 +144,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -138,7 +138,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -142,7 +142,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -137,7 +137,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -134,7 +134,7 @@
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"lect": "^0.13.2",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
......@@ -163,7 +163,7 @@
"lodash.clonedeep": "^4.5.0",
"object-boolean-combinations": "^2.11.59",
"object-path": "^0.11.4",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
......
sudo: true
language: node_js
node_js:
- 8
var DomUtils = module.exports;
[
require("./lib/stringify"),
require("./lib/traversal"),
require("./lib/manipulation"),
require("./lib/querying"),
require("./lib/legacy"),
require("./lib/helpers")
].forEach(function(ext){
Object.keys(ext).forEach(function(key){
DomUtils[key] = ext[key].bind(DomUtils);
});
});
// removeSubsets
// Given an array of nodes, remove any member that is contained by another.
exports.removeSubsets = function(nodes) {
var idx = nodes.length, node, ancestor, replace;
// Check if each node (or one of its ancestors) is already contained in the
// array.
while (--idx > -1) {
node = ancestor = nodes[idx];
// Temporarily remove the node under consideration
nodes[idx] = null;
replace = true;
while (ancestor) {
if (nodes.indexOf(ancestor) > -1) {
replace = false;
nodes.splice(idx, 1);
break;
}
ancestor = ancestor.parent;
}
// If the node has been found to be unique, re-insert it.
if (replace) {
nodes[idx] = node;
}
}
return nodes;
};
// Source: http://dom.spec.whatwg.org/#dom-node-comparedocumentposition
var POSITION = {
DISCONNECTED: 1,
PRECEDING: 2,
FOLLOWING: 4,
CONTAINS: 8,
CONTAINED_BY: 16
};
// Compare the position of one node against another node in any other document.
// The return value is a bitmask with the following values:
//
// document order:
// > There is an ordering, document order, defined on all the nodes in the
// > document corresponding to the order in which the first character of the
// > XML representation of each node occurs in the XML representation of the
// > document after expansion of general entities. Thus, the document element
// > node will be the first node. Element nodes occur before their children.
// > Thus, document order orders element nodes in order of the occurrence of
// > their start-tag in the XML (after expansion of entities). The attribute
// > nodes of an element occur after the element and before its children. The
// > relative order of attribute nodes is implementation-dependent./
// Source:
// http://www.w3.org/TR/DOM-Level-3-Core/glossary.html#dt-document-order
//
// @argument {Node} nodaA The first node to use in the comparison
// @argument {Node} nodeB The second node to use in the comparison
//
// @return {Number} A bitmask describing the input nodes' relative position.
// See http://dom.spec.whatwg.org/#dom-node-comparedocumentposition for
// a description of these values.
var comparePos = exports.compareDocumentPosition = function(nodeA, nodeB) {
var aParents = [];
var bParents = [];
var current, sharedParent, siblings, aSibling, bSibling, idx;
if (nodeA === nodeB) {
return 0;
}
current = nodeA;
while (current) {
aParents.unshift(current);
current = current.parent;
}
current = nodeB;
while (current) {
bParents.unshift(current);
current = current.parent;
}
idx = 0;
while (aParents[idx] === bParents[idx]) {
idx++;
}
if (idx === 0) {
return POSITION.DISCONNECTED;
}
sharedParent = aParents[idx - 1];
siblings = sharedParent.children;
aSibling = aParents[idx];
bSibling = bParents[idx];
if (siblings.indexOf(aSibling) > siblings.indexOf(bSibling)) {
if (sharedParent === nodeB) {
return POSITION.FOLLOWING | POSITION.CONTAINED_BY;
}
return POSITION.FOLLOWING;
} else {
if (sharedParent === nodeA) {
return POSITION.PRECEDING | POSITION.CONTAINS;
}
return POSITION.PRECEDING;
}
};
// Sort an array of nodes based on their relative position in the document and
// remove any duplicate nodes. If the array contains nodes that do not belong
// to the same document, sort order is unspecified.
//
// @argument {Array} nodes Array of DOM nodes
//
// @returns {Array} collection of unique nodes, sorted in document order
exports.uniqueSort = function(nodes) {
var idx = nodes.length, node, position;
nodes = nodes.slice();
while (--idx > -1) {
node = nodes[idx];
position = nodes.indexOf(node);
if (position > -1 && position < idx) {
nodes.splice(idx, 1);
}
}
nodes.sort(function(a, b) {
var relative = comparePos(a, b);
if (relative & POSITION.PRECEDING) {
return -1;
} else if (relative & POSITION.FOLLOWING) {
return 1;
}
return 0;
});
return nodes;
};
var ElementType = require("domelementtype");
var isTag = exports.isTag = ElementType.isTag;
exports.testElement = function(options, element){
for(var key in options){
if(!options.hasOwnProperty(key));
else if(key === "tag_name"){
if(!isTag(element) || !options.tag_name(element.name)){
return false;
}
} else if(key === "tag_type"){
if(!options.tag_type(element.type)) return false;
} else if(key === "tag_contains"){
if(isTag(element) || !options.tag_contains(element.data)){
return false;
}
} else if(!element.attribs || !options[key](element.attribs[key])){
return false;
}
}
return true;
};
var Checks = {
tag_name: function(name){
if(typeof name === "function"){
return function(elem){ return isTag(elem) && name(elem.name); };
} else if(name === "*"){
return isTag;
} else {
return function(elem){ return isTag(elem) && elem.name === name; };
}
},
tag_type: function(type){
if(typeof type === "function"){
return function(elem){ return type(elem.type); };
} else {
return function(elem){ return elem.type === type; };
}
},
tag_contains: function(data){
if(typeof data === "function"){
return function(elem){ return !isTag(elem) && data(elem.data); };
} else {
return function(elem){ return !isTag(elem) && elem.data === data; };
}
}
};
function getAttribCheck(attrib, value){
if(typeof value === "function"){
return function(elem){ return elem.attribs && value(elem.attribs[attrib]); };
} else {
return function(elem){ return elem.attribs && elem.attribs[attrib] === value; };
}
}
function combineFuncs(a, b){
return function(elem){
return a(elem) || b(elem);
};
}
exports.getElements = function(options, element, recurse, limit){
var funcs = Object.keys(options).map(function(key){
var value = options[key];
return key in Checks ? Checks[key](value) : getAttribCheck(key, value);
});
return funcs.length === 0 ? [] : this.filter(
funcs.reduce(combineFuncs),
element, recurse, limit
);
};
exports.getElementById = function(id, element, recurse){
if(!Array.isArray(element)) element = [element];
return this.findOne(getAttribCheck("id", id), element, recurse !== false);
};
exports.getElementsByTagName = function(name, element, recurse, limit){
return this.filter(Checks.tag_name(name), element, recurse, limit);
};
exports.getElementsByTagType = function(type, element, recurse, limit){
return this.filter(Checks.tag_type(type), element, recurse, limit);
};
exports.removeElement = function(elem){
if(elem.prev) elem.prev.next = elem.next;
if(elem.next) elem.next.prev = elem.prev;
if(elem.parent){
var childs = elem.parent.children;
childs.splice(childs.lastIndexOf(elem), 1);
}
};
exports.replaceElement = function(elem, replacement){
var prev = replacement.prev = elem.prev;
if(prev){
prev.next = replacement;
}
var next = replacement.next = elem.next;
if(next){
next.prev = replacement;
}
var parent = replacement.parent = elem.parent;
if(parent){
var childs = parent.children;
childs[childs.lastIndexOf(elem)] = replacement;
}
};
exports.appendChild = function(elem, child){
child.parent = elem;
if(elem.children.push(child) !== 1){
var sibling = elem.children[elem.children.length - 2];
sibling.next = child;
child.prev = sibling;
child.next = null;
}
};
exports.append = function(elem, next){
var parent = elem.parent,
currNext = elem.next;
next.next = currNext;
next.prev = elem;
elem.next = next;
next.parent = parent;
if(currNext){
currNext.prev = next;
if(parent){
var childs = parent.children;
childs.splice(childs.lastIndexOf(currNext), 0, next);
}
} else if(parent){
parent.children.push(next);
}
};
exports.prepend = function(elem, prev){
var parent = elem.parent;
if(parent){
var childs = parent.children;
childs.splice(childs.lastIndexOf(elem), 0, prev);
}
if(elem.prev){
elem.prev.next = prev;
}
prev.parent = parent;
prev.prev = elem.prev;
prev.next = elem;
elem.prev = prev;
};
var isTag = require("domelementtype").isTag;
module.exports = {
filter: filter,
find: find,
findOneChild