1
1
import type { Flag } from './core/flags'
2
2
import { Input , exactly } from './core/inputs'
3
-
4
- const MagicRegExpSymbol = Symbol ( 'MagicRegExp' )
5
-
6
- export type MagicRegExp < Value extends string , T = never > = RegExp & {
7
- [ MagicRegExpSymbol ] : T & Value
8
- }
3
+ import type { MagicRegExp , MagicRegExpMatchArray } from './core/types/magic-regexp'
9
4
10
5
export const createRegExp = < Value extends string , NamedGroups extends string = never > (
11
6
raw : Input < Value , NamedGroups > | Value ,
@@ -14,30 +9,17 @@ export const createRegExp = <Value extends string, NamedGroups extends string =
14
9
15
10
export * from './core/flags'
16
11
export * from './core/inputs'
17
-
18
- type ExtractNamedGroups < T extends MagicRegExp < string , string > > = T extends MagicRegExp <
19
- string ,
20
- infer V
21
- >
22
- ? V
23
- : never
24
-
25
- export type MagicRegExpMatchArray < T extends MagicRegExp < string , string > > = Omit <
26
- RegExpMatchArray ,
27
- 'groups'
28
- > & {
29
- groups : Record < ExtractNamedGroups < T > , string | undefined >
30
- }
12
+ export * from './core/types/magic-regexp'
31
13
32
14
// Add additional overload to global String object types to allow for typed capturing groups
33
15
declare global {
34
16
interface String {
35
- match < T extends string , RegExp extends MagicRegExp < any , T > > (
36
- regexp : RegExp
37
- ) : MagicRegExpMatchArray < RegExp > | null
17
+ match < T extends string , R extends MagicRegExp < any , T > > (
18
+ regexp : R
19
+ ) : MagicRegExpMatchArray < R > | null
38
20
39
- matchAll < T extends string , RegExp extends MagicRegExp < any , T > > (
40
- regexp : RegExp
41
- ) : IterableIterator < MagicRegExpMatchArray < RegExp > >
21
+ matchAll < T extends string , R extends MagicRegExp < any , T > > (
22
+ regexp : R
23
+ ) : IterableIterator < MagicRegExpMatchArray < R > >
42
24
}
43
25
}
0 commit comments