Skip to content

Commit f943212

Browse files
committed
Add improved docs
1 parent 7959f77 commit f943212

File tree

2 files changed

+76
-26
lines changed

2 files changed

+76
-26
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let empty
2020
* @param {null|undefined|Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything>} [test]
2121
* `unist-util-is`-compatible test (such as a node type).
2222
* @returns {number}
23-
* Number of exclusive descendants that pass `test` in `tree`.
23+
* Exclusive descendants of `node` that pass `test`.
2424
*/
2525
export function size(node, test) {
2626
const is = convert(test)

readme.md

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

11-
[**unist**][unist] utility to calculate the number of nodes in a tree.
11+
[unist][] utility to calculate the number of nodes in a tree.
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+
* [`size(node[, test])`](#sizenode-test)
21+
* [Types](#types)
22+
* [Compatibility](#compatibility)
23+
* [Related](#related)
24+
* [Contribute](#contribute)
25+
* [License](#license)
26+
27+
## What is this?
28+
29+
This is a tiny utility that you can use to count nodes (that pass a test) in a
30+
tree.
1431

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.
32+
## When should I use this?
33+
34+
This is super tiny but a sometimes common problem.
35+
You can use [`unist-util-visit`][unist-util-visit] yourself as well.
36+
37+
## Install
1738

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

2042
```sh
2143
npm install unist-util-size
2244
```
2345

46+
In Deno with [`esm.sh`][esmsh]:
47+
48+
```js
49+
import {size} from "https://esm.sh/unist-util-size@3"
50+
```
51+
52+
In browsers with [`esm.sh`][esmsh]:
53+
54+
```html
55+
<script type="module">
56+
import {size} from "https://esm.sh/unist-util-size@3?bundle"
57+
</script>
58+
```
59+
2460
## Use
2561

2662
```js
@@ -44,33 +80,39 @@ console.log(size(tree, 'element')) // => 5
4480

4581
## API
4682

47-
This package exports the following identifiers: `size`.
83+
This package exports the identifier `size`.
4884
There is no default export.
4985

50-
### `size(tree[, test])`
86+
### `size(node[, test])`
87+
88+
Calculate the number of nodes in `node` ([`Node`][node]) that pass the optional
89+
`unist-util-is`-compatible [`Test`][test].
5190

52-
Calculate the number of nodes in [`tree`][node].
91+
##### Returns
5392

54-
###### Parameters
93+
[Exclusive descendants][descendant] of `node` that pass `test` (`number`).
5594

56-
* `tree` ([`Node`][node]) — [Tree][] to traverse
57-
* `test` ([`Test`][is], optional) — [`is`][is]-compatible test (such as a
58-
node type)
95+
## Types
5996

60-
##### Returns
97+
This package is fully typed with [TypeScript][].
98+
It exports no additional types.
6199

62-
`number` — Number of [exclusive descendants][descendant] passing `test` in
63-
`tree`.
100+
## Compatibility
101+
102+
Projects maintained by the unified collective are compatible with all maintained
103+
versions of Node.js.
104+
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
105+
Our projects sometimes work with older versions, but this is not guaranteed.
64106

65107
## Related
66108

67109
* [`unist-util-source`](https://github.com/syntax-tree/unist-util-source)
68-
Get the source of a node or position
110+
get the source of a node or position
69111

70112
## Contribute
71113

72-
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
73-
started.
114+
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
115+
ways to get started.
74116
See [`support.md`][support] for ways to get help.
75117

76118
This project has a [code of conduct][coc].
@@ -111,22 +153,30 @@ abide by its terms.
111153

112154
[npm]: https://docs.npmjs.com/cli/install
113155

156+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
157+
158+
[esmsh]: https://esm.sh
159+
160+
[typescript]: https://www.typescriptlang.org
161+
114162
[license]: license
115163

116164
[author]: https://wooorm.com
117165

118-
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
166+
[health]: https://github.com/syntax-tree/.github
119167

120-
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
168+
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
121169

122-
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
170+
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
123171

124-
[unist]: https://github.com/syntax-tree/unist
172+
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
125173

126-
[is]: https://github.com/syntax-tree/unist-util-is
174+
[unist]: https://github.com/syntax-tree/unist
127175

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

130-
[tree]: https://github.com/syntax-tree/unist#tree
131-
132178
[descendant]: https://github.com/syntax-tree/unist#descendant
179+
180+
[unist-util-visit]: https://github.com/syntax-tree/unist-util-visit
181+
182+
[test]: https://github.com/syntax-tree/unist-util-is#test

0 commit comments

Comments
 (0)