Skip to content

Commit

Permalink
Add improved docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jan 9, 2023
1 parent 32515d3 commit 99309ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

// To do next major: return `undefined`.
/**
* Rank of a heading: H1 -> 1, H2 -> 2, etc.
* Get the rank (`1` to `6`) of headings (`h1` to `h6`).
*
* @param {Node} node
* Node to check.
* @returns {number | null}
* Rank of the heading or `null` if not a heading.
*/
export function headingRank(node) {
const name =
Expand Down
18 changes: 10 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]

[hast][] utility to transform to get the rank (also known as depth or level) of
headings.
[hast][] utility to get the rank (also known as depth or level) of headings.

## Contents

Expand All @@ -28,8 +27,8 @@ headings.

## What is this?

This package is a utility that lets you get the rank (`1..6`) of heading
elements (`h1..h6`).
This package is a utility that lets you get the rank (`1`, `6`) of heading
elements (`h1`, `h6`).

## When should I use this?

Expand All @@ -42,7 +41,7 @@ To change heading ranks, use
## Install

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

```sh
npm install hast-util-heading-rank
Expand Down Expand Up @@ -74,7 +73,7 @@ headingRank(h('h5', 'Alpha')) //=> 5

## API

This package exports the identifier `headingRank`.
This package exports the identifier [`headingRank`][headingrank].
There is no default export.

### `headingRank(node)`
Expand All @@ -83,7 +82,8 @@ Get the rank (`1` to `6`) of headings (`h1` to `h6`).

###### Parameters

* `node` ([`Node`][node]) — node to check
* `node` ([`Node`][node])
— node to check

###### Returns

Expand All @@ -98,7 +98,7 @@ It exports no additional types.

Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.

## Security
Expand Down Expand Up @@ -182,3 +182,5 @@ abide by its terms.
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting

[hast-util-shift-heading]: https://github.com/syntax-tree/hast-util-shift-heading

[headingrank]: #headingranknode

0 comments on commit 99309ce

Please sign in to comment.