@zwa73/utils 1.0.224 → 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.
Files changed (46) hide show
  1. package/dist/{types/QuickExport.d.ts → QuickExport.d.ts} +1 -1
  2. package/dist/{cjs/QuickExport.js → QuickExport.js} +2 -2
  3. package/dist/UtilClass/index.d.ts +3 -0
  4. package/dist/{cjs/UtilClass → UtilClass}/index.js +7 -6
  5. package/dist/{cjs/UtilCodecs.js → UtilCodecs.js} +1 -5
  6. package/dist/{cjs/UtilFileTools.js → UtilFileTools.js} +2 -2
  7. package/dist/{types/UtilFunctions.d.ts → UtilFunctions.d.ts} +1 -19
  8. package/dist/{cjs/UtilFunctions.js → UtilFunctions.js} +2 -26
  9. package/dist/{types/UtilInterfaces.d.ts → UtilInterfaces.d.ts} +1 -1
  10. package/package.json +2 -8
  11. package/dist/mjs/QuickExport.mjs +0 -35
  12. package/dist/mjs/UtilClass/Hbs.mjs +0 -51
  13. package/dist/mjs/UtilClass/index.mjs +0 -3
  14. package/dist/mjs/UtilCodecs.mjs +0 -109
  15. package/dist/mjs/UtilDecorators.mjs +0 -2
  16. package/dist/mjs/UtilFP.mjs +0 -2
  17. package/dist/mjs/UtilFileTools.mjs +0 -407
  18. package/dist/mjs/UtilFunctions.mjs +0 -138
  19. package/dist/mjs/UtilHttp.mjs +0 -475
  20. package/dist/mjs/UtilI18n.mjs +0 -206
  21. package/dist/mjs/UtilInterfaces.mjs +0 -2
  22. package/dist/mjs/UtilLogger.mjs +0 -361
  23. package/dist/mjs/UtilSymbol.mjs +0 -2
  24. package/dist/mjs/index.mjs +0 -17
  25. package/dist/types/UtilClass/index.d.ts +0 -3
  26. package/index.d.ts +0 -1
  27. package/index.js +0 -1
  28. /package/dist/{types/UtilClass → UtilClass}/Hbs.d.ts +0 -0
  29. /package/dist/{cjs/UtilClass → UtilClass}/Hbs.js +0 -0
  30. /package/dist/{types/UtilCodecs.d.ts → UtilCodecs.d.ts} +0 -0
  31. /package/dist/{types/UtilDecorators.d.ts → UtilDecorators.d.ts} +0 -0
  32. /package/dist/{cjs/UtilDecorators.js → UtilDecorators.js} +0 -0
  33. /package/dist/{types/UtilFP.d.ts → UtilFP.d.ts} +0 -0
  34. /package/dist/{cjs/UtilFP.js → UtilFP.js} +0 -0
  35. /package/dist/{types/UtilFileTools.d.ts → UtilFileTools.d.ts} +0 -0
  36. /package/dist/{types/UtilHttp.d.ts → UtilHttp.d.ts} +0 -0
  37. /package/dist/{cjs/UtilHttp.js → UtilHttp.js} +0 -0
  38. /package/dist/{types/UtilI18n.d.ts → UtilI18n.d.ts} +0 -0
  39. /package/dist/{cjs/UtilI18n.js → UtilI18n.js} +0 -0
  40. /package/dist/{cjs/UtilInterfaces.js → UtilInterfaces.js} +0 -0
  41. /package/dist/{types/UtilLogger.d.ts → UtilLogger.d.ts} +0 -0
  42. /package/dist/{cjs/UtilLogger.js → UtilLogger.js} +0 -0
  43. /package/dist/{types/UtilSymbol.d.ts → UtilSymbol.d.ts} +0 -0
  44. /package/dist/{cjs/UtilSymbol.js → UtilSymbol.js} +0 -0
  45. /package/dist/{types/index.d.ts → index.d.ts} +0 -0
  46. /package/dist/{cjs/index.js → index.js} +0 -0
@@ -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) {
@@ -0,0 +1,3 @@
1
+ export * from './Hbs';
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,13 +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
19
  var js_utils_1 = require("@zwa73/js-utils");
20
- Object.defineProperty(exports, "Bridge", { enumerable: true, get: function () { return js_utils_1.Bridge; } });
21
- Object.defineProperty(exports, "DLinkedList", { enumerable: true, get: function () { return js_utils_1.DLinkedList; } });
22
- Object.defineProperty(exports, "Piper", { enumerable: true, get: function () { return js_utils_1.Piper; } });
23
- Object.defineProperty(exports, "PromiseQueue", { enumerable: true, get: function () { return js_utils_1.PromiseQueue; } });
24
- Object.defineProperty(exports, "SmartCache", { enumerable: true, get: function () { return js_utils_1.SmartCache; } });
25
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; } });
26
27
  //#endregion
@@ -26,12 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.UtilCodec = void 0;
27
27
  const he = __importStar(require("html-entities"));
28
28
  const UtilFunctions_1 = require("./UtilFunctions");
29
- let tiktoken = undefined;
30
29
  async function importTikToken() {
31
- if (tiktoken != null)
32
- return tiktoken;
33
- tiktoken = await UtilFunctions_1.UtilFunc.dynamicImport("tiktoken");
34
- return tiktoken;
30
+ return await UtilFunctions_1.UtilFunc.dynamicImport("tiktoken");
35
31
  }
36
32
  /**编码/解码器 */
37
33
  var UtilCodec;
@@ -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;
@@ -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<T = any>(moduleName: string): Promise<T>;
62
44
  }
63
- 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" | "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;
@@ -115,36 +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');
120
+ const pip = await js_utils_1.JsFunc.dynamicImport('public-ip');
123
121
  //if(_UtilFunc.publicIp===undefined)
124
122
  // _UtilFunc.publicIp = await import("public-ip");
125
- return _UtilFunc.publicIp.publicIpv4();
126
- }
127
- /**动态导入模块的函数。这个函数是为了在TypeScript的模块系统配置为CommonJS时,防止动态import被转译为require而设计的。
128
- * 使用这个函数,你可以在TypeScript中动态地导入模块,而不需要担心import()被转译为require()。
129
- * 请注意,这个函数使用了eval(),可能会带来安全风险。
130
- *
131
- * @param moduleName - 需要导入的模块的名称。
132
- * @returns 返回一个Promise。当模块被成功导入时,这个Promise会解析为导入的模块。如果导入失败,这个Promise会被拒绝。
133
- *
134
- * @example
135
- * async function main() {
136
- * const pip = (await dynamicImport('public-ip')).default;
137
- * console.log(await pip.v4());
138
- * }
139
- * main();
140
- *
141
- * @since Node.js 13.2,Node.js开始支持动态import。
142
- */
143
- static async dynamicImport(moduleName) {
144
- const mod = await eval(`import('${moduleName}')`);
145
- if ('default' in mod)
146
- return mod.default;
147
- return mod;
123
+ return pip.publicIpv4();
148
124
  }
149
125
  }
150
126
  const key = '__jsUtils';
@@ -1 +1 @@
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, 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";
package/package.json CHANGED
@@ -1,14 +1,8 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.224",
3
+ "version": "1.0.225",
4
4
  "description": "my utils",
5
- "exports": {
6
- ".": {
7
- "require": "./dist/cjs/index.js",
8
- "import": "./dist/mjs/index.mjs",
9
- "types": "./dist/types/index.d.ts"
10
- }
11
- },
5
+ "main": "dist/index.js",
12
6
  "scripts": {
13
7
  "test": "jest",
14
8
  "release": "powershell scripts/release",
@@ -1,35 +0,0 @@
1
- import { UtilFT } from "./UtilFileTools.mjs";
2
- import { UtilFP } from "./UtilFP.mjs";
3
- import { UtilFunc } from "./UtilFunctions.mjs";
4
- export const { outcome, success, failed, match, isSafeNumber, assertType, assertLiteral, deepClone, sleep, stringifyJToken, getTime, mapEntries, dedent, throwError, eitherize, memoize, ivk, l2s, s2l, structEqual, } = UtilFunc;
5
- export const { stylizePath, posixizePath, win32izePath, currosizePath, } = UtilFT;
6
- export const { when, map, flow, pipe, chain, alt, tap, curry, } = UtilFP;
7
- if (false) {
8
- //let aaser = assertLiteral({a:1});
9
- //let a:"asd"|"dsa" = null as any;
10
- //const r = matchProc(a,{
11
- // "asd":(a)=>"ssa" as const,
12
- // "dsa":(b)=>"ssb" as const,
13
- //});
14
- //let b:Outcome<"a","123">|NoneOut = null as any;
15
- //const r1 = matchProc(b,{
16
- // "a":(a,s)=>"ssa" as const,
17
- // [None]:(b,s)=>"ssb" as const,
18
- //});
19
- //let udt = outcome("ssa","None");
20
- //type test = Outcome<"a"|"b",any> extends Outcome<"a",12>|Outcome<"b",34>
21
- // ? "suc" : "fal"
22
- //let assa = isFailed(null as any as Failed);
23
- //let assb = isFailed(null as any as Failed|Success);
24
- //let assc = isFailed(null as any as Success);
25
- //let asssc = isFailed(null);
26
- //let assa1 = isFailed(null as any as Outcome<Failed,unknown>);
27
- //let assb1 = isFailed(null as any as Outcome<Failed|Success,unknown>);
28
- //let assc1 = isFailed(null as any as Outcome<Success,unknown>);
29
- //let proct = sucesProc(null as any as Outcome<Failed|Success,"123">|Outcome<Failed,"1234">|Outcome<Success,"1s23">,
30
- // (s)=>"ssa" as const,
31
- // (f)=>"ssad" as const,
32
- // ()=>123 as const);
33
- //let matt = matchProc(null as any as Outcome<symbol,123>,{
34
- //});
35
- }
@@ -1,51 +0,0 @@
1
- import { SLogger } from '../UtilLogger.mjs';
2
- import { UtilFunc } from '../UtilFunctions.mjs';
3
- /**文本模板渲染器
4
- * @template T - 上下文对象的类型,默认为记录类型
5
- */
6
- export class Hbs {
7
- hbs;
8
- context;
9
- /**创建一个新的 Hbs 实例
10
- * @param context - 上下文对象,用于在渲染模板时提供数据
11
- */
12
- constructor(hbs, context = {}) {
13
- this.hbs = hbs;
14
- this.context = context;
15
- this.hbs.registerHelper('def', (name, options) => {
16
- const value = options.fn(this.context).trim();
17
- this.context[name] = value;
18
- return '';
19
- });
20
- this.hbs.registerHelper('defli', (name, options) => {
21
- const rawvalue = options.fn(this.context);
22
- const values = rawvalue
23
- .split('[[br]]')
24
- .map(value => value.trim());
25
- this.context[name] = values;
26
- return '';
27
- });
28
- }
29
- /**创建一个新的 Hbs 实例
30
- * @param context - 上下文对象,用于在渲染模板时提供数据
31
- */
32
- static async create(context = {}) {
33
- const Handlebars = await UtilFunc.dynamicImport('handlebars');
34
- //console.log(Handlebars);
35
- const hbs = Handlebars.create();
36
- return new Hbs(hbs, context);
37
- }
38
- /**渲染模板
39
- * @param template - 要渲染的 Handlebars 模板字符串
40
- * @returns 渲染后的字符串
41
- */
42
- render(template) {
43
- try {
44
- return this.hbs.compile(template)(this.context);
45
- }
46
- catch (e) {
47
- SLogger.error(e);
48
- return '';
49
- }
50
- }
51
- }
@@ -1,3 +0,0 @@
1
- export * from './Hbs.mjs';
2
- export { Bridge, DLinkedList, Piper, PromiseQueue, SmartCache, Stream } from "@zwa73/js-utils";
3
- //#endregion
@@ -1,109 +0,0 @@
1
- import * as he from 'html-entities';
2
- import { UtilFunc } from './UtilFunctions.mjs';
3
- let tiktoken = undefined;
4
- async function importTikToken() {
5
- if (tiktoken != null)
6
- return tiktoken;
7
- tiktoken = await UtilFunc.dynamicImport("tiktoken");
8
- return tiktoken;
9
- }
10
- /**编码/解码器 */
11
- export var UtilCodec;
12
- (function (UtilCodec) {
13
- /**gpt-4, gpt-3.5-turbo, text-embedding-ada-002, text-embedding-3-small, text-embedding-3-large
14
- */
15
- let encoderCl100kBase = null;
16
- /**Codex models, text-davinci-002, text-davinci-003
17
- */
18
- let encoderP50kBase = null;
19
- const textDecoder = new TextDecoder();
20
- /**HTML实体解码 将一个字符串中的HTML实体转换为对应的字符
21
- * @param str - 要转换的字符串
22
- * @returns 转换后的字符串
23
- */
24
- function decodeHtmlEntities(str) {
25
- return he.decode(str);
26
- }
27
- UtilCodec.decodeHtmlEntities = decodeHtmlEntities;
28
- /**HTML实体编码 将一个字符串中的 需编码字符转换为 HTML实体
29
- * @param str - 要转换的字符串
30
- * @returns 转换后的字符串
31
- */
32
- function encodeHtmlEntities(str) {
33
- return he.encode(str);
34
- }
35
- UtilCodec.encodeHtmlEntities = encodeHtmlEntities;
36
- //#region LAM
37
- //token长度计算器
38
- //cl100k_base ChatGPT models, text-embedding-ada-002
39
- //p50k_base Code models, text-davinci-002, text-davinci-003
40
- //r50k_base (or gpt2) GPT-3 models like davinci
41
- //避免在nextjs调用时出错
42
- async function initTikTokenEncoder() {
43
- if (encoderCl100kBase != null && encoderP50kBase != null)
44
- return;
45
- const { get_encoding } = await importTikToken();
46
- encoderCl100kBase = get_encoding("cl100k_base");
47
- encoderP50kBase = get_encoding("p50k_base");
48
- }
49
- /**token长度计算器 Turbo模型
50
- * @param str = 所要计算的消息
51
- * @returns 整数长度结果
52
- */
53
- async function tokenNumTurbo(str) {
54
- await initTikTokenEncoder();
55
- //return encoder.encode(str).length
56
- return encoderCl100kBase?.encode(str).length;
57
- }
58
- UtilCodec.tokenNumTurbo = tokenNumTurbo;
59
- /**token长度计算器 Davinci模型
60
- * @param str = 所要计算的消息
61
- * @returns 整数长度结果
62
- */
63
- async function tokenNumDavinci(str) {
64
- await initTikTokenEncoder();
65
- return encoderP50kBase?.encode(str).length;
66
- }
67
- UtilCodec.tokenNumDavinci = tokenNumDavinci;
68
- /**token编码 Turbo模型
69
- * @param str = 所要计算的消息
70
- * @returns Token数组
71
- */
72
- async function encodeTokenTurbo(str) {
73
- await initTikTokenEncoder();
74
- return encoderCl100kBase?.encode(str);
75
- }
76
- UtilCodec.encodeTokenTurbo = encodeTokenTurbo;
77
- /**token编码 Davinci模型
78
- * @param str = 所要计算的消息
79
- * @returns Token数组
80
- */
81
- async function encodeTokenDavinci(str) {
82
- await initTikTokenEncoder();
83
- return encoderP50kBase?.encode(str);
84
- }
85
- UtilCodec.encodeTokenDavinci = encodeTokenDavinci;
86
- /**token解码 Turbo模型
87
- * @param arr = Token数组
88
- * @returns 消息字符串
89
- */
90
- async function decodeTokenTurbo(arr) {
91
- await initTikTokenEncoder();
92
- if (Array.isArray(arr))
93
- arr = new Uint32Array(arr);
94
- return textDecoder.decode(encoderCl100kBase?.decode(arr));
95
- }
96
- UtilCodec.decodeTokenTurbo = decodeTokenTurbo;
97
- /**token解码 Davinci模型
98
- * @param arr = Token数组
99
- * @returns 消息字符串
100
- */
101
- async function decodeTokenDavinci(arr) {
102
- await initTikTokenEncoder();
103
- if (Array.isArray(arr))
104
- arr = new Uint32Array(arr);
105
- return textDecoder.decode(encoderP50kBase?.decode(arr));
106
- }
107
- UtilCodec.decodeTokenDavinci = decodeTokenDavinci;
108
- //#endregion
109
- })(UtilCodec || (UtilCodec = {}));
@@ -1,2 +0,0 @@
1
- export { LogTrace, PostProcess, AwaitInited } from "@zwa73/js-utils";
2
- //#endregion
@@ -1,2 +0,0 @@
1
- import { JsFP } from "@zwa73/js-utils";
2
- export const UtilFP = JsFP;