|
1 | 1 | import { createInput, Input } from './internal'
|
2 | 2 | import type { GetValue, EscapeChar } from './types/escape'
|
3 | 3 | import type { Join } from './types/join'
|
4 |
| -import type { MapToGroups, MapToValues, InputSource } from './types/sources' |
| 4 | +import type { MapToGroups, MapToValues, InputSource, GetGroup } from './types/sources' |
5 | 5 | import { IfSingle, wrap } from './wrap'
|
6 | 6 |
|
7 | 7 | export type { Input }
|
@@ -49,19 +49,21 @@ export const not = {
|
49 | 49 | export const maybe = <New extends InputSource<string>>(str: New) =>
|
50 | 50 | createInput(`${wrap(exactly(str))}?`) as IfSingle<
|
51 | 51 | GetValue<New>,
|
52 |
| - Input<`${GetValue<New>}?`>, |
53 |
| - Input<`(${GetValue<New>})?`> |
| 52 | + Input<`${GetValue<New>}?`, GetGroup<New>>, |
| 53 | + Input<`(${GetValue<New>})?`, GetGroup<New>> |
54 | 54 | >
|
55 | 55 |
|
56 | 56 | /** This escapes a string input to match it exactly */
|
57 |
| -export const exactly = <New extends InputSource<string>>(input: New): Input<GetValue<New>> => |
| 57 | +export const exactly = <New extends InputSource<string>>( |
| 58 | + input: New |
| 59 | +): Input<GetValue<New>, GetGroup<New>> => |
58 | 60 | typeof input === 'string'
|
59 | 61 | ? (createInput(input.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&')) as any)
|
60 | 62 | : input
|
61 | 63 |
|
62 | 64 | export const oneOrMore = <New extends InputSource<string>>(str: New) =>
|
63 | 65 | createInput(`${wrap(exactly(str))}+`) as IfSingle<
|
64 | 66 | GetValue<New>,
|
65 |
| - Input<`${GetValue<New>}+`>, |
66 |
| - Input<`(${GetValue<New>})+`> |
| 67 | + Input<`${GetValue<New>}+`, GetGroup<New>>, |
| 68 | + Input<`(${GetValue<New>})+`, GetGroup<New>> |
67 | 69 | >
|
0 commit comments