@@ -7,7 +7,7 @@ const GROUPED_AS_REPLACE_RE = /^(?:\(\?:(.+)\)|(\(?.+\)?))$/
77const GROUPED_REPLACE_RE = / ^ (?: \( \? : ( .+ ) \) ( [ ? + * ] | { [ \d , ] + } ) ? | ( .+ ) ) $ /
88
99export interface Input <
10- in V extends string ,
10+ V extends string ,
1111 G extends string = never ,
1212 C extends ( string | undefined ) [ ] = [ ]
1313> {
@@ -67,22 +67,34 @@ export interface Input<
6767 ) => Input < `${V } (?!${Join < MapToValues < I > , '' , '' > } )`, G , [ ...C , ...CG ] >
6868 /** repeat the previous pattern an exact number of times */
6969 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 >
7173 /** 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 >
7375 /** 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+ > (
7580 number : N
76- ) => Input < IfUnwrapped < V , `(?:${ V } ){${ N } ,}` , `${ V } {${ N } ,}` > , G , C >
81+ ) => Input < NV , G , C >
7782 /** 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+ > (
7987 number : N
80- ) => Input < IfUnwrapped < V , `(?:${ V } ){0,${ N } }` , `${ V } {0,${ N } }` > , G , C >
88+ ) => Input < NV , G , C >
8189 /** 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+ > (
8395 min : Min ,
8496 max : Max
85- ) => Input < IfUnwrapped < V , `(?:${ V } ){${ Min } ,${ Max } }` , `${ V } {${ Min } ,${ Max } }` > , G , C >
97+ ) => Input < NV , G , C >
8698 }
8799 /** 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` */
88100 as : < K extends string > (
@@ -112,7 +124,8 @@ export interface Input<
112124 lineEnd : ( ) => Input < `${V } $`, G , C >
113125 }
114126 /** 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+
116129 toString : ( ) => string
117130}
118131
0 commit comments