8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
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.
12
12
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.
14
31
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
17
38
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] [ ] :
19
41
20
42
``` sh
21
43
npm install unist-util-size
22
44
```
23
45
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
+
24
60
## Use
25
61
26
62
``` js
@@ -44,33 +80,39 @@ console.log(size(tree, 'element')) // => 5
44
80
45
81
## API
46
82
47
- This package exports the following identifiers: ` size ` .
83
+ This package exports the identifier ` size ` .
48
84
There is no default export.
49
85
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 ] .
51
90
52
- Calculate the number of nodes in [ ` tree ` ] [ node ] .
91
+ ##### Returns
53
92
54
- ###### Parameters
93
+ [ Exclusive descendants ] [ descendant ] of ` node ` that pass ` test ` ( ` number ` ).
55
94
56
- * ` tree ` ([ ` Node ` ] [ node ] ) — [ Tree] [ ] to traverse
57
- * ` test ` ([ ` Test ` ] [ is ] , optional) — [ ` is ` ] [ is ] -compatible test (such as a
58
- node type)
95
+ ## Types
59
96
60
- ##### Returns
97
+ This package is fully typed with [ TypeScript] [ ] .
98
+ It exports no additional types.
61
99
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.
64
106
65
107
## Related
66
108
67
109
* [ ` 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
69
111
70
112
## Contribute
71
113
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.
74
116
See [ ` support.md ` ] [ support ] for ways to get help.
75
117
76
118
This project has a [ code of conduct] [ coc ] .
@@ -111,22 +153,30 @@ abide by its terms.
111
153
112
154
[ npm ] : https://docs.npmjs.com/cli/install
113
155
156
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
157
+
158
+ [ esmsh ] : https://esm.sh
159
+
160
+ [ typescript ] : https://www.typescriptlang.org
161
+
114
162
[ license ] : license
115
163
116
164
[ author ] : https://wooorm.com
117
165
118
- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
166
+ [ health ] : https://github.com/syntax-tree/.github
119
167
120
- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support .md
168
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing .md
121
169
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
123
171
124
- [ unist ] : https://github.com/syntax-tree/unist
172
+ [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
125
173
126
- [ is ] : https://github.com/syntax-tree/unist-util-is
174
+ [ unist ] : https://github.com/syntax-tree/unist
127
175
128
176
[ node ] : https://github.com/syntax-tree/unist#node
129
177
130
- [ tree ] : https://github.com/syntax-tree/unist#tree
131
-
132
178
[ 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