JSPM

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

Unist utility to visit direct children of a parent

Package Exports

  • unist-util-visit-children

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-children) 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-children Build Status Coverage Status

Unist (mdast, retext) utility to visit direct children of a parent. As in, wrap fn so it accepts a parent and invoke fn for each of its children.

Installation

npm:

npm install unist-util-visit-children

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

Usage

var visitChildren = require('unist-util-visit-children');
var visitor = visitChildren(console.log.bind(console));

var parent = {
    'type': 'foo',
    'children': [
        { 'type': 'bar', 'value': 'alpha' },
        { 'type': 'bar', 'value': 'bravo' },
        { 'type': 'bar', 'value': 'charlie' }
    ]
};

visitor(parent);
/*
 * { 'type': 'bar', 'value': 'alpha' }
 * { 'type': 'bar', 'value': 'bravo' }
 * { 'type': 'bar', 'value': 'charlie' }
 */

API

visitChildren(fn)

Parameters

Return

Function — Wrapped fn.

function fn(child, index, parent)

Visitor for children of parent.

Parameters

  • child (Node) — Current iteration;

  • index (number) — Position of child in parent;

  • parent (Node) — Parent node of child.

function visitor(parent)

Function invoking fn for each child of parent.

Parameters

  • parent (Node) — Node with children.

Throws

  • Error — When not given a parent node.

License

MIT © Titus Wormer