File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -4,18 +4,48 @@ import type {Node, Parent} from 'unist'
4
4
import type { Test } from 'unist-util-is'
5
5
import type { Visitor } from './index.js'
6
6
7
+ type LessThan <
8
+ A extends number ,
9
+ B extends number ,
10
+ S extends any [ ] = [ ]
11
+ > = S [ 'length' ] extends B
12
+ ? false
13
+ : S [ 'length' ] extends A
14
+ ? true
15
+ : LessThan < A , B , [ ...S , any ] >
16
+
17
+ type Subtract <
18
+ A extends number ,
19
+ B extends number ,
20
+ I extends any [ ] = [ ] ,
21
+ O extends any [ ] = [ ]
22
+ > = LessThan < A , B > extends true
23
+ ? never
24
+ : LessThan < I [ 'length' ] , A > extends true
25
+ ? Subtract <
26
+ A ,
27
+ B ,
28
+ [ ...I , any ] ,
29
+ LessThan < I [ 'length' ] , B > extends true ? O : [ ...O , any ]
30
+ >
31
+ : O [ 'length' ]
32
+
7
33
/**
8
34
* Internal utility to collect all descendants of in `Tree`.
9
35
*/
10
36
export type InclusiveDescendant <
11
37
Tree extends Node = never ,
12
- Found = void
13
- > = Tree extends Parent
38
+ Found = void ,
39
+ Depth extends number = 5
40
+ > = Depth extends 0
41
+ ? Tree
42
+ : Tree extends Parent
14
43
?
15
44
| Tree
16
45
| InclusiveDescendant <
17
46
Exclude < Tree [ 'children' ] [ number ] , Found | Tree > ,
18
- Found | Tree
47
+ Found | Tree ,
48
+ Subtract < Depth , 1 >
19
49
>
20
50
: Tree
21
51
Original file line number Diff line number Diff line change 62
62
"tsd" : " ^0.25.0" ,
63
63
"type-coverage" : " ^2.0.0" ,
64
64
"typescript" : " ^4.7.0" ,
65
- "xo" : " ^0.53 .0"
65
+ "xo" : " ^0.60 .0"
66
66
},
67
67
"scripts" : {
68
68
"prepack" : " npm run build && npm run format" ,
You can’t perform that action at this time.
0 commit comments