Skip to content

Commit 71db888

Browse files
committed
Add improved docs
1 parent d4fa3ec commit 71db888

File tree

1 file changed

+80
-19
lines changed

1 file changed

+80
-19
lines changed

readme.md

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,60 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

11-
[**hast**][hast] utility to change the rank (depth, level) of headings.
11+
[hast][] utility to change ranks (also knows as depth or level) of headings.
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+
* [`shiftHeading(tree, shift)`](#shiftheadingtree-shift)
21+
* [Types](#types)
22+
* [Compatibility](#compatibility)
23+
* [Security](#security)
24+
* [Related](#related)
25+
* [Contribute](#contribute)
26+
* [License](#license)
27+
28+
## What is this?
29+
30+
This package is a small utility that rewrites heading ranks relative to a
31+
number.
32+
33+
## When should I use this?
34+
35+
You can use this package when you have some content, say an article that starts
36+
with an `h1`, but want to display it on a page that uses for example an `h1`
37+
already as the website name (logo?).
1438

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.
39+
You can use the package [`hast-util-heading-rank`][hast-util-heading-rank]
40+
to get the rank of an element.
1741

18-
[npm][]:
42+
## Install
43+
44+
This package is [ESM only][esm].
45+
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]:
1946

2047
```sh
2148
npm install hast-util-shift-heading
2249
```
2350

51+
In Deno with [`esm.sh`][esmsh]:
52+
53+
```js
54+
import {shiftHeading} from 'https://esm.sh/hast-util-shift-heading@3'
55+
```
56+
57+
In browsers with [`esm.sh`][esmsh]:
58+
59+
```html
60+
<script type="module">
61+
import {shiftHeading} from 'https://esm.sh/hast-util-shift-heading@3?bundle'
62+
</script>
63+
```
64+
2465
## Use
2566

2667
```js
@@ -81,28 +122,40 @@ Yields:
81122

82123
## API
83124

84-
This package exports the following identifiers: `shiftHeading`.
125+
This package exports the identifier `shiftHeading`.
85126
There is no default export.
86127

87128
### `shiftHeading(tree, shift)`
88129

89130
Change the rank of all headings (`h1` to `h6`) in `tree`.
90131
Mutates the tree.
91-
Caps the rank so that shifting would not create invalid headings (such as `h0`
92-
or `h7`).
132+
Caps the rank so that shifting would not create invalid headings (so no `h0` or
133+
`h7`).
93134

94135
###### Parameters
95136

96-
* `tree` ([`Node`][node]) — [*Tree*][tree] to walk
97-
* `shift` (`number`) — Non-null finite integer to use to shift ranks
137+
* `tree` ([`Node`][node]) — tree to walk
138+
* `shift` (`number`) — non-null finite integer to use to shift ranks
98139

99140
###### Returns
100141

101-
`tree` ([`Node`][node]) — The given, mutated, tree.
142+
The given, mutated, tree ([`Node`][node]).
102143

103144
###### Throws
104145

105-
`Error` — When `shift` is not a valid non-null finite integer.
146+
When `shift` is not a valid non-null finite integer.
147+
148+
## Types
149+
150+
This package is fully typed with [TypeScript][].
151+
It exports no additional types.
152+
153+
## Compatibility
154+
155+
Projects maintained by the unified collective are compatible with all maintained
156+
versions of Node.js.
157+
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
158+
Our projects sometimes work with older versions, but this is not guaranteed.
106159

107160
## Security
108161

@@ -113,14 +166,14 @@ There are no openings for [cross-site scripting (XSS)][xss] attacks.
113166
## Related
114167

115168
* [`hast-util-heading`](https://github.com/syntax-tree/hast-util-heading)
116-
— check if a node is a heading element
169+
— check if a node is heading content
117170
* [`hast-util-heading-rank`](https://github.com/syntax-tree/hast-util-heading-rank)
118171
— get the rank (or depth, level) of headings
119172

120173
## Contribute
121174

122-
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
123-
started.
175+
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
176+
ways to get started.
124177
See [`support.md`][support] for ways to get help.
125178

126179
This project has a [code of conduct][coc].
@@ -161,20 +214,28 @@ abide by its terms.
161214

162215
[npm]: https://docs.npmjs.com/cli/install
163216

217+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
218+
219+
[esmsh]: https://esm.sh
220+
221+
[typescript]: https://www.typescriptlang.org
222+
164223
[license]: license
165224

166225
[author]: https://wooorm.com
167226

168-
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
227+
[health]: https://github.com/syntax-tree/.github
169228

170-
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
229+
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
171230

172-
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
231+
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
173232

174-
[tree]: https://github.com/syntax-tree/unist#tree
233+
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
175234

176235
[hast]: https://github.com/syntax-tree/hast
177236

178237
[node]: https://github.com/syntax-tree/hast#nodes
179238

239+
[hast-util-heading-rank]: https://github.com/syntax-tree/hast-util-heading-rank
240+
180241
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting

0 commit comments

Comments
 (0)