UNPKG

1.07 kBTypeScriptView Raw
1/**
2 * Change the given `tree` by removing all nodes that pass `test`.
3 *
4 * The tree is walked in preorder (NLR), visiting the node itself, then its
5 * head, etc.
6 *
7 * @param tree
8 * Tree to change.
9 * @param options
10 * Configuration (optional).
11 * @param test
12 * `unist-util-is` compatible test.
13 * @returns
14 * The given `tree` without nodes that pass `test`.
15 *
16 * `null` is returned if `tree` itself didn’t pass the test or is cascaded
17 * away.
18 */
19export const remove: (<Tree extends import('unist').Node<import('unist').Data>>(
20 node: Tree,
21 options: Options,
22 test: Test
23) => Tree | null) &
24 (<Tree_1 extends import('unist').Node<import('unist').Data>>(
25 node: Tree_1,
26 test: Test
27 ) => Tree_1 | null)
28export type Node = import('unist').Node
29export type Parent = import('unist').Parent
30export type Test = import('unist-util-is').Test
31/**
32 * Configuration.
33 */
34export type Options = {
35 /**
36 * Whether to drop parent nodes if they had children, but all their children
37 * were filtered out.
38 */
39 cascade?: boolean | null | undefined
40}