Package Exports
- unist-util-remove
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-remove) 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-remove
Remove one or more nodes from Unist tree, mutating it.
Example
var u = require('unist-builder');
var remove = require('unist-util-remove');
var inspect = require('unist-util-inspect');
var ast = u('root', [
u('leaf', 1),
u('node', [
u('leaf', 2),
u('node', [
u('leaf', 3),
u('other', 4)
]),
// this node will be removed as well because of `opts.cascade`.
u('node', [
u('leaf', 5),
])
]),
u('leaf', 6)
]);
// Remove all nodes of type `leaf`.
remove(ast, 'leaf')
//=> root[1]
// └─ node[1]
// └─ node[1]
// └─ other: "4"If the root node gets removed, the entire tree is destroyed and remove returns null. That's the only case in which remove doesn't return the original root node.
remove(ast, ast)
//=> nullAPI
remove(ast, [opts], predicate)
ast— Unist tree.predicate— anytestas given tounist-util-is.
Iterates over ast in preorder traversal and removes all nodes matching predicate from ast. Returns a modified Unist tree.
Note:
unist-util-isused to remove a node when given astest. This no longer works. To migrate, pass a function as a predicate, like so:remove(ast, function (node) { return node === predicate; }).
opts.cascade
Type: Boolean
Default: true
If true, removing of the last child triggers removal of its parent node.
Install
npm install unist-util-removeLicense
MIT

