js-dev-tool 1.0.20 → 1.0.21
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 +29 -13
- package/scripts/publish-version.json +1 -1
- package/tool-lib/cjbm.js +5 -1
package/package.json
CHANGED
package/regex.d.ts
CHANGED
|
@@ -75,6 +75,9 @@ export declare function createRegExp<
|
|
|
75
75
|
const P extends string,
|
|
76
76
|
const F extends string = ""
|
|
77
77
|
>(pattern: P, flags?: F): TypedRegExp<P, F>;
|
|
78
|
+
type IsEmptyRecord<T> =
|
|
79
|
+
[T] extends [undefined] ? true :
|
|
80
|
+
[keyof T] extends [never] ? true : false;
|
|
78
81
|
/*!
|
|
79
82
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
80
83
|
// Named Capture Groups
|
|
@@ -91,7 +94,9 @@ export type ExtractGroupNames<S extends unknown> =
|
|
|
91
94
|
? FirstChar<Rest> extends "=" | "!"
|
|
92
95
|
? ExtractGroupNames<Rest>
|
|
93
96
|
: Rest extends `${infer GroupName}>${infer After}`
|
|
94
|
-
? GroupName
|
|
97
|
+
? GroupName extends ""
|
|
98
|
+
? "ExtractGroupNames: regex pattern error!"
|
|
99
|
+
: GroupName | ExtractGroupNames<After>
|
|
95
100
|
: never
|
|
96
101
|
: never;
|
|
97
102
|
/**
|
|
@@ -100,10 +105,14 @@ export type ExtractGroupNames<S extends unknown> =
|
|
|
100
105
|
* @template R - A RegExp type.
|
|
101
106
|
* @date 2025/12/24 14:46:30 - It may be possible to extract the group name accurately (?)
|
|
102
107
|
*/
|
|
103
|
-
export type RegExpNamedGroups<R extends RegExp> =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
export type RegExpNamedGroups<R extends RegExp> =
|
|
109
|
+
R extends RegExp & { readonly source: infer S extends string }
|
|
110
|
+
? ExtractGroupNames<S> extends infer K
|
|
111
|
+
? [K] extends [never]
|
|
112
|
+
? undefined
|
|
113
|
+
: { [P in K & string]: string | undefined }
|
|
114
|
+
: undefined
|
|
115
|
+
: undefined;
|
|
107
116
|
/*!
|
|
108
117
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
109
118
|
// Capture Groups
|
|
@@ -150,9 +159,10 @@ export type CountCaptureGroups<
|
|
|
150
159
|
export type RegExpExecArrayFixed<
|
|
151
160
|
R extends RegExp,
|
|
152
161
|
S extends RegExpSource<R> = RegExpSource<R>,
|
|
153
|
-
GroupCount extends number = CountCaptureGroups<S
|
|
162
|
+
GroupCount extends number = CountCaptureGroups<S>,
|
|
163
|
+
NamedGroups = RegExpNamedGroups<R>
|
|
154
164
|
> = [match: string, ...BuildCaptureTuple<GroupCount>] & {
|
|
155
|
-
groups
|
|
165
|
+
groups: IsEmptyRecord<NamedGroups> extends true ? undefined : NamedGroups;
|
|
156
166
|
index: number;
|
|
157
167
|
input: string;
|
|
158
168
|
};
|
|
@@ -185,13 +195,19 @@ export type BuildCaptureTuple<
|
|
|
185
195
|
export type ReplaceCallbackParams<
|
|
186
196
|
R extends RegExp,
|
|
187
197
|
S extends RegExpSource<R> = RegExpSource<R>,
|
|
188
|
-
GroupCount extends number = CountCaptureGroups<S
|
|
189
|
-
|
|
198
|
+
GroupCount extends number = CountCaptureGroups<S>,
|
|
199
|
+
NamedGroups = RegExpNamedGroups<R>
|
|
200
|
+
> = IsEmptyRecord<NamedGroups> extends true ? [
|
|
190
201
|
match: string,
|
|
191
202
|
...captures: BuildCaptureTuple<GroupCount>,
|
|
192
203
|
offset: number,
|
|
193
204
|
input: string,
|
|
194
|
-
|
|
205
|
+
] : [
|
|
206
|
+
match: string,
|
|
207
|
+
...captures: BuildCaptureTuple<GroupCount>,
|
|
208
|
+
offset: number,
|
|
209
|
+
input: string,
|
|
210
|
+
groups: NamedGroups
|
|
195
211
|
];
|
|
196
212
|
export type ReplacerFunctionSignature<R extends unknown> =
|
|
197
213
|
R extends (
|
|
@@ -324,15 +340,15 @@ type StripLine<S extends string, Acc extends string = ""> =
|
|
|
324
340
|
* (?:\\#\\w+) # keep literal "#"
|
|
325
341
|
* ` as const;
|
|
326
342
|
*
|
|
327
|
-
* type Src =
|
|
343
|
+
* type Src = PCREStyleToJsRegExpSource<typeof RE_SOURCE>;
|
|
328
344
|
* // "^(:?##\\w+)" ... (depending on your actual input)
|
|
329
345
|
*/
|
|
330
|
-
export type
|
|
346
|
+
export type PCREStyleToJsRegExpSource<
|
|
331
347
|
Input extends string,
|
|
332
348
|
Acc extends string = "",
|
|
333
349
|
S extends string = NormalizeNewlines<Input>,
|
|
334
350
|
> =
|
|
335
351
|
S extends `${infer Line}\n${infer Rest}`
|
|
336
|
-
?
|
|
352
|
+
? PCREStyleToJsRegExpSource<Input, `${Acc}${StripLine<Line>}`, Rest>
|
|
337
353
|
: `${Acc}${StripLine<S>}`;
|
|
338
354
|
export as namespace XRegex;
|
package/tool-lib/cjbm.js
CHANGED
|
@@ -41,8 +41,12 @@ function getReplacer(ext) {
|
|
|
41
41
|
*/
|
|
42
42
|
/** @type {TImportExportDetectRegexReplacer} */
|
|
43
43
|
return (
|
|
44
|
-
|
|
44
|
+
...args
|
|
45
45
|
) => {
|
|
46
|
+
const [
|
|
47
|
+
match,,,,,,,,,,,,,
|
|
48
|
+
groups
|
|
49
|
+
] = args;
|
|
46
50
|
if (/\s*?\/\*/.test(match)) return match;
|
|
47
51
|
const {
|
|
48
52
|
clause,
|