unist-util-visit
- Version 5.1.0
- Published
- 33.8 kB
- 3 dependencies
- MIT license
Install
npm i unist-util-visityarn add unist-util-visitpnpm add unist-util-visitOverview
unist utility to visit nodes
Index
Functions
Type Aliases
Functions
function visit
visit: { <Tree extends UnistNode, Check extends unknown>( tree: Tree, check: Check, visitor: BuildVisitor<Tree, Check>, reverse?: boolean | null | undefined ): undefined; <Tree extends UnistNode, Check extends unknown>( tree: Tree, visitor: BuildVisitor<Tree, any>, reverse?: boolean ): undefined;};Visit nodes.
This algorithm performs *depth-first* *tree traversal* in *preorder* (**NLR**) or if
reverseis given, in *reverse preorder* (**NRL**).You can choose for which nodes
visitoris called by passing atest. For complex tests, you should test yourself invisitor, as it will be faster and will have improved type information.Walking the tree is an intensive task. Make use of the return values of the visitor when possible. Instead of walking a tree multiple times, walk it once, use
unist-util-isto check if a node matches, and then perform different operations.You can change the tree. See
Visitorfor more info.Parameter tree
Parameter check
Parameter visitor
Parameter reverse
Parameter tree
Parameter visitor
Parameter reverse
Parameter tree
Tree to traverse.
Parameter testOrVisitor
unist-util-is-compatible test (optional, omit to pass a visitor).Parameter visitorOrReverse
Handle each node (when test is omitted, pass
reverse).Parameter maybeReverse
Traverse in reverse preorder (NRL) instead of the default preorder (NLR).
Returns
{undefined} Nothing.
{UnistNode} Tree Node type. {Test} Check
unist-util-is-compatible test.
Type Aliases
type BuildVisitor
type BuildVisitor< Tree extends UnistNode = UnistNode, Check extends Test = Test> = BuildVisitorFromDescendants<InclusiveDescendant<Tree>, Check>;Build a typed
Visitorfunction from a tree and a test.It will infer which values are passed as
nodeand which asparent.
type Visitor
type Visitor< Visited extends UnistNode = UnistNode, Ancestor extends UnistParent = UnistParent> = ( node: Visited, index: Visited extends UnistNode ? number | undefined : never, parent: Ancestor extends UnistParent ? Ancestor | undefined : never) => VisitorResult;Handle a node (matching
test, if given).Visitors are free to transform
node. They can also transformparent.Replacing
nodeitself, ifSKIPis not returned, still causes its descendants to be walked (which is a bug).When adding or removing previous siblings of
node(or next siblings, in case of reverse), theVisitorshould return a newIndexto specify the sibling to traverse afternodeis traversed. Adding or removing next siblings ofnode(or previous siblings, in case of reverse) is handled as expected without needing to return a newIndex.Removing the children property of
parentstill results in them being traversed.
Package Files (2)
Dependencies (3)
Dev Dependencies (13)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/unist-util-visit.
- Markdown[](https://www.jsdocs.io/package/unist-util-visit)
- HTML<a href="https://www.jsdocs.io/package/unist-util-visit"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 1440 ms. - Missing or incorrect documentation? Open an issue for this package.
