UNPKG

2.78 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at
5 * http://polymer.github.io/LICENSE.txt
6 * The complete set of authors may be found at
7 * http://polymer.github.io/AUTHORS.txt
8 * The complete set of contributors may be found at
9 * http://polymer.github.io/CONTRIBUTORS.txt
10 * Code distributed by Google as part of the polymer project is also
11 * subject to an additional IP rights grant found at
12 * http://polymer.github.io/PATENTS.txt
13 */
14import { ASTNode as Node } from 'parse5';
15import { Predicate } from './predicates';
16import { GetChildNodes } from './util';
17export { ASTNode as Node } from 'parse5';
18/**
19 * Applies `mapfn` to `node` and the tree below `node`, returning a flattened
20 * list of results.
21 */
22export declare function treeMap<U>(node: Node, mapfn: (node: Node) => U[]): U[];
23/**
24 * Walk the tree down from `node`, applying the `predicate` function.
25 * Return the first node that matches the given predicate.
26 *
27 * @returns `null` if no node matches, parse5 node object if a node matches.
28 */
29export declare function nodeWalk(node: Node, predicate: Predicate, getChildNodes?: GetChildNodes): Node | null;
30/**
31 * Walk the tree down from `node`, applying the `predicate` function.
32 * All nodes matching the predicate function from `node` to leaves will be
33 * returned.
34 */
35export declare function nodeWalkAll(node: Node, predicate: Predicate, matches?: Node[], getChildNodes?: GetChildNodes): Node[];
36/**
37 * Equivalent to `nodeWalk`, but only returns nodes that are either
38 * ancestors or earlier siblings in the document.
39 *
40 * Nodes are searched in reverse document order, starting from the sibling
41 * prior to `node`.
42 */
43export declare function nodeWalkPrior(node: Node, predicate: Predicate): Node | undefined;
44/**
45 * Equivalent to `nodeWalkAll`, but only returns nodes that are either
46 * ancestors or earlier cousins/siblings in the document.
47 *
48 * Nodes are returned in reverse document order, starting from `node`.
49 */
50export declare function nodeWalkAllPrior(node: Node, predicate: Predicate, matches?: Node[]): Node[];
51/**
52 * Walk the tree up from the parent of `node`, to its grandparent and so on to
53 * the root of the tree. Return the first ancestor that matches the given
54 * predicate.
55 */
56export declare function nodeWalkAncestors(node: Node, predicate: Predicate): Node | undefined;
57/**
58 * Equivalent to `nodeWalk`, but only matches elements
59 */
60export declare function query(node: Node, predicate: Predicate, getChildNodes?: GetChildNodes): Node | null;
61/**
62 * Equivalent to `nodeWalkAll`, but only matches elements
63 */
64export declare function queryAll(node: Node, predicate: Predicate, matches?: Node[], getChildNodes?: GetChildNodes): Node[];