File tree Expand file tree Collapse file tree 3 files changed +52
-50
lines changed Expand file tree Collapse file tree 3 files changed +52
-50
lines changed Original file line number Diff line number Diff line change 1
- /**
2
- * @typedef {import('unist').Node } Node
3
- * @typedef {import('unist').Parent } Parent
4
- *
5
- * @typedef {string } Type
6
- * @typedef {Record<string, unknown> } Props
7
- * @typedef {import('unist-util-is').TestFunctionAnything } TestFunctionAnything
8
- */
9
-
10
- import { convert } from 'unist-util-is'
11
-
12
- /** @type {Array<Node> } */
13
- let empty
14
-
15
- /**
16
- * Calculate the number of nodes in `node`.
17
- *
18
- * @param {Node } node
19
- * Tree to traverse.
20
- * @param {null|undefined|Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything> } [test]
21
- * `unist-util-is`-compatible test (such as a node type).
22
- * @returns {number }
23
- * Exclusive descendants of `node` that pass `test`.
24
- */
25
- export function size ( node , test ) {
26
- const is = convert ( test )
27
-
28
- return fastSize ( node )
29
-
30
- /**
31
- * @param {Node } node
32
- */
33
- function fastSize ( node ) {
34
- /** @type {Array<Node> } */
35
- // @ts -expect-error Looks like a parent.
36
- const children = ( node && node . children ) || empty
37
- let count = 0
38
- let index = - 1
39
-
40
- if ( children && children . length > 0 ) {
41
- while ( ++ index < children . length ) {
42
- // @ts -expect-error Looks like a parent.
43
- if ( is ( children [ index ] , index , node ) ) count ++
44
- count += fastSize ( children [ index ] )
45
- }
46
- }
47
-
48
- return count
49
- }
50
- }
1
+ export { size } from './lib/index.js'
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @typedef {import('unist').Node } Node
3
+ * @typedef {import('unist').Parent } Parent
4
+ *
5
+ * @typedef {string } Type
6
+ * @typedef {Record<string, unknown> } Props
7
+ * @typedef {import('unist-util-is').TestFunctionAnything } TestFunctionAnything
8
+ */
9
+
10
+ import { convert } from 'unist-util-is'
11
+
12
+ /** @type {Array<Node> } */
13
+ let empty
14
+
15
+ /**
16
+ * Calculate the number of nodes in `node`.
17
+ *
18
+ * @param {Node } node
19
+ * Tree to traverse.
20
+ * @param {null|undefined|Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything> } [test]
21
+ * `unist-util-is`-compatible test (such as a node type).
22
+ * @returns {number }
23
+ * Exclusive descendants of `node` that pass `test`.
24
+ */
25
+ export function size ( node , test ) {
26
+ const is = convert ( test )
27
+
28
+ return fastSize ( node )
29
+
30
+ /**
31
+ * @param {Node } node
32
+ */
33
+ function fastSize ( node ) {
34
+ /** @type {Array<Node> } */
35
+ // @ts -expect-error Looks like a parent.
36
+ const children = ( node && node . children ) || empty
37
+ let count = 0
38
+ let index = - 1
39
+
40
+ if ( children && children . length > 0 ) {
41
+ while ( ++ index < children . length ) {
42
+ // @ts -expect-error Looks like a parent.
43
+ if ( is ( children [ index ] , index , node ) ) count ++
44
+ count += fastSize ( children [ index ] )
45
+ }
46
+ }
47
+
48
+ return count
49
+ }
50
+ }
Original file line number Diff line number Diff line change 27
27
"main" : " index.js" ,
28
28
"types" : " index.d.ts" ,
29
29
"files" : [
30
+ " lib/" ,
30
31
" index.d.ts" ,
31
32
" index.js"
32
33
],
You can’t perform that action at this time.
0 commit comments