11<!-- lint disable no-html-->
22
3- # hast-util-select [ ![ Build ] [ build-badge ]] [ build ] [ ![ Coverage ] [ coverage-badge ]] [ coverage ] [ ![ Downloads ] [ downloads-badge ]] [ downloads ] [ ![ Chat ] [ chat-badge ]] [ chat ]
3+ # hast-util-select
44
5- ` querySelector ` , ` querySelectorAll ` , and ` matches ` for [ HAST] [ ] nodes.
5+ [ ![ Build] [ build-badge ]] [ build ]
6+ [ ![ Coverage] [ coverage-badge ]] [ coverage ]
7+ [ ![ Downloads] [ downloads-badge ]] [ downloads ]
8+ [ ![ Size] [ size-badge ]] [ size ]
9+ [ ![ Sponsors] [ sponsors-badge ]] [ collective ]
10+ [ ![ Backers] [ backers-badge ]] [ collective ]
11+ [ ![ Chat] [ chat-badge ]] [ chat ]
612
7- One notable difference between DOM and HAST is that DOM nodes have references
13+ [ ** hast** ] [ hast ] utility with equivalents ` querySelector ` , ` querySelectorAll ` ,
14+ and ` matches ` .
15+
16+ One notable difference between DOM and hast is that DOM nodes have references
817to their parents, meaning that ` document.body.matches(':last-child') ` can
9- be evaluated. This information is not stored in HAST, so selectors like
10- that don’t work.
18+ be evaluated.
19+ This information is not stored in hast, so selectors like that don’t work.
1120
1221[ View the list of supported selectors »] [ support ]
1322
14- ## Installation
23+ ## Install
1524
1625[ npm] [ ] :
1726
18- ``` bash
27+ ``` sh
1928npm install hast-util-select
2029```
2130
2231## API
2332
2433### ` select.matches(selector, node[, space]) `
2534
26- This only checks the element itself, not the surrounding tree. Thus, nesting
27- in selectors is not supported (` p b ` , ` p > b ` ), neither are selectors like
28- ` :first-child ` , etc. This simply checks that the given element matches the
29- selector.
35+ Check that the given ` node ` matches ` selector ` .
36+ Returns boolean, whether the node matches or not.
37+
38+ This only checks the element itself, not the surrounding tree.
39+ Thus, nesting in selectors is not supported (` p b ` , ` p > b ` ), neither are
40+ selectors like ` :first-child ` , etc.
41+ This only checks that the given element matches the selector.
3042
3143##### Usage
3244
@@ -48,8 +60,8 @@ matches('[lang|=en]', h('a', {lang: 'en-GB'})) // => true
4860
4961* ` selector ` (` string ` )
5062 — CSS selectors (` , ` is also supported)
51- * ` node ` (` Node ` )
52- — Thing to check, could be anything, but should be an [ element] [ ]
63+ * ` node ` ([ ` Node ` ] [ node ] )
64+ — Thing to check, could be anything, but should be an [ * element* ] [ element ]
5365* ` space ` (enum, ` 'svg' ` or ` 'html' ` , default: ` 'html' ` )
5466 — Which space the node exists in
5567
@@ -59,6 +71,10 @@ matches('[lang|=en]', h('a', {lang: 'en-GB'})) // => true
5971
6072### ` select.select(selector, tree[, space]) `
6173
74+ Select the first ` node ` matching ` selector ` in the given ` tree ` (could be the
75+ tree itself).
76+ Searches the [ * tree* ] [ tree ] in [ * preorder* ] [ preorder ] .
77+
6278##### Usage
6379
6480``` js
@@ -88,24 +104,22 @@ Yields:
88104 children: [ { type: ' text' , value: ' Delta' } ] }
89105```
90106
91- Select the first node matching ` selector ` in the given ` tree ` (could be the
92- tree itself).
93-
94107##### Parameters
95108
96109* ` selector ` (` string ` ) — CSS selectors (` , ` is also supported)
97- * ` tree ` (` Node ` ) — Thing to search.
110+ * ` tree ` ([ ` Node ` ] [ node ] ) — [ * Tree * ] [ tree ] to search
98111* ` space ` (enum, ` 'svg' ` or ` 'html' ` , default: ` 'html' ` )
99- — Which v the tree exists in
112+ — Which space the tree exists in
100113
101114##### Returns
102115
103- ` Element? ` — The found element, if any.
116+ [ ` Element? ` ] [ element ] — The found element, if any.
104117
105118### ` select.selectAll(selector, tree[, space]) `
106119
107- Select all nodes matching ` selector ` in the given ` tree ` (could include the
108- tree itself).
120+ Select all nodes matching ` selector ` in the given ` tree ` (could include the tree
121+ itself).
122+ Searches the [ * tree* ] [ tree ] in [ * preorder* ] [ preorder ] .
109123
110124##### Usage
111125
@@ -145,13 +159,13 @@ Yields:
145159##### Parameters
146160
147161* ` selector ` (` string ` ) — CSS selectors (` , ` is also supported)
148- * ` tree ` (` Node ` ) — Thing to search.
162+ * ` tree ` ([ ` Node ` ] [ node ] ) — [ * Tree * ] [ tree ] to search
149163* ` space ` (enum, ` 'svg' ` or ` 'html' ` , default: ` 'html' ` )
150164 — Which space the tree exists in
151165
152166##### Returns
153167
154- ` Array.<Element> ` — All found elements, if any.
168+ [ ` Array.<Element> ` ] [ element ] — All found elements, if any.
155169
156170## Support
157171
@@ -255,19 +269,21 @@ Yields:
255269
256270###### Notes
257271
258- * \* — Not supported in ` matches ` .
272+ * \* — Not supported in ` matches `
259273* † — Needs a user, browser, interactivity, or scripting to make sense
260274* ‡ — Not supported by the underlying algorithm
261275* § — Not very interested in writing / including the code for this
262276* ‖ — Too new, the spec is still changing
263277
264278## Contribute
265279
266- See [ ` contributing.md ` in ` syntax-tree/hast ` ] [ contributing ] for ways to get
280+ See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
267281started.
282+ See [ ` support.md ` ] [ help ] for ways to get help.
268283
269- This organisation has a [ Code of Conduct] [ coc ] . By interacting with this
270- repository, organisation, or community you agree to abide by its terms.
284+ This project has a [ Code of Conduct] [ coc ] .
285+ By interacting with this repository, organisation, or community you agree to
286+ abide by its terms.
271287
272288## License
273289
@@ -287,22 +303,40 @@ repository, organisation, or community you agree to abide by its terms.
287303
288304[ downloads ] : https://www.npmjs.com/package/hast-util-select
289305
306+ [ size-badge ] : https://img.shields.io/bundlephobia/minzip/hast-util-select.svg
307+
308+ [ size ] : https://bundlephobia.com/result?p=hast-util-select
309+
310+ [ sponsors-badge ] : https://opencollective.com/unified/sponsors/badge.svg
311+
312+ [ backers-badge ] : https://opencollective.com/unified/backers/badge.svg
313+
314+ [ collective ] : https://opencollective.com/unified
315+
290316[ chat-badge ] : https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
291317
292- [ chat ] : https://spectrum.chat/unified/rehype
318+ [ chat ] : https://spectrum.chat/unified/syntax-tree
293319
294320[ npm ] : https://docs.npmjs.com/cli/install
295321
296322[ license ] : license
297323
298324[ author ] : https://wooorm.com
299325
326+ [ contributing ] : https://github.com/syntax-tree/.github/blob/master/contributing.md
327+
328+ [ help ] : https://github.com/syntax-tree/.github/blob/master/support.md
329+
330+ [ coc ] : https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
331+
332+ [ tree ] : https://github.com/syntax-tree/unist#tree
333+
334+ [ preorder ] : https://github.com/syntax-tree/unist#preorder
335+
300336[ hast ] : https://github.com/syntax-tree/hast
301337
338+ [ node ] : https://github.com/syntax-tree/hast#nodes
339+
302340[ element ] : https://github.com/syntax-tree/hast#element
303341
304342[ support ] : #support
305-
306- [ contributing ] : https://github.com/syntax-tree/hast/blob/master/contributing.md
307-
308- [ coc ] : https://github.com/syntax-tree/hast/blob/master/code-of-conduct.md
0 commit comments