Socket
Socket
Sign inDemoInstall

domutils

Package Overview
Dependencies
4
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.1.0

readme.md

8

lib/helpers.d.ts

@@ -5,3 +5,3 @@ import { Node } from "domhandler";

*
* @param nodes — Nodes to filter.
* @param nodes Nodes to filter.
*/

@@ -33,4 +33,4 @@ export declare function removeSubsets(nodes: Node[]): Node[];

* http://www.w3.org/TR/DOM-Level-3-Core/glossary.html#dt-document-order
* @argument nodaA The first node to use in the comparison
* @argument nodeB The second node to use in the comparison
* @param nodaA The first node to use in the comparison
* @param nodeB The second node to use in the comparison
*

@@ -48,3 +48,3 @@ * @return A bitmask describing the input nodes' relative position.

*
* @argument nodes Array of DOM nodes
* @param nodes Array of DOM nodes
* @returns collection of unique nodes, sorted in document order

@@ -51,0 +51,0 @@ */

@@ -7,3 +7,3 @@ "use strict";

*
* @param nodes — Nodes to filter.
* @param nodes Nodes to filter.
*/

@@ -50,4 +50,4 @@ function removeSubsets(nodes) {

* http://www.w3.org/TR/DOM-Level-3-Core/glossary.html#dt-document-order
* @argument nodaA The first node to use in the comparison
* @argument nodeB The second node to use in the comparison
* @param nodaA The first node to use in the comparison
* @param nodeB The second node to use in the comparison
*

@@ -105,3 +105,3 @@ * @return A bitmask describing the input nodes' relative position.

*
* @argument nodes Array of DOM nodes
* @param nodes Array of DOM nodes
* @returns collection of unique nodes, sorted in document order

@@ -108,0 +108,0 @@ */

@@ -36,3 +36,3 @@ "use strict";

}
}
},
};

@@ -54,4 +54,5 @@ /* eslint-enable @typescript-eslint/camelcase */

var value = options[key];
// @ts-ignore
return key in Checks ? Checks[key](value) : getAttribCheck(key, value);
return key in Checks
? Checks[key](value)
: getAttribCheck(key, value);
});

@@ -58,0 +59,0 @@ return funcs.length === 0 ? null : funcs.reduce(combineFuncs);

@@ -5,3 +5,3 @@ import { Node, Element } from "domhandler";

*
* @argument elem The element to be removed
* @param elem The element to be removed
*/

@@ -12,4 +12,4 @@ export declare function removeElement(elem: Node): void;

*
* @argument elem The element to be replaced
* @argument replacement The element to be added
* @param elem The element to be replaced
* @param replacement The element to be added
*/

@@ -20,4 +20,4 @@ export declare function replaceElement(elem: Node, replacement: Node): void;

*
* @argument elem The element to append to
* @argument child The element to be added as a child
* @param elem The element to append to
* @param child The element to be added as a child
*/

@@ -28,4 +28,4 @@ export declare function appendChild(elem: Element, child: Node): void;

*
* @argument elem The element to append to
* @argument next The element be added
* @param elem The element to append to
* @param next The element be added
*/

@@ -36,6 +36,6 @@ export declare function append(elem: Node, next: Node): void;

*
* @argument elem The element to append to
* @argument prev The element be added
* @param elem The element to append to
* @param prev The element be added
*/
export declare function prepend(elem: Node, prev: Node): void;
//# sourceMappingURL=manipulation.d.ts.map

@@ -6,3 +6,3 @@ "use strict";

*
* @argument elem The element to be removed
* @param elem The element to be removed
*/

@@ -23,4 +23,4 @@ function removeElement(elem) {

*
* @argument elem The element to be replaced
* @argument replacement The element to be added
* @param elem The element to be replaced
* @param replacement The element to be added
*/

@@ -46,4 +46,4 @@ function replaceElement(elem, replacement) {

*
* @argument elem The element to append to
* @argument child The element to be added as a child
* @param elem The element to append to
* @param child The element to be added as a child
*/

@@ -63,7 +63,8 @@ function appendChild(elem, child) {

*
* @argument elem The element to append to
* @argument next The element be added
* @param elem The element to append to
* @param next The element be added
*/
function append(elem, next) {
var parent = elem.parent, currNext = elem.next;
var parent = elem.parent;
var currNext = elem.next;
next.next = currNext;

@@ -88,4 +89,4 @@ next.prev = elem;

*
* @argument elem The element to append to
* @argument prev The element be added
* @param elem The element to append to
* @param prev The element be added
*/

@@ -92,0 +93,0 @@ function prepend(elem, prev) {

import { Node, Element } from "domhandler";
export declare function filter(test: (elem: Node) => boolean, element: Node | Node[], recurse?: boolean, limit?: number): Node[];
export declare function find(test: (elem: Node) => boolean, elems: Node[], recurse: boolean, limit: number): Node[];
export declare function findOneChild(test: (elem: Node) => boolean, elems: Node[]): Node | null;
export declare function findOne(test: (elem: Element) => boolean, elems: Node[], recurse?: boolean): Element | null;
export declare function existsOne(test: (elem: Element) => boolean, elems: Node[]): boolean;
export declare function findAll(test: (elem: Element) => boolean, rootElems: Node[]): Element[];
/**
* Search a node and its children for nodes passing a test function.
*
* @param test Function to test nodes on.
* @param element Element to search. Will be included in the result set if it matches.
* @param recurse Also consider child nodes.
* @param limit Maximum number of nodes to return.
*/
export declare function filter(test: (elem: Node) => boolean, node: Node | Node[], recurse?: boolean, limit?: number): Node[];
/**
* Like `filter`, but only works on an array of nodes.
*
* @param test Function to test nodes on.
* @param nodes Array of nodes to search.
* @param recurse Also consider child nodes.
* @param limit Maximum number of nodes to return.
*/
export declare function find(test: (elem: Node) => boolean, nodes: Node[], recurse: boolean, limit: number): Node[];
/**
* Finds the first element inside of an array that matches a test function.
*
* @param test Function to test nodes on.
* @param nodes Array of nodes to search.
*/
export declare function findOneChild(test: (elem: Node) => boolean, nodes: Node[]): Node | undefined;
/**
* Finds one element in a tree that passes a test.
*
* @param test Function to test nodes on.
* @param nodes Array of nodes to search.
* @param recurse Also consider child nodes.
*/
export declare function findOne(test: (elem: Element) => boolean, nodes: Node[], recurse?: boolean): Element | null;
/**
* Returns whether a tree of nodes contains at least one node passing a test.
*
* @param test Function to test nodes on.
* @param nodes Array of nodes to search.
*/
export declare function existsOne(test: (elem: Element) => boolean, nodes: Node[]): boolean;
/**
* Search and array of nodes and its children for nodes passing a test function.
*
* Same as `find`, only with less options, leading to reduced complexity.
*
* @param test Function to test nodes on.
* @param nodes Array of nodes to search.
*/
export declare function findAll(test: (elem: Element) => boolean, nodes: Node[]): Element[];
//# sourceMappingURL=querying.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tagtypes_1 = require("./tagtypes");
function filter(test, element, recurse, limit) {
/**
* Search a node and its children for nodes passing a test function.
*
* @param test Function to test nodes on.
* @param element Element to search. Will be included in the result set if it matches.
* @param recurse Also consider child nodes.
* @param limit Maximum number of nodes to return.
*/
function filter(test, node, recurse, limit) {
if (recurse === void 0) { recurse = true; }
if (limit === void 0) { limit = Infinity; }
if (!Array.isArray(element))
element = [element];
return find(test, element, recurse, limit);
if (!Array.isArray(node))
node = [node];
return find(test, node, recurse, limit);
}
exports.filter = filter;
function find(test, elems, recurse, limit) {
/**
* Like `filter`, but only works on an array of nodes.
*
* @param test Function to test nodes on.
* @param nodes Array of nodes to search.
* @param recurse Also consider child nodes.
* @param limit Maximum number of nodes to return.
*/
function find(test, nodes, recurse, limit) {
var result = [];
for (var i = 0; i < elems.length; i++) {
var elem = elems[i];
for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
var elem = nodes_1[_i];
if (test(elem)) {

@@ -23,3 +39,3 @@ result.push(elem);

var children = find(test, elem.children, recurse, limit);
result = result.concat(children);
result.push.apply(result, children);
limit -= children.length;

@@ -33,15 +49,24 @@ if (limit <= 0)

exports.find = find;
function findOneChild(test, elems) {
for (var i = 0; i < elems.length; i++) {
if (test(elems[i]))
return elems[i];
}
return null;
/**
* Finds the first element inside of an array that matches a test function.
*
* @param test Function to test nodes on.
* @param nodes Array of nodes to search.
*/
function findOneChild(test, nodes) {
return nodes.find(test);
}
exports.findOneChild = findOneChild;
function findOne(test, elems, recurse) {
/**
* Finds one element in a tree that passes a test.
*
* @param test Function to test nodes on.
* @param nodes Array of nodes to search.
* @param recurse Also consider child nodes.
*/
function findOne(test, nodes, recurse) {
if (recurse === void 0) { recurse = true; }
var elem = null;
for (var i = 0; i < elems.length && !elem; i++) {
var checked = elems[i];
for (var i = 0; i < nodes.length && !elem; i++) {
var checked = nodes[i];
if (!tagtypes_1.isTag(checked)) {

@@ -60,24 +85,34 @@ continue;

exports.findOne = findOne;
function existsOne(test, elems) {
for (var i = 0; i < elems.length; i++) {
var checked = elems[i];
if (tagtypes_1.isTag(checked) &&
/**
* Returns whether a tree of nodes contains at least one node passing a test.
*
* @param test Function to test nodes on.
* @param nodes Array of nodes to search.
*/
function existsOne(test, nodes) {
return nodes.some(function (checked) {
return tagtypes_1.isTag(checked) &&
(test(checked) ||
(checked.children.length > 0 &&
existsOne(test, checked.children)))) {
return true;
}
}
return false;
existsOne(test, checked.children)));
});
}
exports.existsOne = existsOne;
function findAll(test, rootElems) {
/**
* Search and array of nodes and its children for nodes passing a test function.
*
* Same as `find`, only with less options, leading to reduced complexity.
*
* @param test Function to test nodes on.
* @param nodes Array of nodes to search.
*/
function findAll(test, nodes) {
var _a;
var result = [];
var stack = rootElems.slice();
while (stack.length) {
var elem = stack.shift();
if (!elem || !tagtypes_1.isTag(elem))
continue;
if (elem.children && elem.children.length > 0) {
stack.unshift.apply(stack, elem.children);
var stack = nodes.filter(tagtypes_1.isTag);
var elem;
while ((elem = stack.shift())) {
var children = (_a = elem.children) === null || _a === void 0 ? void 0 : _a.filter(tagtypes_1.isTag);
if (children && children.length > 0) {
stack.unshift.apply(stack, children);
}

@@ -84,0 +119,0 @@ if (test(elem))

import { Node } from "domhandler";
import { DomSerializerOptions } from "dom-serializer";
export declare const getOuterHTML: (node: Node | Node[], options?: DomSerializerOptions) => string;
export declare function getOuterHTML(node: Node | Node[], options?: DomSerializerOptions): string;
export declare function getInnerHTML(node: Node, options?: DomSerializerOptions): string;
export declare function getText(node: Node | Node[]): string;
//# sourceMappingURL=stringify.d.ts.map

@@ -8,6 +8,9 @@ "use strict";

var dom_serializer_1 = __importDefault(require("dom-serializer"));
exports.getOuterHTML = dom_serializer_1.default;
function getOuterHTML(node, options) {
return dom_serializer_1.default(node, options);
}
exports.getOuterHTML = getOuterHTML;
function getInnerHTML(node, options) {
return tagtypes_1.hasChildren(node)
? node.children.map(function (node) { return exports.getOuterHTML(node, options); }).join("")
? node.children.map(function (node) { return getOuterHTML(node, options); }).join("")
: "";

@@ -14,0 +17,0 @@ }

@@ -9,3 +9,3 @@ "use strict";

function isCDATA(node) {
return "cdata" /* CDATA */ === node.type;
return node.type === "cdata" /* CDATA */;
}

@@ -12,0 +12,0 @@ exports.isCDATA = isCDATA;

import { Node, Element } from "domhandler";
export declare function getChildren(elem: Node): Node[] | null;
export declare function getChildren(elem: Node | Element): Node[] | null;
export declare function getParent(elem: Node): Node | null;

@@ -10,5 +10,5 @@ export declare function getSiblings(elem: Node): Node[] | null;

*
* @argument elem The element to get the name for
* @param elem The element to get the name for
*/
export declare function getName(elem: Element): string;
//# sourceMappingURL=traversal.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getChildren(elem) {
// @ts-ignore
return elem.children || null;

@@ -18,7 +17,10 @@ }

function getAttributeValue(elem, name) {
return elem.attribs && elem.attribs[name];
var _a;
return (_a = elem.attribs) === null || _a === void 0 ? void 0 : _a[name];
}
exports.getAttributeValue = getAttributeValue;
function hasAttrib(elem, name) {
return !!getAttributeValue(elem, name);
return (!!elem.attribs &&
Object.prototype.hasOwnProperty.call(elem.attribs, name) &&
elem.attribs[name] != null);
}

@@ -29,3 +31,3 @@ exports.hasAttrib = hasAttrib;

*
* @argument elem The element to get the name for
* @param elem The element to get the name for
*/

@@ -32,0 +34,0 @@ function getName(elem) {

{
"name": "domutils",
"version": "2.0.0",
"version": "2.1.0",
"description": "Utilities for working with htmlparser2's dom",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [

@@ -12,5 +13,6 @@ "lib/**/*"

"coverage": "cat coverage/lcov.info | coveralls",
"lint": "eslint src/**/*.ts",
"lint": "eslint --ext=js,ts src",
"format": "prettier --write '**/*.{ts,md,json}'",
"build": "tsc",
"update-docs": "typedoc --out docs --exclude src/index.ts --readme none --excludeNotExported --excludePrivate --excludeProtected --excludeExternals --hideGenerator",
"prepare": "npm run build"

@@ -32,12 +34,15 @@ },

"devDependencies": {
"@types/jest": "^24.0.16",
"@types/node": "^12.6.8",
"@typescript-eslint/eslint-plugin": "^1.13.0",
"@typescript-eslint/parser": "^1.13.0",
"eslint": "^6.1.0",
"@types/jest": "^25.1.4",
"@types/node": "^13.9.1",
"@typescript-eslint/eslint-plugin": "^2.31.0",
"@typescript-eslint/parser": "^2.31.0",
"coveralls": "^3.0.5",
"eslint": "^7.0.0",
"eslint-config-prettier": "^6.0.0",
"htmlparser2": "~3.10.0",
"jest": "^24.8.0",
"prettier": "^1.18.2",
"ts-jest": "^24.0.2",
"htmlparser2": "~4.1.0",
"jest": "^26.0.1",
"prettier": "^2.0.5",
"ts-jest": "^25.3.1",
"typedoc": "^0.17.1",
"typedoc-plugin-markdown": "^2.2.16",
"typescript": "^3.5.3"

@@ -44,0 +49,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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