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'
44import type { Test } from 'unist-util-is'
55import type { Visitor } from './index.js'
66
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+
733/**
834 * Internal utility to collect all descendants of in `Tree`.
935 */
1036export type InclusiveDescendant <
1137 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
1443 ?
1544 | Tree
1645 | InclusiveDescendant <
1746 Exclude < Tree [ 'children' ] [ number ] , Found | Tree > ,
18- Found | Tree
47+ Found | Tree ,
48+ Subtract < Depth , 1 >
1949 >
2050 : Tree
2151
Original file line number Diff line number Diff line change 6262 "tsd" : " ^0.25.0" ,
6363 "type-coverage" : " ^2.0.0" ,
6464 "typescript" : " ^4.7.0" ,
65- "xo" : " ^0.53 .0"
65+ "xo" : " ^0.60 .0"
6666 },
6767 "scripts" : {
6868 "prepack" : " npm run build && npm run format" ,
You can’t perform that action at this time.
0 commit comments