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 as parent.

    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 transform parent.

      Replacing node itself, if SKIP 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), the Visitor should return a new Index to specify the sibling to traverse after node is traversed. Adding or removing next siblings of node (or previous siblings, in case of reverse) is handled as expected without needing to return a new Index.

      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 onejsDocs.io badgeto 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
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](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>