JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 21100844
  • Score
    100M100P100Q252381F
  • License MIT

Utility to recursively walk over unist nodes

Package Exports

  • unist-util-visit

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (unist-util-visit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

unist-util-visit Build Status Coverage Status

Unist node visitor. Useful when working with mdast or retext.

Installation

npm:

npm install unist-util-visit

unist-util-visit is also available for bower, component, and duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.

Usage

var mdast = require('mdast');
var visit = require('unist-util-visit');

mdast().use(function (ast) {
    visit(ast, 'text', console.log.bind(console));
}).process('Some *emphasis*, **strongness**, and `code`.');

Yields:

{'type': 'text', 'value': 'Some '}
{'type': 'text', 'value': 'emphasis'}
{'type': 'text', 'value': ', '}
{'type': 'text', 'value': 'strongness'}
{'type': 'text', 'value': ', and '}
{'type': 'text', 'value': '.'}

API

visit(node[, type], callback[, reverse])

visit is synchronous.

Visit nodes. Optionally by node type. Optionally in reverse.

  • node (Node) — Unist node;

  • type (string, optional) — Optional node type to invoke callback for. By default, all nodes are visited.

  • callback (function(node, index?, parent?)) — Callback invoked when a node (matching type?) is found. Invoked with the node, its index in parent (or null), and its parent (or null).

    Can return false to immediately stop checking.

  • reverse (boolean, default: false, optional) — When falsey, checking starts at the first child and continues through to later children. When truthy, this is reversed.

    This does not mean checking starts at the deepest node and continues on to the highest node.

License

MIT © Titus Wormer