@zwa73/utils 1.0.223 → 1.0.225

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.
@@ -1,4 +1,4 @@
1
1
  import { UtilFT } from "./UtilFileTools";
2
- export declare const outcome: typeof import("@zwa73/js-utils").JsFunc.outcome, success: typeof import("@zwa73/js-utils").JsFunc.success, failed: typeof import("@zwa73/js-utils").JsFunc.failed, match: typeof import("@zwa73/js-utils").JsFunc.match, isSafeNumber: typeof import("@zwa73/js-utils").JsFunc.isSafeNumber, assertType: typeof import("@zwa73/js-utils").JsFunc.assertType, assertLiteral: typeof import("@zwa73/js-utils").JsFunc.assertLiteral, deepClone: typeof import("@zwa73/js-utils").JsFunc.deepClone, sleep: typeof import("@zwa73/js-utils").JsFunc.sleep, stringifyJToken: typeof import("@zwa73/js-utils").JsFunc.stringifyJToken, getTime: typeof import("@zwa73/js-utils").JsFunc.getTime, mapEntries: typeof import("@zwa73/js-utils").JsFunc.mapEntries, dedent: typeof import("@zwa73/js-utils").JsFunc.dedent, throwError: typeof import("@zwa73/js-utils").JsFunc.throwError, eitherize: typeof import("@zwa73/js-utils").JsFunc.eitherize, memoize: typeof import("@zwa73/js-utils").JsFunc.memoize, ivk: typeof import("@zwa73/js-utils").JsFunc.ivk, l2s: typeof import("@zwa73/js-utils").JsFunc.l2s, s2l: typeof import("@zwa73/js-utils").JsFunc.s2l, structEqual: typeof import("@zwa73/js-utils").JsFunc.structEqual;
2
+ export declare const outcome: typeof import("@zwa73/js-utils").JsFunc.outcome, success: typeof import("@zwa73/js-utils").JsFunc.success, failed: typeof import("@zwa73/js-utils").JsFunc.failed, match: typeof import("@zwa73/js-utils").JsFunc.match, isSafeNumber: typeof import("@zwa73/js-utils").JsFunc.isSafeNumber, assertType: typeof import("@zwa73/js-utils").JsFunc.assertType, assertLiteral: typeof import("@zwa73/js-utils").JsFunc.assertLiteral, deepClone: typeof import("@zwa73/js-utils").JsFunc.deepClone, sleep: typeof import("@zwa73/js-utils").JsFunc.sleep, stringifyJToken: typeof import("@zwa73/js-utils").JsFunc.stringifyJToken, getTime: typeof import("@zwa73/js-utils").JsFunc.getTime, mapEntries: typeof import("@zwa73/js-utils").JsFunc.mapEntries, dedent: typeof import("@zwa73/js-utils").JsFunc.dedent, throwError: typeof import("@zwa73/js-utils").JsFunc.throwError, eitherize: typeof import("@zwa73/js-utils").JsFunc.eitherize, memoize: typeof import("@zwa73/js-utils").JsFunc.memoize, ivk: typeof import("@zwa73/js-utils").JsFunc.ivk, l2s: typeof import("@zwa73/js-utils").JsFunc.l2s, s2l: typeof import("@zwa73/js-utils").JsFunc.s2l, structEqual: typeof import("@zwa73/js-utils").JsFunc.structEqual, range: typeof import("@zwa73/js-utils").JsFunc.range;
3
3
  export declare const stylizePath: typeof UtilFT.stylizePath, posixizePath: typeof UtilFT.posixizePath, win32izePath: typeof UtilFT.win32izePath, currosizePath: typeof UtilFT.currosizePath;
4
4
  export declare const when: <S extends import("@zwa73/js-utils").Keyable, T, R>(stat: import("@zwa73/js-utils").Literal<S>, f: (arg: Extract<T, import("@zwa73/js-utils").Matchable<S>>) => R) => (arg: T) => ("E" extends import("@zwa73/js-utils").ProperSubsetCheck<symbol, T> ? T | R : import("@zwa73/js-utils").MatchableFlag<T> extends S ? R : import("@zwa73/js-utils").MatchableFlag<T> extends Exclude<S, import("@zwa73/js-utils").MatchableFlag<T>> ? T : Exclude<T, import("@zwa73/js-utils").Matchable<S>> | R), map: typeof import("@zwa73/js-utils").JsFP.map, flow: typeof import("@zwa73/js-utils").JsFP.flow, pipe: typeof import("@zwa73/js-utils").JsFP.pipe, chain: <T, R>(f: (arg: Extract<T, import("@zwa73/js-utils").Matchable<typeof import("@zwa73/js-utils").Success>>) => R) => (arg: T) => ("E" extends import("@zwa73/js-utils").ProperSubsetCheck<symbol, T> ? T | R : import("@zwa73/js-utils").MatchableFlag<T> extends typeof import("@zwa73/js-utils").Success ? R : import("@zwa73/js-utils").MatchableFlag<T> extends Exclude<typeof import("@zwa73/js-utils").Success, import("@zwa73/js-utils").MatchableFlag<T>> ? T : Exclude<T, import("@zwa73/js-utils").Matchable<typeof import("@zwa73/js-utils").Success>> | R), alt: <T, R>(f: (arg: Extract<T, import("@zwa73/js-utils").Matchable<typeof import("@zwa73/js-utils").Failed>>) => R) => (arg: T) => ("E" extends import("@zwa73/js-utils").ProperSubsetCheck<symbol, T> ? T | R : import("@zwa73/js-utils").MatchableFlag<T> extends typeof import("@zwa73/js-utils").Failed ? R : import("@zwa73/js-utils").MatchableFlag<T> extends Exclude<typeof import("@zwa73/js-utils").Failed, import("@zwa73/js-utils").MatchableFlag<T>> ? T : Exclude<T, import("@zwa73/js-utils").Matchable<typeof import("@zwa73/js-utils").Failed>> | R), tap: typeof import("@zwa73/js-utils").JsFP.tap, curry: typeof import("@zwa73/js-utils").JsFP.curry;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.curry = exports.tap = exports.alt = exports.chain = exports.pipe = exports.flow = exports.map = exports.when = exports.currosizePath = exports.win32izePath = exports.posixizePath = exports.stylizePath = exports.structEqual = exports.s2l = exports.l2s = exports.ivk = exports.memoize = exports.eitherize = exports.throwError = exports.dedent = exports.mapEntries = exports.getTime = exports.stringifyJToken = exports.sleep = exports.deepClone = exports.assertLiteral = exports.assertType = exports.isSafeNumber = exports.match = exports.failed = exports.success = exports.outcome = void 0;
3
+ exports.curry = exports.tap = exports.alt = exports.chain = exports.pipe = exports.flow = exports.map = exports.when = exports.currosizePath = exports.win32izePath = exports.posixizePath = exports.stylizePath = exports.range = exports.structEqual = exports.s2l = exports.l2s = exports.ivk = exports.memoize = exports.eitherize = exports.throwError = exports.dedent = exports.mapEntries = exports.getTime = exports.stringifyJToken = exports.sleep = exports.deepClone = exports.assertLiteral = exports.assertType = exports.isSafeNumber = exports.match = exports.failed = exports.success = exports.outcome = void 0;
4
4
  const UtilFileTools_1 = require("./UtilFileTools");
5
5
  const UtilFP_1 = require("./UtilFP");
6
6
  const UtilFunctions_1 = require("./UtilFunctions");
7
- exports.outcome = UtilFunctions_1.UtilFunc.outcome, exports.success = UtilFunctions_1.UtilFunc.success, exports.failed = UtilFunctions_1.UtilFunc.failed, exports.match = UtilFunctions_1.UtilFunc.match, exports.isSafeNumber = UtilFunctions_1.UtilFunc.isSafeNumber, exports.assertType = UtilFunctions_1.UtilFunc.assertType, exports.assertLiteral = UtilFunctions_1.UtilFunc.assertLiteral, exports.deepClone = UtilFunctions_1.UtilFunc.deepClone, exports.sleep = UtilFunctions_1.UtilFunc.sleep, exports.stringifyJToken = UtilFunctions_1.UtilFunc.stringifyJToken, exports.getTime = UtilFunctions_1.UtilFunc.getTime, exports.mapEntries = UtilFunctions_1.UtilFunc.mapEntries, exports.dedent = UtilFunctions_1.UtilFunc.dedent, exports.throwError = UtilFunctions_1.UtilFunc.throwError, exports.eitherize = UtilFunctions_1.UtilFunc.eitherize, exports.memoize = UtilFunctions_1.UtilFunc.memoize, exports.ivk = UtilFunctions_1.UtilFunc.ivk, exports.l2s = UtilFunctions_1.UtilFunc.l2s, exports.s2l = UtilFunctions_1.UtilFunc.s2l, exports.structEqual = UtilFunctions_1.UtilFunc.structEqual;
7
+ exports.outcome = UtilFunctions_1.UtilFunc.outcome, exports.success = UtilFunctions_1.UtilFunc.success, exports.failed = UtilFunctions_1.UtilFunc.failed, exports.match = UtilFunctions_1.UtilFunc.match, exports.isSafeNumber = UtilFunctions_1.UtilFunc.isSafeNumber, exports.assertType = UtilFunctions_1.UtilFunc.assertType, exports.assertLiteral = UtilFunctions_1.UtilFunc.assertLiteral, exports.deepClone = UtilFunctions_1.UtilFunc.deepClone, exports.sleep = UtilFunctions_1.UtilFunc.sleep, exports.stringifyJToken = UtilFunctions_1.UtilFunc.stringifyJToken, exports.getTime = UtilFunctions_1.UtilFunc.getTime, exports.mapEntries = UtilFunctions_1.UtilFunc.mapEntries, exports.dedent = UtilFunctions_1.UtilFunc.dedent, exports.throwError = UtilFunctions_1.UtilFunc.throwError, exports.eitherize = UtilFunctions_1.UtilFunc.eitherize, exports.memoize = UtilFunctions_1.UtilFunc.memoize, exports.ivk = UtilFunctions_1.UtilFunc.ivk, exports.l2s = UtilFunctions_1.UtilFunc.l2s, exports.s2l = UtilFunctions_1.UtilFunc.s2l, exports.structEqual = UtilFunctions_1.UtilFunc.structEqual, exports.range = UtilFunctions_1.UtilFunc.range;
8
8
  exports.stylizePath = UtilFileTools_1.UtilFT.stylizePath, exports.posixizePath = UtilFileTools_1.UtilFT.posixizePath, exports.win32izePath = UtilFileTools_1.UtilFT.win32izePath, exports.currosizePath = UtilFileTools_1.UtilFT.currosizePath;
9
9
  exports.when = UtilFP_1.UtilFP.when, exports.map = UtilFP_1.UtilFP.map, exports.flow = UtilFP_1.UtilFP.flow, exports.pipe = UtilFP_1.UtilFP.pipe, exports.chain = UtilFP_1.UtilFP.chain, exports.alt = UtilFP_1.UtilFP.alt, exports.tap = UtilFP_1.UtilFP.tap, exports.curry = UtilFP_1.UtilFP.curry;
10
10
  if (false) {
@@ -1,15 +1,18 @@
1
1
  import { Keyable } from '@zwa73/js-utils';
2
- import Handlebars from 'handlebars';
3
2
  /**文本模板渲染器
4
3
  * @template T - 上下文对象的类型,默认为记录类型
5
4
  */
6
5
  export declare class Hbs<T extends Record<Keyable, any> = Record<Keyable, any>> {
7
- hbs: typeof Handlebars;
6
+ private hbs;
8
7
  context: T;
9
8
  /**创建一个新的 Hbs 实例
10
9
  * @param context - 上下文对象,用于在渲染模板时提供数据
11
10
  */
12
- constructor(context?: T);
11
+ private constructor();
12
+ /**创建一个新的 Hbs 实例
13
+ * @param context - 上下文对象,用于在渲染模板时提供数据
14
+ */
15
+ static create<T extends Record<Keyable, any> = Record<Keyable, any>>(context?: T): Promise<Hbs<T>>;
13
16
  /**渲染模板
14
17
  * @param template - 要渲染的 Handlebars 模板字符串
15
18
  * @returns 渲染后的字符串
@@ -1,21 +1,19 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Hbs = void 0;
7
4
  const UtilLogger_1 = require("../UtilLogger");
8
- const handlebars_1 = __importDefault(require("handlebars"));
5
+ const UtilFunctions_1 = require("../UtilFunctions");
9
6
  /**文本模板渲染器
10
7
  * @template T - 上下文对象的类型,默认为记录类型
11
8
  */
12
9
  class Hbs {
13
- hbs = handlebars_1.default.create();
10
+ hbs;
14
11
  context;
15
12
  /**创建一个新的 Hbs 实例
16
13
  * @param context - 上下文对象,用于在渲染模板时提供数据
17
14
  */
18
- constructor(context = {}) {
15
+ constructor(hbs, context = {}) {
16
+ this.hbs = hbs;
19
17
  this.context = context;
20
18
  this.hbs.registerHelper('def', (name, options) => {
21
19
  const value = options.fn(this.context).trim();
@@ -31,6 +29,15 @@ class Hbs {
31
29
  return '';
32
30
  });
33
31
  }
32
+ /**创建一个新的 Hbs 实例
33
+ * @param context - 上下文对象,用于在渲染模板时提供数据
34
+ */
35
+ static async create(context = {}) {
36
+ const Handlebars = await UtilFunctions_1.UtilFunc.dynamicImport('handlebars');
37
+ //console.log(Handlebars);
38
+ const hbs = Handlebars.create();
39
+ return new Hbs(hbs, context);
40
+ }
34
41
  /**渲染模板
35
42
  * @param template - 要渲染的 Handlebars 模板字符串
36
43
  * @returns 渲染后的字符串
@@ -1,2 +1,3 @@
1
1
  export * from './Hbs';
2
- export { BridgeInterface, Bridge, DListMiddleNode, DListHeadNode, DListTailNode, DListNode, DListMaybeNode, DLinkedList, Piper, PromoseQueueOption, PromiseQueue, SmartCache, Stream } from "@zwa73/js-utils";
2
+ export type { PromoseQueueOption, DListMiddleNode, DListHeadNode, DListTailNode, DListNode, DListMaybeNode, BridgeInterface } from "@zwa73/js-utils";
3
+ export { Stream, Spool, SmartCache, PromiseQueue, Piper, DLinkedList, Bridge } from "@zwa73/js-utils";
@@ -14,14 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Stream = exports.SmartCache = exports.PromiseQueue = exports.Piper = exports.DLinkedList = exports.Bridge = void 0;
17
+ exports.Bridge = exports.DLinkedList = exports.Piper = exports.PromiseQueue = exports.SmartCache = exports.Spool = exports.Stream = void 0;
18
18
  __exportStar(require("./Hbs"), exports);
19
- //#region UtilClass转导
20
19
  var js_utils_1 = require("@zwa73/js-utils");
21
- Object.defineProperty(exports, "Bridge", { enumerable: true, get: function () { return js_utils_1.Bridge; } });
22
- Object.defineProperty(exports, "DLinkedList", { enumerable: true, get: function () { return js_utils_1.DLinkedList; } });
23
- Object.defineProperty(exports, "Piper", { enumerable: true, get: function () { return js_utils_1.Piper; } });
24
- Object.defineProperty(exports, "PromiseQueue", { enumerable: true, get: function () { return js_utils_1.PromiseQueue; } });
25
- Object.defineProperty(exports, "SmartCache", { enumerable: true, get: function () { return js_utils_1.SmartCache; } });
26
20
  Object.defineProperty(exports, "Stream", { enumerable: true, get: function () { return js_utils_1.Stream; } });
21
+ Object.defineProperty(exports, "Spool", { enumerable: true, get: function () { return js_utils_1.Spool; } });
22
+ Object.defineProperty(exports, "SmartCache", { enumerable: true, get: function () { return js_utils_1.SmartCache; } });
23
+ Object.defineProperty(exports, "PromiseQueue", { enumerable: true, get: function () { return js_utils_1.PromiseQueue; } });
24
+ Object.defineProperty(exports, "Piper", { enumerable: true, get: function () { return js_utils_1.Piper; } });
25
+ Object.defineProperty(exports, "DLinkedList", { enumerable: true, get: function () { return js_utils_1.DLinkedList; } });
26
+ Object.defineProperty(exports, "Bridge", { enumerable: true, get: function () { return js_utils_1.Bridge; } });
27
27
  //#endregion
@@ -14,30 +14,30 @@ export declare namespace UtilCodec {
14
14
  * @param str = 所要计算的消息
15
15
  * @returns 整数长度结果
16
16
  */
17
- function tokenNumTurbo(str: string): number;
17
+ function tokenNumTurbo(str: string): Promise<number>;
18
18
  /**token长度计算器 Davinci模型
19
19
  * @param str = 所要计算的消息
20
20
  * @returns 整数长度结果
21
21
  */
22
- function tokenNumDavinci(str: string): number;
22
+ function tokenNumDavinci(str: string): Promise<number>;
23
23
  /**token编码 Turbo模型
24
24
  * @param str = 所要计算的消息
25
25
  * @returns Token数组
26
26
  */
27
- function encodeTokenTurbo(str: string): Uint32Array;
27
+ function encodeTokenTurbo(str: string): Promise<Uint32Array>;
28
28
  /**token编码 Davinci模型
29
29
  * @param str = 所要计算的消息
30
30
  * @returns Token数组
31
31
  */
32
- function encodeTokenDavinci(str: string): Uint32Array;
32
+ function encodeTokenDavinci(str: string): Promise<Uint32Array>;
33
33
  /**token解码 Turbo模型
34
34
  * @param arr = Token数组
35
35
  * @returns 消息字符串
36
36
  */
37
- function decodeTokenTurbo(arr: Uint32Array | number[]): string;
37
+ function decodeTokenTurbo(arr: Uint32Array | number[]): Promise<string>;
38
38
  /**token解码 Davinci模型
39
39
  * @param arr = Token数组
40
40
  * @returns 消息字符串
41
41
  */
42
- function decodeTokenDavinci(arr: Uint32Array | number[]): string;
42
+ function decodeTokenDavinci(arr: Uint32Array | number[]): Promise<string>;
43
43
  }
@@ -25,7 +25,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.UtilCodec = void 0;
27
27
  const he = __importStar(require("html-entities"));
28
- const tiktoken_1 = require("tiktoken");
28
+ const UtilFunctions_1 = require("./UtilFunctions");
29
+ async function importTikToken() {
30
+ return await UtilFunctions_1.UtilFunc.dynamicImport("tiktoken");
31
+ }
29
32
  /**编码/解码器 */
30
33
  var UtilCodec;
31
34
  (function (UtilCodec) {
@@ -58,18 +61,19 @@ var UtilCodec;
58
61
  //p50k_base Code models, text-davinci-002, text-davinci-003
59
62
  //r50k_base (or gpt2) GPT-3 models like davinci
60
63
  //避免在nextjs调用时出错
61
- function initTikTokenEncoder() {
64
+ async function initTikTokenEncoder() {
62
65
  if (encoderCl100kBase != null && encoderP50kBase != null)
63
66
  return;
64
- encoderCl100kBase = (0, tiktoken_1.get_encoding)("cl100k_base");
65
- encoderP50kBase = (0, tiktoken_1.get_encoding)("p50k_base");
67
+ const { get_encoding } = await importTikToken();
68
+ encoderCl100kBase = get_encoding("cl100k_base");
69
+ encoderP50kBase = get_encoding("p50k_base");
66
70
  }
67
71
  /**token长度计算器 Turbo模型
68
72
  * @param str = 所要计算的消息
69
73
  * @returns 整数长度结果
70
74
  */
71
- function tokenNumTurbo(str) {
72
- initTikTokenEncoder();
75
+ async function tokenNumTurbo(str) {
76
+ await initTikTokenEncoder();
73
77
  //return encoder.encode(str).length
74
78
  return encoderCl100kBase?.encode(str).length;
75
79
  }
@@ -78,8 +82,8 @@ var UtilCodec;
78
82
  * @param str = 所要计算的消息
79
83
  * @returns 整数长度结果
80
84
  */
81
- function tokenNumDavinci(str) {
82
- initTikTokenEncoder();
85
+ async function tokenNumDavinci(str) {
86
+ await initTikTokenEncoder();
83
87
  return encoderP50kBase?.encode(str).length;
84
88
  }
85
89
  UtilCodec.tokenNumDavinci = tokenNumDavinci;
@@ -87,8 +91,8 @@ var UtilCodec;
87
91
  * @param str = 所要计算的消息
88
92
  * @returns Token数组
89
93
  */
90
- function encodeTokenTurbo(str) {
91
- initTikTokenEncoder();
94
+ async function encodeTokenTurbo(str) {
95
+ await initTikTokenEncoder();
92
96
  return encoderCl100kBase?.encode(str);
93
97
  }
94
98
  UtilCodec.encodeTokenTurbo = encodeTokenTurbo;
@@ -96,8 +100,8 @@ var UtilCodec;
96
100
  * @param str = 所要计算的消息
97
101
  * @returns Token数组
98
102
  */
99
- function encodeTokenDavinci(str) {
100
- initTikTokenEncoder();
103
+ async function encodeTokenDavinci(str) {
104
+ await initTikTokenEncoder();
101
105
  return encoderP50kBase?.encode(str);
102
106
  }
103
107
  UtilCodec.encodeTokenDavinci = encodeTokenDavinci;
@@ -105,8 +109,8 @@ var UtilCodec;
105
109
  * @param arr = Token数组
106
110
  * @returns 消息字符串
107
111
  */
108
- function decodeTokenTurbo(arr) {
109
- initTikTokenEncoder();
112
+ async function decodeTokenTurbo(arr) {
113
+ await initTikTokenEncoder();
110
114
  if (Array.isArray(arr))
111
115
  arr = new Uint32Array(arr);
112
116
  return textDecoder.decode(encoderCl100kBase?.decode(arr));
@@ -116,8 +120,8 @@ var UtilCodec;
116
120
  * @param arr = Token数组
117
121
  * @returns 消息字符串
118
122
  */
119
- function decodeTokenDavinci(arr) {
120
- initTikTokenEncoder();
123
+ async function decodeTokenDavinci(arr) {
124
+ await initTikTokenEncoder();
121
125
  if (Array.isArray(arr))
122
126
  arr = new Uint32Array(arr);
123
127
  return textDecoder.decode(encoderP50kBase?.decode(arr));
@@ -1 +1,2 @@
1
- export { ParamsDecoratorsGener, BaseDecoratorsGener, LogTraceOpt, LogTrace, PostProcessOpt, PostProcess, AwaitInited } from "@zwa73/js-utils";
1
+ export type { ParamsDecoratorsGener, BaseDecoratorsGener, LogTraceOpt, PostProcessOpt } from "@zwa73/js-utils";
2
+ export { LogTrace, PostProcess, AwaitInited } from "@zwa73/js-utils";
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AwaitInited = exports.PostProcess = exports.LogTrace = void 0;
4
- //#region UtilDecorators转导
5
4
  var js_utils_1 = require("@zwa73/js-utils");
6
5
  Object.defineProperty(exports, "LogTrace", { enumerable: true, get: function () { return js_utils_1.LogTrace; } });
7
6
  Object.defineProperty(exports, "PostProcess", { enumerable: true, get: function () { return js_utils_1.PostProcess; } });
@@ -20,6 +20,8 @@ type FileSearchGlobOpt = Partial<{
20
20
  ingore: string | string[];
21
21
  /**忽略目录 默认 true */
22
22
  nodir: boolean;
23
+ /**忽略大小写 默认 跟随系统 mac/win为true 其他false */
24
+ nocese: boolean;
23
25
  }>;
24
26
  /**regex搜索选项 */
25
27
  type FileSearchRegexOpt = Partial<{
@@ -154,8 +156,10 @@ export declare namespace UtilFT {
154
156
  function currosizePath(filePath: string): string;
155
157
  /**逐级寻找node_modules文件夹
156
158
  * @param basePath - 基础位置
159
+ * @param extpaths - 额外的路径 如 .bin
160
+ * @returns node_modules文件夹路径 包含额外路径
157
161
  */
158
- function findNodeModulesDir(basePath: string): Promise<string | undefined>;
162
+ function findNodeModulesDir(basePath: string, ...extpaths: string[]): Promise<string | undefined>;
159
163
  /**搜索路径符合正则表达式的文件
160
164
  * @param dir - 起始目录
161
165
  * @param traitRegex - 正则表达式
@@ -176,7 +180,9 @@ export declare namespace UtilFT {
176
180
  * @param dir - 起始目录
177
181
  * @param globPattern - glob匹配
178
182
  * @param opt - 可选参数
179
- * @param opt.ignore - 忽略的文件
183
+ * @param opt.ignore - 忽略的文件
184
+ * @param opt.relative - 忽略目录 默认 true
185
+ * @param opt.nodir - 忽略大小写 默认 跟随系统 mac/win为true 其他false
180
186
  * @returns 文件绝对路径数组
181
187
  */
182
188
  function fileSearchGlob(dir: string, globPattern: string | string[], opt?: FileSearchGlobOpt): Promise<string[]>;
@@ -184,7 +190,9 @@ export declare namespace UtilFT {
184
190
  * @param dir - 起始目录
185
191
  * @param globPattern - glob匹配
186
192
  * @param opt - 可选参数
187
- * @param opt.ignore - 忽略的文件
193
+ * @param opt.ignore - 忽略的文件
194
+ * @param opt.relative - 忽略目录 默认 true
195
+ * @param opt.nodir - 忽略大小写 默认 跟随系统 mac/win为true 其他false
188
196
  * @returns 文件绝对路径数组
189
197
  */
190
198
  function fileSearchGlobSync(dir: string, globPattern: string | string[], opt?: FileSearchGlobOpt): string[];
@@ -223,8 +223,8 @@ var UtilFT;
223
223
  if (style === undefined)
224
224
  return filePath;
225
225
  return UtilFunctions_1.UtilFunc.match(style, {
226
- posix: (nor) => filePath.replaceAll("\\", "/"),
227
- win32: (nor) => filePath.replaceAll("/", "\\"),
226
+ posix: nor => filePath.replaceAll("\\", "/"),
227
+ win32: nor => filePath.replaceAll("/", "\\"),
228
228
  });
229
229
  }
230
230
  UtilFT.stylizePath = stylizePath;
@@ -257,11 +257,13 @@ var UtilFT;
257
257
  UtilFT.currosizePath = currosizePath;
258
258
  /**逐级寻找node_modules文件夹
259
259
  * @param basePath - 基础位置
260
+ * @param extpaths - 额外的路径 如 .bin
261
+ * @returns node_modules文件夹路径 包含额外路径
260
262
  */
261
- async function findNodeModulesDir(basePath) {
263
+ async function findNodeModulesDir(basePath, ...extpaths) {
262
264
  let currentDir = basePath;
263
265
  while (currentDir) {
264
- const nodeModulesPath = pathe_1.default.join(currentDir, 'node_modules');
266
+ const nodeModulesPath = pathe_1.default.join(currentDir, 'node_modules', ...extpaths);
265
267
  if (await UtilFT.pathExists(nodeModulesPath))
266
268
  return nodeModulesPath;
267
269
  const parentDir = pathe_1.default.dirname(currentDir);
@@ -344,7 +346,9 @@ var UtilFT;
344
346
  * @param dir - 起始目录
345
347
  * @param globPattern - glob匹配
346
348
  * @param opt - 可选参数
347
- * @param opt.ignore - 忽略的文件
349
+ * @param opt.ignore - 忽略的文件
350
+ * @param opt.relative - 忽略目录 默认 true
351
+ * @param opt.nodir - 忽略大小写 默认 跟随系统 mac/win为true 其他false
348
352
  * @returns 文件绝对路径数组
349
353
  */
350
354
  async function fileSearchGlob(dir, globPattern, opt) {
@@ -359,7 +363,9 @@ var UtilFT;
359
363
  * @param dir - 起始目录
360
364
  * @param globPattern - glob匹配
361
365
  * @param opt - 可选参数
362
- * @param opt.ignore - 忽略的文件
366
+ * @param opt.ignore - 忽略的文件
367
+ * @param opt.relative - 忽略目录 默认 true
368
+ * @param opt.nodir - 忽略大小写 默认 跟随系统 mac/win为true 其他false
363
369
  * @returns 文件绝对路径数组
364
370
  */
365
371
  function fileSearchGlobSync(dir, globPattern, opt) {
@@ -1,6 +1,6 @@
1
1
  import { LogLevel } from "./UtilInterfaces";
2
2
  import { JsFunc } from "@zwa73/js-utils";
3
- export { PromiseRetries, PromiseRetryResult } from "@zwa73/js-utils";
3
+ export type { PromiseRetries, PromiseRetryResult } from "@zwa73/js-utils";
4
4
  declare const HashAlgorithmList: readonly ["RSA-MD5", "RSA-RIPEMD160", "RSA-SHA1", "RSA-SHA1-2", "RSA-SHA224", "RSA-SHA256", "RSA-SHA3-224", "RSA-SHA3-256", "RSA-SHA3-384", "RSA-SHA3-512", "RSA-SHA384", "RSA-SHA512", "RSA-SHA512/224", "RSA-SHA512/256", "RSA-SM3", "blake2b512", "blake2s256", "id-rsassa-pkcs1-v1_5-with-sha3-224", "id-rsassa-pkcs1-v1_5-with-sha3-256", "id-rsassa-pkcs1-v1_5-with-sha3-384", "id-rsassa-pkcs1-v1_5-with-sha3-512", "md5", "md5-sha1", "md5WithRSAEncryption", "ripemd", "ripemd160", "ripemd160WithRSA", "rmd160", "sha1", "sha1WithRSAEncryption", "sha224", "sha224WithRSAEncryption", "sha256", "sha256WithRSAEncryption", "sha3-224", "sha3-256", "sha3-384", "sha3-512", "sha384", "sha384WithRSAEncryption", "sha512", "sha512-224", "sha512-224WithRSAEncryption", "sha512-256", "sha512-256WithRSAEncryption", "sha512WithRSAEncryption", "shake128", "shake256", "sm3", "sm3WithRSAEncryption", "ssl3-md5", "ssl3-sha1"];
5
5
  export type HashAlgorithm = typeof HashAlgorithmList[number];
6
6
  /**执行选项 */
@@ -39,26 +39,8 @@ declare class _UtilFunc {
39
39
  stdout: string;
40
40
  stderr: string;
41
41
  }>;
42
- private static publicIp?;
43
42
  /**获取当前公网ipv4 */
44
43
  static getPublicIpv4(): Promise<string>;
45
- /**动态导入模块的函数。这个函数是为了在TypeScript的模块系统配置为CommonJS时,防止动态import被转译为require而设计的。
46
- * 使用这个函数,你可以在TypeScript中动态地导入模块,而不需要担心import()被转译为require()。
47
- * 请注意,这个函数使用了eval(),可能会带来安全风险。
48
- *
49
- * @param moduleName - 需要导入的模块的名称。
50
- * @returns 返回一个Promise。当模块被成功导入时,这个Promise会解析为导入的模块。如果导入失败,这个Promise会被拒绝。
51
- *
52
- * @example
53
- * async function main() {
54
- * const pip = (await dynamicImport('public-ip')).default;
55
- * console.log(await pip.v4());
56
- * }
57
- * main();
58
- *
59
- * @since Node.js 13.2,Node.js开始支持动态import。
60
- */
61
- static dynamicImport(moduleName: string): Promise<any>;
62
44
  }
63
- export declare const UtilFunc: import("@zwa73/modular-mixer").ComposedClass<typeof _UtilFunc, typeof JsFunc, "__jsUtils", "match" | "failed" | "success" | "prototype" | "genUUID" | "range" | "concurrency" | "getTime" | "initField" | "initObject" | "unifyApply" | "sleep" | "getNeverResolvedPromise" | "retryPromise" | "timelimitPromise" | "mapEntries" | "eachField" | "stringifyJToken" | "assertType" | "assertLiteral" | "deepClone" | "isSafeNumber" | "dedent" | "throwError" | "getFuncLoc" | "cachePool" | "memoize" | "asyncize" | "splitToChunk" | "mergeFromChunk" | "structEqual" | "outcome" | "isStatus" | "eitherize" | "parseSrtTime" | "formatSrtTime" | "parseSrt" | "createSrt" | "ivk" | "s2l" | "l2s">;
45
+ export declare const UtilFunc: import("@zwa73/modular-mixer").ComposedClass<typeof _UtilFunc, typeof JsFunc, "__jsUtils", "match" | "failed" | "success" | "prototype" | "genUUID" | "range" | "getTime" | "initField" | "initObject" | "unifyApply" | "sleep" | "getNeverResolvedPromise" | "retryPromise" | "timelimitPromise" | "mapEntries" | "eachField" | "stringifyJToken" | "assertType" | "assertLiteral" | "deepClone" | "isSafeNumber" | "dedent" | "throwError" | "getFuncLoc" | "cachePool" | "memoize" | "asyncize" | "lazyize" | "splitToChunk" | "mergeFromChunk" | "structEqual" | "concurrent" | "dynamicImport" | "outcome" | "isStatus" | "eitherize" | "parseSrtTime" | "formatSrtTime" | "parseSrt" | "createSrt" | "ivk" | "s2l" | "l2s">;
64
46
  export type UtilFunc = typeof UtilFunc;
@@ -77,10 +77,10 @@ class _UtilFunc {
77
77
  return new Promise(async (resolve, reject) => {
78
78
  // 创建一个新的环境变量对象,并将项目的 node_modules/.bin 目录添加到 PATH 环境变量中
79
79
  const env = Object.create(process.env);
80
- const penv = path_1.default.join(opt?.nodeModules
81
- ? UtilFileTools_1.UtilFT.currosizePath(opt.nodeModules)
82
- : UtilFileTools_1.UtilFT.currosizePath(await exports.UtilFunc.memoize(UtilFileTools_1.UtilFT.findNodeModulesDir)(process.cwd()) ?? ''), '.bin');
83
- if (_UtilFunc.checkEnv && !await UtilFileTools_1.UtilFT.pathExists(penv)) {
80
+ const penv = opt?.nodeModules
81
+ ? path_1.default.join(UtilFileTools_1.UtilFT.currosizePath(opt.nodeModules), '.bin')
82
+ : UtilFileTools_1.UtilFT.currosizePath(await exports.UtilFunc.memoize(UtilFileTools_1.UtilFT.findNodeModulesDir)(process.cwd(), '.bin') ?? '');
83
+ if (_UtilFunc.checkEnv && (penv == "" || !await UtilFileTools_1.UtilFT.pathExists(penv))) {
84
84
  UtilLogger_1.SLogger.warn(`UtilFunc.exec 错误, 没有检测到 node_modules/.bin 环境 penv:${penv}`);
85
85
  _UtilFunc.checkEnv = false;
86
86
  }
@@ -115,31 +115,12 @@ class _UtilFunc {
115
115
  });
116
116
  });
117
117
  }
118
- static publicIp;
119
118
  /**获取当前公网ipv4 */
120
119
  static async getPublicIpv4() {
121
- if (_UtilFunc.publicIp === undefined)
122
- _UtilFunc.publicIp = await _UtilFunc.dynamicImport('public-ip');
123
- return _UtilFunc.publicIp.publicIpv4();
124
- }
125
- /**动态导入模块的函数。这个函数是为了在TypeScript的模块系统配置为CommonJS时,防止动态import被转译为require而设计的。
126
- * 使用这个函数,你可以在TypeScript中动态地导入模块,而不需要担心import()被转译为require()。
127
- * 请注意,这个函数使用了eval(),可能会带来安全风险。
128
- *
129
- * @param moduleName - 需要导入的模块的名称。
130
- * @returns 返回一个Promise。当模块被成功导入时,这个Promise会解析为导入的模块。如果导入失败,这个Promise会被拒绝。
131
- *
132
- * @example
133
- * async function main() {
134
- * const pip = (await dynamicImport('public-ip')).default;
135
- * console.log(await pip.v4());
136
- * }
137
- * main();
138
- *
139
- * @since Node.js 13.2,Node.js开始支持动态import。
140
- */
141
- static async dynamicImport(moduleName) {
142
- return await eval(`import('${moduleName}')`);
120
+ const pip = await js_utils_1.JsFunc.dynamicImport('public-ip');
121
+ //if(_UtilFunc.publicIp===undefined)
122
+ // _UtilFunc.publicIp = await import("public-ip");
123
+ return pip.publicIpv4();
143
124
  }
144
125
  }
145
126
  const key = '__jsUtils';
@@ -1 +1 @@
1
- export { JToken, JValue, JArray, JObject, IJData, AnyFunc, Keyable, PartialOption, ProperSubset, ProperSubsetCheck, IncludeCheck, UnionCheck, Literal, LiteralCheck, AllExtends, AssignObject, Writeable, Inverted, FixedLengthTuple, Increment, RangeTuple, AnyString, UnionToIntersection, ExclusiveRecord, ExclusiveJObject, PromiseStatus, StatusVerifyFn, Await, FuncPropNames, ExtendThen, RequiredOnly, WithPrefix, Outcome, Either, Matchable, MatchableFlag, ExtractOutcome, ExtractMatchable, SchemaString, NeedInit, PRecord, MPromise, SPromise, SMPromise, NotPromise, AnyRecord, CmtTuple, Flasy, SrtSegment, ILogger, LogLevel, Asyncize } from "@zwa73/js-utils";
1
+ export type { JToken, JValue, JArray, JObject, IJData, AnyFunc, Keyable, PartialOption, ProperSubset, ProperSubsetCheck, IncludeCheck, UnionCheck, Literal, LiteralCheck, AllExtends, AssignObject, Writeable, Inverted, FixedLengthTuple, Increment, RangeTuple, AnyString, UnionToIntersection, ExclusiveRecord, ExclusiveJObject, PromiseStatus, StatusVerifyFn, Await, FuncPropNames, ExtendThen, RequiredOnly, WithPrefix, Outcome, Either, Matchable, MatchableFlag, ExtractOutcome, ExtractMatchable, NeedInit, PRecord, MPromise, SPromise, SMPromise, NotPromise, AnyRecord, CmtTuple, Flasy, SrtSegment, ILogger, LogLevel, Asyncize } from "@zwa73/js-utils";
@@ -1 +1,2 @@
1
- export { Success, Failed, None, Uninited, Completed, Terminated, Timeout, FailedLike, SuccessLike, StatusSymbol, NoneOut } from "@zwa73/js-utils";
1
+ export type { FailedLike, SuccessLike, StatusSymbol } from "@zwa73/js-utils";
2
+ export { Success, Failed, None, Uninited, Completed, Terminated, Timeout, NoneOut } from "@zwa73/js-utils";
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NoneOut = exports.Timeout = exports.Terminated = exports.Completed = exports.Uninited = exports.None = exports.Failed = exports.Success = void 0;
4
- //#region UtilSymbol转导
5
4
  var js_utils_1 = require("@zwa73/js-utils");
6
5
  Object.defineProperty(exports, "Success", { enumerable: true, get: function () { return js_utils_1.Success; } });
7
6
  Object.defineProperty(exports, "Failed", { enumerable: true, get: function () { return js_utils_1.Failed; } });
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.223",
3
+ "version": "1.0.225",
4
4
  "description": "my utils",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "test": "jest",
8
8
  "release": "powershell scripts/release",
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './dist';
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require("./dist");