UNPKG

unist-utils-core

Version:

A collection of commonly used (albeit enhanced) algorithms based on unist and unist-util-xxx

28 lines (27 loc) 1.4 kB
import { Node, Parent } from './nodes'; import { Test } from './test'; /** * Return the first node that matches test, or undefined if no node matches. * * @param {Node} tree - Node(s) to search * @param [tst] - 'is-compatible' test (such as a type). */ export declare function find<T extends Node>(tree: T | T[], tst: Test<T>): T; /** * Return all nodes that match test, or an empty array if no node matches. * * @param {Node} tree - Node(s) to search * @param [tst] - 'is-compatible' test (such as a type). * @returns an Array of zero or more Nodes in the tree that matched the condition. */ export declare function findAll<T extends Node>(tree: T | T[], tst: Test<T>): T[]; /** * Search upward (using the Node.parent property) for an ancestor that meets a supplied test. * * @param node The node from which to start the upward search. * @param [tst] - 'is-compatible' test to apply to each parent along the upward walk. * @returns An array representing the "path" to the first ancestor that matched the condition. * The first element in the "path" array will be the ancestor that matched the condition, and the node's immediate parent will be the last element of the array. * If no ancestors were found (or none passed the test), an empty array will be returned. */ export declare function findAncestor<T extends Parent, V = T>(node: Node, tst: Test<T>): V[];