js-dev-tool 1.0.15 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/regex.d.ts +44 -14
- package/scripts/publish-version.json +1 -1
package/package.json
CHANGED
package/regex.d.ts
CHANGED
|
@@ -9,18 +9,30 @@
|
|
|
9
9
|
* @file js-dev-scripts/regex.d.ts
|
|
10
10
|
*/
|
|
11
11
|
declare global {
|
|
12
|
+
interface RegExp/* extends TypedRegExp<string, string>*/ {
|
|
13
|
+
/**
|
|
14
|
+
* Executes a search on a string using a regular expression pattern, and returns an array containing the results of that search.
|
|
15
|
+
* @param string The String object or string literal on which to perform the search.
|
|
16
|
+
*/
|
|
17
|
+
exec<const P extends string, const F extends string = "">(this: TypedRegExp<P, F>, string: string): RegExpExecArrayFixed< this > | null;
|
|
18
|
+
}
|
|
12
19
|
interface RegExpConstructor {
|
|
13
|
-
new <const P extends string, const F extends string = "">(pattern:
|
|
20
|
+
new <const P extends string, const F extends string = "">(pattern: P, flags?: F): RegExp & {
|
|
14
21
|
readonly source: P;
|
|
15
22
|
readonly flags: F;
|
|
16
23
|
};
|
|
17
|
-
<const P extends string, const F extends string = "">(pattern:
|
|
24
|
+
<const P extends string, const F extends string = "">(pattern: P, flags?: F): RegExp & {
|
|
18
25
|
readonly source: P;
|
|
19
26
|
readonly flags: F;
|
|
20
27
|
};
|
|
21
28
|
readonly "prototype": RegExp;
|
|
22
29
|
}
|
|
23
30
|
}
|
|
31
|
+
/*!
|
|
32
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
33
|
+
// Basics
|
|
34
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
35
|
+
*/
|
|
24
36
|
/**
|
|
25
37
|
* Extracts the literal type from the source property of a RegExp.
|
|
26
38
|
* @template R - A RegExp type.
|
|
@@ -34,6 +46,11 @@ export declare function createRegExp<
|
|
|
34
46
|
const P extends string,
|
|
35
47
|
const F extends string = ""
|
|
36
48
|
>(pattern: P, flags?: F): TypedRegExp<P, F>;
|
|
49
|
+
/*!
|
|
50
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
51
|
+
// Named Capture Groups
|
|
52
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
53
|
+
*/
|
|
37
54
|
type FirstChar<S extends string> = S extends `${infer F}${infer _}` ? F : never;
|
|
38
55
|
/**
|
|
39
56
|
* Recursively extracts parts that match the format (?<GroupName>...) from a string pattern,
|
|
@@ -52,10 +69,12 @@ export type ExtractGroupNames<S extends string> =
|
|
|
52
69
|
* Creates an object type with keys as the extracted group names and values as strings.
|
|
53
70
|
* If no groups are found, it results in an empty object.
|
|
54
71
|
* @template R - A RegExp type.
|
|
72
|
+
* @date 2025/12/24 14:46:30 - It may be possible to extract the group name accurately (?)
|
|
55
73
|
*/
|
|
56
|
-
export type ReGroups<R extends RegExp> = {
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
export type ReGroups<R extends RegExp> = R extends (/*RegExp &*/ { readonly source: infer T })
|
|
75
|
+
? {
|
|
76
|
+
[K in ExtractGroupNames<T>]?: string;
|
|
77
|
+
} : never;
|
|
59
78
|
/**
|
|
60
79
|
* Preprocesses escape sequences in a string pattern by replacing escaped backslashes and characters.
|
|
61
80
|
*
|
|
@@ -86,7 +105,7 @@ export type CountCaptureGroups<
|
|
|
86
105
|
? Rest extends `${"?:" | "?=" | "?!" | "?<=" | "?<!"}${infer After}`
|
|
87
106
|
? CountCaptureGroups<After, Counter>
|
|
88
107
|
: CountCaptureGroups<Rest, [...Counter, unknown]>
|
|
89
|
-
: Counter[
|
|
108
|
+
: Counter["length"];
|
|
90
109
|
/**
|
|
91
110
|
* Represents a fixed version of RegExpExecArray that includes the matched string,
|
|
92
111
|
* captures, and optionally named groups.
|
|
@@ -98,19 +117,30 @@ export type RegExpExecArrayFixed<
|
|
|
98
117
|
R extends RegExp,
|
|
99
118
|
S extends ReSource<R> = ReSource<R>,
|
|
100
119
|
GroupCount extends number = CountCaptureGroups<S>
|
|
101
|
-
> = [match: string, ...
|
|
120
|
+
> = [match: string, ...BuildCaptureTuple<GroupCount>] & {
|
|
102
121
|
groups?: ReGroups<R>;
|
|
103
122
|
index: number;
|
|
104
123
|
input: string;
|
|
105
124
|
};
|
|
125
|
+
export type TupleOf<
|
|
126
|
+
Count extends number, ArrayType,
|
|
127
|
+
Result extends ArrayType[] = []
|
|
128
|
+
> = Result["length"] extends Count
|
|
129
|
+
? Result
|
|
130
|
+
: TupleOf<Count, ArrayType, [...Result, ArrayType]>;
|
|
106
131
|
/**
|
|
107
|
-
*
|
|
108
|
-
* @template Count -
|
|
109
|
-
* @template Result -
|
|
132
|
+
* Builds a tuple type whose length equals the number of capture groups.
|
|
133
|
+
* @template Count - Number of capture groups.
|
|
134
|
+
* @template Result - Accumulator (internal).
|
|
110
135
|
*/
|
|
111
|
-
export type
|
|
112
|
-
|
|
113
|
-
|
|
136
|
+
export type BuildCaptureTuple<
|
|
137
|
+
Count extends number, ArrayType = string,
|
|
138
|
+
> = TupleOf<Count, ArrayType>;
|
|
139
|
+
/*!
|
|
140
|
+
// ============================================================================
|
|
141
|
+
// Helper Types for Replacer
|
|
142
|
+
// ============================================================================
|
|
143
|
+
*/
|
|
114
144
|
/**
|
|
115
145
|
* Creates the parameter types for String.replace callback function.
|
|
116
146
|
*
|
|
@@ -124,7 +154,7 @@ export type ReplaceCallbackParams<
|
|
|
124
154
|
GroupCount extends number = CountCaptureGroups<S>
|
|
125
155
|
> = [
|
|
126
156
|
match: string,
|
|
127
|
-
...captures:
|
|
157
|
+
...captures: BuildCaptureTuple<GroupCount>,
|
|
128
158
|
offset: number,
|
|
129
159
|
input: string,
|
|
130
160
|
groups: ReGroups<R>
|