js-dev-tool 1.0.17 → 1.0.19

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-dev-tool",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "bin": {
5
5
  "jstool": "tools.js"
6
6
  },
@@ -50,7 +50,7 @@
50
50
  "fflate": "^0.8.2",
51
51
  "mini-semaphore": "^1.4.4",
52
52
  "replace": "^1.2.2",
53
- "rm-cstyle-cmts": "^3.3.25",
53
+ "rm-cstyle-cmts": "^3.3.26",
54
54
  "terser": "^5.44.1",
55
55
  "tin-args": "^0.1.1"
56
56
  }
package/regex.d.ts CHANGED
@@ -7,9 +7,11 @@
7
7
  */
8
8
  /**
9
9
  * @file js-dev-scripts/regex.d.ts
10
+ * @desc It is recommended to add `"skipLibCheck": true` to your tsconfig.
11
+ * @todo publish as "annotate-regex"
10
12
  */
11
13
  declare global {
12
- interface RegExp/* extends TypedRegExp<string, string>*/ {
14
+ interface RegExp {
13
15
  /**
14
16
  * Executes a search on a string using a regular expression pattern, and returns an array containing the results of that search.
15
17
  * @template {string} P
@@ -38,10 +40,7 @@ declare global {
38
40
  * @param {F} [flags] The flags for the regular expression.
39
41
  * @returns {RegExp & { readonly source: P; readonly flags: F }} A typed RegExp object.
40
42
  */
41
- new <const P extends string, const F extends string = "">(pattern: P, flags?: F): RegExp & {
42
- readonly source: P;
43
- readonly flags: F;
44
- };
43
+ new <const P extends string, const F extends string = "">(pattern: P, flags?: F): TypedRegExp<P, F>;
45
44
  /**
46
45
  * Creates a typed RegExp object with literal types for the pattern and flags.
47
46
  * @template {string} P
@@ -50,10 +49,7 @@ declare global {
50
49
  * @param {F} [flags] The flags for the regular expression.
51
50
  * @returns {RegExp & { readonly source: P; readonly flags: F }} A typed RegExp object.
52
51
  */
53
- <const P extends string, const F extends string = "">(pattern: P, flags?: F): RegExp & {
54
- readonly source: P;
55
- readonly flags: F;
56
- };
52
+ <const P extends string, const F extends string = "">(pattern: P, flags?: F): TypedRegExp<P, F>;
57
53
  readonly "prototype": RegExp;
58
54
  }
59
55
  }
@@ -62,15 +58,19 @@ declare global {
62
58
  // Basics
63
59
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
64
60
  */
61
+ export type Brand<Tag extends string> = {
62
+ [k in Tag]: true;
63
+ };
64
+ export type TypedRegExpBrand = Brand<"__TypedRegExp">;
65
+ export type TypedRegExp<P extends string, F extends string = ""> = RegExp & {
66
+ readonly source: P;
67
+ readonly flags: F;
68
+ } & TypedRegExpBrand;
65
69
  /**
66
70
  * Extracts the literal type from the source property of a RegExp.
67
71
  * @template R - A RegExp type.
68
72
  */
69
73
  export type RegExpSource<R extends RegExp> = R extends RegExp & { readonly source: infer T } ? T : never;
70
- export type TypedRegExp<const P extends string, const F extends string = ""> = RegExp & {
71
- readonly source: P;
72
- readonly flags: F;
73
- };
74
74
  export declare function createRegExp<
75
75
  const P extends string,
76
76
  const F extends string = ""
@@ -86,7 +86,7 @@ type FirstChar<S extends string> = S extends `${infer F}${infer _}` ? F : never;
86
86
  * without considering nesting, and unions them.
87
87
  * @template S - A string pattern.
88
88
  */
89
- export type ExtractGroupNames<S extends string> =
89
+ export type ExtractGroupNames<S extends unknown> =
90
90
  S extends `${infer _Before}(?<${infer Rest}`
91
91
  ? FirstChar<Rest> extends "=" | "!"
92
92
  ? ExtractGroupNames<Rest>
@@ -193,8 +193,11 @@ export type ReplaceCallbackParams<
193
193
  input: string,
194
194
  groups: RegExpNamedGroups<R>
195
195
  ];
196
- export type ReplacerFunctionSignature<R extends unkown> =
196
+ export type ReplacerFunctionSignature<R extends unknown> =
197
197
  R extends (
198
198
  RegExp & { readonly source: infer T }
199
- ) ? (...args: ReplaceCallbackParams<R, T>) => string : string;
199
+ ) ? R extends TypedRegExpBrand
200
+ ? (...args: ReplaceCallbackParams<R/* , T */>) => string
201
+ : (match: string, ...rest: any[]) => string
202
+ : string;
200
203
  export as namespace XRegex;
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "1.0.17"
2
+ "version": "1.0.19"
3
3
  }
package/tool-lib/cjbm.js CHANGED
@@ -13,21 +13,15 @@
13
13
  const fs = require("fs");
14
14
  const path = require("path");
15
15
  /**
16
- * Creates a typed RegExp object with literal types for the pattern and flags.
17
- * @template {string} P
18
- * @template {string} F
19
- * @param {P} pattern The regular expression pattern.
20
- * @param {F} [flags] The flags for the regular expression.
21
- * @returns {XRegex.TypedRegExp<P, F>} A typed RegExp object.
16
+ * DEVNOTE: Improved `RegExpConstructor` interface makes `createRegExp` unnecessary
17
+ * @date 2025/12/25 22:10:17
22
18
  */
23
- function createRegExp(pattern, flags) {
24
- return new RegExp(pattern, flags);
25
- }
26
- const reImportExportDetection = createRegExp(
27
- `(?<!\\s*\\/\\/+.*?)(?:(?<!@)import|export)\\s*(?:(?<qcGlobal>["'])(?!https?:)(?=[.\\/]+)\
28
- (?:(?<globalName>(?:[.\\/]+)?[^'"]+?)(?:\\.(?<globalExt>(?:c|m)?jsx?))?)\\k<qcGlobal>|\\(\\s*(?<qcDynamic>["'])(?!https?:)(?=[.\\/]+)(?<dynamicName>(?:[.\\/]+)?[^'"]+?)\
29
- (?:\\.(?<dynamicExt>(?:c|m)?jsx?))?\\k<qcDynamic>\\s*\\)|(?:(?<clause>.+?|(?:\\w+\\s*,)?\\s*\\{[^}]+\\})\\s*from)\\s*(?<qcEsm>["'])(?!https?:)(?=[.\\/]+)\
30
- (?:(?<moduleName>(?:[.\\/]+)?[^'"]+?)(?:\\.(?<moduleExt>(?:c|m)?jsx?))?)\\k<qcEsm>)(?=\\s*;)?`, "g"
19
+ const reImportExportDetection = new RegExp(
20
+ `(?:(?:^\\s*?\\/\\*+?[\\s\\S]*?\\*\\/)|(?<!\\s*\\/\\/+.*?)(?:(?<!@)import|export)\\s*\
21
+ (?:(?<qcGlobal>["'])(?!https?:)(?=(?:\\.\\.?\\/)+)(?:(?<globalName>(?:(?:\\.\\.?\\/)+)?[^'"]+?)(?:\\.(?<globalExt>(?:c|m)?jsx?))?)\\k<qcGlobal>|\
22
+ \\(\\s*(?<qcDynamic>["'])(?!https?:)(?=(?:\\.\\.?\\/)+)(?<dynamicName>(?:(?:\\.\\.?\\/)+)?[^'"]+?)(?:\\.(?<dynamicExt>(?:c|m)?jsx?))?\\k<qcDynamic>\\s*\\)|\
23
+ (?:(?<clause>.+?|(?:\\w+\\s*,)?\\s*\\{[^}]+})\\s*from)\\s*(?<qcEsm>["'])(?!https?:)(?=(?:\\.\\.?\\/)+)(?:(?<moduleName>(?:(?:\\.\\.?\\/)+)?[^'"]+?)(?:\\.(?<moduleExt>(?:c|m)?jsx?))?)\\k<qcEsm>)\
24
+ (?=\\s*;)?)`, "gm"
31
25
  );
32
26
  /**
33
27
  * @typedef {XRegex.ReplacerFunctionSignature<typeof reImportExportDetection>} TImportExportDetectRegexReplacer
@@ -49,6 +43,7 @@ function getReplacer(ext) {
49
43
  return (
50
44
  match, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _offset, _input, groups
51
45
  ) => {
46
+ if (/\s*?\/\*/.test(match)) return match;
52
47
  const {
53
48
  clause,
54
49
  dynamicName,