@zwa73/utils 1.0.111 → 1.0.113
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.
- package/dist/QuickFunction.d.ts +1 -1
- package/dist/QuickFunction.js +2 -2
- package/dist/UtilFunctions.d.ts +11 -5
- package/dist/UtilFunctions.js +24 -15
- package/package.json +2 -2
- package/scripts/postinstall.js +1 -1
- package/src/QuickFunction.ts +0 -1
- package/src/UtilFunctions.ts +37 -22
package/dist/QuickFunction.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { UtilFunc } from "./UtilFunctions";
|
|
2
|
-
export declare const outcome: typeof UtilFunc.outcome, matchProc: typeof UtilFunc.matchProc, sucesProc: typeof UtilFunc.sucesProc, isFailed: typeof UtilFunc.isFailed, isSafeNumber: typeof UtilFunc.isSafeNumber, isSuccess: typeof UtilFunc.isSuccess, likeNone: typeof UtilFunc.likeNone, expect: typeof UtilFunc.expect, assertType: typeof UtilFunc.assertType, assertLiteral: typeof UtilFunc.assertLiteral, deepClone: typeof UtilFunc.deepClone, sleep: typeof UtilFunc.sleep, stringifyJToken: typeof UtilFunc.stringifyJToken, getTime: typeof UtilFunc.getTime, mapEntries: typeof UtilFunc.mapEntries,
|
|
2
|
+
export declare const outcome: typeof UtilFunc.outcome, matchProc: typeof UtilFunc.matchProc, sucesProc: typeof UtilFunc.sucesProc, isFailed: typeof UtilFunc.isFailed, isSafeNumber: typeof UtilFunc.isSafeNumber, isSuccess: typeof UtilFunc.isSuccess, likeNone: typeof UtilFunc.likeNone, expect: typeof UtilFunc.expect, assertType: typeof UtilFunc.assertType, assertLiteral: typeof UtilFunc.assertLiteral, deepClone: typeof UtilFunc.deepClone, sleep: typeof UtilFunc.sleep, stringifyJToken: typeof UtilFunc.stringifyJToken, getTime: typeof UtilFunc.getTime, mapEntries: typeof UtilFunc.mapEntries, dedent: typeof UtilFunc.dedent, throwError: typeof UtilFunc.throwError;
|
package/dist/QuickFunction.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwError = exports.dedent = exports.
|
|
3
|
+
exports.throwError = exports.dedent = exports.mapEntries = exports.getTime = exports.stringifyJToken = exports.sleep = exports.deepClone = exports.assertLiteral = exports.assertType = exports.expect = exports.likeNone = exports.isSuccess = exports.isSafeNumber = exports.isFailed = exports.sucesProc = exports.matchProc = exports.outcome = void 0;
|
|
4
4
|
const UtilFunctions_1 = require("./UtilFunctions");
|
|
5
5
|
const UtilSymbol_1 = require("./UtilSymbol");
|
|
6
|
-
exports.outcome = UtilFunctions_1.UtilFunc.outcome, exports.matchProc = UtilFunctions_1.UtilFunc.matchProc, exports.sucesProc = UtilFunctions_1.UtilFunc.sucesProc, exports.isFailed = UtilFunctions_1.UtilFunc.isFailed, exports.isSafeNumber = UtilFunctions_1.UtilFunc.isSafeNumber, exports.isSuccess = UtilFunctions_1.UtilFunc.isSuccess, exports.likeNone = UtilFunctions_1.UtilFunc.likeNone, exports.expect = UtilFunctions_1.UtilFunc.expect, 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.
|
|
6
|
+
exports.outcome = UtilFunctions_1.UtilFunc.outcome, exports.matchProc = UtilFunctions_1.UtilFunc.matchProc, exports.sucesProc = UtilFunctions_1.UtilFunc.sucesProc, exports.isFailed = UtilFunctions_1.UtilFunc.isFailed, exports.isSafeNumber = UtilFunctions_1.UtilFunc.isSafeNumber, exports.isSuccess = UtilFunctions_1.UtilFunc.isSuccess, exports.likeNone = UtilFunctions_1.UtilFunc.likeNone, exports.expect = UtilFunctions_1.UtilFunc.expect, 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;
|
|
7
7
|
if (false) {
|
|
8
8
|
let aaser = (0, exports.assertLiteral)({ a: 1 });
|
|
9
9
|
let a = null;
|
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ import { LogLevel } from "./UtilLogger";
|
|
|
3
3
|
import { FailedLike, None, StatusSymbol, Success, SuccessLike, Timeout } from "./UtilSymbol";
|
|
4
4
|
declare const HashMethodList: readonly ["md5", "sha1", "sha256", "sha512", "sha3", "blake2", "blake3"];
|
|
5
5
|
type HashMethod = typeof HashMethodList[number];
|
|
6
|
+
/**执行选项 */
|
|
7
|
+
type ExecOpt = Partial<{
|
|
8
|
+
outlvl: LogLevel;
|
|
9
|
+
errlvl: LogLevel;
|
|
10
|
+
}>;
|
|
6
11
|
type SuccessOut<T> = Outcome<Success, T>;
|
|
7
12
|
type TimeoutOut<T> = Outcome<Timeout, Promise<T>>;
|
|
8
13
|
/**常用函数 */
|
|
@@ -14,7 +19,7 @@ export declare class UtilFunc {
|
|
|
14
19
|
/**初始化对象的字段
|
|
15
20
|
* 会改变obj
|
|
16
21
|
* @param obj - 所要初始化的对象
|
|
17
|
-
* @param field
|
|
22
|
+
* @param field - 所要初始化的字段
|
|
18
23
|
* @param defaultVal - 默认值
|
|
19
24
|
* @returns 最终值
|
|
20
25
|
*/
|
|
@@ -50,12 +55,13 @@ export declare class UtilFunc {
|
|
|
50
55
|
* @returns
|
|
51
56
|
*/
|
|
52
57
|
static sleep<T>(timeMs: number, result: T): Promise<T>;
|
|
53
|
-
/**封装的 cp.
|
|
58
|
+
/**封装的 cp.spawn 执行一段指令,指令运行时实时返回输出
|
|
54
59
|
* @param command - 指令文本
|
|
55
|
-
* @param
|
|
56
|
-
* @param
|
|
60
|
+
* @param opt - 可选参数
|
|
61
|
+
* @param opt.outlvl - 普通输出的日志等级
|
|
62
|
+
* @param opt.errlvl - 错误的日志等级
|
|
57
63
|
*/
|
|
58
|
-
static exec(command: string,
|
|
64
|
+
static exec(command: string, opt?: ExecOpt): Promise<{
|
|
59
65
|
stdout: string;
|
|
60
66
|
stderr: string;
|
|
61
67
|
}>;
|
package/dist/UtilFunctions.js
CHANGED
|
@@ -52,7 +52,7 @@ class UtilFunc {
|
|
|
52
52
|
/**初始化对象的字段
|
|
53
53
|
* 会改变obj
|
|
54
54
|
* @param obj - 所要初始化的对象
|
|
55
|
-
* @param field
|
|
55
|
+
* @param field - 所要初始化的字段
|
|
56
56
|
* @param defaultVal - 默认值
|
|
57
57
|
* @returns 最终值
|
|
58
58
|
*/
|
|
@@ -103,23 +103,32 @@ class UtilFunc {
|
|
|
103
103
|
}, timeMs);
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
|
-
/**封装的 cp.
|
|
106
|
+
/**封装的 cp.spawn 执行一段指令,指令运行时实时返回输出
|
|
107
107
|
* @param command - 指令文本
|
|
108
|
-
* @param
|
|
109
|
-
* @param
|
|
108
|
+
* @param opt - 可选参数
|
|
109
|
+
* @param opt.outlvl - 普通输出的日志等级
|
|
110
|
+
* @param opt.errlvl - 错误的日志等级
|
|
110
111
|
*/
|
|
111
|
-
static exec(command,
|
|
112
|
+
static exec(command, opt) {
|
|
112
113
|
return new Promise((resolve, reject) => {
|
|
113
|
-
cp.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
114
|
+
const child = cp.spawn(command, { shell: true });
|
|
115
|
+
let stdout = '';
|
|
116
|
+
let stderr = '';
|
|
117
|
+
child.stdout.on('data', (data) => {
|
|
118
|
+
stdout += data;
|
|
119
|
+
if (opt?.outlvl)
|
|
120
|
+
UtilLogger_1.SLogger.log(opt?.outlvl, data.toString());
|
|
121
|
+
});
|
|
122
|
+
child.stderr.on('data', (data) => {
|
|
123
|
+
stderr += data;
|
|
124
|
+
if (opt?.errlvl)
|
|
125
|
+
UtilLogger_1.SLogger.log(opt?.errlvl, data.toString());
|
|
126
|
+
});
|
|
127
|
+
child.on('error', reject);
|
|
128
|
+
child.on('close', (code) => {
|
|
129
|
+
if (code !== 0)
|
|
130
|
+
UtilLogger_1.SLogger.warn(`UtilFunc.exec 命令:"${command}" 结束 代码为:${code}`);
|
|
131
|
+
resolve({ stdout, stderr });
|
|
123
132
|
});
|
|
124
133
|
});
|
|
125
134
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zwa73/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.113",
|
|
4
4
|
"description": "my utils",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/jest": "^29.5.12",
|
|
34
34
|
"@types/node": "^18.16.3",
|
|
35
|
-
"@zwa73/dev-utils": "^1.0.
|
|
35
|
+
"@zwa73/dev-utils": "^1.0.22",
|
|
36
36
|
"jest": "^29.7.0",
|
|
37
37
|
"ts-jest": "^29.1.2",
|
|
38
38
|
"tsc-alias": "^1.8.8",
|
package/scripts/postinstall.js
CHANGED
|
@@ -56,7 +56,7 @@ async function main(){
|
|
|
56
56
|
const hasOut = showUpgradeMessages(prevVersion, currentVersion);
|
|
57
57
|
|
|
58
58
|
versionTable.utils.version = currentVersion;
|
|
59
|
-
await UtilFT.writeJSONFile(
|
|
59
|
+
await UtilFT.writeJSONFile(VERSION_PATH, versionTable);
|
|
60
60
|
|
|
61
61
|
if(!hasOut) return;
|
|
62
62
|
const rl = readline.createInterface({
|
package/src/QuickFunction.ts
CHANGED
package/src/UtilFunctions.ts
CHANGED
|
@@ -8,6 +8,12 @@ import { Catch, DeferAsync, LogTimeAsync } from "./UtilDecorators";
|
|
|
8
8
|
const HashMethodList = ["md5","sha1","sha256","sha512","sha3","blake2","blake3"] as const;
|
|
9
9
|
type HashMethod = typeof HashMethodList[number];
|
|
10
10
|
|
|
11
|
+
/**执行选项 */
|
|
12
|
+
type ExecOpt = Partial<{
|
|
13
|
+
outlvl:LogLevel,
|
|
14
|
+
errlvl:LogLevel,
|
|
15
|
+
}>
|
|
16
|
+
|
|
11
17
|
type SuccessOut<T> = Outcome<Success,T>;
|
|
12
18
|
type TimeoutOut<T> = Outcome<Timeout,Promise<T>>;
|
|
13
19
|
/**永不完成的Promise单例 */
|
|
@@ -33,7 +39,7 @@ static getTime(): number {
|
|
|
33
39
|
/**初始化对象的字段
|
|
34
40
|
* 会改变obj
|
|
35
41
|
* @param obj - 所要初始化的对象
|
|
36
|
-
* @param field
|
|
42
|
+
* @param field - 所要初始化的字段
|
|
37
43
|
* @param defaultVal - 默认值
|
|
38
44
|
* @returns 最终值
|
|
39
45
|
*/
|
|
@@ -105,26 +111,35 @@ static async sleep<T>(timeMs: number, result?:T): Promise<T|undefined> {
|
|
|
105
111
|
});
|
|
106
112
|
}
|
|
107
113
|
|
|
108
|
-
/**封装的 cp.
|
|
114
|
+
/**封装的 cp.spawn 执行一段指令,指令运行时实时返回输出
|
|
109
115
|
* @param command - 指令文本
|
|
110
|
-
* @param
|
|
111
|
-
* @param
|
|
116
|
+
* @param opt - 可选参数
|
|
117
|
+
* @param opt.outlvl - 普通输出的日志等级
|
|
118
|
+
* @param opt.errlvl - 错误的日志等级
|
|
112
119
|
*/
|
|
113
|
-
static exec(command: string,
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
}
|
|
120
|
+
static exec(command: string, opt?:ExecOpt) {
|
|
121
|
+
return new Promise<{ stdout: string, stderr: string }>((resolve, reject) => {
|
|
122
|
+
const child = cp.spawn(command,{shell:true});
|
|
123
|
+
|
|
124
|
+
let stdout = '';
|
|
125
|
+
let stderr = '';
|
|
126
|
+
|
|
127
|
+
child.stdout.on('data', (data) => {
|
|
128
|
+
stdout += data;
|
|
129
|
+
if (opt?.outlvl) SLogger.log(opt?.outlvl, data.toString());
|
|
130
|
+
});
|
|
127
131
|
|
|
132
|
+
child.stderr.on('data', (data) => {
|
|
133
|
+
stderr += data;
|
|
134
|
+
if (opt?.errlvl) SLogger.log(opt?.errlvl, data.toString());
|
|
135
|
+
});
|
|
136
|
+
child.on('error', reject);
|
|
137
|
+
child.on('close', (code) => {
|
|
138
|
+
if (code!==0) SLogger.warn(`UtilFunc.exec 命令:"${command}" 结束 代码为:${code}`);
|
|
139
|
+
resolve({ stdout, stderr });
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
128
143
|
|
|
129
144
|
/**获得一个永不完成的Promise单例 */
|
|
130
145
|
static getNeverResolvedPromise<T>():Promise<T>{
|
|
@@ -153,7 +168,7 @@ static async repeatPromise<T>(procFn:()=>Promise<T>,verifyFn?:PromiseVerifyFn<T>
|
|
|
153
168
|
verifyFn = ()=>Success;
|
|
154
169
|
|
|
155
170
|
//进行中的请求
|
|
156
|
-
|
|
171
|
+
const plist:Promise<
|
|
157
172
|
SuccessOut<PromiseResult<T>>|
|
|
158
173
|
TimeoutOut<PromiseResult<T>>
|
|
159
174
|
>[] = [];
|
|
@@ -377,9 +392,9 @@ static mapEntries<T extends object>
|
|
|
377
392
|
* @returns 转换完成的字符串
|
|
378
393
|
*/
|
|
379
394
|
static stringifyJToken(token:JToken|IJData,space:string|number|null|undefined="\t"){
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
395
|
+
if(space==null)
|
|
396
|
+
space=undefined;
|
|
397
|
+
return JSON.stringify(token,null,space);
|
|
383
398
|
}
|
|
384
399
|
|
|
385
400
|
/**代办表 用于队列处理等待 */
|