@zwa73/utils 1.0.264 → 1.0.266

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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Hbs = void 0;
4
4
  const UtilLogger_1 = require("../UtilLogger");
5
5
  const js_utils_1 = require("@zwa73/js-utils");
6
+ const UtilFunctions_1 = require("../UtilFunctions");
6
7
  /**文本模板渲染器
7
8
  * @template T - 上下文对象的类型,默认为记录类型
8
9
  */
@@ -34,6 +35,8 @@ class Hbs {
34
35
  */
35
36
  static async create(context = {}) {
36
37
  const Handlebars = await js_utils_1.JsFunc.dynamicImport('handlebars');
38
+ if (Handlebars == undefined)
39
+ UtilFunctions_1.UtilFunc.throwError(`npm包 handlebars 动态导入失败, 此包不会随@zwa73/utils自动安装, 可能是未安装, 可使用 npm i handlebars@4.7.8 来安装`);
37
40
  //console.log(Handlebars);
38
41
  const hbs = Handlebars.create();
39
42
  return new Hbs(hbs, context);
@@ -27,7 +27,10 @@ exports.UtilCodec = void 0;
27
27
  const he = __importStar(require("html-entities"));
28
28
  const UtilFunctions_1 = require("./UtilFunctions");
29
29
  async function importTikToken() {
30
- return await UtilFunctions_1.UtilFunc.dynamicImport("tiktoken");
30
+ const tik = await UtilFunctions_1.UtilFunc.dynamicImport("tiktoken");
31
+ if (tik == undefined)
32
+ UtilFunctions_1.UtilFunc.throwError(`npm包 tiktoken 动态导入失败, 此包不会随@zwa73/utils自动安装, 可能是未安装, 可使用 npm i tiktoken@1.0.7 来安装`);
33
+ return tik;
31
34
  }
32
35
  /**编码/解码器 */
33
36
  var UtilCodec;
@@ -57,9 +60,9 @@ var UtilCodec;
57
60
  UtilCodec.encodeHtmlEntities = encodeHtmlEntities;
58
61
  //#region LAM
59
62
  //token长度计算器
60
- //cl100k_base ChatGPT models, text-embedding-ada-002
61
- //p50k_base Code models, text-davinci-002, text-davinci-003
62
- //r50k_base (or gpt2) GPT-3 models like davinci
63
+ //cl100k_base ChatGPT models, text-embedding-ada-002
64
+ //p50k_base Code models, text-davinci-002, text-davinci-003
65
+ //r50k_base (or gpt2) GPT-3 models like davinci
63
66
  //避免在nextjs调用时出错
64
67
  async function initTikTokenEncoder() {
65
68
  if (encoderCl100kBase != null && encoderP50kBase != null)
@@ -45,7 +45,7 @@ declare class _UtilFunc {
45
45
  /**获取当前公网ipv4
46
46
  * 依赖于 public-ip@6.0.2 但不会自动安装
47
47
  */
48
- static getPublicIpv4(): Promise<string>;
48
+ static getPublicIpv4(): Promise<string | undefined>;
49
49
  }
50
50
  export declare const UtilFunc: import("@zwa73/modular-mixer").ComposedClass<typeof _UtilFunc, typeof JsFunc, "__jsUtils", "match" | "failed" | "success" | "prototype" | "genUUID" | "range" | "preset" | "assignOption" | "getTime" | "initField" | "initObject" | "afterward" | "sleep" | "getNeverResolvedPromise" | "retryPromise" | "timelimitPromise" | "mapEntries" | "eachField" | "stringifyJToken" | "sortJToken" | "assertType" | "assertLiteral" | "deepClone" | "isSafeNumber" | "dedent" | "throwError" | "getFuncLoc" | "cachePool" | "memoize" | "asyncize" | "lazyFunction" | "splitToChunk" | "mergeFromChunk" | "structEqual" | "concurrent" | "dynamicImport" | "createInjectable" | "createAsyncProxy" | "checkSharpSchema" | "outcome" | "extractOutcome" | "isStatus" | "eitherize" | "parseSrtTime" | "formatSrtTime" | "parseSrt" | "createSrt" | "ivk" | "s2l" | "l2s">;
51
51
  export type UtilFunc = typeof UtilFunc;
@@ -123,6 +123,10 @@ class _UtilFunc {
123
123
  const pip = await js_utils_1.JsFunc.dynamicImport('public-ip');
124
124
  //if(_UtilFunc.publicIp===undefined)
125
125
  // _UtilFunc.publicIp = await import("public-ip");
126
+ if (pip == undefined) {
127
+ UtilLogger_1.SLogger.warn(`npm包 public-ip 动态导入失败, 此包不会随@zwa73/utils自动安装, 可能是未安装, 可使用 npm i public-ip@6.0.2 来安装`);
128
+ return undefined;
129
+ }
126
130
  return pip.publicIpv4();
127
131
  }
128
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.264",
3
+ "version": "1.0.266",
4
4
  "description": "my utils",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -20,14 +20,12 @@
20
20
  "@zwa73/modular-mixer": "^1.0.8",
21
21
  "form-data": "^4.0.2",
22
22
  "glob": "^10.4.1",
23
- "handlebars": "^4.7.8",
24
23
  "html-entities": "^2.3.3",
25
24
  "http-proxy-agent": "^5.0.0",
26
25
  "https-proxy-agent": "^5.0.1",
27
26
  "json5": "^2.2.3",
28
27
  "pathe": "^1.1.2",
29
28
  "querystring": "^0.2.1",
30
- "tiktoken": "^1.0.7",
31
29
  "winston": "^3.10.0",
32
30
  "winston-daily-rotate-file": "^4.7.1"
33
31
  },
@@ -36,7 +34,9 @@
36
34
  "@types/jest": "^29.5.12",
37
35
  "@types/node": "^20.14.11",
38
36
  "@zwa73/dev-utils": "*",
37
+ "handlebars": "^4.7.8",
39
38
  "public-ip": "^6.0.2",
39
+ "tiktoken": "^1.0.7",
40
40
  "tsc-alias": "^1.8.8",
41
41
  "typescript": "^5.3.3"
42
42
  },