@zwa73/utils 1.0.57 → 1.0.61
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/UtilCodecs.d.ts +16 -16
- package/dist/UtilCodecs.js +16 -16
- package/dist/UtilCom.d.ts +22 -25
- package/dist/UtilCom.js +35 -38
- package/dist/UtilDecorators.d.ts +15 -8
- package/dist/UtilDecorators.js +79 -25
- package/dist/UtilFP.d.ts +46 -0
- package/dist/UtilFP.js +52 -0
- package/dist/UtilFfmpegTools.d.ts +30 -30
- package/dist/UtilFfmpegTools.js +32 -32
- package/dist/UtilFileTools.d.ts +30 -35
- package/dist/UtilFileTools.js +17 -18
- package/dist/UtilFunctions.d.ts +37 -78
- package/dist/UtilFunctions.js +27 -62
- package/dist/UtilInterfaces.d.ts +11 -11
- package/dist/UtilInterfaces.js +2 -2
- package/dist/UtilLogger.d.ts +55 -55
- package/dist/UtilLogger.js +55 -55
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/test/composeTest.d.ts +21 -0
- package/dist/test/composeTest.js +33 -0
- package/dist/test/importtest.d.ts +1 -0
- package/dist/test/importtest.js +4 -0
- package/dist/test/test.js +5 -3
- package/package.json +2 -2
- package/src/UtilClass.ts +1051 -1051
- package/src/UtilCodecs.ts +117 -117
- package/src/UtilCom.ts +171 -174
- package/src/UtilDecorators.ts +174 -116
- package/src/UtilFP.ts +98 -0
- package/src/UtilFfmpegTools.ts +271 -271
- package/src/UtilFileTools.ts +231 -236
- package/src/UtilFunctions.ts +289 -364
- package/src/UtilInterfaces.ts +137 -137
- package/src/UtilLogger.ts +386 -386
- package/src/index.ts +10 -9
- package/src/test/composeTest.ts +37 -0
- package/src/test/importtest.ts +5 -0
- package/src/test/test.ts +8 -6
- package/src/test/test2.ts +2 -3
- package/tsconfig.json +2 -7
package/dist/UtilCodecs.d.ts
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
/**编码/解码器 */
|
|
2
2
|
export declare namespace UtilCodec {
|
|
3
3
|
/**HTML实体解码 将一个字符串中的HTML实体转换为对应的字符
|
|
4
|
-
* @param
|
|
5
|
-
* @returns
|
|
4
|
+
* @param str - 要转换的字符串
|
|
5
|
+
* @returns 转换后的字符串
|
|
6
6
|
*/
|
|
7
7
|
function decodeHtmlEntities(str: string): string;
|
|
8
8
|
/**HTML实体编码 将一个字符串中的 需编码字符转换为 HTML实体
|
|
9
|
-
* @param
|
|
10
|
-
* @returns
|
|
9
|
+
* @param str - 要转换的字符串
|
|
10
|
+
* @returns 转换后的字符串
|
|
11
11
|
*/
|
|
12
12
|
function encodeHtmlEntities(str: string): string;
|
|
13
13
|
/**token长度计算器 Turbo模型
|
|
14
|
-
* @param
|
|
15
|
-
* @returns
|
|
14
|
+
* @param str = 所要计算的消息
|
|
15
|
+
* @returns 整数长度结果
|
|
16
16
|
*/
|
|
17
17
|
function tokenNumTurbo(str: string): number;
|
|
18
18
|
/**token长度计算器 Davinci模型
|
|
19
|
-
* @param
|
|
20
|
-
* @returns
|
|
19
|
+
* @param str = 所要计算的消息
|
|
20
|
+
* @returns 整数长度结果
|
|
21
21
|
*/
|
|
22
22
|
function tokenNumDavinci(str: string): number;
|
|
23
23
|
/**token编码 Turbo模型
|
|
24
|
-
* @param
|
|
25
|
-
* @returns
|
|
24
|
+
* @param str = 所要计算的消息
|
|
25
|
+
* @returns Token数组
|
|
26
26
|
*/
|
|
27
27
|
function encodeTokenTurbo(str: string): Uint32Array;
|
|
28
28
|
/**token编码 Davinci模型
|
|
29
|
-
* @param
|
|
30
|
-
* @returns
|
|
29
|
+
* @param str = 所要计算的消息
|
|
30
|
+
* @returns Token数组
|
|
31
31
|
*/
|
|
32
32
|
function encodeTokenDavinci(str: string): Uint32Array;
|
|
33
33
|
/**token解码 Turbo模型
|
|
34
|
-
* @param
|
|
35
|
-
* @returns
|
|
34
|
+
* @param arr = Token数组
|
|
35
|
+
* @returns 消息字符串
|
|
36
36
|
*/
|
|
37
37
|
function decodeTokenTurbo(arr: Uint32Array): string;
|
|
38
38
|
/**token解码 Davinci模型
|
|
39
|
-
* @param
|
|
40
|
-
* @returns
|
|
39
|
+
* @param arr = Token数组
|
|
40
|
+
* @returns 消息字符串
|
|
41
41
|
*/
|
|
42
42
|
function decodeTokenDavinci(arr: Uint32Array): string;
|
|
43
43
|
}
|
package/dist/UtilCodecs.js
CHANGED
|
@@ -20,8 +20,8 @@ var UtilCodec;
|
|
|
20
20
|
"]": "]"
|
|
21
21
|
};
|
|
22
22
|
/**HTML实体解码 将一个字符串中的HTML实体转换为对应的字符
|
|
23
|
-
* @param
|
|
24
|
-
* @returns
|
|
23
|
+
* @param str - 要转换的字符串
|
|
24
|
+
* @returns 转换后的字符串
|
|
25
25
|
*/
|
|
26
26
|
function decodeHtmlEntities(str) {
|
|
27
27
|
//for(let code in htmlEntities){
|
|
@@ -33,8 +33,8 @@ var UtilCodec;
|
|
|
33
33
|
}
|
|
34
34
|
UtilCodec.decodeHtmlEntities = decodeHtmlEntities;
|
|
35
35
|
/**HTML实体编码 将一个字符串中的 需编码字符转换为 HTML实体
|
|
36
|
-
* @param
|
|
37
|
-
* @returns
|
|
36
|
+
* @param str - 要转换的字符串
|
|
37
|
+
* @returns 转换后的字符串
|
|
38
38
|
*/
|
|
39
39
|
function encodeHtmlEntities(str) {
|
|
40
40
|
//for(let code in htmlEntities){
|
|
@@ -57,8 +57,8 @@ var UtilCodec;
|
|
|
57
57
|
encoderDavinci = (0, tiktoken_1.get_encoding)("p50k_base");
|
|
58
58
|
}
|
|
59
59
|
/**token长度计算器 Turbo模型
|
|
60
|
-
* @param
|
|
61
|
-
* @returns
|
|
60
|
+
* @param str = 所要计算的消息
|
|
61
|
+
* @returns 整数长度结果
|
|
62
62
|
*/
|
|
63
63
|
function tokenNumTurbo(str) {
|
|
64
64
|
initTikTokenEncoder();
|
|
@@ -67,8 +67,8 @@ var UtilCodec;
|
|
|
67
67
|
}
|
|
68
68
|
UtilCodec.tokenNumTurbo = tokenNumTurbo;
|
|
69
69
|
/**token长度计算器 Davinci模型
|
|
70
|
-
* @param
|
|
71
|
-
* @returns
|
|
70
|
+
* @param str = 所要计算的消息
|
|
71
|
+
* @returns 整数长度结果
|
|
72
72
|
*/
|
|
73
73
|
function tokenNumDavinci(str) {
|
|
74
74
|
initTikTokenEncoder();
|
|
@@ -76,8 +76,8 @@ var UtilCodec;
|
|
|
76
76
|
}
|
|
77
77
|
UtilCodec.tokenNumDavinci = tokenNumDavinci;
|
|
78
78
|
/**token编码 Turbo模型
|
|
79
|
-
* @param
|
|
80
|
-
* @returns
|
|
79
|
+
* @param str = 所要计算的消息
|
|
80
|
+
* @returns Token数组
|
|
81
81
|
*/
|
|
82
82
|
function encodeTokenTurbo(str) {
|
|
83
83
|
initTikTokenEncoder();
|
|
@@ -85,8 +85,8 @@ var UtilCodec;
|
|
|
85
85
|
}
|
|
86
86
|
UtilCodec.encodeTokenTurbo = encodeTokenTurbo;
|
|
87
87
|
/**token编码 Davinci模型
|
|
88
|
-
* @param
|
|
89
|
-
* @returns
|
|
88
|
+
* @param str = 所要计算的消息
|
|
89
|
+
* @returns Token数组
|
|
90
90
|
*/
|
|
91
91
|
function encodeTokenDavinci(str) {
|
|
92
92
|
initTikTokenEncoder();
|
|
@@ -94,8 +94,8 @@ var UtilCodec;
|
|
|
94
94
|
}
|
|
95
95
|
UtilCodec.encodeTokenDavinci = encodeTokenDavinci;
|
|
96
96
|
/**token解码 Turbo模型
|
|
97
|
-
* @param
|
|
98
|
-
* @returns
|
|
97
|
+
* @param arr = Token数组
|
|
98
|
+
* @returns 消息字符串
|
|
99
99
|
*/
|
|
100
100
|
function decodeTokenTurbo(arr) {
|
|
101
101
|
initTikTokenEncoder();
|
|
@@ -103,8 +103,8 @@ var UtilCodec;
|
|
|
103
103
|
}
|
|
104
104
|
UtilCodec.decodeTokenTurbo = decodeTokenTurbo;
|
|
105
105
|
/**token解码 Davinci模型
|
|
106
|
-
* @param
|
|
107
|
-
* @returns
|
|
106
|
+
* @param arr = Token数组
|
|
107
|
+
* @returns 消息字符串
|
|
108
108
|
*/
|
|
109
109
|
function decodeTokenDavinci(arr) {
|
|
110
110
|
initTikTokenEncoder();
|
package/dist/UtilCom.d.ts
CHANGED
|
@@ -2,45 +2,42 @@ import { JObject, PromiseVerifyFn } from "./UtilInterfaces";
|
|
|
2
2
|
/**网络工具 */
|
|
3
3
|
export declare namespace UtilCom {
|
|
4
4
|
/**发送一个 https POST请求并接受数据
|
|
5
|
-
* Object ()
|
|
6
5
|
* @async
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
10
|
-
* @returns
|
|
6
|
+
* @param json - 数据对象
|
|
7
|
+
* @param options - 参数对象
|
|
8
|
+
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
9
|
+
* @returns 结果 null 为未能成功接收
|
|
11
10
|
*/
|
|
12
11
|
function shttpsPost(json: JObject, options: Object, timeLimit?: number): Promise<JObject | null>;
|
|
13
12
|
/**发送一个 http POST请求并接受数据
|
|
14
|
-
* Object ()
|
|
15
13
|
* @async
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
* @returns
|
|
14
|
+
* @param json - 数据对象
|
|
15
|
+
* @param options - 参数对象
|
|
16
|
+
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
17
|
+
* @returns 结果 null 为未能成功接收
|
|
20
18
|
*/
|
|
21
19
|
function shttpPost(json: JObject, options: Object, timeLimit?: number): Promise<JObject | null>;
|
|
22
20
|
/**重复一个 https POST请求并接受数据
|
|
23
|
-
* Object ()
|
|
24
21
|
* @async
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @returns
|
|
22
|
+
* @param json - 数据对象
|
|
23
|
+
* @param options - 参数对象
|
|
24
|
+
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
25
|
+
* @param repeatCount - 重试次数
|
|
26
|
+
* @param repeatTime - 超时时间/秒 最小为10秒
|
|
27
|
+
* @param verifyFn - 判断有效性函数
|
|
28
|
+
* @returns 结果 null 为未能成功接收
|
|
32
29
|
*/
|
|
33
30
|
function shttpsRepeatPost(json: JObject, options: Object, timeLimit?: number, repeatCount?: number, repeatTime?: number, verifyFn?: PromiseVerifyFn<JObject | null>): Promise<JObject | null>;
|
|
34
31
|
/**重复一个 http POST请求并接受数据
|
|
35
32
|
* Object ()
|
|
36
33
|
* @async
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
43
|
-
* @returns
|
|
34
|
+
* @param json - 数据对象
|
|
35
|
+
* @param options - 参数对象
|
|
36
|
+
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
37
|
+
* @param repeatCount - 重试次数
|
|
38
|
+
* @param repeatTime - 超时时间/秒 最小为10秒
|
|
39
|
+
* @param verifyFn - 判断有效性函数
|
|
40
|
+
* @returns 结果 null 为未能成功接收
|
|
44
41
|
*/
|
|
45
42
|
function shttpRepeatPost(json: JObject, options: Object, timeLimit?: number, repeatCount?: number, repeatTime?: number, verifyFn?: PromiseVerifyFn<JObject | null>): Promise<JObject | null>;
|
|
46
43
|
}
|
package/dist/UtilCom.js
CHANGED
|
@@ -10,11 +10,11 @@ const UtilFunctions_1 = require("./UtilFunctions");
|
|
|
10
10
|
var UtilCom;
|
|
11
11
|
(function (UtilCom) {
|
|
12
12
|
/**通用post处理
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @returns
|
|
13
|
+
* @param posttype - post类型
|
|
14
|
+
* @param json - 数据对象
|
|
15
|
+
* @param options - 参数对象
|
|
16
|
+
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
17
|
+
* @returns 结果 null 为未能成功接收
|
|
18
18
|
*/
|
|
19
19
|
function sPost(posttype, json, options, timeLimit = -1) {
|
|
20
20
|
//转换为毫秒
|
|
@@ -90,24 +90,22 @@ var UtilCom;
|
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
/**发送一个 https POST请求并接受数据
|
|
93
|
-
* Object ()
|
|
94
93
|
* @async
|
|
95
|
-
* @param
|
|
96
|
-
* @param
|
|
97
|
-
* @param
|
|
98
|
-
* @returns
|
|
94
|
+
* @param json - 数据对象
|
|
95
|
+
* @param options - 参数对象
|
|
96
|
+
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
97
|
+
* @returns 结果 null 为未能成功接收
|
|
99
98
|
*/
|
|
100
99
|
function shttpsPost(json, options, timeLimit = -1) {
|
|
101
100
|
return sPost("https", json, options, timeLimit);
|
|
102
101
|
}
|
|
103
102
|
UtilCom.shttpsPost = shttpsPost;
|
|
104
103
|
/**发送一个 http POST请求并接受数据
|
|
105
|
-
* Object ()
|
|
106
104
|
* @async
|
|
107
|
-
* @param
|
|
108
|
-
* @param
|
|
109
|
-
* @param
|
|
110
|
-
* @returns
|
|
105
|
+
* @param json - 数据对象
|
|
106
|
+
* @param options - 参数对象
|
|
107
|
+
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
108
|
+
* @returns 结果 null 为未能成功接收
|
|
111
109
|
*/
|
|
112
110
|
function shttpPost(json, options, timeLimit = -1) {
|
|
113
111
|
return sPost("http", json, options, timeLimit);
|
|
@@ -115,29 +113,28 @@ var UtilCom;
|
|
|
115
113
|
UtilCom.shttpPost = shttpPost;
|
|
116
114
|
/**通用重复post处理
|
|
117
115
|
* @async
|
|
118
|
-
* @param
|
|
119
|
-
* @param
|
|
120
|
-
* @param
|
|
121
|
-
* @param
|
|
122
|
-
* @param
|
|
123
|
-
* @param
|
|
124
|
-
* @param
|
|
125
|
-
* @returns
|
|
116
|
+
* @param posttype - post类型
|
|
117
|
+
* @param json - 数据对象
|
|
118
|
+
* @param options - 参数对象
|
|
119
|
+
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
120
|
+
* @param repeatCount - 重试次数
|
|
121
|
+
* @param repeatTime - 超时时间/秒 最小为10秒
|
|
122
|
+
* @param verifyFn - 判断有效性函数
|
|
123
|
+
* @returns 结果 null 为未能成功接收
|
|
126
124
|
*/
|
|
127
125
|
async function sRepeatPost(posttype, json, options, timeLimit = -1, repeatCount = 3, repeatTime = 180, verifyFn) {
|
|
128
126
|
const procFn = () => sPost(posttype, json, options, timeLimit);
|
|
129
127
|
return UtilFunctions_1.UtilFunc.repeatPromise(procFn, verifyFn, repeatCount, repeatTime);
|
|
130
128
|
}
|
|
131
129
|
/**重复一个 https POST请求并接受数据
|
|
132
|
-
* Object ()
|
|
133
130
|
* @async
|
|
134
|
-
* @param
|
|
135
|
-
* @param
|
|
136
|
-
* @param
|
|
137
|
-
* @param
|
|
138
|
-
* @param
|
|
139
|
-
* @param
|
|
140
|
-
* @returns
|
|
131
|
+
* @param json - 数据对象
|
|
132
|
+
* @param options - 参数对象
|
|
133
|
+
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
134
|
+
* @param repeatCount - 重试次数
|
|
135
|
+
* @param repeatTime - 超时时间/秒 最小为10秒
|
|
136
|
+
* @param verifyFn - 判断有效性函数
|
|
137
|
+
* @returns 结果 null 为未能成功接收
|
|
141
138
|
*/
|
|
142
139
|
function shttpsRepeatPost(json, options, timeLimit = -1, repeatCount = 3, repeatTime = 180, verifyFn) {
|
|
143
140
|
return sRepeatPost("https", json, options, timeLimit, repeatCount, repeatTime, verifyFn);
|
|
@@ -146,13 +143,13 @@ var UtilCom;
|
|
|
146
143
|
/**重复一个 http POST请求并接受数据
|
|
147
144
|
* Object ()
|
|
148
145
|
* @async
|
|
149
|
-
* @param
|
|
150
|
-
* @param
|
|
151
|
-
* @param
|
|
152
|
-
* @param
|
|
153
|
-
* @param
|
|
154
|
-
* @param
|
|
155
|
-
* @returns
|
|
146
|
+
* @param json - 数据对象
|
|
147
|
+
* @param options - 参数对象
|
|
148
|
+
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
149
|
+
* @param repeatCount - 重试次数
|
|
150
|
+
* @param repeatTime - 超时时间/秒 最小为10秒
|
|
151
|
+
* @param verifyFn - 判断有效性函数
|
|
152
|
+
* @returns 结果 null 为未能成功接收
|
|
156
153
|
*/
|
|
157
154
|
function shttpRepeatPost(json, options, timeLimit = -1, repeatCount = 3, repeatTime = 180, verifyFn) {
|
|
158
155
|
return sRepeatPost("http", json, options, timeLimit, repeatCount, repeatTime, verifyFn);
|
package/dist/UtilDecorators.d.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
type TDTg<T> = (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>;
|
|
2
|
+
type DTg = (target: Object, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
1
3
|
/**用于打印方法的调用 */
|
|
2
|
-
export declare function
|
|
4
|
+
export declare function LogCall(): DTg;
|
|
3
5
|
/**用于打印异步方法的调用 */
|
|
4
|
-
export declare function
|
|
6
|
+
export declare function LogCallAsync(): DTg;
|
|
7
|
+
/**用于打印方法的调用 */
|
|
8
|
+
export declare function LogErr(): DTg;
|
|
9
|
+
/**用于打印异步方法的调用 */
|
|
10
|
+
export declare function LogErrAsync(): DTg;
|
|
5
11
|
/**try-finally包装 */
|
|
6
|
-
export declare function Defer(
|
|
12
|
+
export declare function Defer<T extends (...args: any) => any>(deferLogic: (...args: Parameters<T>) => any): TDTg<T>;
|
|
7
13
|
/**异步的try-finally包装 */
|
|
8
|
-
export declare function DeferAsync(
|
|
9
|
-
|
|
10
|
-
export declare function
|
|
11
|
-
|
|
12
|
-
export declare function
|
|
14
|
+
export declare function DeferAsync<T extends (...args: any) => Promise<any>>(deferLogic: (...args: Parameters<T>) => any | Promise<any>): TDTg<T>;
|
|
15
|
+
/**try-catch包装 */
|
|
16
|
+
export declare function DCatch<T extends (...args: any) => any>(catchLogic: (error: any, ...args: Parameters<T>) => ReturnType<T>): TDTg<T>;
|
|
17
|
+
/**异步的try-catch包装 */
|
|
18
|
+
export declare function CatchAsync<T extends (...args: any) => Promise<any>>(catchLogic: (error: any, ...args: Parameters<T>) => ReturnType<T>): TDTg<T>;
|
|
19
|
+
export {};
|
package/dist/UtilDecorators.js
CHANGED
|
@@ -9,32 +9,70 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.CatchAsync = exports.DCatch = exports.DeferAsync = exports.Defer = exports.LogErrAsync = exports.LogErr = exports.LogCallAsync = exports.LogCall = void 0;
|
|
13
13
|
const UtilLogger_1 = require("./UtilLogger");
|
|
14
14
|
/**用于打印方法的调用 */
|
|
15
|
-
function
|
|
15
|
+
function LogCall() {
|
|
16
16
|
return function (target, propertyKey, descriptor) {
|
|
17
17
|
const originalMethod = descriptor.value;
|
|
18
18
|
descriptor.value = function (...args) {
|
|
19
19
|
let result = originalMethod.apply(this, args);
|
|
20
|
-
UtilLogger_1.SLogger.info(
|
|
20
|
+
UtilLogger_1.SLogger.info(`调用函数: ${propertyKey}(${args}) => ${result}`);
|
|
21
21
|
return result;
|
|
22
22
|
};
|
|
23
|
+
return descriptor;
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
|
-
exports.
|
|
26
|
+
exports.LogCall = LogCall;
|
|
26
27
|
/**用于打印异步方法的调用 */
|
|
27
|
-
function
|
|
28
|
+
function LogCallAsync() {
|
|
28
29
|
return function (target, propertyKey, descriptor) {
|
|
29
30
|
const originalMethod = descriptor.value;
|
|
30
31
|
descriptor.value = async function (...args) {
|
|
31
32
|
let result = await originalMethod.apply(this, args);
|
|
32
|
-
UtilLogger_1.SLogger.info(
|
|
33
|
+
UtilLogger_1.SLogger.info(`调用函数: ${propertyKey}(${args}) => ${result}`);
|
|
33
34
|
return result;
|
|
34
35
|
};
|
|
36
|
+
return descriptor;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.LogCallAsync = LogCallAsync;
|
|
40
|
+
/**用于打印方法的调用 */
|
|
41
|
+
function LogErr() {
|
|
42
|
+
return function (target, propertyKey, descriptor) {
|
|
43
|
+
const originalMethod = descriptor.value;
|
|
44
|
+
descriptor.value = function (...args) {
|
|
45
|
+
try {
|
|
46
|
+
const result = originalMethod.apply(this, args);
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
UtilLogger_1.SLogger.warn(`函数出现错误: ${propertyKey}(${args}): ${err}`);
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return descriptor;
|
|
35
55
|
};
|
|
36
56
|
}
|
|
37
|
-
exports.
|
|
57
|
+
exports.LogErr = LogErr;
|
|
58
|
+
/**用于打印异步方法的调用 */
|
|
59
|
+
function LogErrAsync() {
|
|
60
|
+
return function (target, propertyKey, descriptor) {
|
|
61
|
+
const originalMethod = descriptor.value;
|
|
62
|
+
descriptor.value = async function (...args) {
|
|
63
|
+
try {
|
|
64
|
+
const result = await originalMethod.apply(this, args);
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
UtilLogger_1.SLogger.warn(`函数出现错误: ${propertyKey}(${args}): ${err}`);
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
return descriptor;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
exports.LogErrAsync = LogErrAsync;
|
|
38
76
|
/**try-finally包装 */
|
|
39
77
|
function Defer(deferLogic) {
|
|
40
78
|
return function (target, propertyKey, descriptor) {
|
|
@@ -42,12 +80,10 @@ function Defer(deferLogic) {
|
|
|
42
80
|
descriptor.value = function (...args) {
|
|
43
81
|
try {
|
|
44
82
|
const result = originalMethod.apply(this, args);
|
|
45
|
-
deferLogic();
|
|
46
83
|
return result;
|
|
47
84
|
}
|
|
48
|
-
|
|
49
|
-
deferLogic();
|
|
50
|
-
throw e;
|
|
85
|
+
finally {
|
|
86
|
+
deferLogic(...args);
|
|
51
87
|
}
|
|
52
88
|
};
|
|
53
89
|
return descriptor;
|
|
@@ -61,48 +97,53 @@ function DeferAsync(deferLogic) {
|
|
|
61
97
|
descriptor.value = async function (...args) {
|
|
62
98
|
try {
|
|
63
99
|
const result = await originalMethod.apply(this, args);
|
|
64
|
-
deferLogic();
|
|
100
|
+
await deferLogic(...args);
|
|
65
101
|
return result;
|
|
66
102
|
}
|
|
67
|
-
|
|
68
|
-
deferLogic();
|
|
69
|
-
throw e;
|
|
103
|
+
finally {
|
|
104
|
+
await deferLogic(...args);
|
|
70
105
|
}
|
|
71
106
|
};
|
|
72
107
|
return descriptor;
|
|
73
108
|
};
|
|
74
109
|
}
|
|
75
110
|
exports.DeferAsync = DeferAsync;
|
|
76
|
-
|
|
77
|
-
function
|
|
111
|
+
/**try-catch包装 */
|
|
112
|
+
function DCatch(catchLogic) {
|
|
78
113
|
return function (target, propertyKey, descriptor) {
|
|
79
114
|
const originalMethod = descriptor.value;
|
|
80
115
|
descriptor.value = function (...args) {
|
|
81
116
|
try {
|
|
82
|
-
originalMethod.apply(this, args);
|
|
117
|
+
const result = originalMethod.apply(this, args);
|
|
118
|
+
return result;
|
|
83
119
|
}
|
|
84
120
|
catch (err) {
|
|
85
|
-
|
|
121
|
+
//SLogger.warn(`一个函数出现了错误 ${propertyKey}: ${err}`);
|
|
122
|
+
return catchLogic(err, ...args);
|
|
86
123
|
}
|
|
87
124
|
};
|
|
125
|
+
return descriptor;
|
|
88
126
|
};
|
|
89
127
|
}
|
|
90
|
-
exports.
|
|
91
|
-
|
|
92
|
-
function
|
|
128
|
+
exports.DCatch = DCatch;
|
|
129
|
+
/**异步的try-catch包装 */
|
|
130
|
+
function CatchAsync(catchLogic) {
|
|
93
131
|
return function (target, propertyKey, descriptor) {
|
|
94
132
|
const originalMethod = descriptor.value;
|
|
95
133
|
descriptor.value = async function (...args) {
|
|
96
134
|
try {
|
|
97
|
-
await originalMethod.apply(this, args);
|
|
135
|
+
const result = await originalMethod.apply(this, args);
|
|
136
|
+
return result;
|
|
98
137
|
}
|
|
99
138
|
catch (err) {
|
|
100
|
-
|
|
139
|
+
//SLogger.warn(`一个函数出现了错误 ${propertyKey}: ${err}`);
|
|
140
|
+
return await catchLogic(err, ...args);
|
|
101
141
|
}
|
|
102
142
|
};
|
|
143
|
+
return descriptor;
|
|
103
144
|
};
|
|
104
145
|
}
|
|
105
|
-
exports.
|
|
146
|
+
exports.CatchAsync = CatchAsync;
|
|
106
147
|
function AddNumberDecorator(n) {
|
|
107
148
|
return function (target, propertyKey, descriptor) {
|
|
108
149
|
const originalMethod = descriptor.value;
|
|
@@ -117,6 +158,9 @@ class Example {
|
|
|
117
158
|
myMethod(num) {
|
|
118
159
|
return num;
|
|
119
160
|
}
|
|
161
|
+
async myMethod1(num, ss) {
|
|
162
|
+
return 312;
|
|
163
|
+
}
|
|
120
164
|
}
|
|
121
165
|
__decorate([
|
|
122
166
|
AddNumberDecorator(10),
|
|
@@ -124,5 +168,15 @@ __decorate([
|
|
|
124
168
|
__metadata("design:paramtypes", [Number]),
|
|
125
169
|
__metadata("design:returntype", Number)
|
|
126
170
|
], Example.prototype, "myMethod", null);
|
|
171
|
+
__decorate([
|
|
172
|
+
LogCall(),
|
|
173
|
+
Defer((a, b) => null),
|
|
174
|
+
__metadata("design:type", Function),
|
|
175
|
+
__metadata("design:paramtypes", [Number, String]),
|
|
176
|
+
__metadata("design:returntype", Promise)
|
|
177
|
+
], Example.prototype, "myMethod1", null);
|
|
178
|
+
//let e = new Example();
|
|
179
|
+
//e.myMethod1(1,"");
|
|
180
|
+
//console.log(123);
|
|
127
181
|
//let a = new Example();
|
|
128
182
|
//a.myMethod(10);//?
|
package/dist/UtilFP.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**常用函数式编程库 */
|
|
2
|
+
export declare namespace UtilFP {
|
|
3
|
+
/**柯里化函数类型 */
|
|
4
|
+
type CurryFunc<T, PrevArgs extends any[] = []> = 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
|
+
/**柯里化转换
|
|
6
|
+
* @param {T} fn - 将要转换的函数
|
|
7
|
+
* @returns {CurryFunc<T>} 柯里化的函数
|
|
8
|
+
*/
|
|
9
|
+
export function curry<T extends Function>(fn: T): CurryFunc<T>;
|
|
10
|
+
/**可组合的函数 */
|
|
11
|
+
type CompFunc<T, R> = (arg: T) => R;
|
|
12
|
+
/**函数管道组合
|
|
13
|
+
* 从左到右执行
|
|
14
|
+
* @param fs - 待组合的函数
|
|
15
|
+
* @returns 组合完成的函数
|
|
16
|
+
*/
|
|
17
|
+
export function flow<I>(...fs: CompFunc<I, I>[]): CompFunc<I, I>;
|
|
18
|
+
export function flow<I, R1>(f1: CompFunc<I, R1>, ...fs: CompFunc<R1, R1>[]): CompFunc<I, R1>;
|
|
19
|
+
export function flow<I, R1, R2>(f1: CompFunc<I, R1>, f2: CompFunc<R1, R2>, ...fs: CompFunc<R2, R2>[]): CompFunc<I, R2>;
|
|
20
|
+
export function flow<I, R1, R2, R3>(f1: CompFunc<I, R1>, f2: CompFunc<R1, R2>, f3: CompFunc<R2, R3>, ...fs: CompFunc<R3, R3>[]): CompFunc<I, R3>;
|
|
21
|
+
export function flow<I, R1, R2, R3, R4>(f1: CompFunc<I, R1>, f2: CompFunc<R1, R2>, f3: CompFunc<R2, R3>, f4: CompFunc<R3, R4>, ...fs: CompFunc<R4, R4>[]): CompFunc<I, R4>;
|
|
22
|
+
export function flow<I, R1, R2, R3, R4, R5>(f1: CompFunc<I, R1>, f2: CompFunc<R1, R2>, f3: CompFunc<R2, R3>, f4: CompFunc<R3, R4>, f5: CompFunc<R4, R5>, ...fs: CompFunc<R5, R5>[]): CompFunc<I, R5>;
|
|
23
|
+
export function flow<I, R1, R2, R3, R4, R5, R6>(f1: CompFunc<I, R1>, f2: CompFunc<R1, R2>, f3: CompFunc<R2, R3>, f4: CompFunc<R3, R4>, f5: CompFunc<R4, R5>, f6: CompFunc<R5, R6>, ...fs: CompFunc<R6, R6>[]): CompFunc<I, R6>;
|
|
24
|
+
export function flow<I, R1, R2, R3, R4, R5, R6, R7>(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>[]): CompFunc<I, R7>;
|
|
25
|
+
export function flow<I, R1, R2, R3, R4, R5, R6, R7, R8>(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>[]): CompFunc<I, R8>;
|
|
26
|
+
export function flow<I, R1, R2, R3, R4, R5, R6, R7, R8, R9>(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>[]): CompFunc<I, R9>;
|
|
27
|
+
/**函数管道
|
|
28
|
+
* 从左到右执行
|
|
29
|
+
* @param input - 初始输入值
|
|
30
|
+
* @param fs - 待组合的函数
|
|
31
|
+
* @returns 经过所有函数处理后的结果
|
|
32
|
+
*/
|
|
33
|
+
export function pipe<I>(input: I, ...fs: CompFunc<I, I>[]): I;
|
|
34
|
+
export function pipe<I, R1>(input: I, f1: CompFunc<I, R1>, ...fs: CompFunc<R1, R1>[]): R1;
|
|
35
|
+
export function pipe<I, R1, R2>(input: I, f1: CompFunc<I, R1>, f2: CompFunc<R1, R2>, ...fs: CompFunc<R2, R2>[]): R2;
|
|
36
|
+
export function pipe<I, R1, R2, R3>(input: I, f1: CompFunc<I, R1>, f2: CompFunc<R1, R2>, f3: CompFunc<R2, R3>, ...fs: CompFunc<R3, R3>[]): R3;
|
|
37
|
+
export function pipe<I, R1, R2, R3, R4>(input: I, f1: CompFunc<I, R1>, f2: CompFunc<R1, R2>, f3: CompFunc<R2, R3>, f4: CompFunc<R3, R4>, ...fs: CompFunc<R4, R4>[]): R4;
|
|
38
|
+
export function pipe<I, R1, R2, R3, R4, R5>(input: I, f1: CompFunc<I, R1>, f2: CompFunc<R1, R2>, f3: CompFunc<R2, R3>, f4: CompFunc<R3, R4>, f5: CompFunc<R4, R5>, ...fs: CompFunc<R5, R5>[]): R5;
|
|
39
|
+
export function pipe<I, R1, R2, R3, R4, R5, R6>(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>, ...fs: CompFunc<R6, R6>[]): R6;
|
|
40
|
+
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
|
+
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
|
+
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>;
|
|
45
|
+
export {};
|
|
46
|
+
}
|
package/dist/UtilFP.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UtilFP = void 0;
|
|
4
|
+
/**常用函数式编程库 */
|
|
5
|
+
var UtilFP;
|
|
6
|
+
(function (UtilFP) {
|
|
7
|
+
/**柯里化转换
|
|
8
|
+
* @param {T} fn - 将要转换的函数
|
|
9
|
+
* @returns {CurryFunc<T>} 柯里化的函数
|
|
10
|
+
*/
|
|
11
|
+
function curry(fn) {
|
|
12
|
+
return (function curried(...args) {
|
|
13
|
+
if (args.length >= fn.length)
|
|
14
|
+
return fn(...args);
|
|
15
|
+
return (...restArgs) => curried(...args, ...restArgs);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
UtilFP.curry = curry;
|
|
19
|
+
function flow(...fs) {
|
|
20
|
+
return (arg) => {
|
|
21
|
+
return fs.reduce((value, func) => func(value), arg);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
UtilFP.flow = flow;
|
|
25
|
+
function pipe(input, ...fs) {
|
|
26
|
+
return fs.reduce((value, func) => func(value), input);
|
|
27
|
+
}
|
|
28
|
+
UtilFP.pipe = pipe;
|
|
29
|
+
/**将一个字段加入一个对象中,返回新类型 */
|
|
30
|
+
function bindTo(key, value, base) {
|
|
31
|
+
let out = base;
|
|
32
|
+
out = out ?? {};
|
|
33
|
+
out[key] = value;
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
UtilFP.bindTo = bindTo;
|
|
37
|
+
/**
|
|
38
|
+
let asd = bindTo("sss",123,{abc:223});//?
|
|
39
|
+
let sumvoid = ()=>10;
|
|
40
|
+
let a = curry(sumvoid);//?
|
|
41
|
+
console.log(a());
|
|
42
|
+
let sum = (a:number,b:string,c:number,d:boolean)=>a+b+c+d;
|
|
43
|
+
let sumCu = curry(sum);//?
|
|
44
|
+
let suma = sumCu(1)("ss");//?
|
|
45
|
+
let sumb = sumCu(1,"1")(2);//?
|
|
46
|
+
let sumc = sumCu(4);//?
|
|
47
|
+
let sumz = sumCu(1,"b",3)(false);//?
|
|
48
|
+
console.log(suma(2,true));
|
|
49
|
+
console.log(sumb(true));
|
|
50
|
+
console.log(sumc("s",3,false));
|
|
51
|
+
*/
|
|
52
|
+
})(UtilFP = exports.UtilFP || (exports.UtilFP = {}));
|