New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details → →
Socket
Book a DemoSign in
Socket

jsx-select-utils

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsx-select-utils

A util can help you find dom by enter CSS selectors in JSX. it has a method,

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

jsx-select-utils

A util can help you find dom by enter CSS selectors in JSX. it has a method,

such as,

  • find(selector: string): array<Node {}>

Usage

const jsxSelect = require('jsx-select-utils')

const code = `
<div className="container">
  <div className="title">
    <ul className="paragraph">
      <li>1</li>
      <li>2</li>
    </ul>
  </div>
  <div className="body">
    <h1>body</h1>
    <ul className="paragraph">
      <li>3</li>
      <li>4</li>
    </ul>
  </div>
</div>
`
const ast = require('@babel/parser').parse(code, {
  sourceType: "module",
  plugins: [
    "jsx"
  ]
})

const { find } = jsxSelect(ast)

// case one
find('div .title').length

// case two
find('ul li').length

// case three
find('.body h1')

Output:

1 // case one

4 // case two

[Node {/* .body下h1节点的AST */}] // case three

Supported selectors

add constantly according to CSS3.

  • Tag (<tagname>)
  • ClassName (className="")
  • Id (id="")
  • Parent (className=".a .b")

FAQs

Package last updated on 10 Dec 2019

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