UNPKG

2.92 kBTypeScriptView Raw
1import { AnyNode, Element } from "domhandler";
2import type { ElementType } from "domelementtype";
3/**
4 * An object with keys to check elements against. If a key is `tag_name`,
5 * `tag_type` or `tag_contains`, it will check the value against that specific
6 * value. Otherwise, it will check an attribute with the key's name.
7 *
8 * @category Legacy Query Functions
9 */
10export interface TestElementOpts {
11 tag_name?: string | ((name: string) => boolean);
12 tag_type?: string | ((name: string) => boolean);
13 tag_contains?: string | ((data?: string) => boolean);
14 [attributeName: string]: undefined | string | ((attributeValue: string) => boolean);
15}
16/**
17 * Checks whether a node matches the description in `options`.
18 *
19 * @category Legacy Query Functions
20 * @param options An object describing nodes to look for.
21 * @param node The element to test.
22 * @returns Whether the element matches the description in `options`.
23 */
24export declare function testElement(options: TestElementOpts, node: AnyNode): boolean;
25/**
26 * Returns all nodes that match `options`.
27 *
28 * @category Legacy Query Functions
29 * @param options An object describing nodes to look for.
30 * @param nodes Nodes to search through.
31 * @param recurse Also consider child nodes.
32 * @param limit Maximum number of nodes to return.
33 * @returns All nodes that match `options`.
34 */
35export declare function getElements(options: TestElementOpts, nodes: AnyNode | AnyNode[], recurse: boolean, limit?: number): AnyNode[];
36/**
37 * Returns the node with the supplied ID.
38 *
39 * @category Legacy Query Functions
40 * @param id The unique ID attribute value to look for.
41 * @param nodes Nodes to search through.
42 * @param recurse Also consider child nodes.
43 * @returns The node with the supplied ID.
44 */
45export declare function getElementById(id: string | ((id: string) => boolean), nodes: AnyNode | AnyNode[], recurse?: boolean): Element | null;
46/**
47 * Returns all nodes with the supplied `tagName`.
48 *
49 * @category Legacy Query Functions
50 * @param tagName Tag name to search for.
51 * @param nodes Nodes to search through.
52 * @param recurse Also consider child nodes.
53 * @param limit Maximum number of nodes to return.
54 * @returns All nodes with the supplied `tagName`.
55 */
56export declare function getElementsByTagName(tagName: string | ((name: string) => boolean), nodes: AnyNode | AnyNode[], recurse?: boolean, limit?: number): Element[];
57/**
58 * Returns all nodes with the supplied `type`.
59 *
60 * @category Legacy Query Functions
61 * @param type Element type to look for.
62 * @param nodes Nodes to search through.
63 * @param recurse Also consider child nodes.
64 * @param limit Maximum number of nodes to return.
65 * @returns All nodes with the supplied `type`.
66 */
67export declare function getElementsByTagType(type: ElementType | ((type: ElementType) => boolean), nodes: AnyNode | AnyNode[], recurse?: boolean, limit?: number): AnyNode[];
68//# sourceMappingURL=legacy.d.ts.map
\No newline at end of file