unist-util-visit
- Version 5.0.0
- Published
- 28.5 kB
- 3 dependencies
- MIT license
Install
npm i unist-util-visit
yarn add unist-util-visit
pnpm add unist-util-visit
Overview
unist utility to visit nodes
Index
Functions
Type Aliases
Functions
function visit
visit: { <Tree extends any, Check extends unknown>( tree: Tree, check: Check, visitor: BuildVisitor<Tree, Check>, reverse?: boolean | null | undefined ): undefined; <Tree extends any, Check extends unknown>( tree: Tree, visitor: BuildVisitor<Tree, any>, reverse?: boolean ): undefined;};
Type Aliases
type BuildVisitor
type BuildVisitor< Tree extends import('unist').Node = import('unist').Node, Check extends Test = Test> = BuildVisitorFromDescendants<InclusiveDescendant<Tree>, Check>;
Build a typed
Visitor
function from a tree and a test.It will infer which values are passed as
node
and which asparent
.
type Visitor
type Visitor< Visited extends import('unist').Node = import('unist').Node, Ancestor extends import('unist').Parent = import('unist').Parent> = ( 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
node
itself, ifSKIP
is 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), theVisitor
should return a newIndex
to specify the sibling to traverse afternode
is 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
parent
still 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 2178 ms. - Missing or incorrect documentation? Open an issue for this package.