@zwa73/utils 1.0.90 → 1.0.93

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,7 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.UtilCodec = void 0;
4
- const he = require("html-entities");
7
+ const html_entities_1 = __importDefault(require("html-entities"));
5
8
  const tiktoken_1 = require("tiktoken");
6
9
  /**编码/解码器 */
7
10
  var UtilCodec;
@@ -9,27 +12,12 @@ var UtilCodec;
9
12
  let encoderTurbo = null;
10
13
  let encoderDavinci = null;
11
14
  const textDecoder = new TextDecoder();
12
- // 定义一个对象,存储常见的HTML实体和对应的字符
13
- let htmlEntities = {
14
- "&lt;": "<",
15
- "&gt;": ">",
16
- "&amp;": "&",
17
- "&quot;": "\"",
18
- "&#39;": "'",
19
- "&#91;": "[",
20
- "&#93;": "]"
21
- };
22
15
  /**HTML实体解码 将一个字符串中的HTML实体转换为对应的字符
23
16
  * @param str - 要转换的字符串
24
17
  * @returns 转换后的字符串
25
18
  */
26
19
  function decodeHtmlEntities(str) {
27
- //for(let code in htmlEntities){
28
- // let cha = htmlEntities[code]
29
- // str = str.replaceAll(code, cha);
30
- //}
31
- //return str
32
- return he.decode(str);
20
+ return html_entities_1.default.decode(str);
33
21
  }
34
22
  UtilCodec.decodeHtmlEntities = decodeHtmlEntities;
35
23
  /**HTML实体编码 将一个字符串中的 需编码字符转换为 HTML实体
@@ -37,14 +25,10 @@ var UtilCodec;
37
25
  * @returns 转换后的字符串
38
26
  */
39
27
  function encodeHtmlEntities(str) {
40
- //for(let code in htmlEntities){
41
- // let cha = htmlEntities[code]
42
- // str = str.replaceAll(cha, code);
43
- //}
44
- //return str
45
- return he.encode(str);
28
+ return html_entities_1.default.encode(str);
46
29
  }
47
30
  UtilCodec.encodeHtmlEntities = encodeHtmlEntities;
31
+ //#region LAM
48
32
  //token长度计算器
49
33
  //cl100k_base ChatGPT models, text-embedding-ada-002
50
34
  //p50k_base Code models, text-davinci-002, text-davinci-003
@@ -111,4 +95,5 @@ var UtilCodec;
111
95
  return textDecoder.decode(encoderDavinci?.decode(arr));
112
96
  }
113
97
  UtilCodec.decodeTokenDavinci = decodeTokenDavinci;
98
+ //#endregion
114
99
  })(UtilCodec || (exports.UtilCodec = UtilCodec = {}));
package/dist/UtilCom.js CHANGED
@@ -1,8 +1,31 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.UtilCom = void 0;
4
- const https = require("https");
5
- const http = require("http");
27
+ const https = __importStar(require("https"));
28
+ const http = __importStar(require("http"));
6
29
  const UtilLogger_1 = require("./UtilLogger");
7
30
  const UtilFunctions_1 = require("./UtilFunctions");
8
31
  /**网络工具 */
package/dist/UtilFP.d.ts CHANGED
@@ -1,7 +1,8 @@
1
+ import { Keyable, LiteralCheck } from "./UtilInterfaces";
1
2
  /**常用函数式编程库 */
2
3
  export declare namespace UtilFP {
3
4
  /**柯里化函数类型 */
4
- type CurryFunc<T, PrevArgs extends unknown[] = []> = T extends (...args: infer Args) => infer Result ? Args extends [infer Arg, ...infer RestArgs] ? RestArgs extends [] ? (...args: [...PrevArgs, Arg]) => Result : (...args: [...PrevArgs, Arg]) => CurryFunc<(...rest: RestArgs) => Result> & CurryFunc<(...args: RestArgs) => Result, [...PrevArgs, Arg]> : Args extends [] ? () => Result : "CurryFunc错误 可选无法被识别" & Error : never;
5
+ type CurryFunc<T, PrevArgs extends unknown[] = []> = T extends (...args: infer Args) => infer Result ? Args extends [infer Arg, ...infer RestArgs] ? RestArgs extends [] ? ((...args: [...PrevArgs, Arg]) => Result) : ((...args: [...PrevArgs, Arg]) => CurryFunc<(...rest: RestArgs) => Result>) & (CurryFunc<(...args: RestArgs) => Result, [...PrevArgs, Arg]>) : Args extends [] ? () => Result : "CurryFunc错误 默认参数可选无法被识别" & Error : "CurryFunc错误 传入的并非函数" & Error;
5
6
  /**柯里化转换
6
7
  * @param {T} fn - 将要转换的函数
7
8
  * @returns {CurryFunc<T>} 柯里化的函数
@@ -40,7 +41,53 @@ export declare namespace UtilFP {
40
41
  export function pipe<I, R1, R2, R3, R4, R5, R6, R7>(input: I, f1: CompFunc<I, R1>, f2: CompFunc<R1, R2>, f3: CompFunc<R2, R3>, f4: CompFunc<R3, R4>, f5: CompFunc<R4, R5>, f6: CompFunc<R5, R6>, f7: CompFunc<R6, R7>, ...fs: CompFunc<R7, R7>[]): R7;
41
42
  export function pipe<I, R1, R2, R3, R4, R5, R6, R7, R8>(input: I, f1: CompFunc<I, R1>, f2: CompFunc<R1, R2>, f3: CompFunc<R2, R3>, f4: CompFunc<R3, R4>, f5: CompFunc<R4, R5>, f6: CompFunc<R5, R6>, f7: CompFunc<R6, R7>, f8: CompFunc<R7, R8>, ...fs: CompFunc<R8, R8>[]): R8;
42
43
  export function pipe<I, R1, R2, R3, R4, R5, R6, R7, R8, R9>(input: I, f1: CompFunc<I, R1>, f2: CompFunc<R1, R2>, f3: CompFunc<R2, R3>, f4: CompFunc<R3, R4>, f5: CompFunc<R4, R5>, f6: CompFunc<R5, R6>, f7: CompFunc<R6, R7>, f8: CompFunc<R7, R8>, f9: CompFunc<R8, R9>, ...fs: CompFunc<R9, R9>[]): R9;
43
- /**将一个字段加入一个对象中,返回新类型 */
44
- export function bindTo<K extends string, T, B extends {} = {}>(key: K, value: T, base?: B): B & Record<K, T>;
44
+ /**将一个字段加入一个对象中, 返回新类型 */
45
+ /**绑定一个键和一个值到一个基础对象上, 并返回一个新的对象
46
+ * 新的对象包含了基础对象的所有属性, 以及一个新的属性,
47
+ * 这个新的属性的键是`key`, 值是`value`
48
+ * @template K - 要添加到对象的键的类型 必须为字面量
49
+ * @template V - 要添加到对象的值的类型
50
+ * @param key - 要添加到对象的键 必须为字面量
51
+ * @param value - 要添加到对象的值
52
+ * @returns 一个函数, 这个函数接受一个基础对象,
53
+ * 然后返回一个新的对象新的对象包含了基础对象的所有属性,
54
+ * 以及一个新的属性, 这个新的属性的键是`key`, 值是`value`
55
+ */
56
+ export function bind<K extends Keyable, V>(key: LiteralCheck<K>, value: V): <B extends {}>(base?: B) => keyof B extends K ? "Base中已有对应键" & Error : {
57
+ [P in K | keyof B]: P extends K ? V : P extends keyof B ? B[P] : never;
58
+ };
59
+ /**绑定一个键到一个基础对象上,
60
+ * 并返回一个新的对象新的对象包含了基础对象的所有属性,
61
+ * 以及一个新的属性, 这个新的属性的键是`key`, 值是基础对象
62
+ * @template K - 要添加到对象的键的类型 必须为字面量
63
+ * @param key - 要添加到对象的键 必须为字面量
64
+ * @returns 一个函数, 这个函数接受一个基础对象,
65
+ * 然后返回一个新的对象新的对象包含了基础对象的所有属性,
66
+ * 以及一个新的属性, 这个新的属性的键是`key`, 值是基础对象
67
+ */
68
+ export function bind<K extends Keyable>(key: LiteralCheck<K>): <B extends {}>(base?: B) => {
69
+ [P in K]: B;
70
+ };
71
+ /**绑定一个键和一个值到一个基础对象上, 并返回一个新的对象
72
+ * 新的对象包含了基础对象的所有属性, 以及一个新的属性,
73
+ * 这个新的属性的键是`key`, 值是`value`
74
+ * @template K - 要添加到对象的键的类型 必须为字面量
75
+ * @template V - 要添加到对象的值的类型
76
+ * @template B - 基础对象的类型
77
+ * @param key - 要添加到对象的键 必须为字面量
78
+ * @param value - 要添加到对象的值
79
+ * @param base - 基础对象
80
+ * @returns 完成绑定的基础对象
81
+ */
82
+ export function bind<K extends Keyable, V, B extends {}>(key: LiteralCheck<K>, value: V, base: B): keyof B extends K ? "Base中已有对应键" & Error : {
83
+ [P in K | keyof B]: P extends K ? V : P extends keyof B ? B[P] : never;
84
+ };
85
+ /**创建一个对对象的每个属性进行映射的函数
86
+ * @param func - 映射函数, 接受一个属性值和它的键, 返回一个新的属性值
87
+ * @returns 一个函数, 这个函数接受一个对象, 然后返回一个新的对象新的对象的每个属性都是原始对象的属性经过映射函数处理后的结果
88
+ */
89
+ export function map<VAL, OUT, KEY extends symbol | string = string>(func: (input: VAL, k: KEY) => OUT): <OM extends Record<KEY, VAL>>(input: OM) => keyof OM extends KEY ? {
90
+ [P in keyof OM]: OUT;
91
+ } : "map函数传入的键类型无法处理此对象" & Error;
45
92
  export {};
46
93
  }
package/dist/UtilFP.js CHANGED
@@ -28,14 +28,31 @@ var UtilFP;
28
28
  return fs.reduce((value, func) => func(value), input);
29
29
  }
30
30
  UtilFP.pipe = pipe;
31
- /**将一个字段加入一个对象中,返回新类型 */
32
- function bindTo(key, value, base) {
33
- let out = base;
34
- out = out ?? {};
35
- out[key] = value;
36
- return out;
31
+ //#endregion
32
+ function bind(key, value, base) {
33
+ if (base !== undefined)
34
+ return { ...base, [key]: value };
35
+ if (value === undefined)
36
+ return (base) => ({ [key]: base });
37
+ return (base) => base !== undefined
38
+ ? { ...base, [key]: value }
39
+ : { [key]: value };
40
+ }
41
+ UtilFP.bind = bind;
42
+ /**创建一个对对象的每个属性进行映射的函数
43
+ * @param func - 映射函数, 接受一个属性值和它的键, 返回一个新的属性值
44
+ * @returns 一个函数, 这个函数接受一个对象, 然后返回一个新的对象新的对象的每个属性都是原始对象的属性经过映射函数处理后的结果
45
+ */
46
+ function map(func) {
47
+ return (input) => {
48
+ return Reflect
49
+ .ownKeys(input)
50
+ .reduce((sum, curr) => ({ ...sum,
51
+ [curr]: func(input[curr], curr)
52
+ }), {});
53
+ };
37
54
  }
38
- UtilFP.bindTo = bindTo;
55
+ UtilFP.map = map;
39
56
  /**
40
57
  let asd = bindTo("sss",123,{abc:223});//?
41
58
  let sumvoid = ()=>10;
@@ -50,5 +67,11 @@ var UtilFP;
50
67
  console.log(suma(2,true));
51
68
  console.log(sumb(true));
52
69
  console.log(sumc("s",3,false));
53
- */
70
+
71
+ Reflect.ownKeys({[1]:1,[None]:2});//?
72
+ let as = "ssa" as string;//?
73
+ let asv = {"s":1};//?
74
+ let a = map((v:number,k)=>v*21);//?
75
+ let b = a({["ss"]:1})//?
76
+ */
54
77
  })(UtilFP || (exports.UtilFP = UtilFP = {}));
@@ -8,11 +8,9 @@ export type IOMap = {
8
8
  /**ffmpeg工具类
9
9
  */
10
10
  declare class SFfmpegTool {
11
- /**静态构造函数
12
- */
11
+ /**静态构造函数 */
13
12
  static init(): void;
14
- /**设置ffmpeg路径
15
- */
13
+ /**设置ffmpeg路径 */
16
14
  static setFfmpegPath(ffmpegPath: string): void;
17
15
  /**获取音频文件的元数据
18
16
  * @param inputWavPath - 输入音频文件路径
@@ -1,16 +1,41 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
2
28
  Object.defineProperty(exports, "__esModule", { value: true });
3
29
  exports.SFfmpegTool = void 0;
4
- const fluentFfmpeg = require("fluent-ffmpeg");
5
- const path = require("path");
6
- const fs = require("fs");
7
- const UtilClass_1 = require("./UtilClass");
30
+ const fluent_ffmpeg_1 = __importDefault(require("fluent-ffmpeg"));
31
+ const path = __importStar(require("path"));
32
+ const fs = __importStar(require("fs"));
8
33
  const UtilLogger_1 = require("./UtilLogger");
34
+ const UtilClass_1 = require("./UtilClass");
9
35
  /**ffmpeg工具类
10
36
  */
11
37
  class SFfmpegTool {
12
- /**静态构造函数
13
- */
38
+ /**静态构造函数 */
14
39
  static init() {
15
40
  let ffmpegPath = process.env.FFMPEG_PATH;
16
41
  if (ffmpegPath != null) {
@@ -18,10 +43,9 @@ class SFfmpegTool {
18
43
  SFfmpegTool.setFfmpegPath(exepath);
19
44
  }
20
45
  }
21
- /**设置ffmpeg路径
22
- */
46
+ /**设置ffmpeg路径 */
23
47
  static setFfmpegPath(ffmpegPath) {
24
- fluentFfmpeg.setFfmpegPath(ffmpegPath);
48
+ fluent_ffmpeg_1.default.setFfmpegPath(ffmpegPath);
25
49
  }
26
50
  /**获取音频文件的元数据
27
51
  * @param inputWavPath - 输入音频文件路径
@@ -29,7 +53,7 @@ class SFfmpegTool {
29
53
  */
30
54
  static async getAudioMetaData(inputWavPath) {
31
55
  return new Promise((resolve, reject) => {
32
- fluentFfmpeg.ffprobe(inputWavPath, function (err, metadata) {
56
+ fluent_ffmpeg_1.default.ffprobe(inputWavPath, function (err, metadata) {
33
57
  if (err) {
34
58
  UtilLogger_1.SLogger.error("SFfmpegTool.getAudioMetaData 错误", err);
35
59
  resolve(null);
@@ -48,7 +72,7 @@ class SFfmpegTool {
48
72
  static async flac2ogg(inputFlacFile, outputOggPath, quality = 10) {
49
73
  let wavPath = path.join(path.dirname(inputFlacFile), `tmp_${path.basename(inputFlacFile, ".flac")}.wav`);
50
74
  await new Promise((resolve, reject) => {
51
- fluentFfmpeg(inputFlacFile)
75
+ (0, fluent_ffmpeg_1.default)(inputFlacFile)
52
76
  .audioCodec("pcm_s16le")
53
77
  .save(wavPath)
54
78
  .on("end", function () {
@@ -76,7 +100,7 @@ class SFfmpegTool {
76
100
  //.audioChannels(channels)
77
101
  //.noMetadata()
78
102
  return new Promise((resolve, reject) => {
79
- fluentFfmpeg(inputWavPath)
103
+ (0, fluent_ffmpeg_1.default)(inputWavPath)
80
104
  .audioQuality(quality)
81
105
  .audioCodec("libvorbis")
82
106
  .save(outputOggPath)
@@ -92,7 +116,7 @@ class SFfmpegTool {
92
116
  */
93
117
  static async cutAudio(audioPath, outPath, start, time) {
94
118
  return new Promise((resolve, reject) => {
95
- fluentFfmpeg(audioPath)
119
+ (0, fluent_ffmpeg_1.default)(audioPath)
96
120
  .setStartTime(start)
97
121
  .setDuration(time)
98
122
  .save(outPath)
@@ -108,7 +132,7 @@ class SFfmpegTool {
108
132
  */
109
133
  static async trimSilence(inputWavPath, outputWavPath, threshold = -50, silence = 0.2) {
110
134
  return new Promise((resolve, reject) => {
111
- fluentFfmpeg(inputWavPath)
135
+ (0, fluent_ffmpeg_1.default)(inputWavPath)
112
136
  .audioFilters(`silenceremove=start_periods=1:start_threshold=${threshold}dB:start_silence=${silence}`)
113
137
  .audioFilters("areverse")
114
138
  .audioFilters(`silenceremove=start_periods=1:start_threshold=${threshold}dB:start_silence=${silence}`)
@@ -124,7 +148,7 @@ class SFfmpegTool {
124
148
  */
125
149
  static async resample(inputWavPath, outputWavPath, rate = 22050) {
126
150
  return new Promise((resolve, reject) => {
127
- fluentFfmpeg(inputWavPath)
151
+ (0, fluent_ffmpeg_1.default)(inputWavPath)
128
152
  .audioFrequency(rate)
129
153
  .save(outputWavPath)
130
154
  .on("end", () => resolve(true))
@@ -138,13 +162,12 @@ class SFfmpegTool {
138
162
  * @param cpCount - 并发数
139
163
  */
140
164
  static async wav2oggMP(ioMap, quality = 10, cpCount = 16) {
141
- await new UtilClass_1.SList(Object.entries(ioMap))
142
- .toSStream(cpCount)
165
+ await new UtilClass_1.Stream(Object.entries(ioMap))
143
166
  .map(async ([inPath, outPath]) => {
144
167
  UtilLogger_1.SLogger.info("SFfmpegTool.wav2oggMP 正在处理:" + outPath);
145
168
  await SFfmpegTool.wav2ogg(inPath, outPath, quality);
146
169
  })
147
- .appendOperations();
170
+ .append();
148
171
  }
149
172
  /**flac转ogg多线程
150
173
  * @param ioMap - 输入输出路径映射
@@ -152,13 +175,12 @@ class SFfmpegTool {
152
175
  * @param cpCount - 并发数
153
176
  */
154
177
  static async flac2oggMP(ioMap, quality = 10, cpCount = 16) {
155
- await new UtilClass_1.SList(Object.entries(ioMap))
156
- .toSStream(cpCount)
178
+ await new UtilClass_1.Stream(Object.entries(ioMap))
157
179
  .map(async ([inPath, outPath]) => {
158
180
  UtilLogger_1.SLogger.info("SFfmpegTool.flac2oggMP 正在处理:" + outPath);
159
181
  await SFfmpegTool.flac2ogg(inPath, outPath, quality);
160
182
  })
161
- .appendOperations();
183
+ .append();
162
184
  }
163
185
  /**删除静音多线程
164
186
  * @param ioMap - 输入输出路径映射
@@ -166,13 +188,12 @@ class SFfmpegTool {
166
188
  * @param silence - 保留静音时长
167
189
  */
168
190
  static async trimSilenceMP(ioMap, threshold = -50, silence = 0.2, cpCount = 16) {
169
- await new UtilClass_1.SList(Object.entries(ioMap))
170
- .toSStream(cpCount)
191
+ await new UtilClass_1.Stream(Object.entries(ioMap))
171
192
  .map(async ([inPath, outPath]) => {
172
193
  UtilLogger_1.SLogger.info("SFfmpegTool.trimSilenceMP 正在处理:" + outPath);
173
194
  await SFfmpegTool.trimSilence(inPath, outPath, threshold, silence);
174
195
  })
175
- .appendOperations();
196
+ .append();
176
197
  }
177
198
  /**重采样多线程
178
199
  * @param ioMap - 输入输出路径映射
@@ -180,13 +201,12 @@ class SFfmpegTool {
180
201
  * @param cpCount - 并发数
181
202
  */
182
203
  static async resampleMP(ioMap, rate = 22050, cpCount = 16) {
183
- await new UtilClass_1.SList(Object.entries(ioMap))
184
- .toSStream(cpCount)
204
+ await new UtilClass_1.Stream(Object.entries(ioMap))
185
205
  .map(async ([inPath, outPath]) => {
186
206
  UtilLogger_1.SLogger.info("SFfmpegTool.resampleMP 正在处理:" + outPath);
187
207
  await SFfmpegTool.resample(inPath, outPath, rate);
188
208
  })
189
- .appendOperations();
209
+ .append();
190
210
  }
191
211
  }
192
212
  exports.SFfmpegTool = SFfmpegTool;
@@ -1,10 +1,33 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.UtilFT = void 0;
4
- const fs = require("fs");
5
- const path = require("path");
27
+ const fs = __importStar(require("fs"));
28
+ const path = __importStar(require("path"));
6
29
  const UtilLogger_1 = require("./UtilLogger");
7
- const JSON5 = require("json5");
30
+ const JSON5 = __importStar(require("json5"));
8
31
  const glob_1 = require("glob");
9
32
  const UtilFunctions_1 = require("./UtilFunctions");
10
33
  /**文件工具 */
@@ -103,7 +103,7 @@ export declare class UtilFunc {
103
103
  * @param task - 任务逻辑
104
104
  * @returns 处理结果
105
105
  */
106
- static queueProc<T>(flag: Keyable, task: (() => Promise<T>)): Promise<T>;
106
+ static queueProc<T>(flag: Keyable, task: () => Promise<T>): Promise<T>;
107
107
  /**队列获取目标的代办事件数
108
108
  * @param flag - 队列标签
109
109
  */
@@ -137,6 +137,13 @@ export declare class UtilFunc {
137
137
  * @param strictLog - 应该严格等于None 否则将输出警告 但任然返回true
138
138
  */
139
139
  static likeNone(t: unknown, strictLog?: boolean): t is None;
140
+ /**验证一个值是否为空
141
+ * 为空则抛异
142
+ * @param t - 验证目标
143
+ * @param errLog - 异常信息
144
+ * @returns 排除None的原值
145
+ */
146
+ static expect<T>(t: T, errLog?: string): Exclude<T, None>;
140
147
  /**验证一个变量的类型是否为 T
141
148
  * @template T - 验证类型
142
149
  * @param t - 验证目标
@@ -161,5 +168,9 @@ export declare class UtilFunc {
161
168
  * @returns 是否安全
162
169
  */
163
170
  static isSafeNumber(num: unknown): boolean;
171
+ /**将一个字段加入一个对象中,将改变对象,返回新类型 */
172
+ static bindTo<K extends Keyable, V, B extends {} = {}>(key: LiteralCheck<K>, value: V, base?: B): keyof B extends K ? "Base中已有对应键" & Error : {
173
+ [P in K | keyof B]: P extends K ? V : P extends keyof B ? B[P] : never;
174
+ };
164
175
  }
165
176
  export {};
@@ -1,17 +1,40 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
2
18
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
19
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
20
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
21
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
22
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
23
  };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
8
31
  var __metadata = (this && this.__metadata) || function (k, v) {
9
32
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
33
  };
11
34
  Object.defineProperty(exports, "__esModule", { value: true });
12
35
  exports.UtilFunc = void 0;
13
- const crypto = require("crypto");
14
- const cp = require("child_process");
36
+ const crypto = __importStar(require("crypto"));
37
+ const cp = __importStar(require("child_process"));
15
38
  const UtilLogger_1 = require("./UtilLogger");
16
39
  const UtilSymbol_1 = require("./UtilSymbol");
17
40
  const UtilDecorators_1 = require("./UtilDecorators");
@@ -297,32 +320,48 @@ class UtilFunc {
297
320
  * @param task - 任务逻辑
298
321
  * @returns 处理结果
299
322
  */
300
- static async queueProc(flag, task) {
301
- this.pendingMap[flag] = this.pendingMap[flag] ?? [];
302
- const pending = this.pendingMap[flag];
303
- //尝试解除下个任务的等待
304
- const tryRes = () => {
305
- const thispd = pending;
306
- const resolve = thispd.shift();
307
- if (resolve)
308
- resolve();
323
+ static queueProc(flag, task) {
324
+ // 如果当前标签的队列不存在,则创建一个新的队列
325
+ if (!this.pendingMap[flag])
326
+ this.pendingMap[flag] = [];
327
+ // 创建一个新的Promise,并保存resolve函数以便后续调用
328
+ let resolveFunc;
329
+ const promise = new Promise((resolve) => {
330
+ resolveFunc = resolve;
331
+ });
332
+ // 定义处理任务的函数
333
+ const processTask = async () => {
334
+ let result;
335
+ try {
336
+ // 执行任务并等待结果
337
+ result = await task();
338
+ // 使用保存的resolve函数来解决Promise
339
+ resolveFunc(result);
340
+ }
341
+ catch (error) {
342
+ // 如果任务执行出错,记录错误日志
343
+ UtilLogger_1.SLogger.warn(`queueProc 错误: `, error, `flag: ${String(flag)}`);
344
+ }
345
+ finally {
346
+ // 无论任务是否成功,都从队列中移除当前任务
347
+ this.pendingMap[flag].shift();
348
+ // 如果队列中还有任务,执行下一个任务
349
+ if (this.pendingMap[flag].length > 0) {
350
+ this.pendingMap[flag][0]();
351
+ }
352
+ else {
353
+ // 如果队列中没有任务,删除队列
354
+ delete this.pendingMap[flag];
355
+ }
356
+ }
309
357
  };
310
- //空时直接运行 非空时等待
311
- if (pending.length <= 0)
312
- pending.push(() => tryRes());
313
- else
314
- await new Promise((resolve) => pending.push(resolve));
315
- try {
316
- return await task();
317
- ;
318
- }
319
- catch (e) {
320
- UtilLogger_1.SLogger.fatal(`queuePromise 出现错误`, e);
321
- throw e;
322
- }
323
- finally {
324
- tryRes();
325
- }
358
+ // 将处理任务的函数添加到队列中
359
+ this.pendingMap[flag].push(processTask);
360
+ // 如果队列中只有当前任务,立即执行
361
+ if (this.pendingMap[flag].length === 1)
362
+ processTask();
363
+ // 返回Promise,以便调用者可以等待任务完成
364
+ return promise;
326
365
  }
327
366
  /**队列获取目标的代办事件数
328
367
  * @param flag - 队列标签
@@ -347,15 +386,12 @@ class UtilFunc {
347
386
  if (typeof t === 'string' || typeof t === 'number' || typeof t === 'symbol') {
348
387
  if (procObj[t])
349
388
  return procObj[t](t);
350
- UtilLogger_1.SLogger.fatal(`matchProc 传入了一个预料之外的值: `, t);
351
- throw UtilSymbol_1.None;
352
- }
353
- else {
354
- if (procObj[t.status])
355
- return procObj[t.status](t.status, t.result);
356
- UtilLogger_1.SLogger.fatal(`matchProc 传入了一个预料之外的值: `, t);
357
- throw UtilSymbol_1.None;
358
389
  }
390
+ else if (procObj[t.status])
391
+ return procObj[t.status](t.status, t.result);
392
+ const err = new Error(`matchProc 传入了一个预料之外的值: ${String(t)}`);
393
+ UtilLogger_1.SLogger.fatal(err);
394
+ throw err;
359
395
  }
360
396
  /**根据典型的成功或失败状态运行函数
361
397
  * @param t - 目标值
@@ -405,6 +441,17 @@ class UtilFunc {
405
441
  UtilLogger_1.SLogger.warn(`输入值不严格等于 None , 已作为 None 处理`, `具体类型: ${t}`);
406
442
  return t == null;
407
443
  }
444
+ /**验证一个值是否为空
445
+ * 为空则抛异
446
+ * @param t - 验证目标
447
+ * @param errLog - 异常信息
448
+ * @returns 排除None的原值
449
+ */
450
+ static expect(t, errLog) {
451
+ if (t === UtilSymbol_1.None)
452
+ throw new Error(errLog);
453
+ return t;
454
+ }
408
455
  /**验证一个变量的类型是否为 T
409
456
  * @template T - 验证类型
410
457
  * @param t - 验证目标
@@ -440,6 +487,13 @@ class UtilFunc {
440
487
  }
441
488
  return false;
442
489
  }
490
+ /**将一个字段加入一个对象中,将改变对象,返回新类型 */
491
+ static bindTo(key, value, base) {
492
+ let out = base;
493
+ out = out ?? {};
494
+ out[key] = value;
495
+ return out;
496
+ }
443
497
  }
444
498
  exports.UtilFunc = UtilFunc;
445
499
  __decorate([
@@ -29,6 +29,10 @@ export type PartialOption<B, D> = keyof D extends keyof B ? Omit<B, keyof D> & P
29
29
  export type ProperSubset<B, T = B> = T extends B ? B extends T ? never : T : never;
30
30
  /**字面量检测 */
31
31
  export type LiteralCheck<L> = ProperSubset<string, L> | ProperSubset<number, L> | ProperSubset<boolean, L> | ProperSubset<symbol, L> | ProperSubset<any[], L> | ProperSubset<Record<any, any>, L> | null | undefined;
32
+ /**返回将Mixin分配给Base的结果,相同字段时Mixin覆盖Base */
33
+ export type AssignObject<Base extends {}, Mixin extends {}> = {
34
+ [P in keyof Mixin | keyof Base]: P extends keyof Mixin ? Mixin[P] : P extends keyof Base ? Base[P] : never;
35
+ };
32
36
  /**转为可写的 */
33
37
  export type Writeable<T> = {
34
38
  -readonly [P in keyof T]: T[P];