@zwa73/utils 1.0.273 → 1.0.274

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: <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 ? Exclude<T, import("@zwa73/js-utils").Matchable<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) => (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 ? Exclude<T, import("@zwa73/js-utils").Matchable<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,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 - 额外环境变量
@@ -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 - 额外环境变量
@@ -97,12 +97,19 @@ class _UtilFunc {
97
97
  child.stdout.on('data', (data) => {
98
98
  stdout += data;
99
99
  if (opt?.outlvl)
100
- UtilLogger_1.SLogger.log(opt?.outlvl, data.toString());
100
+ if (typeof opt.outlvl === "function")
101
+ opt.outlvl(data.toString());
102
+ else
103
+ UtilLogger_1.SLogger.log(opt?.outlvl, data.toString());
101
104
  });
102
105
  child.stderr.on('data', (data) => {
103
106
  stderr += data;
104
- if (opt?.errlvl)
105
- UtilLogger_1.SLogger.log(opt?.errlvl, data.toString());
107
+ if (opt?.errlvl) {
108
+ if (typeof opt.errlvl === "function")
109
+ opt.errlvl(data.toString());
110
+ else
111
+ UtilLogger_1.SLogger.log(opt?.errlvl, data.toString());
112
+ }
106
113
  });
107
114
  child.on('error', reject);
108
115
  child.on('close', (code) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.273",
3
+ "version": "1.0.274",
4
4
  "description": "my utils",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -27,13 +27,13 @@
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,6 +44,9 @@
44
44
  },
45
45
  "tiktoken": {
46
46
  "optional": true
47
+ },
48
+ "yaml": {
49
+ "optional": true
47
50
  }
48
51
  },
49
52
  "devDependencies": {
@@ -55,7 +58,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",