@zwa73/utils 1.0.80 → 1.0.81
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/{test/test.js → backup/repeatPromise.test.ts} +0 -1
- package/compile.bat +2 -0
- package/dist/QuickFunction.d.ts +2 -15
- package/dist/QuickFunction.js +21 -19
- package/dist/UtilCodecs.js +1 -1
- package/dist/UtilCom.js +1 -1
- package/dist/UtilDecorators.d.ts +1 -1
- package/dist/UtilDecorators.js +4 -3
- package/dist/UtilFP.js +1 -1
- package/dist/UtilFileTools.js +1 -1
- package/dist/UtilFunctions.d.ts +65 -18
- package/dist/UtilFunctions.js +141 -29
- package/dist/UtilInterfaces.d.ts +18 -13
- package/dist/UtilSymbol.d.ts +29 -10
- package/dist/UtilSymbol.js +22 -9
- package/dist/test/test.js +16 -16
- package/jest/UtilFunction/queueProc.test.ts +23 -0
- package/jest/UtilFunction/repeatPromise.test.ts +38 -0
- package/jest/jest.test.ts +46 -0
- package/jest.config.js +16 -0
- package/package.json +12 -5
- package/release.bat +3 -4
- package/{postinstall.js → scripts/postinstall.js} +2 -2
- package/src/QuickFunction.ts +47 -28
- package/src/UtilDecorators.ts +3 -1
- package/src/UtilFunctions.ts +183 -44
- package/src/UtilInterfaces.ts +44 -11
- package/src/UtilSymbol.ts +35 -11
- package/src/test/repeatTest.ts +1 -1
- package/test.bat +1 -1
- package/tsconfig.compile.json +4 -0
- package/tsconfig.json +3 -2
- package/watch.bat +1 -0
- package/test/test.bat +0 -2
- package/testAndCompile.bat +0 -4
- package/tsCompile.bat +0 -3
- package/tsCompileWatch.bat +0 -2
- /package/{test.js → backup/SLogger.test.ts} +0 -0
- /package/{req_test → backup/req_test}/cjsRmjs.bat +0 -0
- /package/{req_test → backup/req_test}/cjsRmjs.cjs +0 -0
- /package/{req_test → backup/req_test}/mjsRcjs.bat +0 -0
- /package/{req_test → backup/req_test}/mjsRcjs.mjs +0 -0
- /package/{req_test → backup/req_test}/req.cjs +0 -0
- /package/{req_test → backup/req_test}/req.mjs +0 -0
package/src/UtilInterfaces.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Failed, Success, Terminated } from "./UtilSymbol";
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
/**可以序列化为JSON文件的对象 */
|
|
@@ -17,10 +17,25 @@ export interface IJData{
|
|
|
17
17
|
*/
|
|
18
18
|
toJSON():JToken;
|
|
19
19
|
}
|
|
20
|
+
/**任何可能有ReturnType的函数 */
|
|
21
|
+
export type AnyFunc = (...args:any)=>any;
|
|
20
22
|
|
|
21
23
|
/**任意可作为键值的类型 */
|
|
22
24
|
export type Keyable = string | number | symbol;
|
|
23
25
|
|
|
26
|
+
/**真子集 */
|
|
27
|
+
export type ProperSubset<B, T = B> = T extends B ? B extends T ? never : T : never;
|
|
28
|
+
|
|
29
|
+
/**字面量检测 */
|
|
30
|
+
export type LiteralCheck<L> =
|
|
31
|
+
ProperSubset<string, L> |
|
|
32
|
+
ProperSubset<number, L> |
|
|
33
|
+
ProperSubset<boolean, L>|
|
|
34
|
+
ProperSubset<symbol, L> |
|
|
35
|
+
ProperSubset<any[], L> |
|
|
36
|
+
ProperSubset<Record<any,any>, L> |
|
|
37
|
+
null | undefined;
|
|
38
|
+
|
|
24
39
|
/**转为可写的 */
|
|
25
40
|
export type Writeable<T> = {
|
|
26
41
|
-readonly [P in keyof T]: T[P]
|
|
@@ -84,9 +99,13 @@ export type PromiseStat = Success|Failed|Terminated;
|
|
|
84
99
|
/**promise验证函数 */
|
|
85
100
|
export type PromiseVerifyFn<T> = (obj:T)=>Promise<PromiseStat>|PromiseStat;
|
|
86
101
|
|
|
102
|
+
/**获取Promise的结果类型 */
|
|
103
|
+
export type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
|
|
104
|
+
|
|
105
|
+
|
|
87
106
|
/**类型中任意函数的字符串名称 */
|
|
88
107
|
export type FuncPropNames<T> = {
|
|
89
|
-
[K in keyof T]: T[K] extends
|
|
108
|
+
[K in keyof T]: T[K] extends AnyFunc ? K : never;
|
|
90
109
|
}[keyof T];
|
|
91
110
|
|
|
92
111
|
/**部分组合的类
|
|
@@ -124,20 +143,23 @@ export type ComposedMixinable<B, Ms extends unknown[]> =
|
|
|
124
143
|
* @template N - 如果为假的返回值
|
|
125
144
|
*/
|
|
126
145
|
export type ExtendThen<B,T,Y,N = never> = B extends T ? Y : N;
|
|
127
|
-
/** 一个联合类型 B 中如果包含 T
|
|
146
|
+
/** 一个联合类型 B 中如果包含 联合类型 T 中的任意项
|
|
147
|
+
* 无效
|
|
128
148
|
* @template B - 基础类型
|
|
129
149
|
* @template T - 判断的目标类型
|
|
130
150
|
* @template Y - 如果为真的返回值
|
|
131
151
|
* @template N - 如果为假的返回值
|
|
132
152
|
*/
|
|
133
|
-
|
|
153
|
+
type UnionInclude<B,T,Y,N = never> =
|
|
134
154
|
B extends Exclude<B,T>
|
|
135
|
-
?
|
|
136
|
-
:
|
|
155
|
+
? N
|
|
156
|
+
: Y
|
|
137
157
|
/**排除可选字段 */
|
|
138
158
|
export type RequiredOnly<T> = {
|
|
139
159
|
[K in keyof T as
|
|
140
|
-
|
|
160
|
+
T[K] extends Exclude<T[K],undefined>
|
|
161
|
+
? K
|
|
162
|
+
: never
|
|
141
163
|
]: T[K]
|
|
142
164
|
};
|
|
143
165
|
/**添加前缀 */
|
|
@@ -154,12 +176,23 @@ export type WithPrefix<T,P extends string> = {
|
|
|
154
176
|
*/
|
|
155
177
|
export type Outcome<K extends Keyable,V> = {
|
|
156
178
|
/**状态类型 */
|
|
157
|
-
status:K;
|
|
179
|
+
readonly status:K;
|
|
158
180
|
/**值 */
|
|
159
|
-
result:V;
|
|
181
|
+
readonly result:V;
|
|
160
182
|
}
|
|
161
183
|
|
|
162
|
-
|
|
184
|
+
/**可进行匹配的 outcome或symbol */
|
|
185
|
+
export type Matchable<T extends Keyable> = T|Outcome<T,unknown>;
|
|
186
|
+
/**可进行匹配的 outcome或symbol 中的状态类型 */
|
|
187
|
+
export type MatchableFlag<T> =
|
|
188
|
+
T extends infer O|Outcome<infer O,unknown>
|
|
189
|
+
? O : never;
|
|
190
|
+
|
|
191
|
+
/**从联合 Outcome 中 根据 id 提取对应 Outcome */
|
|
163
192
|
export type ExtractOutcome<T,K extends Keyable> =
|
|
164
|
-
T extends Outcome<
|
|
193
|
+
T extends Outcome<infer O,unknown>
|
|
194
|
+
? O extends Exclude<O,K>
|
|
195
|
+
? never
|
|
196
|
+
: T
|
|
197
|
+
: never;
|
|
165
198
|
|
package/src/UtilSymbol.ts
CHANGED
|
@@ -1,18 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/**成功 */
|
|
1
|
+
import { Outcome } from "./UtilInterfaces";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**成功 经过验证的结果 */
|
|
5
5
|
export const Success = Symbol("Success");
|
|
6
6
|
export type Success = typeof Success;
|
|
7
|
-
/**失败 */
|
|
7
|
+
/**失败 可重试的 */
|
|
8
8
|
export const Failed = Symbol("Failed");
|
|
9
9
|
export type Failed = typeof Failed;
|
|
10
|
-
|
|
11
|
-
export const Terminated = Symbol("Terminated");
|
|
12
|
-
export type Terminated = typeof Terminated;
|
|
13
|
-
/**不存在 */
|
|
10
|
+
/**不存在 无 */
|
|
14
11
|
export const None = Symbol("None");
|
|
15
12
|
export type None = typeof None;
|
|
16
|
-
|
|
13
|
+
/**完成 未经验证/未超时的结果
|
|
14
|
+
* Success扩展
|
|
15
|
+
* 仅在Success同时出现时使用
|
|
16
|
+
*/
|
|
17
|
+
export const Completed = Symbol("Completed");
|
|
18
|
+
export type Completed = typeof Completed;
|
|
19
|
+
/**终止 熔断运行
|
|
20
|
+
* Failed扩展
|
|
21
|
+
* 仅在Failed同时出现时使用
|
|
22
|
+
*/
|
|
23
|
+
export const Terminated = Symbol("Terminated");
|
|
24
|
+
export type Terminated = typeof Terminated;
|
|
25
|
+
/**超时 超时类型的失败
|
|
26
|
+
* Failed扩展
|
|
27
|
+
* 仅在超时时使用
|
|
28
|
+
*/
|
|
17
29
|
export const Timeout = Symbol("Timeout");
|
|
18
|
-
export type Timeout = typeof Timeout;
|
|
30
|
+
export type Timeout = typeof Timeout;
|
|
31
|
+
/**失败及其拓展 */
|
|
32
|
+
export type FailedLike = Failed|Timeout|Terminated;
|
|
33
|
+
/**成功及其拓展 */
|
|
34
|
+
export type SuccessLike = Success|Completed;
|
|
35
|
+
/**任意状态标识符 */
|
|
36
|
+
export type StatusSymbol = FailedLike|SuccessLike|None;
|
|
37
|
+
/**结果为 None 的 Outcome */
|
|
38
|
+
export type NoneOut = Outcome<None,None>;
|
|
39
|
+
export const NoneOut = {
|
|
40
|
+
status:None,
|
|
41
|
+
result:None,
|
|
42
|
+
} as const as NoneOut;
|
package/src/test/repeatTest.ts
CHANGED
package/test.bat
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
call npm run test
|
|
2
2
|
pause
|
package/tsconfig.json
CHANGED
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
"experimentalDecorators": true,
|
|
12
12
|
"paths": {
|
|
13
13
|
"@src/*": ["./src/*"],
|
|
14
|
-
"
|
|
14
|
+
"@/*" : ["./*"],
|
|
15
|
+
"@" : ["./src/index"]
|
|
15
16
|
}
|
|
16
17
|
},
|
|
17
|
-
"include": ["./src/**/*.ts", "./src/**/*.js"],
|
|
18
|
+
"include": ["./src/**/*.ts", "./src/**/*.js","./jest/**/*.ts"],
|
|
18
19
|
"exclude": ["./node_modules/**/*"]
|
|
19
20
|
}
|
package/watch.bat
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npm run watch
|
package/test/test.bat
DELETED
package/testAndCompile.bat
DELETED
package/tsCompile.bat
DELETED
package/tsCompileWatch.bat
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|