Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unist-util-modify-children

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-modify-children

Unist utility to modify direct children of a parent

  • 1.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
498K
decreased by-4.84%
Maintainers
1
Weekly downloads
 
Created
Source

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).

Contribute

See contribute.md in syntax-tree/unist for ways to get started.

This organisation has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 30 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc