unist-util-select

WebJar for unist-util-select

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

unist-util-select
Last Version

Last Version

2.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

unist-util-select
WebJar for unist-util-select
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/syntax-tree/unist-util-select

Download unist-util-select

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/unist-util-select/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>unist-util-select</artifactId>
    <version>2.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/unist-util-select/
implementation 'org.webjars.npm:unist-util-select:2.0.2'
// https://jarcasting.com/artifacts/org.webjars.npm/unist-util-select/
implementation ("org.webjars.npm:unist-util-select:2.0.2")
'org.webjars.npm:unist-util-select:jar:2.0.2'
<dependency org="org.webjars.npm" name="unist-util-select" rev="2.0.2">
  <artifact name="unist-util-select" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='unist-util-select', version='2.0.2')
)
libraryDependencies += "org.webjars.npm" % "unist-util-select" % "2.0.2"
[org.webjars.npm/unist-util-select "2.0.2"]

Dependencies

compile (5)

Group / Artifact Type Version
org.webjars.npm : css-selector-parser jar [1.1.0,2)
org.webjars.npm : zwitch jar [1.0.3,2)
org.webjars.npm : nth-check jar [1.0.1,2)
org.webjars.npm : unist-util-is jar [3.0.0,4)
org.webjars.npm : not jar [0.1.0,0.2)

Project Modules

There are no modules declared in this project.

unist-util-select

Build Coverage Downloads Size Sponsors Backers Chat

unist utility with equivalents for querySelector, querySelectorAll, and matches.

Note that the DOM has references to their parent nodes, meaning that document.body.matches(':last-child') can be evaluated. This information is not stored in unist, so selectors like that don’t work.

View the list of supported selectors »

Install

npm:

npm install unist-util-select

API

select.matches(selector, node)

Check that the given node matches selector. Returns boolean, whether the node matches or not.

This only checks the element itself, not the surrounding tree. Thus, nesting in selectors is not supported (paragraph strong, paragraph > strong), nor are selectors like :first-child, etc. This only checks that the given element matches the selector.

var u = require('unist-builder')
var matches = require('unist-util-select').matches

matches('strong, em', u('strong', [u('text', 'important')])) // => true
matches('[lang]', u('code', {lang: 'js'}, 'console.log(1)')) // => true

select.select(selector, tree)

Select the first node matching selector in the given tree (could be the tree itself). Returns the found node, if any.

var u = require('unist-builder')
var select = require('unist-util-select').select

console.log(
  select(
    'code ~ :nth-child(even)',
    u('blockquote', [
      u('paragraph', [u('text', 'Alpha')]),
      u('paragraph', [u('text', 'Bravo')]),
      u('code', 'Charlie'),
      u('paragraph', [u('text', 'Delta')]),
      u('paragraph', [u('text', 'Echo')])
    ])
  )
)

Yields:

{type: 'paragraph', children: [{type: 'text', value: 'Delta'}]}

select.selectAll(selector, tree)

Select all nodes matching selector in the given tree (could include the tree itself). Returns all found nodes, if any.

var u = require('unist-builder')
var selectAll = require('unist-util-select').selectAll

console.log(
  selectAll(
    'code ~ :nth-child(even)',
    u('blockquote', [
      u('paragraph', [u('text', 'Alpha')]),
      u('paragraph', [u('text', 'Bravo')]),
      u('code', 'Charlie'),
      u('paragraph', [u('text', 'Delta')]),
      u('paragraph', [u('text', 'Echo')]),
      u('paragraph', [u('text', 'Foxtrot')]),
      u('paragraph', [u('text', 'Golf')])
    ])
  )
)

Yields:

[
  {type: 'paragraph', children: [{type: 'text', value: 'Delta'}]},
  {type: 'paragraph', children: [{type: 'text', value: 'Foxtrot'}]}
]

Support

  • * (universal selector)
  • , (multiple selector)
  • paragraph (type selector)
  • blockquote paragraph (combinator: descendant selector)
  • blockquote > paragraph (combinator: child selector)
  • code + paragraph (combinator: adjacent sibling selector)
  • code ~ paragraph (combinator: general sibling selector)
  • [attr] (attribute existence, checks that the value on the tree is not nullish)
  • [attr=value] (attribute equality, this stringifies values on the tree)
  • [attr^=value] (attribute begins with, only works on strings)
  • [attr$=value] (attribute ends with, only works on strings)
  • [attr*=value] (attribute contains, only works on strings)
  • [attr~=value] (attribute contains, checks if value is in the array, if there’s an array on the tree, otherwise same as attribute equality)
  • :any() (functional pseudo-class, use :matches instead)
  • :has() (functional pseudo-class) Relative selectors (:has(> img)) are not supported, but :scope is
  • :matches() (functional pseudo-class)
  • :not() (functional pseudo-class)
  • :blank (pseudo-class, blank and empty are the same: a parent without children, or a node without value)
  • :empty (pseudo-class, blank and empty are the same: a parent without children, or a node without value)
  • :root (pseudo-class, matches the given node)
  • :scope (pseudo-class, matches the given node)
  • * :first-child (pseudo-class)
  • * :first-of-type (pseudo-class)
  • * :last-child (pseudo-class)
  • * :last-of-type (pseudo-class)
  • * :only-child (pseudo-class)
  • * :only-of-type (pseudo-class)
  • * :nth-child() (functional pseudo-class)
  • * :nth-last-child() (functional pseudo-class)
  • * :nth-last-of-type() (functional pseudo-class)
  • * :nth-of-type() (functional pseudo-class)
Notes
  • * — Not supported in matches

Related

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Eugene Sharygin

org.webjars.npm
🌲🌲🌲🌳🌲🌳🌲🌲🌲🌳🌳🌲🌲🌳🌲🌲🎄🌲🌳🌲🌲🌳🐻🌳🌳🌳🌲🌲🌳🌲🎄🌲🌳🌲🌲🌳🌳🌳

Versions

Version
2.0.2