1
1
import type { Flag } from './core/flags'
2
2
import { Input , exactly } from './core/inputs'
3
+ import type { Join } from './core/types/join'
3
4
import type { MagicRegExp , MagicRegExpMatchArray } from './core/types/magic-regexp'
4
5
5
- export const createRegExp = < Value extends string , NamedGroups extends string = never > (
6
+ export const createRegExp = <
7
+ Value extends string ,
8
+ NamedGroups extends string = never ,
9
+ Flags extends Flag [ ] = never [ ]
10
+ > (
6
11
raw : Input < Value , NamedGroups > | Value ,
7
- flags ?: Flag [ ] | string | Set < Flag >
12
+ flags ?: [ ... Flags ] | string | Set < Flag >
8
13
) =>
9
14
new RegExp ( exactly ( raw ) . toString ( ) , [ ...( flags || '' ) ] . join ( '' ) ) as MagicRegExp <
10
- `/${Value } /`,
11
- NamedGroups
15
+ `/${Value } /${Join < Flags , '' , '' > } `,
16
+ NamedGroups ,
17
+ Flags [ number ]
12
18
>
13
19
14
20
export * from './core/flags'
@@ -18,11 +24,9 @@ export * from './core/types/magic-regexp'
18
24
// Add additional overload to global String object types to allow for typed capturing groups
19
25
declare global {
20
26
interface String {
21
- match < T extends string , R extends MagicRegExp < any , T > > (
22
- regexp : R
23
- ) : MagicRegExpMatchArray < R > | null
27
+ match < R extends MagicRegExp < string , string , string > > ( regexp : R ) : MagicRegExpMatchArray < R > | null
24
28
25
- matchAll < T extends string , R extends MagicRegExp < any , T > > (
29
+ matchAll < R extends MagicRegExp < string , string , string > > (
26
30
regexp : R
27
31
) : IterableIterator < MagicRegExpMatchArray < R > >
28
32
}
0 commit comments