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

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
fn
(Function
) — Function to wrap.
Return
Function
— Wrapped fn
.
function fn(child, index, parent)
Visitor for children of parent
.
Parameters
child
(Node
) — Current iteration;index
(number
) — Position ofchild
inparent
;parent
(Node
) — Parent node ofchild
.
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.