js-dev-tool 1.2.6 → 1.2.8

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/basic-types.d.ts CHANGED
@@ -24,12 +24,12 @@ type TBD<T> = T | undefined;
24
24
  type TBC<T> = T | null;
25
25
  type Maybe<T> = T | null | undefined;
26
26
  /**
27
- * T is falsy then return A, trusy then B
28
- *
27
+ * T is falsy then return A, truthy then B
28
+ *
29
29
  * ```ts
30
30
  * type ConditionalX<T, A, B> = T extends (void | false | undefined) ? A : B // <- maybe not works
31
31
  * type Conditional<T, A, B> = void extends T ? A : T extends (void | false | undefined) ? A : B;
32
- *
32
+ *
33
33
  * function x<T extends true | void, R extends ConditionalX<T, string, string[]>>(need?: T): R {
34
34
  * return (need? "": [""]) as R;
35
35
  * }
@@ -80,15 +80,18 @@ type Prettify<T> = { [K in keyof T]: T[K] } & {};
80
80
  type Constructor<T> = new (...args: any[]) => T;
81
81
  /**
82
82
  * mark a specific property as `required`
83
- *
84
- * + About `Merge` parameter - Accepts values ​​of `1` or `0`.
83
+ *
84
+ * + About `Flatten` parameter - Accepts values ​​of `1` or `0`.
85
85
  * - If it is **1**, the types are displayed concatenated.
86
86
  * - If it is **0**, the types are displayed separated by "&".
87
+ *
88
+ * @date Renamed due to reasons. (`RequireThese` to `RequireKeys`)
87
89
  */
88
- type RequireThese<
89
- T, K extends keyof T, Merge extends 1 | 0 = 0,
90
- Intersected = T & Required<Pick<T, K>>
91
- > = Merge extends 1 ? Prettify<Intersected> : Intersected;
90
+ type RequireKeys<
91
+ T, K extends keyof T = keyof T,
92
+ Flatten extends 1 | 0 = 0,
93
+ Intersected = T & { [P in K]-?: T[P] }
94
+ > = Flatten extends 1 ? Prettify<Intersected> : Intersected;
92
95
  /**
93
96
  * pick any `property` as excludes
94
97
  */
@@ -118,8 +121,9 @@ type TypedCtor<T> = {
118
121
  interface ITypedCtor<T> extends TypedCtor<T> {}
119
122
  /**
120
123
  * Array.sort etc...
124
+ * @date 2026/03/03 - Improved to allow comparison of different types
121
125
  */
122
- declare type TComparator<T> = (a: T, b: T) => number;
126
+ declare type TComparator<T, T2 = T> = (a: T, b: T2) => number;
123
127
  /**
124
128
  * Generates all combinations of the string S. The order of characters does not matter.
125
129
  * @template S - The target string type
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-dev-tool",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "bin": {
5
5
  "jstool": "tools.js"
6
6
  },
@@ -85,11 +85,11 @@
85
85
  "dependencies": {
86
86
  "colors.ts": "^1.0.20",
87
87
  "fflate": "^0.8.2",
88
- "literate-regex": "^0.6.9",
89
- "mini-semaphore": "^1.5.1",
88
+ "literate-regex": "^0.6.11",
89
+ "mini-semaphore": "^1.5.4",
90
90
  "replace": "^1.2.2",
91
- "rm-cstyle-cmts": "^3.4.2",
91
+ "rm-cstyle-cmts": "^3.4.4",
92
92
  "terser": "^5.46.0",
93
- "tin-args": "^0.1.3"
93
+ "tin-args": "^0.1.4"
94
94
  }
95
95
  }
package/tools.js CHANGED
@@ -9,16 +9,14 @@
9
9
  */
10
10
  // @ts-check
11
11
  "use strict";
12
+ require("colors.ts");
12
13
  const fs = require("fs");
13
14
  const path = require("path");
14
15
  const rmc = require("rm-cstyle-cmts");
15
16
  /* utilities module by own. */
16
17
  const utils = require("./utils");
17
- // @ts-expect- error
18
18
  global.params = require("tin-args")();
19
- // @ts-expect- error
20
19
  global.verbose = params.verb;
21
- // @ts-expect- error
22
20
  global.isArray = Array.isArray;
23
21
  require("./tool-lib/ps").globalize(fs, utils);
24
22
  utils.log(params);
@@ -83,21 +81,28 @@ const ToolFunctions = {
83
81
  fn() {
84
82
  const re = params.regex;
85
83
  const after = params.after || "";
84
+ let targets = params.args || params.targets
85
+ if (typeof targets === "string") targets = [targets];
86
+ params.targets = targets;
86
87
  if (re) {
87
88
  processSources(this.taskName, (data) => data.replace(re, after), {
88
89
  base: "",
89
- targets: params.args || params.targets,
90
90
  });
91
91
  }
92
92
  },
93
- help: `jstool -cmd replace [-after <replacement>] -regex \"/^\\s+<!--[\\s\\S]+?-->(?:\\r?\\n)?/gm\" [-targets "<path>,<path>,..." | <args: file, file file...>]
94
- note:
95
- targets - must be array type arg, "['<path>', '<path>',...]" or "<path>,<path>,..."
96
- note: targets - can use args parameter instead
97
- It is better to use the <args: file, file file...>
98
- e.g - jstool -cmd replace -after ".." -regex "re/(?<=reference path=\")(\\.)(?=\\/index.d.ts\")/" build/**/*.js
99
- ^^^^^^^^^^^^^
100
- `,
93
+ get help() {
94
+ return `jstool -cmd replace [-after <replacement>] -regex \"/^\\s+<!--[\\s\\S]+?-->(?:\\r?\\n)?/gm\" [-targets "<path>,<path>,..." | <args: file, file file...>]
95
+
96
+ ${"Options:".red}
97
+ ${"after".cyan} ${`: If omitted, "" (empty string) is used, meaning that the matched string is deleted.`.gray(16)}
98
+ ${"targets".cyan}${`: Single path string or Array type arg, "['<path>', '<path>',...]" or "<path>,<path>,..."`.gray(16)}
99
+
100
+ ${"remarks".magenta}${": targets - can use args parameter instead".gray(16)}${`
101
+ It is better to use the <args: file, file file...>
102
+ e.g - ${"jstool".yellow} ${"-cmd".green} ${"replace".cyan} ${"-after".green} ${`".."`.red} ${"-regex".green} ${String.raw`'re/(?<=reference path=")(\.)(?=\/index.d.ts")/'`.magenta} ${"build/**/*.js".gray(16)}
103
+ ^^^^^^^^^^^^^
104
+ `.gray(16)}`;
105
+ },
101
106
  },
102
107
  version: {
103
108
  taskName: "version",
@@ -287,19 +292,11 @@ function isJSToolEntry(entry) {
287
292
  if (typeof entry !== "object") return false;
288
293
  return typeof entry.fn === "function" && typeof entry.help === "string";
289
294
  }
290
- let colorEnable = false;
291
- function enableColors() {
292
- if (!colorEnable) {
293
- require("colors.ts");
294
- colorEnable = true;
295
- }
296
- }
297
295
  /**
298
296
  * @param {string} cmd
299
297
  * @returns {void}
300
298
  */
301
299
  function printHelp(cmd) {
302
- enableColors();
303
300
  const entry = ToolFunctions[cmd];
304
301
  console.log(`${cmd.yellow + " help:".green} ${entry.help.gray(8)}`);
305
302
  }
@@ -318,7 +315,6 @@ if (params.cmd) {
318
315
  process.cwd(),
319
316
  );
320
317
  } else if (params.v) {
321
- enableColors();
322
318
  const thisVersion = require("./package.json").version;
323
319
  console.log(
324
320
  `${"jstool".magenta} in "js-dev-scripts", version: ${thisVersion.green}
package/tsconfig.json CHANGED
@@ -15,6 +15,7 @@
15
15
  "module": "nodenext",
16
16
  "outDir": "./build",
17
17
  // "baseUrl": ".",
18
+ "rootDir": ".",
18
19
  "paths": {
19
20
  "*": [
20
21
  "./*"
@@ -22,12 +23,12 @@
22
23
  },
23
24
  },
24
25
  "include": [
25
- "index.js",
26
- "utils.js",
27
- "tools.js",
28
26
  "*.d.ts",
29
- "./**/*.js",
30
27
  "./**/*.d.ts",
28
+ "./index.js",
29
+ "./utils.js",
30
+ "./tools.js",
31
+ "./**/*.js",
31
32
  ],
32
33
  "exclude": [
33
34
  "./**/npm-outdated*.js",