@zwa73/utils 1.0.77 → 1.0.79
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 +15 -0
- package/dist/QuickFunction.js +27 -0
- package/dist/UtilDecorators.d.ts +10 -0
- package/dist/UtilDecorators.js +40 -3
- package/dist/UtilFunctions.d.ts +34 -37
- package/dist/UtilFunctions.js +99 -111
- package/dist/UtilInterfaces.d.ts +6 -3
- package/dist/UtilSymbol.d.ts +15 -0
- package/dist/UtilSymbol.js +13 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/test/repeatTest.d.ts +1 -0
- package/dist/test/repeatTest.js +29 -0
- package/package.json +1 -1
- package/src/QuickFunction.ts +36 -0
- package/src/UtilDecorators.ts +37 -1
- package/src/UtilFunctions.ts +121 -106
- package/src/UtilInterfaces.ts +7 -3
- package/src/UtilSymbol.ts +15 -0
- package/src/index.ts +3 -1
- package/src/test/repeatTest.ts +29 -0
- package/test/test.bat +2 -0
- package/test/test.js +37 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**完成 */
|
|
2
|
+
export const Completed = Symbol("Completed");
|
|
3
|
+
export type Completed = typeof Completed;
|
|
4
|
+
/**失败 */
|
|
5
|
+
export const Failed = Symbol("Failed");
|
|
6
|
+
export type Failed = typeof Failed;
|
|
7
|
+
/**终止 */
|
|
8
|
+
export const Terminated = Symbol("Terminated");
|
|
9
|
+
export type Terminated = typeof Terminated;
|
|
10
|
+
/**不存在 */
|
|
11
|
+
export const None = Symbol("None");
|
|
12
|
+
export type None = typeof None;
|
|
13
|
+
/**超时 */
|
|
14
|
+
export const Timeout = Symbol("Timeout");
|
|
15
|
+
export type Timeout = typeof Timeout;
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './UtilFunctions';
|
|
2
2
|
export * from './UtilInterfaces';
|
|
3
|
+
export * from './UtilSymbol';
|
|
3
4
|
export * from './UtilClass';
|
|
4
5
|
export * from './UtilCom';
|
|
5
6
|
export * from './UtilCodecs';
|
|
@@ -7,4 +8,5 @@ export * from './UtilFfmpegTools';
|
|
|
7
8
|
export * from './UtilDecorators';
|
|
8
9
|
export * from './UtilFileTools';
|
|
9
10
|
export * from './UtilLogger';
|
|
10
|
-
export * from './UtilFP';
|
|
11
|
+
export * from './UtilFP';
|
|
12
|
+
export * from './QuickFunction';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Completed, Failed, PromiseStat, PromiseVerifyFn, UtilFunc } from "..";
|
|
2
|
+
|
|
3
|
+
// 模拟的异步函数,有一定几率失败
|
|
4
|
+
async function mockAsyncFunction(): Promise<string> {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
setTimeout(() => {
|
|
7
|
+
Math.random() > 0.5 ? resolve("Success") : reject("Failure");
|
|
8
|
+
}, Math.random()%2000);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 验证函数,只有当结果为 "Success" 时才认为成功
|
|
13
|
+
function mockVerifyFunction(result: string): PromiseStat {
|
|
14
|
+
return result === "Success" ? Completed : Failed;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 测试 repeatPromise 函数
|
|
18
|
+
UtilFunc.repeatPromise(mockAsyncFunction, mockVerifyFunction, 3, 10)
|
|
19
|
+
.then(result => {
|
|
20
|
+
console.log("then")
|
|
21
|
+
if (result === null) {
|
|
22
|
+
console.log("全部超时");
|
|
23
|
+
} else {
|
|
24
|
+
console.log("成功:", result);
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
.catch(err => {
|
|
28
|
+
console.error("出现错误", err);
|
|
29
|
+
});
|
package/test/test.bat
ADDED
package/test/test.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const { Completed, Failed, PromiseStat, PromiseVerifyFn, UtilFunc } = require("../dist");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
let timeList = [21000,5000,1000000]
|
|
5
|
+
let resList = ["Success","Failure","Failure"]
|
|
6
|
+
let index = 0;
|
|
7
|
+
// 模拟的异步函数,有一定几率失败
|
|
8
|
+
async function mockAsyncFunction() {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
|
|
11
|
+
let delay =timeList[index];
|
|
12
|
+
let result = resList[index];
|
|
13
|
+
console.log("延迟: "+delay,"结果: "+result)
|
|
14
|
+
setTimeout(() => {
|
|
15
|
+
resolve(result);
|
|
16
|
+
}, delay);
|
|
17
|
+
index++;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 验证函数,只有当结果为 "Success" 时才认为成功
|
|
22
|
+
function mockVerifyFunction(result) {
|
|
23
|
+
return result === "Success" ? Completed : Failed;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 测试 repeatPromise 函数
|
|
27
|
+
UtilFunc.repeatPromise(mockAsyncFunction, mockVerifyFunction, 3, 10)
|
|
28
|
+
.then(result => {
|
|
29
|
+
if (result === null) {
|
|
30
|
+
console.log("全部超时");
|
|
31
|
+
} else {
|
|
32
|
+
console.log("成功:", result);
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
.catch(err => {
|
|
36
|
+
console.error("出现错误", err);
|
|
37
|
+
});
|