Skip to content

Commit 2290848

Browse files
committed
Add improved docs
1 parent 6f4d2fd commit 2290848

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
* @param {Style | null | undefined} [relative]
2020
* Relative style.
2121
* @returns {Style | null}
22-
* Style, if it can be inferred.
22+
* Style, if it can be inferred, `null` otherwise.
2323
*/
24+
// To do: next major: use `undefined`.
2425
export function headingStyle(node, relative) {
2526
const last = node.children[node.children.length - 1]
2627
const depth = node.depth

readme.md

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* [Use](#use)
1919
* [API](#api)
2020
* [`headingStyle(node[, relative])`](#headingstylenode-relative)
21+
* [`Style`](#style)
2122
* [Types](#types)
2223
* [Compatibility](#compatibility)
2324
* [Security](#security)
@@ -45,7 +46,7 @@ It’s used in [`remark-lint`][remark-lint].
4546
## Install
4647

4748
This package is [ESM only][esm].
48-
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
49+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
4950

5051
```sh
5152
npm install mdast-util-heading-style
@@ -82,31 +83,48 @@ headingStyle(fromMarkdown('### ATX').children[0], 'setext') // => 'setext'
8283

8384
## API
8485

85-
This package exports the identifier `headingStyle`.
86+
This package exports the identifier [`headingStyle`][api-headingstyle].
8687
There is no default export.
8788

8889
### `headingStyle(node[, relative])`
8990

90-
Get the heading style of a node ([`Node`][node]), optionally `relative` to
91-
a preferred style (`'atx'`, `'atx-closed'`, `'setext'`, optional).
92-
This is because ATX headings with a depth of three or more could be considered
93-
setext.
91+
Get the heading style of a heading, optionally `relative` to a preferred
92+
style.
93+
94+
This is because ATX headings with a depth of three or more could be
95+
considered setext.
96+
97+
###### Parameters
98+
99+
* `node` ([`Heading`][heading])
100+
— heading node to check
101+
* `style` ([`Style`][api-style], optional)
102+
— relative style
94103

95104
###### Returns
96105

97-
Style (`'atx'`, `'atx-closed'`, or `'setext'`).
98-
When an ambiguous heading is found, either `relative` or `null` is returned.
106+
Style ([`Style`][api-style]) if it can be inferred, `null` otherwise.
107+
108+
### `Style`
109+
110+
Style of heading (TypeScript type).
111+
112+
###### Type
113+
114+
```ts
115+
type Style = 'atx' | 'atx-closed' | 'setext'
116+
```
99117
100118
## Types
101119
102120
This package is fully typed with [TypeScript][].
103-
It exports the type `Style`.
121+
It exports the additional type [`Style`][api-style].
104122
105123
## Compatibility
106124
107125
Projects maintained by the unified collective are compatible with all maintained
108126
versions of Node.js.
109-
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
127+
As of now, that is Node.js 14.14+ and 16.0+.
110128
Our projects sometimes work with older versions, but this is not guaranteed.
111129
112130
## Security
@@ -185,10 +203,14 @@ abide by its terms.
185203
186204
[mdast]: https://github.com/syntax-tree/mdast
187205
188-
[node]: https://github.com/syntax-tree/unist#node
206+
[heading]: https://github.com/syntax-tree/mdast#heading
189207
190208
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
191209
192210
[hast]: https://github.com/syntax-tree/hast
193211
194212
[remark-lint]: https://github.com/remarkjs/remark-lint
213+
214+
[api-headingstyle]: #headingstylenode-relative
215+
216+
[api-style]: #style

0 commit comments

Comments
 (0)