Skip to content

Commit 44017e2

Browse files
committed
Add improved docs
1 parent b527dd4 commit 44017e2

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ parser.registerNestingOperators('>', '+', '~')
3333
parser.registerAttrEqualityMods('~', '|', '^', '$', '*')
3434

3535
/**
36-
* Turn a selector into a tree.
36+
* Create one or more `Element`s from a CSS selector.
3737
*
3838
* @param {string | null | undefined} [selector='']
3939
* CSS selector.

readme.md

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`fromSelector([selector][, options])`](#fromselectorselector-options)
20+
* [`fromSelector(selector?[, options|space])`](#fromselectorselector-optionsspace)
21+
* [`Options`](#options)
22+
* [`Space`](#space)
2123
* [Support](#support)
2224
* [Types](#types)
2325
* [Compatibility](#compatibility)
@@ -41,7 +43,7 @@ and similar to [`hastscript`][hastscript].
4143
## Install
4244

4345
This package is [ESM only][esm].
44-
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]:
46+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
4547

4648
```sh
4749
npm install hast-util-from-selector
@@ -96,27 +98,46 @@ Yields:
9698

9799
## API
98100

99-
This package exports the identifier `fromSelector`.
101+
This package exports the identifier [`fromSelector`][fromselector].
100102
There is no default export.
101103

102-
### `fromSelector([selector][, options])`
104+
### `fromSelector(selector?[, options|space])`
103105

104-
Create one or more [*element*][element]s from a CSS selector.
106+
Create one or more [`Element`][element]s from a CSS selector.
105107

106108
###### Parameters
107109

108110
* `selector` (`string`, optional)
109111
— CSS selector
110-
* `space` (`string`, optional)
112+
* `options` ([`Options`][options], optional)
113+
— configuration
114+
* `space` ([`Space`][space], optional)
111115
— treated as `options.space`
112-
* `options.space` (enum, `'svg'` or `'html'`, default: `'html'`)
116+
117+
###### Returns
118+
119+
[`Element`][element].
120+
121+
### `Options`
122+
123+
Configuration (TypeScript type).
124+
125+
###### Fields
126+
127+
* `space` ([`Space`][space], optional)
113128
— which space first element in the selector is in.
114129
When an `svg` element is created in HTML, the space is automatically
115130
switched to SVG
116131

117-
###### Returns
132+
### `Space`
118133

119-
[`Element`][element].
134+
Name of namespace (TypeScript type).
135+
136+
###### Type
137+
138+
```ts
139+
type Space = 'html' | 'svg'
140+
```
120141
121142
## Support
122143
@@ -134,19 +155,20 @@ Create one or more [*element*][element]s from a CSS selector.
134155
## Types
135156
136157
This package is fully typed with [TypeScript][].
137-
It exports the additional types `Options` and `Space`.
158+
It exports the additional types [`Options`][options] and [`Space`][space].
138159
139160
## Compatibility
140161
141162
Projects maintained by the unified collective are compatible with all maintained
142163
versions of Node.js.
143-
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
164+
As of now, that is Node.js 14.14+ and 16.0+.
144165
Our projects sometimes work with older versions, but this is not guaranteed.
145166
146167
## Security
147168
148-
Use of `from-selector` can open you up to a [cross-site scripting (XSS)][xss]
149-
attack as values are injected into the syntax tree.
169+
Use of `hast-util-from-selector` can open you up to a
170+
[cross-site scripting (XSS)][xss] attack as values are injected into the syntax
171+
tree.
150172
151173
Either do not use user input in `from-selector` or use
152174
[`hast-util-santize`][hast-util-sanitize].
@@ -229,3 +251,9 @@ abide by its terms.
229251
[hast-util-parse-selector]: https://github.com/syntax-tree/hast-util-parse-selector
230252
231253
[hastscript]: https://github.com/syntax-tree/hastscript
254+
255+
[fromselector]: #fromselectorselector-optionsspace
256+
257+
[options]: #options
258+
259+
[space]: #space

0 commit comments

Comments
 (0)