UNPKG

2.73 kBTypeScriptView Raw
1import { Element, AnyNode } from "domhandler";
2/**
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.
4 *
5 * @category Querying
6 * @param test Function to test nodes on.
7 * @param node Node to search. Will be included in the result set if it matches.
8 * @param recurse Also consider child nodes.
9 * @param limit Maximum number of nodes to return.
10 * @returns All nodes passing `test`.
11 */
12export declare function filter(test: (elem: AnyNode) => boolean, node: AnyNode | AnyNode[], recurse?: boolean, limit?: number): AnyNode[];
13/**
14 * Search an array of nodes and their children for nodes passing a test function.
15 *
16 * @category Querying
17 * @param test Function to test nodes on.
18 * @param nodes Array of nodes to search.
19 * @param recurse Also consider child nodes.
20 * @param limit Maximum number of nodes to return.
21 * @returns All nodes passing `test`.
22 */
23export declare function find(test: (elem: AnyNode) => boolean, nodes: AnyNode[], recurse: boolean, limit: number): AnyNode[];
24/**
25 * Finds the first element inside of an array that matches a test function. This is an alias for `Array.prototype.find`.
26 *
27 * @category Querying
28 * @param test Function to test nodes on.
29 * @param nodes Array of nodes to search.
30 * @returns The first node in the array that passes `test`.
31 * @deprecated Use `Array.prototype.find` directly.
32 */
33export declare function findOneChild<T>(test: (elem: T) => boolean, nodes: T[]): T | undefined;
34/**
35 * Finds one element in a tree that passes a test.
36 *
37 * @category Querying
38 * @param test Function to test nodes on.
39 * @param nodes Node or array of nodes to search.
40 * @param recurse Also consider child nodes.
41 * @returns The first node that passes `test`.
42 */
43export declare function findOne(test: (elem: Element) => boolean, nodes: AnyNode[], recurse?: boolean): Element | null;
44/**
45 * Checks if a tree of nodes contains at least one node passing a test.
46 *
47 * @category Querying
48 * @param test Function to test nodes on.
49 * @param nodes Array of nodes to search.
50 * @returns Whether a tree of nodes contains at least one node passing the test.
51 */
52export declare function existsOne(test: (elem: Element) => boolean, nodes: AnyNode[]): boolean;
53/**
54 * Search an array of nodes and their children for elements passing a test function.
55 *
56 * Same as `find`, but limited to elements and with less options, leading to reduced complexity.
57 *
58 * @category Querying
59 * @param test Function to test nodes on.
60 * @param nodes Array of nodes to search.
61 * @returns All nodes passing `test`.
62 */
63export declare function findAll(test: (elem: Element) => boolean, nodes: AnyNode[]): Element[];
64//# sourceMappingURL=querying.d.ts.map
\No newline at end of file