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

unist-util-select

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-select

unist utility to select nodes with CSS-like selectors

  • 3.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
164K
decreased by-7.59%
Maintainers
2
Weekly downloads
 
Created

What is unist-util-select?

The unist-util-select package is a utility for selecting nodes in a Unist syntax tree using CSS-like selectors. It allows for querying and manipulating nodes in a tree structure, making it easier to work with abstract syntax trees (ASTs) in JavaScript.

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

Select a single node

This feature allows you to select a single node from the tree that matches the given selector. In this example, it selects the first 'paragraph' node in the tree.

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

Select multiple nodes

This feature allows you to select all nodes from the tree that match the given selector. In this example, it selects all 'paragraph' nodes in the tree.

const selectAll = require('unist-util-select').selectAll;
const tree = { type: 'root', children: [{ type: 'paragraph', children: [{ type: 'text', value: 'Hello, world!' }] }, { type: 'paragraph', children: [{ type: 'text', value: 'Another paragraph.' }] }] };
const nodes = selectAll('paragraph', tree);
console.log(nodes);

Select nodes with specific attributes

This feature allows you to select nodes that have specific attributes. In this example, it selects all nodes with a 'data-id' attribute equal to 'intro'.

const selectAll = require('unist-util-select').selectAll;
const tree = { type: 'root', children: [{ type: 'paragraph', data: { id: 'intro' }, children: [{ type: 'text', value: 'Introduction' }] }, { type: 'paragraph', data: { id: 'main' }, children: [{ type: 'text', value: 'Main content' }] }] };
const nodes = selectAll('[data-id="intro"]', tree);
console.log(nodes);

Other packages similar to unist-util-select

Keywords

FAQs

Package last updated on 15 Dec 2020

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