@zwa73/utils 1.0.273 → 1.0.275

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
2
  export declare const outcome: typeof import("@zwa73/js-utils").JsFunc.outcome, extractOutcome: typeof import("@zwa73/js-utils").JsFunc.extractOutcome, 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, lazyFunction: typeof import("@zwa73/js-utils").JsFunc.lazyFunction, 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, preset: typeof import("@zwa73/js-utils").JsFunc.preset, assignOption: typeof import("@zwa73/js-utils").JsFunc.assignOption;
3
3
  export declare const stylizePath: typeof UtilFT.stylizePath, posixizePath: typeof UtilFT.posixizePath, win32izePath: typeof UtilFT.win32izePath, currosizePath: typeof UtilFT.currosizePath;
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;
4
+ export declare const when: <const 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) => (false extends (symbol extends T ? S extends T & symbol ? false : true : string extends T ? S extends T & string ? false : true : number extends T ? S extends T & number ? false : true : true) ? T | R : import("@zwa73/js-utils").MatchableFlag<T> extends S ? Exclude<T, import("@zwa73/js-utils").Matchable<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) => false extends (symbol extends T ? typeof import("@zwa73/js-utils").Success extends infer T_1 ? T_1 extends typeof import("@zwa73/js-utils").Success ? T_1 extends T & symbol ? false : true : never : never : string extends T ? typeof import("@zwa73/js-utils").Success extends infer T_2 ? T_2 extends typeof import("@zwa73/js-utils").Success ? T_2 extends T & string ? false : true : never : never : number extends T ? typeof import("@zwa73/js-utils").Success extends infer T_3 ? T_3 extends typeof import("@zwa73/js-utils").Success ? T_3 extends T & number ? false : true : never : never : true) ? T | R : import("@zwa73/js-utils").MatchableFlag<T> extends typeof import("@zwa73/js-utils").Success ? R | Exclude<T, import("@zwa73/js-utils").Matchable<typeof import("@zwa73/js-utils").Success>> : import("@zwa73/js-utils").MatchableFlag<T> extends Exclude<typeof import("@zwa73/js-utils").Success, import("@zwa73/js-utils").MatchableFlag<T>> ? T : R | Exclude<T, import("@zwa73/js-utils").Matchable<typeof import("@zwa73/js-utils").Success>>, alt: <T, R>(f: (arg: Extract<T, import("@zwa73/js-utils").Matchable<typeof import("@zwa73/js-utils").Failed>>) => R) => (arg: T) => false extends (symbol extends T ? typeof import("@zwa73/js-utils").Failed extends infer T_1 ? T_1 extends typeof import("@zwa73/js-utils").Failed ? T_1 extends T & symbol ? false : true : never : never : string extends T ? typeof import("@zwa73/js-utils").Failed extends infer T_2 ? T_2 extends typeof import("@zwa73/js-utils").Failed ? T_2 extends T & string ? false : true : never : never : number extends T ? typeof import("@zwa73/js-utils").Failed extends infer T_3 ? T_3 extends typeof import("@zwa73/js-utils").Failed ? T_3 extends T & number ? false : true : never : never : true) ? T | R : import("@zwa73/js-utils").MatchableFlag<T> extends typeof import("@zwa73/js-utils").Failed ? R | Exclude<T, import("@zwa73/js-utils").Matchable<typeof import("@zwa73/js-utils").Failed>> : import("@zwa73/js-utils").MatchableFlag<T> extends Exclude<typeof import("@zwa73/js-utils").Failed, import("@zwa73/js-utils").MatchableFlag<T>> ? T : R | Exclude<T, import("@zwa73/js-utils").Matchable<typeof import("@zwa73/js-utils").Failed>>, tap: typeof import("@zwa73/js-utils").JsFP.tap, curry: typeof import("@zwa73/js-utils").JsFP.curry;
@@ -1,4 +1,4 @@
1
- import { stringify } from 'yaml';
1
+ import type { stringify } from 'yaml';
2
2
  type ExtractBlockOpt = {
3
3
  /**要提取的标题 必须为 "# 标题" 的格式 */
4
4
  title: string;
@@ -21,7 +21,7 @@ export declare class Markdown {
21
21
  /**从数据构建 */
22
22
  static from(arg?: FromArg): Markdown;
23
23
  /**输出md文本 */
24
- stringify(opt: Exclude<Parameters<typeof stringify>[2], string | number>): string;
24
+ stringify(opt: Exclude<Parameters<typeof stringify>[2], string | number>): Promise<string>;
25
25
  /**根据标题提取块
26
26
  * @param opt - 选项
27
27
  */
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Markdown = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const js_utils_1 = require("@zwa73/js-utils");
9
- const yaml_1 = require("yaml");
9
+ const UtilFunctions_1 = require("../UtilFunctions");
10
10
  const UtilLogger_1 = require("../UtilLogger");
11
11
  const getMatter = async () => {
12
12
  const matter = await js_utils_1.JsFunc.dynamicImport('gray-matter');
@@ -14,6 +14,12 @@ const getMatter = async () => {
14
14
  js_utils_1.JsFunc.throwError(`npm包 gray-matter 动态导入失败, 此包不会随@zwa73/utils自动安装, 可能是未安装, 可使用 npm i gray-matter@4.0.3 来安装`);
15
15
  return matter;
16
16
  };
17
+ const getYaml = async () => {
18
+ const yaml = await UtilFunctions_1.UtilFunc.dynamicImport('yaml');
19
+ if (yaml == undefined)
20
+ UtilFunctions_1.UtilFunc.throwError(`npm包 yaml 动态导入失败, 此包不会随@zwa73/utils自动安装, 可能是未安装, 可使用 npm i yaml@2.8.1 来安装`);
21
+ return yaml;
22
+ };
17
23
  /**Markdown解析器 */
18
24
  class Markdown {
19
25
  data;
@@ -37,8 +43,8 @@ class Markdown {
37
43
  return new Markdown(arg.data, arg.content);
38
44
  }
39
45
  /**输出md文本 */
40
- stringify(opt) {
41
- const yamlText = Object.values(this.data ?? {}).length > 0 ? `---\n${(0, yaml_1.stringify)(this.data, opt)}---\n` : '';
46
+ async stringify(opt) {
47
+ const yamlText = Object.values(this.data ?? {}).length > 0 ? `---\n${(await getYaml()).stringify(this.data, opt)}---\n` : '';
42
48
  return `${yamlText}${this.content}`;
43
49
  //return (await getMatter()).stringify(this.content,this.data);
44
50
  }
@@ -5,8 +5,8 @@ declare const HashAlgorithmList: readonly ["RSA-MD5", "RSA-RIPEMD160", "RSA-SHA1
5
5
  export type HashAlgorithm = typeof HashAlgorithmList[number];
6
6
  /**执行选项 */
7
7
  type ExecOpt = Partial<{
8
- outlvl: LogLevel;
9
- errlvl: LogLevel;
8
+ outlvl: LogLevel | ((arg: string) => any);
9
+ errlvl: LogLevel | ((arg: string) => any);
10
10
  /**node_modules文件夹目录, 用于设定环境变量 */
11
11
  nodeModules: string;
12
12
  /**工作路径 */
@@ -32,8 +32,8 @@ declare class _UtilFunc {
32
32
  /**封装的 cp.spawn 执行一段指令,指令运行时实时返回输出
33
33
  * @param command - 指令文本
34
34
  * @param opt - 可选参数
35
- * @param opt.outlvl - 普通输出的日志等级
36
- * @param opt.errlvl - 错误的日志等级
35
+ * @param opt.outlvl - 普通输出的日志等级 传入函数时直接转接为函数
36
+ * @param opt.errlvl - 错误的日志等级 传入函数时直接转接为函数
37
37
  * @param opt.nodeModules - nodeModules文件夹路径
38
38
  * @param opt.cwd - 执行目录
39
39
  * @param opt.env - 额外环境变量
@@ -47,5 +47,5 @@ declare class _UtilFunc {
47
47
  */
48
48
  static getPublicIpv4(): Promise<string | undefined>;
49
49
  }
50
- export declare const UtilFunc: import("@zwa73/modular-mixer").ComposedClass<typeof _UtilFunc, typeof JsFunc, "__jsUtils", "match" | "failed" | "success" | "prototype" | "range" | "genUUID" | "preset" | "assignOption" | "getTime" | "initField" | "initObject" | "afterward" | "sleep" | "getNeverResolvedPromise" | "retryPromise" | "timelimitPromise" | "mapEntries" | "eachField" | "stringifyJToken" | "sortJToken" | "assertType" | "assertLiteral" | "deepClone" | "isSafeNumber" | "dedent" | "throwError" | "getStack" | "getFuncLoc" | "cachePool" | "memoize" | "asyncize" | "lazyFunction" | "splitToChunk" | "mergeFromChunk" | "structEqual" | "concurrent" | "dynamicImport" | "createInjectable" | "createAsyncProxy" | "checkSharpSchema" | "unwarpReadonly" | "outcome" | "extractOutcome" | "isStatus" | "eitherize" | "parseSrtTime" | "formatSrtTime" | "parseSrt" | "createSrt" | "ivk" | "s2l" | "l2s">;
50
+ export declare const UtilFunc: import("@zwa73/modular-mixer").ComposedClass<typeof _UtilFunc, typeof JsFunc, "__jsUtils", "prototype" | "preset" | "assignOption" | "genUUID" | "getTime" | "initField" | "initObject" | "afterward" | "sleep" | "getNeverResolvedPromise" | "retryPromise" | "timelimitPromise" | "mapEntries" | "eachField" | "stringifyJToken" | "sortJToken" | "assertType" | "assertLiteral" | "deepClone" | "isSafeNumber" | "dedent" | "throwError" | "getStack" | "getFuncLoc" | "cachePool" | "memoize" | "asyncize" | "lazyFunction" | "splitToChunk" | "mergeFromChunk" | "structEqual" | "concurrent" | "dynamicImport" | "createInjectable" | "createAsyncProxy" | "checkSharpSchema" | "unwarpReadonly" | "outcome" | "extractOutcome" | "success" | "failed" | "match" | "isStatus" | "eitherize" | "parseSrtTime" | "formatSrtTime" | "parseSrt" | "createSrt" | "ivk" | "range" | "s2l" | "l2s">;
51
51
  export type UtilFunc = typeof UtilFunc;
@@ -68,8 +68,8 @@ class _UtilFunc {
68
68
  /**封装的 cp.spawn 执行一段指令,指令运行时实时返回输出
69
69
  * @param command - 指令文本
70
70
  * @param opt - 可选参数
71
- * @param opt.outlvl - 普通输出的日志等级
72
- * @param opt.errlvl - 错误的日志等级
71
+ * @param opt.outlvl - 普通输出的日志等级 传入函数时直接转接为函数
72
+ * @param opt.errlvl - 错误的日志等级 传入函数时直接转接为函数
73
73
  * @param opt.nodeModules - nodeModules文件夹路径
74
74
  * @param opt.cwd - 执行目录
75
75
  * @param opt.env - 额外环境变量
@@ -96,13 +96,23 @@ class _UtilFunc {
96
96
  let stderr = '';
97
97
  child.stdout.on('data', (data) => {
98
98
  stdout += data;
99
- if (opt?.outlvl)
100
- UtilLogger_1.SLogger.log(opt?.outlvl, data.toString());
99
+ if (opt?.outlvl) {
100
+ const text = data.toString().replace(/\r?\n$/, '');
101
+ if (typeof opt.outlvl === "function")
102
+ opt.outlvl(text);
103
+ else
104
+ UtilLogger_1.SLogger.log(opt?.outlvl, text);
105
+ }
101
106
  });
102
107
  child.stderr.on('data', (data) => {
103
108
  stderr += data;
104
- if (opt?.errlvl)
105
- UtilLogger_1.SLogger.log(opt?.errlvl, data.toString());
109
+ if (opt?.errlvl) {
110
+ const text = data.toString().replace(/\r?\n$/, '');
111
+ if (typeof opt.errlvl === "function")
112
+ opt.errlvl(text);
113
+ else
114
+ UtilLogger_1.SLogger.log(opt?.errlvl, text);
115
+ }
106
116
  });
107
117
  child.on('error', reject);
108
118
  child.on('close', (code) => {
package/dist/UtilHttp.js CHANGED
@@ -11,8 +11,8 @@ const querystring_1 = __importDefault(require("querystring"));
11
11
  const url_1 = require("url");
12
12
  const js_utils_1 = require("@zwa73/js-utils");
13
13
  const form_data_1 = __importDefault(require("form-data"));
14
- const http_proxy_agent_1 = __importDefault(require("http-proxy-agent"));
15
- const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
14
+ const http_proxy_agent_1 = require("http-proxy-agent");
15
+ const https_proxy_agent_1 = require("https-proxy-agent");
16
16
  const pathe_1 = __importDefault(require("pathe"));
17
17
  const UtilFunctions_1 = require("./UtilFunctions");
18
18
  const UtilLogger_1 = require("./UtilLogger");
@@ -104,8 +104,8 @@ class UtilHttp {
104
104
  /**设置agent */
105
105
  proxyAgent(url) {
106
106
  this._data.agent = UtilFunctions_1.UtilFunc.match(this._data['protocol'], {
107
- 'http:': () => (0, http_proxy_agent_1.default)(url),
108
- 'https:': () => (0, https_proxy_agent_1.default)(url),
107
+ 'http:': () => new http_proxy_agent_1.HttpProxyAgent(url),
108
+ 'https:': () => new https_proxy_agent_1.HttpsProxyAgent(url),
109
109
  });
110
110
  return this;
111
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.273",
3
+ "version": "1.0.275",
4
4
  "description": "my utils",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -21,19 +21,19 @@
21
21
  "form-data": "^4.0.2",
22
22
  "glob": "^10.4.1",
23
23
  "html-entities": "^2.3.3",
24
- "http-proxy-agent": "^5.0.0",
25
- "https-proxy-agent": "^5.0.1",
24
+ "http-proxy-agent": "^7.0.2",
25
+ "https-proxy-agent": "^7.0.6",
26
26
  "json5": "^2.2.3",
27
27
  "pathe": "^1.1.2",
28
28
  "querystring": "^0.2.1",
29
29
  "winston": "^3.10.0",
30
- "winston-daily-rotate-file": "^4.7.1",
31
- "yaml": "^2.8.1"
30
+ "winston-daily-rotate-file": "^4.7.1"
32
31
  },
33
32
  "peerDependencies": {
34
33
  "handlebars": "^4.7.8",
35
34
  "public-ip": "^6.0.2",
36
- "tiktoken": "^1.0.7"
35
+ "tiktoken": "^1.0.7",
36
+ "yaml": "^2.8.1"
37
37
  },
38
38
  "peerDependenciesMeta": {
39
39
  "handlebars": {
@@ -44,18 +44,22 @@
44
44
  },
45
45
  "tiktoken": {
46
46
  "optional": true
47
+ },
48
+ "yaml": {
49
+ "optional": true
47
50
  }
48
51
  },
49
52
  "devDependencies": {
50
53
  "@deepkit/type": "^1.0.1-alpha.153",
51
54
  "@types/jest": "^29.5.12",
52
- "@types/node": "^20.14.11",
55
+ "@types/node": "^20.19.25",
53
56
  "@zwa73/dev-utils": "*",
54
57
  "handlebars": "^4.7.8",
55
58
  "public-ip": "^6.0.2",
56
59
  "tiktoken": "^1.0.7",
57
60
  "tsc-alias": "^1.8.8",
58
- "typescript": "^5.3.3"
61
+ "typescript": "^5.3.3",
62
+ "yaml": "^2.8.1"
59
63
  },
60
64
  "files": [
61
65
  "dist",