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 24, 2023
1 parent 2fae894 commit 322e6d1
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ But this helps when integrating with the rest of unified and unist.
## Install

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

```sh
npm install unist-util-find-before
Expand All @@ -47,14 +47,14 @@ npm install unist-util-find-before
In Deno with [`esm.sh`][esmsh]:

```js
import {findBefore} from "https://esm.sh/unist-util-find-before@3"
import {findBefore} from 'https://esm.sh/unist-util-find-before@3'
```

In browsers with [`esm.sh`][esmsh]:

```html
<script type="module">
import {findBefore} from "https://esm.sh/unist-util-find-before@3?bundle"
import {findBefore} from 'https://esm.sh/unist-util-find-before@3?bundle'
</script>
```

Expand Down Expand Up @@ -87,18 +87,28 @@ Yields:

## API

This package exports the identifier `findBefore`.
This package exports the identifier [`findBefore`][api-findbefore].
There is no default export.

### `findBefore(parent, node|index[, test])`

Find the first node in `parent` ([`Parent`][parent]) before another `node`
([`Node`][node]) or before an index, that passes `test` (`Test` from
[`unist-util-is`][test]).
Find the first node in `parent` before another `node` or before an index,
that passes `test`.

###### Parameters

* `parent` ([`Node`][node])
— parent node
* `index` (`number`)
— index of child in `parent`
* `child` ([`Node`][node])
— child in `parent`
* `test` ([`Test`][test])
`unist-util-is`-compatible test

###### Returns

Child of `parent` that passes `test`, if found ([`Node?`][node]).
Child of `parent` ([`Node`][node]) or `null`.

## Types

Expand All @@ -109,7 +119,7 @@ It exports no additional types (types for the test are in `unist-util-is`).

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.

## Related
Expand Down Expand Up @@ -203,6 +213,6 @@ abide by its terms.

[node]: https://github.com/syntax-tree/unist#node

[parent]: https://github.com/syntax-tree/unist#parent-1

[test]: https://github.com/syntax-tree/unist-util-is#test

[api-findbefore]: #findbeforeparent-nodeindex-test

0 comments on commit 322e6d1

Please sign in to comment.