1
- <!-- lint disable no-html-->
2
-
3
1
# hast-util-select
4
2
5
3
[ ![ Build] [ build-badge ]] [ build ]
@@ -18,6 +16,7 @@ and `matches`.
18
16
* [ What is this?] ( #what-is-this )
19
17
* [ When should I use this?] ( #when-should-i-use-this )
20
18
* [ Install] ( #install )
19
+ * [ Use] ( #use )
21
20
* [ API] ( #api )
22
21
* [ ` matches(selector, node[, space]) ` ] ( #matchesselector-node-space )
23
22
* [ ` select(selector, tree[, space]) ` ] ( #selectselector-tree-space )
@@ -56,7 +55,7 @@ find and match any unist node.
56
55
## Install
57
56
58
57
This package is [ ESM only] [ esm ] .
59
- In Node.js (version 12.20+, 14.14+, 16.0+, 18 .0+), install with [ npm] [ ] :
58
+ In Node.js (version 14.14+, 16.0+), install with [ npm] [ ] :
60
59
61
60
``` sh
62
61
npm install hast-util-select
@@ -76,6 +75,31 @@ In browsers with [`esm.sh`][esmsh]:
76
75
</script >
77
76
```
78
77
78
+ ## Use
79
+
80
+ ``` js
81
+ import {h } from ' hastscript'
82
+ import {matches , select , selectAll } from ' hast-util-select'
83
+
84
+ const tree = h (' section' , [
85
+ h (' p' , ' Alpha' ),
86
+ h (' p' , ' Bravo' ),
87
+ h (' h1' , ' Charlie' ),
88
+ h (' p' , ' Delta' ),
89
+ h (' p' , ' Echo' ),
90
+ h (' p' , ' Foxtrot' ),
91
+ h (' p' , ' Golf' )
92
+ ])
93
+
94
+ matches (' section' , tree) // `true`
95
+
96
+ console .log (select (' h1 ~ :nth-child(even)' , tree))
97
+ // The paragraph with `Delta`
98
+
99
+ console .log (selectAll (' h1 ~ :nth-child(even)' , tree))
100
+ // The paragraphs with `Delta` and `Foxtrot`
101
+ ```
102
+
79
103
## API
80
104
81
105
This package exports the identifiers ` matches ` , ` select ` , and ` selectAll ` .
@@ -116,7 +140,6 @@ matches('.classy', h('a', {className: ['classy']})) // => true
116
140
matches (' #id' , h (' a' , {id: ' id' })) // => true
117
141
matches (' [lang|=en]' , h (' a' , {lang: ' en' })) // => true
118
142
matches (' [lang|=en]' , h (' a' , {lang: ' en-GB' })) // => true
119
- // …
120
143
```
121
144
122
145
### ` select(selector, tree[, space]) `
@@ -278,13 +301,12 @@ Yields:
278
301
* [ ] ‡ ` [*|attr] ` (any namespace attribute)
279
302
* [ ] ‡ ` [|attr] ` (no namespace attribute)
280
303
* [ ] ‡ ` [attr=value i] ` (attribute case-insensitive)
281
- * [ ] ‡ ` :has() ` (functional pseudo-class). <small >Relative
282
- selectors (` :has(> img) ` ) are not supported, but scope is
283
- (` :has(:scope > img) ` ) </small >
284
- * [ ] ‖ ` :nth-child(n of S) ` (functional pseudo-class). <small >Scoping
285
- to parents is not supported</small >
286
- * [ ] ‖ ` :nth-last-child(n of S) ` (scoped to parent S). <small >Scoping
287
- to parents is not supported</small >
304
+ * [ ] ‡ ` :has() ` (functional pseudo-class, note: relative selectors such as
305
+ ` :has(> img) ` are not supported, but scope is: ` :has(:scope > img) ` )
306
+ * [ ] ‖ ` :nth-child(n of S) ` (functional pseudo-class, note: scoping to
307
+ parents is not supported)
308
+ * [ ] ‖ ` :nth-last-child(n of S) ` (functional pseudo-class, note: scoping to
309
+ parents is not supported)
288
310
* [ ] † ` :active ` (pseudo-class)
289
311
* [ ] † ` :current ` (pseudo-class)
290
312
* [ ] † ` :current() ` (functional pseudo-class)
@@ -323,11 +345,11 @@ Yields:
323
345
324
346
###### Notes
325
347
326
- * \* — Not supported in ` matches `
327
- * † — Needs a user, browser, interactivity, or scripting to make sense
328
- * ‡ — Not supported by the underlying algorithm
329
- * § — Not very interested in writing / including the code for this
330
- * ‖ — Too new, the spec is still changing
348
+ * \* — not supported in ` matches `
349
+ * † — needs a user, browser, interactivity, or scripting to make sense
350
+ * ‡ — not supported by the underlying algorithm
351
+ * § — not very interested in writing / including the code for this
352
+ * ‖ — too new, the spec is still changing
331
353
332
354
## Types
333
355
@@ -338,12 +360,12 @@ It exports the additional type `Space`.
338
360
339
361
Projects maintained by the unified collective are compatible with all maintained
340
362
versions of Node.js.
341
- As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18 .0+.
363
+ As of now, that is Node.js 14.14+ and 16 .0+.
342
364
Our projects sometimes work with older versions, but this is not guaranteed.
343
365
344
366
## Security
345
367
346
- ` hast-util-select ` does not change the syntax tree so there are no openings for
368
+ This package does not change the syntax tree so there are no openings for
347
369
[ cross-site scripting (XSS)] [ xss ] attacks.
348
370
349
371
## Related
0 commit comments