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

unist-util-is

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-is

unist utility to check if a node passes a test

  • 6.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13M
decreased by-17.39%
Maintainers
2
Weekly downloads
 
Created

What is unist-util-is?

The unist-util-is npm package is a utility library for working with Unist nodes. Unist (Universal Syntax Tree) is part of the unified ecosystem, which provides a way to work with syntax trees for content such as Markdown, HTML, or plain text. unist-util-is specifically helps in testing and filtering nodes in these trees based on certain conditions.

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

Test nodes with a condition

This feature allows you to test if a node matches a specific type or condition. In the example, `is` is used to check if the root node is a 'leaf' (which it isn't), and then if the first child of the root is a 'leaf' (which it is).

const is = require('unist-util-is');
const u = require('unist-builder');

const tree = u('root', [
  u('leaf', 'first leaf'),
  u('node', [u('leaf', 'nested leaf')])
]);

const test = is(tree, 'leaf'); // false
const testLeaf = is(tree.children[0], 'leaf'); // true

Filter nodes by type

This feature demonstrates how to filter nodes by type using `is` in combination with `unist-util-select`. It selects all 'leaf' nodes from the tree and filters them to ensure they are of type 'leaf'.

const is = require('unist-util-is');
const u = require('unist-builder');
const select = require('unist-util-select');

const tree = u('root', [
  u('leaf', 'first leaf'),
  u('node', [u('leaf', 'nested leaf')])
]);

const leaves = select.selectAll('leaf', tree).filter(node => is(node, 'leaf'));

Other packages similar to unist-util-is

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