Skip to content

Commit 388b141

Browse files
committed
Add improved docs
1 parent faec57d commit 388b141

File tree

1 file changed

+78
-15
lines changed

1 file changed

+78
-15
lines changed

readme.md

Lines changed: 78 additions & 15 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 get the rank (or depth, level) of headings.
11+
[hast][] utility to transform to get the rank (also known as depth or level) of
12+
headings.
1213

13-
## Install
14+
## Contents
15+
16+
* [What is this?](#what-is-this)
17+
* [When should I use this?](#when-should-i-use-this)
18+
* [Install](#install)
19+
* [Use](#use)
20+
* [API](#api)
21+
* [`headingRank(node)`](#headingranknode)
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 lets you get the rank (`1..6`) of heading
32+
elements (`h1..h6`).
33+
34+
## When should I use this?
35+
36+
This utility is pretty niche, if you’re here you probably know what you’re
37+
looking for!
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+
To change heading ranks, use
40+
[`hast-util-shift-heading`][hast-util-shift-heading].
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-heading-rank
2249
```
2350

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

2667
```js
@@ -33,7 +74,7 @@ headingRank(h('h5', 'Alpha')) //=> 5
3374

3475
## API
3576

36-
This package exports the following identifiers: `headingRank`.
77+
This package exports the identifier `headingRank`.
3778
There is no default export.
3879

3980
### `headingRank(node)`
@@ -42,11 +83,23 @@ Get the rank (`1` to `6`) of headings (`h1` to `h6`).
4283

4384
###### Parameters
4485

45-
* `node` ([`Node`][node]) — Node to check
86+
* `node` ([`Node`][node]) — node to check
4687

4788
###### Returns
4889

49-
`rank` (`number?`) — Rank of the heading, or `null` if not a heading.
90+
Rank of the heading or `null` if not a heading (`number?`).
91+
92+
## Types
93+
94+
This package is fully typed with [TypeScript][].
95+
It exports no additional types.
96+
97+
## Compatibility
98+
99+
Projects maintained by the unified collective are compatible with all maintained
100+
versions of Node.js.
101+
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
102+
Our projects sometimes work with older versions, but this is not guaranteed.
50103

51104
## Security
52105

@@ -56,14 +109,14 @@ There are no openings for [cross-site scripting (XSS)][xss] attacks.
56109
## Related
57110

58111
* [`hast-util-heading`](https://github.com/syntax-tree/hast-util-heading)
59-
— check if a node is a heading element
112+
— check if a node is heading content
60113
* [`hast-util-shift-heading`](https://github.com/syntax-tree/hast-util-heading)
61-
utility to change heading rank
114+
— change heading rank
62115

63116
## Contribute
64117

65-
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
66-
started.
118+
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
119+
ways to get started.
67120
See [`support.md`][support] for ways to get help.
68121

69122
This project has a [code of conduct][coc].
@@ -104,18 +157,28 @@ abide by its terms.
104157

105158
[npm]: https://docs.npmjs.com/cli/install
106159

160+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
161+
162+
[esmsh]: https://esm.sh
163+
164+
[typescript]: https://www.typescriptlang.org
165+
107166
[license]: license
108167

109168
[author]: https://wooorm.com
110169

111-
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
170+
[health]: https://github.com/syntax-tree/.github
171+
172+
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
112173

113-
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
174+
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
114175

115-
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
176+
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
116177

117178
[hast]: https://github.com/syntax-tree/hast
118179

119180
[node]: https://github.com/syntax-tree/hast#nodes
120181

121182
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
183+
184+
[hast-util-shift-heading]: https://github.com/syntax-tree/hast-util-shift-heading

0 commit comments

Comments
 (0)