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

unist-util-remove

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-remove

Remove nodes from Unist tree

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.7M
decreased by-6.87%
Maintainers
1
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 23 Jan 2016

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