@@ -7,7 +7,7 @@ const GROUPED_AS_REPLACE_RE = /^(?:\(\?:(.+)\)|(\(?.+\)?))$/
7
7
const GROUPED_REPLACE_RE = / ^ (?: \( \? : ( .+ ) \) ( [ ? + * ] | { [ \d , ] + } ) ? | ( .+ ) ) $ /
8
8
9
9
export interface Input <
10
- in V extends string ,
10
+ V extends string ,
11
11
G extends string = never ,
12
12
C extends ( string | undefined ) [ ] = [ ]
13
13
> {
@@ -67,22 +67,34 @@ export interface Input<
67
67
) => Input < `${V } (?!${Join < MapToValues < I > , '' , '' > } )`, G , [ ...C , ...CG ] >
68
68
/** repeat the previous pattern an exact number of times */
69
69
times : {
70
- < N extends number > ( number : N ) : Input < IfUnwrapped < V , `(?:${V } ){${N } }`, `${V } {${N } }`> , G , C >
70
+ < N extends number , NV extends string = IfUnwrapped < V , `(?:${V } ){${N } }`, `${V } {${N } }`> > (
71
+ number : N
72
+ ) : Input < NV , G , C >
71
73
/** specify that the expression can repeat any number of times, _including none_ */
72
- any : ( ) => Input < IfUnwrapped < V , `(?:${V } )*`, `${V } *`> , G , C >
74
+ any : < NV extends string = IfUnwrapped < V , `(?:${V } )*`, `${V } *`> > ( ) => Input < NV , G , C >
73
75
/** specify that the expression must occur at least `N` times */
74
- atLeast : < N extends number > (
76
+ atLeast : <
77
+ N extends number ,
78
+ NV extends string = IfUnwrapped < V , `(?:${V } ){${N } ,}`, `${V } {${N } ,}`>
79
+ > (
75
80
number : N
76
- ) => Input < IfUnwrapped < V , `(?:${ V } ){${ N } ,}` , `${ V } {${ N } ,}` > , G , C >
81
+ ) => Input < NV , G , C >
77
82
/** specify that the expression must occur at most `N` times */
78
- atMost : < N extends number > (
83
+ atMost : <
84
+ N extends number ,
85
+ NV extends string = IfUnwrapped < V , `(?:${V } ){0,${N } }`, `${V } {0,${N } }`>
86
+ > (
79
87
number : N
80
- ) => Input < IfUnwrapped < V , `(?:${ V } ){0,${ N } }` , `${ V } {0,${ N } }` > , G , C >
88
+ ) => Input < NV , G , C >
81
89
/** specify a range of times to repeat the previous pattern */
82
- between : < Min extends number , Max extends number > (
90
+ between : <
91
+ Min extends number ,
92
+ Max extends number ,
93
+ NV extends string = IfUnwrapped < V , `(?:${V } ){${Min } ,${Max } }`, `${V } {${Min } ,${Max } }`>
94
+ > (
83
95
min : Min ,
84
96
max : Max
85
- ) => Input < IfUnwrapped < V , `(?:${ V } ){${ Min } ,${ Max } }` , `${ V } {${ Min } ,${ Max } }` > , G , C >
97
+ ) => Input < NV , G , C >
86
98
}
87
99
/** this defines the entire input so far as a named capture group. You will get type safety when using the resulting RegExp with `String.match()`. Alias for `groupedAs` */
88
100
as : < K extends string > (
@@ -112,7 +124,8 @@ export interface Input<
112
124
lineEnd : ( ) => Input < `${V } $`, G , C >
113
125
}
114
126
/** this allows you to mark the input so far as optional */
115
- optionally : ( ) => Input < IfUnwrapped < V , `(?:${V } )?`, `${V } ?`> , G , C >
127
+ optionally : < NV extends string = IfUnwrapped < V , `(?:${V } )?`, `${V } ?`> > ( ) => Input < NV , G , C >
128
+
116
129
toString : ( ) => string
117
130
}
118
131
0 commit comments