Skip to content

Commit f348cf9

Browse files
committed
Add improved docs
1 parent 4677465 commit f348cf9

File tree

1 file changed

+81
-19
lines changed

1 file changed

+81
-19
lines changed

readme.md

+81-19
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,59 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

11-
[**hast**][hast] utility to create nodes from an advanced CSS selector.
11+
[hast][] utility to create nodes from a complex CSS selectors.
1212

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.
1432

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
1742

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][]:
1945

2046
```sh
2147
npm install hast-util-from-selector
2248
```
2349

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+
2464
## Use
2565

2666
```js
@@ -56,22 +96,22 @@ Yields:
5696

5797
## API
5898

59-
This package exports the following identifiers: `fromSelector`.
99+
This package exports the identifier `fromSelector`.
60100
There is no default export.
61101

62102
### `fromSelector([selector][, options])`
63103

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.
65105

66106
###### Parameters
67107

68108
* `selector` (`string`, optional)
69109
— CSS selector
70110
* `space` (`string`, optional)
71-
Treated as `options.space`
111+
treated as `options.space`
72112
* `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
75115

76116
###### Returns
77117

@@ -90,13 +130,25 @@ Create one or more [*element*][element] [*node*][node]s from a CSS selector.
90130
* [x] `section h1 + p` (next-sibling combinator, *not at root*)
91131
* [x] `section h1 ~ p` (subsequent-sibling combinator, *not at root*)
92132

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+
93145
## Security
94146

95147
Use of `from-selector` can open you up to a [cross-site scripting (XSS)][xss]
96148
attack as values are injected into the syntax tree.
97149

98150
Either do not use user input in `from-selector` or use
99-
[`hast-util-santize`][sanitize].
151+
[`hast-util-santize`][hast-util-sanitize].
100152

101153
## Related
102154

@@ -105,8 +157,8 @@ Either do not use user input in `from-selector` or use
105157

106158
## Contribute
107159

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.
110162
See [`support.md`][support] for ways to get help.
111163

112164
This project has a [code of conduct][coc].
@@ -147,22 +199,32 @@ abide by its terms.
147199

148200
[npm]: https://docs.npmjs.com/cli/install
149201

202+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
203+
204+
[esmsh]: https://esm.sh
205+
206+
[typescript]: https://www.typescriptlang.org
207+
150208
[license]: license
151209

152210
[author]: https://wooorm.com
153211

154-
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
212+
[health]: https://github.com/syntax-tree/.github
155213

156-
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
214+
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
157215

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
159217

160-
[hast]: https://github.com/syntax-tree/hast
218+
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
161219

162-
[node]: https://github.com/syntax-tree/hast#nodes
220+
[hast]: https://github.com/syntax-tree/hast
163221

164222
[element]: https://github.com/syntax-tree/hast#element
165223

166224
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
167225

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

Comments
 (0)