8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- [ ** hast** ] [ hast ] utility to create nodes from an advanced CSS selector .
11
+ [ hast] [ ] utility to create nodes from a complex CSS selectors .
12
12
13
- ## Install
13
+ ## Contents
14
+
15
+ * [ What is this?] ( #what-is-this )
16
+ * [ When should I use this?] ( #when-should-i-use-this )
17
+ * [ Install] ( #install )
18
+ * [ Use] ( #use )
19
+ * [ API] ( #api )
20
+ * [ ` fromSelector([selector][, options]) ` ] ( #fromselectorselector-options )
21
+ * [ Support] ( #support )
22
+ * [ Types] ( #types )
23
+ * [ Compatibility] ( #compatibility )
24
+ * [ Security] ( #security )
25
+ * [ Related] ( #related )
26
+ * [ Contribute] ( #contribute )
27
+ * [ License] ( #license )
28
+
29
+ ## What is this?
30
+
31
+ This package is a utility that can generate elements from complex CSS selectors.
14
32
15
- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
16
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
33
+ ## When should I use this?
34
+
35
+ You can use this when you’re generating a bunch of elements, and manually
36
+ creating objects each time is starting to feel like a waste.
37
+ This package is much more powerful than
38
+ [ ` hast-util-parse-selector ` ] [ hast-util-parse-selector ] ,
39
+ and similar to [ ` hastscript ` ] [ hastscript ] .
40
+
41
+ ## Install
17
42
18
- [ npm] [ ] :
43
+ This package is [ ESM only] [ esm ] .
44
+ In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [ npm] [ ] :
19
45
20
46
``` sh
21
47
npm install hast-util-from-selector
22
48
```
23
49
50
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
51
+
52
+ ``` js
53
+ import {fromSelector } from ' https://esm.sh/hast-util-from-selector@2'
54
+ ```
55
+
56
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
57
+
58
+ ``` html
59
+ <script type =" module" >
60
+ import {fromSelector } from ' https://esm.sh/hast-util-from-selector@2?bundle'
61
+ </script >
62
+ ```
63
+
24
64
## Use
25
65
26
66
``` js
@@ -56,22 +96,22 @@ Yields:
56
96
57
97
## API
58
98
59
- This package exports the following identifiers: ` fromSelector ` .
99
+ This package exports the identifier ` fromSelector ` .
60
100
There is no default export.
61
101
62
102
### ` fromSelector([selector][, options]) `
63
103
64
- Create one or more [ * element* ] [ element ] [ * node * ] [ node ] s from a CSS selector.
104
+ Create one or more [ * element* ] [ element ] s from a CSS selector.
65
105
66
106
###### Parameters
67
107
68
108
* ` selector ` (` string ` , optional)
69
109
— CSS selector
70
110
* ` space ` (` string ` , optional)
71
- — Treated as ` options.space `
111
+ — treated as ` options.space `
72
112
* ` options.space ` (enum, ` 'svg' ` or ` 'html' ` , default: ` 'html' ` )
73
- — Which space first element in the selector is in.
74
- When an ` svg ` is created in HTML, the space is switched automatically to SVG
113
+ — which space first element in the selector is in.
114
+ When an ` svg ` is created in HTML, the space is automatically switched to SVG
75
115
76
116
###### Returns
77
117
@@ -90,13 +130,25 @@ Create one or more [*element*][element] [*node*][node]s from a CSS selector.
90
130
* [x] ` section h1 + p ` (next-sibling combinator, * not at root* )
91
131
* [x] ` section h1 ~ p ` (subsequent-sibling combinator, * not at root* )
92
132
133
+ ## Types
134
+
135
+ This package is fully typed with [ TypeScript] [ ] .
136
+ It exports the additional types ` Options ` and ` Space ` .
137
+
138
+ ## Compatibility
139
+
140
+ Projects maintained by the unified collective are compatible with all maintained
141
+ versions of Node.js.
142
+ As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
143
+ Our projects sometimes work with older versions, but this is not guaranteed.
144
+
93
145
## Security
94
146
95
147
Use of ` from-selector ` can open you up to a [ cross-site scripting (XSS)] [ xss ]
96
148
attack as values are injected into the syntax tree.
97
149
98
150
Either do not use user input in ` from-selector ` or use
99
- [ ` hast-util-santize ` ] [ sanitize ] .
151
+ [ ` hast-util-santize ` ] [ hast-util- sanitize] .
100
152
101
153
## Related
102
154
@@ -105,8 +157,8 @@ Either do not use user input in `from-selector` or use
105
157
106
158
## Contribute
107
159
108
- See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
109
- started.
160
+ See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
161
+ ways to get started.
110
162
See [ ` support.md ` ] [ support ] for ways to get help.
111
163
112
164
This project has a [ code of conduct] [ coc ] .
@@ -147,22 +199,32 @@ abide by its terms.
147
199
148
200
[ npm ] : https://docs.npmjs.com/cli/install
149
201
202
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
203
+
204
+ [ esmsh ] : https://esm.sh
205
+
206
+ [ typescript ] : https://www.typescriptlang.org
207
+
150
208
[ license ] : license
151
209
152
210
[ author ] : https://wooorm.com
153
211
154
- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
212
+ [ health ] : https://github.com/syntax-tree/.github
155
213
156
- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support .md
214
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing .md
157
215
158
- [ coc ] : https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct .md
216
+ [ support ] : https://github.com/syntax-tree/.github/blob/main/support .md
159
217
160
- [ hast ] : https://github.com/syntax-tree/hast
218
+ [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
161
219
162
- [ node ] : https://github.com/syntax-tree/hast#nodes
220
+ [ hast ] : https://github.com/syntax-tree/hast
163
221
164
222
[ element ] : https://github.com/syntax-tree/hast#element
165
223
166
224
[ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
167
225
168
- [ sanitize ] : https://github.com/syntax-tree/hast-util-sanitize
226
+ [ hast-util-sanitize ] : https://github.com/syntax-tree/hast-util-sanitize
227
+
228
+ [ hast-util-parse-selector ] : https://github.com/syntax-tree/hast-util-parse-selector
229
+
230
+ [ hastscript ] : https://github.com/syntax-tree/hastscript
0 commit comments