JSPM

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

Unist utility to modify direct children of a parent

Package Exports

  • unist-util-modify-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-modify-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-modify-children Build Status Coverage Status

Modify direct children of a parent.

Installation

npm:

npm install unist-util-modify-children

Usage

var remark = require('remark');
var modifyChildren = require('unist-util-modify-children');

var doc = remark().use(plugin).process('This _and_ that');

console.log(String(doc));

function plugin() {
  return transformer;
  function transformer(tree) {
    modifyChildren(modifier)(tree.children[0]);
  }
}

function modifier(node, index, parent) {
  if (node.type === 'emphasis') {
    parent.children.splice(index, 1, {type: 'strong', children: node.children});
    return index + 1;
  }
}

Yields:

This **and** that

API

modify = modifyChildren(modifier)

Wrap modifier to be invoked for each child in the node given to modify.

next? = modifier(child, index, parent)

Invoked if modify is called on a parent node for each child in parent.

Returns

number (optional) — Next position to iterate.

function modify(parent)

Invoke the bound modifier for each child in parent (Node).

License

MIT © Titus Wormer