|
1 | | -import { createInput } from './internal' |
| 1 | +import { createInput, Input } from './internal' |
2 | 2 |
|
3 | | -export interface Input<T extends string = never> { |
4 | | - /** this adds a new pattern to the current input */ |
5 | | - and: <X extends string = never>(input: string | Input<X>) => Input<T | X> |
6 | | - /** this provides an alternative to the current input */ |
7 | | - or: <X extends string = never>(input: string | Input<X>) => Input<T | X> |
8 | | - /** this is a positive lookbehind. Make sure to check [browser support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#browser_compatibility) as not all browsers support lookbehinds (notably Safari) */ |
9 | | - after: (input: string | Input) => Input<T> |
10 | | - /** this is a positive lookahead */ |
11 | | - before: (input: string | Input) => Input<T> |
12 | | - /** these is a negative lookbehind. Make sure to check [browser support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#browser_compatibility) as not all browsers support lookbehinds (notably Safari) */ |
13 | | - notAfter: (input: string | Input) => Input<T> |
14 | | - /** this is a negative lookahead */ |
15 | | - notBefore: (input: string | Input) => Input<T> |
16 | | - times: { |
17 | | - /** repeat the previous pattern an exact number of times */ |
18 | | - (number: number): Input<T> |
19 | | - /** specify a range of times to repeat the previous pattern */ |
20 | | - between: (min: number, max: number) => Input<T> |
21 | | - /** specify that the expression can repeat any number of times, _including none_ */ |
22 | | - any: () => Input<T> |
23 | | - /** specify that the expression must occur at least x times */ |
24 | | - atLeast: (min: number) => Input<T> |
25 | | - } |
26 | | - /** 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()` */ |
27 | | - as: <K extends string>(key: K) => Input<T | K> |
28 | | - /** this allows you to match beginning/ends of lines with `at.lineStart()` and `at.lineEnd()` */ |
29 | | - at: { |
30 | | - lineStart: () => Input<T> |
31 | | - lineEnd: () => Input<T> |
32 | | - } |
33 | | - /** this allows you to mark the input so far as optional */ |
34 | | - optionally: () => Input<T> |
35 | | - toString: () => string |
36 | | -} |
| 3 | +export type { Input } |
37 | 4 |
|
38 | 5 | /** This matches any character in the string provided */ |
39 | 6 | export const charIn = (chars: string) => createInput(`[${chars.replace(/[-\\^\]]/g, '\\$&')}]`) |
|
0 commit comments