Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

domutils

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

domutils - npm Package Compare versions

Comparing version 3.2.0 to 3.2.1

10

lib/esm/querying.d.ts

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

import { Element, AnyNode } from "domhandler";
import { Element, AnyNode, ParentNode } from "domhandler";
/**

@@ -23,3 +23,3 @@ * Search a node and its children for nodes passing a test function. If `node` is not an array, it will be wrapped in one.

*/
export declare function find(test: (elem: AnyNode) => boolean, nodes: AnyNode[], recurse: boolean, limit: number): AnyNode[];
export declare function find(test: (elem: AnyNode) => boolean, nodes: AnyNode[] | ParentNode, recurse: boolean, limit: number): AnyNode[];
/**

@@ -44,3 +44,3 @@ * Finds the first element inside of an array that matches a test function. This is an alias for `Array.prototype.find`.

*/
export declare function findOne(test: (elem: Element) => boolean, nodes: AnyNode[], recurse?: boolean): Element | null;
export declare function findOne(test: (elem: Element) => boolean, nodes: AnyNode[] | ParentNode, recurse?: boolean): Element | null;
/**

@@ -54,3 +54,3 @@ * Checks if a tree of nodes contains at least one node passing a test.

*/
export declare function existsOne(test: (elem: Element) => boolean, nodes: AnyNode[]): boolean;
export declare function existsOne(test: (elem: Element) => boolean, nodes: AnyNode[] | ParentNode): boolean;
/**

@@ -66,3 +66,3 @@ * Search an array of nodes and their children for elements passing a test function.

*/
export declare function findAll(test: (elem: Element) => boolean, nodes: AnyNode[]): Element[];
export declare function findAll(test: (elem: Element) => boolean, nodes: AnyNode[] | ParentNode): Element[];
//# sourceMappingURL=querying.d.ts.map

@@ -28,3 +28,3 @@ import { isTag, hasChildren } from "domhandler";

/** Stack of the arrays we are looking at. */
const nodeStack = [nodes];
const nodeStack = [Array.isArray(nodes) ? nodes : [nodes]];
/** Stack of the indices within the arrays. */

@@ -83,16 +83,13 @@ const indexStack = [0];

export function findOne(test, nodes, recurse = true) {
let elem = null;
for (let i = 0; i < nodes.length && !elem; i++) {
const node = nodes[i];
if (!isTag(node)) {
continue;
const searchedNodes = Array.isArray(nodes) ? nodes : [nodes];
for (let i = 0; i < searchedNodes.length; i++) {
const node = searchedNodes[i];
if (isTag(node) && test(node)) {
return node;
}
else if (test(node)) {
elem = node;
if (recurse && hasChildren(node) && node.children.length > 0) {
return findOne(test, node.children, true);
}
else if (recurse && node.children.length > 0) {
elem = findOne(test, node.children, true);
}
}
return elem;
return null;
}

@@ -108,4 +105,4 @@ /**

export function existsOne(test, nodes) {
return nodes.some((checked) => isTag(checked) &&
(test(checked) || existsOne(test, checked.children)));
return (Array.isArray(nodes) ? nodes : [nodes]).some((node) => (isTag(node) && test(node)) ||
(hasChildren(node) && existsOne(test, node.children)));
}

@@ -124,3 +121,3 @@ /**

const result = [];
const nodeStack = [nodes];
const nodeStack = [Array.isArray(nodes) ? nodes : [nodes]];
const indexStack = [0];

@@ -139,7 +136,5 @@ for (;;) {

const elem = nodeStack[0][indexStack[0]++];
if (!isTag(elem))
continue;
if (test(elem))
if (isTag(elem) && test(elem))
result.push(elem);
if (elem.children.length > 0) {
if (hasChildren(elem) && elem.children.length > 0) {
indexStack.unshift(0);

@@ -146,0 +141,0 @@ nodeStack.unshift(elem.children);

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

import { Element, AnyNode } from "domhandler";
import { Element, AnyNode, ParentNode } from "domhandler";
/**

@@ -23,3 +23,3 @@ * Search a node and its children for nodes passing a test function. If `node` is not an array, it will be wrapped in one.

*/
export declare function find(test: (elem: AnyNode) => boolean, nodes: AnyNode[], recurse: boolean, limit: number): AnyNode[];
export declare function find(test: (elem: AnyNode) => boolean, nodes: AnyNode[] | ParentNode, recurse: boolean, limit: number): AnyNode[];
/**

@@ -44,3 +44,3 @@ * Finds the first element inside of an array that matches a test function. This is an alias for `Array.prototype.find`.

*/
export declare function findOne(test: (elem: Element) => boolean, nodes: AnyNode[], recurse?: boolean): Element | null;
export declare function findOne(test: (elem: Element) => boolean, nodes: AnyNode[] | ParentNode, recurse?: boolean): Element | null;
/**

@@ -54,3 +54,3 @@ * Checks if a tree of nodes contains at least one node passing a test.

*/
export declare function existsOne(test: (elem: Element) => boolean, nodes: AnyNode[]): boolean;
export declare function existsOne(test: (elem: Element) => boolean, nodes: AnyNode[] | ParentNode): boolean;
/**

@@ -66,3 +66,3 @@ * Search an array of nodes and their children for elements passing a test function.

*/
export declare function findAll(test: (elem: Element) => boolean, nodes: AnyNode[]): Element[];
export declare function findAll(test: (elem: Element) => boolean, nodes: AnyNode[] | ParentNode): Element[];
//# sourceMappingURL=querying.d.ts.map

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

/** Stack of the arrays we are looking at. */
var nodeStack = [nodes];
var nodeStack = [Array.isArray(nodes) ? nodes : [nodes]];
/** Stack of the indices within the arrays. */

@@ -94,16 +94,13 @@ var indexStack = [0];

if (recurse === void 0) { recurse = true; }
var elem = null;
for (var i = 0; i < nodes.length && !elem; i++) {
var node = nodes[i];
if (!(0, domhandler_1.isTag)(node)) {
continue;
var searchedNodes = Array.isArray(nodes) ? nodes : [nodes];
for (var i = 0; i < searchedNodes.length; i++) {
var node = searchedNodes[i];
if ((0, domhandler_1.isTag)(node) && test(node)) {
return node;
}
else if (test(node)) {
elem = node;
if (recurse && (0, domhandler_1.hasChildren)(node) && node.children.length > 0) {
return findOne(test, node.children, true);
}
else if (recurse && node.children.length > 0) {
elem = findOne(test, node.children, true);
}
}
return elem;
return null;
}

@@ -119,5 +116,5 @@ /**

function existsOne(test, nodes) {
return nodes.some(function (checked) {
return (0, domhandler_1.isTag)(checked) &&
(test(checked) || existsOne(test, checked.children));
return (Array.isArray(nodes) ? nodes : [nodes]).some(function (node) {
return ((0, domhandler_1.isTag)(node) && test(node)) ||
((0, domhandler_1.hasChildren)(node) && existsOne(test, node.children));
});

@@ -137,3 +134,3 @@ }

var result = [];
var nodeStack = [nodes];
var nodeStack = [Array.isArray(nodes) ? nodes : [nodes]];
var indexStack = [0];

@@ -152,7 +149,5 @@ for (;;) {

var elem = nodeStack[0][indexStack[0]++];
if (!(0, domhandler_1.isTag)(elem))
continue;
if (test(elem))
if ((0, domhandler_1.isTag)(elem) && test(elem))
result.push(elem);
if (elem.children.length > 0) {
if ((0, domhandler_1.hasChildren)(elem) && elem.children.length > 0) {
indexStack.unshift(0);

@@ -159,0 +154,0 @@ nodeStack.unshift(elem.children);

{
"name": "domutils",
"version": "3.2.0",
"version": "3.2.1",
"description": "Utilities for working with htmlparser2's dom",

@@ -5,0 +5,0 @@ "author": "Felix Boehm <me@feedic.com>",

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

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

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

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

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

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

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

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc