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

unist-util-find

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-find

Unist node finder utility. Useful for working with remark, rehype and retext.

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
78K
increased by32.73%
Maintainers
1
Weekly downloads
 
Created
Source

unist-util-find Travis

Unist node finder utility. Useful for working with remark, rehype and retext.

Installation

npm install --save unist-util-find

Usage

Example

var remark = require('remark')
var find = require('unist-util-find')

remark()
  .use(function () {
    return function (tree) {
      // string condition
      console.log(find(tree, 'value'))

      // object condition
      console.log(find(tree, { value: 'emphasis' }))

      // function condition
      console.log(find(tree, function (node) {
        return node.type === 'inlineCode'
      }))
    }
  })
  .processSync('Some _emphasis_, **strongness**, and `code`.')

Result:

// string condition: 'value'
{ type: 'text',
  value: 'Some ',
  position:
   Position {
     start: { line: 1, column: 1, offset: 0 },
     end: { line: 1, column: 6, offset: 5 },
     indent: [] } }

// object condition: { value: 'emphasis' }
{ type: 'text',
  value: 'emphasis',
  position:
   Position {
     start: { line: 1, column: 7, offset: 6 },
     end: { line: 1, column: 15, offset: 14 },
     indent: [] } }

// function condition: function (node) { return node.type === 'inlineCode' }
{ type: 'inlineCode',
  value: 'code',
  position:
   Position {
     start: { line: 1, column: 38, offset: 37 },
     end: { line: 1, column: 44, offset: 43 },
     indent: [] } }

API

find(node, condition)

Return the first node that matches condition, or undefined if no node matches.

  • node (Node) - Node to search
  • condition (string, object or function) - Condition used to test each node. Behaviour depends on the type of the condition:
    • string finds first node with a truthy property matching string
    • object finds first node that has matching values for all properties of object
    • function finds first node for which function returns true when passed node as argument

License

MIT

Keywords

FAQs

Package last updated on 14 Jun 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