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

unist-util-remove

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-remove

unist utility to remove nodes from a tree

  • 4.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.7M
increased by4.71%
Maintainers
2
Weekly downloads
 
Created

What is unist-util-remove?

The unist-util-remove package is a utility for removing nodes from a Unist syntax tree. It allows you to filter out nodes based on specific criteria, making it useful for manipulating abstract syntax trees (ASTs) in various text processing tasks.

What are unist-util-remove's main functionalities?

Remove nodes by type

This feature allows you to remove all nodes of a specific type from the tree. In this example, all 'paragraph' nodes are removed from the tree.

const remove = require('unist-util-remove');
const tree = { type: 'root', children: [ { type: 'paragraph', children: [ { type: 'text', value: 'Hello' } ] }, { type: 'paragraph', children: [ { type: 'text', value: 'World' } ] } ] };
remove(tree, 'paragraph');
console.log(tree);

Remove nodes by test function

This feature allows you to remove nodes based on a test function. In this example, only the 'paragraph' node containing the text 'World' is removed.

const remove = require('unist-util-remove');
const tree = { type: 'root', children: [ { type: 'paragraph', children: [ { type: 'text', value: 'Hello' } ] }, { type: 'paragraph', children: [ { type: 'text', value: 'World' } ] } ] };
remove(tree, node => node.type === 'paragraph' && node.children[0].value === 'World');
console.log(tree);

Remove nodes by index

This feature allows you to remove nodes by their index in the parent node's children array. In this example, the second 'paragraph' node (index 1) is removed.

const remove = require('unist-util-remove');
const tree = { type: 'root', children: [ { type: 'paragraph', children: [ { type: 'text', value: 'Hello' } ] }, { type: 'paragraph', children: [ { type: 'text', value: 'World' } ] } ] };
remove(tree, { type: 'paragraph' }, 1);
console.log(tree);

Other packages similar to unist-util-remove

Keywords

FAQs

Package last updated on 07 Jul 2023

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