@zwa73/utils 1.0.81 → 1.0.83

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.81",
3
+ "version": "1.0.83",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,53 +0,0 @@
1
- let {SList,SHashMap,SEntry,SFfmpegTool,fileSearch,sleep,SLogger} = require('./dist');
2
-
3
- let slist = new SList([1,2,3,3,4,5,6]);
4
- slist.each(val => console.log(val));
5
- for(let v of slist)
6
- console.log(v)
7
-
8
- let map = new SHashMap();
9
- map.put("123",456)
10
- map.put("789",111)
11
- for(let {key,value} of map)
12
- console.log(key,value)
13
-
14
- //SFfmpegTool.setFfmpegPath("E:/系统工具/ffmpeg-master-latest-win64-gpl/bin/ffmpeg.exe");
15
- async function main(){
16
- //SFfmpegTool.setFfmpegPath("E:/系统工具/ffmpeg-master-latest-win64-gpl/bin/ffmpeg.exe");
17
- //console.log(111111111111)
18
- let timelog = SLogger.time("timetest0")
19
- timelog[0]=process.hrtime()[0]-1000;
20
- SLogger.timeEnd("timetest0")
21
- SLogger.time("timetest")
22
- let data = await SFfmpegTool.getAudioMetaData("input.wav");
23
- //console.log(22)
24
- console.log(data);
25
- //
26
- //let fileMap = fileSearch("F:/Sosarciel/SoulTide-Collection-VITS-TrainingSet/TrainingSet/Akaset/sliced_audio",'.*\\.wav');
27
- //let ioMap = {};
28
- //for(let key in fileMap){
29
- // let value = fileMap[key];
30
- // ioMap[value] = "./test/"+key;
31
- //}
32
- //console.log(ioMap)
33
- //await SFfmpegTool.resampleMP(ioMap)
34
- await sleep(2000);
35
- SLogger.timeEnd("timetest")
36
- }
37
-
38
- main();
39
- let a= {a:1};
40
- SLogger.createLogger("default","silly","./testlog","silly")
41
- //SLogger.createLogger("default","silly");
42
- SLogger.fatal('This is an fatal message');
43
- SLogger.error('This is an error message');
44
- SLogger.warn('This is a warning message');
45
- SLogger.info('This is an info message');
46
- SLogger.http('This is an http message');
47
- SLogger.verbose('This is a verbose message');
48
- SLogger.debug('This is a debug message');
49
- SLogger.silly('This is a silly message');
50
-
51
- SLogger.fatal('This is an info message',123,true);
52
- SLogger.info({a:"1111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111"});
53
-
@@ -1,26 +0,0 @@
1
- {
2
- "name": "@zwa73/utils",
3
- "version": "1.0.5",
4
- "description": "my utils",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "node test"
8
- },
9
- "keywords": [
10
- "zwa73"
11
- ],
12
- "author": "zwa73",
13
- "license": "ISC",
14
- "dependencies": {
15
- "@dqbd/tiktoken": "^1.0.7",
16
- "esm": "^3.2.25",
17
- "esm-resolve": "^1.0.8",
18
- "html-entities": "^2.3.3",
19
- "http-proxy-agent": "^5.0.0",
20
- "https-proxy-agent": "^5.0.1",
21
- "tiktoken": "^1.0.7"
22
- },
23
- "devDependencies": {
24
- "@types/node": "^18.16.3"
25
- }
26
- }
@@ -1,36 +0,0 @@
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
- let delay =timeList[index];
11
- let result = resList[index];
12
- console.log("延迟: "+delay,"结果: "+result)
13
- setTimeout(() => {
14
- resolve(result);
15
- }, delay);
16
- index++;
17
- });
18
- }
19
-
20
- // 验证函数,只有当结果为 "Success" 时才认为成功
21
- function mockVerifyFunction(result) {
22
- return result === "Success" ? Completed : Failed;
23
- }
24
-
25
- // 测试 repeatPromise 函数
26
- UtilFunc.repeatPromise(mockAsyncFunction, mockVerifyFunction, 3, 10)
27
- .then(result => {
28
- if (result === null) {
29
- console.log("全部超时");
30
- } else {
31
- console.log("成功:", result);
32
- }
33
- })
34
- .catch(err => {
35
- console.error("出现错误", err);
36
- });
@@ -1,2 +0,0 @@
1
- node cjsRmjs.cjs
2
- pause
@@ -1,3 +0,0 @@
1
- require = require("esm")(module);
2
- const req = require('./req.mjs');
3
- console.log(req.test())
@@ -1,2 +0,0 @@
1
- node mjsRcjs.mjs
2
- pause
@@ -1,3 +0,0 @@
1
- import pkg from './req.cjs';
2
- const { test } = pkg;
3
- console.log(test())
@@ -1,7 +0,0 @@
1
- function test(){
2
- console.log(123)
3
- }
4
-
5
- module.exports = {
6
- test
7
- }
@@ -1,3 +0,0 @@
1
- export function test(){
2
- console.log(123)
3
- }
@@ -1,78 +0,0 @@
1
- import { Mixinable } from "..";
2
- type MixinA = Mixinable<A>;
3
- declare class A implements MixinA {
4
- anum: number;
5
- constructor(n?: number);
6
- getNum: () => number;
7
- /**A的函数 */
8
- getA: () => this;
9
- readonly MIXIN_KEY: "__a";
10
- static MIXIN_FIELDS: readonly ["getNum", "getA", "anum"];
11
- readonly MIXIN_FIELDS: readonly ["getNum", "getA", "anum"];
12
- }
13
- declare class B implements Mixinable<B> {
14
- private text;
15
- getText: () => string;
16
- /**B的函数 */
17
- getB: () => this;
18
- /**B的静态函数 */
19
- static getNewB: () => B;
20
- /**保留的函数 */
21
- privateFunc(): void;
22
- readonly MIXIN_KEY: "__b";
23
- static readonly MIXIN_FIELDS: readonly ["getText", "getB"];
24
- readonly MIXIN_FIELDS: readonly ["getText", "getB"];
25
- }
26
- declare class _C {
27
- static create(): _C & Pick<B, "getText" | "getB"> & {
28
- __b: B;
29
- } & Pick<A, "anum" | "getNum" | "getA"> & {
30
- __a: A;
31
- } & Record<"bindFunc", () => "这是动态绑定的函数">;
32
- private constructor();
33
- getC(this: C): _C & Pick<B, "getText" | "getB"> & {
34
- __b: B;
35
- } & Pick<A, "anum" | "getNum" | "getA"> & {
36
- __a: A;
37
- } & Record<"bindFunc", () => "这是动态绑定的函数">;
38
- testFunc(this: C): number;
39
- readonly MIXIN_KEY: "__c";
40
- static readonly MIXIN_FIELDS: readonly ["getNum", "getA", "anum", "getText", "getB", "getC", "__a"];
41
- readonly MIXIN_FIELDS: readonly ["getNum", "getA", "anum", "getText", "getB", "getC", "__a"];
42
- }
43
- declare function composeC(obj: _C): _C & Pick<B, "getText" | "getB"> & {
44
- __b: B;
45
- } & Pick<A, "anum" | "getNum" | "getA"> & {
46
- __a: A;
47
- } & Record<"bindFunc", () => "这是动态绑定的函数">;
48
- export type C = ReturnType<typeof composeC>;
49
- export declare const C: typeof _C;
50
- declare class _D {
51
- #private;
52
- private constructor();
53
- static create(): _D & Pick<_C & Pick<B, "getText" | "getB"> & {
54
- __b: B;
55
- } & Pick<A, "anum" | "getNum" | "getA"> & {
56
- __a: A;
57
- } & Record<"bindFunc", () => "这是动态绑定的函数">, "__a" | "anum" | "getNum" | "getA" | "getText" | "getB" | "getC"> & {
58
- __c: _C & Pick<B, "getText" | "getB"> & {
59
- __b: B;
60
- } & Pick<A, "anum" | "getNum" | "getA"> & {
61
- __a: A;
62
- } & Record<"bindFunc", () => "这是动态绑定的函数">;
63
- } & Record<"bindFunc", () => "这是动态绑定的函数">;
64
- }
65
- declare function composeD(obj: _D): _D & Pick<_C & Pick<B, "getText" | "getB"> & {
66
- __b: B;
67
- } & Pick<A, "anum" | "getNum" | "getA"> & {
68
- __a: A;
69
- } & Record<"bindFunc", () => "这是动态绑定的函数">, "__a" | "anum" | "getNum" | "getA" | "getText" | "getB" | "getC"> & {
70
- __c: _C & Pick<B, "getText" | "getB"> & {
71
- __b: B;
72
- } & Pick<A, "anum" | "getNum" | "getA"> & {
73
- __a: A;
74
- } & Record<"bindFunc", () => "这是动态绑定的函数">;
75
- } & Record<"bindFunc", () => "这是动态绑定的函数">;
76
- export type D = ReturnType<typeof composeD>;
77
- export declare const D: typeof _D;
78
- export {};
@@ -1,95 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.D = exports.C = void 0;
4
- const __1 = require("..");
5
- class A {
6
- anum = 1;
7
- constructor(n = 1) { this.anum = n; }
8
- getNum = () => this.anum;
9
- /**A的函数 */
10
- getA = () => this;
11
- MIXIN_KEY = "__a";
12
- static MIXIN_FIELDS = ['getNum', 'getA', 'anum'];
13
- MIXIN_FIELDS = A.MIXIN_FIELDS;
14
- }
15
- class B {
16
- text = "B的text";
17
- getText = () => this.text;
18
- /**B的函数 */
19
- getB = () => this;
20
- /**B的静态函数 */
21
- static getNewB = () => new B();
22
- /**保留的函数 */
23
- privateFunc() {
24
- console.log();
25
- }
26
- MIXIN_KEY = "__b";
27
- static MIXIN_FIELDS = ['getText', 'getB'];
28
- MIXIN_FIELDS = B.MIXIN_FIELDS;
29
- }
30
- class _C {
31
- static create() {
32
- return new _C();
33
- }
34
- constructor() {
35
- composeC(this);
36
- }
37
- getC() { return this; }
38
- ;
39
- testFunc() {
40
- console.log(this);
41
- return 2;
42
- }
43
- MIXIN_KEY = "__c";
44
- static MIXIN_FIELDS = [
45
- ...A.MIXIN_FIELDS,
46
- ...B.MIXIN_FIELDS,
47
- 'getC', '__a'
48
- ];
49
- MIXIN_FIELDS = exports.C.MIXIN_FIELDS;
50
- }
51
- function composeC(obj) {
52
- let ob1 = __1.UtilFunc.composeMixinable(obj, new B(), new A());
53
- let ob3 = __1.UtilFP.bindTo('bindFunc', () => "这是动态绑定的函数", ob1);
54
- return ob3;
55
- }
56
- exports.C = _C;
57
- const insc = exports.C.create(); //?
58
- console.log(insc.__a);
59
- insc.getC().testFunc(); //?
60
- insc.getNum(); //?
61
- insc.anum; //?
62
- insc.__a = new A(2);
63
- insc.getNum(); //?
64
- insc.anum; //?
65
- insc.testFunc(); //?
66
- insc.getText(); //?
67
- insc.getB().getText(); //?
68
- insc.bindFunc(); //?
69
- class _D {
70
- constructor() { }
71
- ;
72
- static create() {
73
- return composeD(new _D());
74
- }
75
- #d = 123;
76
- }
77
- function composeD(obj) {
78
- let ob1 = __1.UtilFunc.composeMixinable(obj, exports.C.create());
79
- let ob3 = __1.UtilFP.bindTo('bindFunc', () => "这是动态绑定的函数", ob1);
80
- return ob3;
81
- }
82
- exports.D = _D;
83
- let insd = exports.D.create();
84
- insd; //?
85
- insd.getB(); //?
86
- insd.getNum(); //?
87
- insd.__a = new A(3);
88
- insd.getNum(); //?
89
- let jot = {
90
- c: 1
91
- };
92
- __1.UtilFunc.initObject(jot, {
93
- c: () => console.log("缺少c" + insd.getNum())
94
- });
95
- jot; //?
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const composeTest_1 = require("./composeTest");
4
- let a = composeTest_1.C.create();
@@ -1 +0,0 @@
1
- export {};
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const __1 = require("..");
4
- // 模拟的异步函数,有一定几率失败
5
- async function mockAsyncFunction() {
6
- return new Promise((resolve, reject) => {
7
- setTimeout(() => {
8
- Math.random() > 0.5 ? resolve("Success") : reject("Failure");
9
- }, Math.random() % 2000);
10
- });
11
- }
12
- // 验证函数,只有当结果为 "Success" 时才认为成功
13
- function mockVerifyFunction(result) {
14
- return result === "Success" ? __1.Success : __1.Failed;
15
- }
16
- // 测试 repeatPromise 函数
17
- __1.UtilFunc.repeatPromise(mockAsyncFunction, mockVerifyFunction, 3, 10)
18
- .then(result => {
19
- console.log("then");
20
- if (result === null) {
21
- console.log("全部超时");
22
- }
23
- else {
24
- console.log("成功:", result);
25
- }
26
- })
27
- .catch(err => {
28
- console.error("出现错误", err);
29
- });
@@ -1 +0,0 @@
1
- export {};
package/dist/test/test.js DELETED
@@ -1,139 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const UtilFP_1 = require("../UtilFP");
4
- const UtilFunctions_1 = require("../UtilFunctions");
5
- const backup_1 = require("../backup");
6
- // 使用示例
7
- class Monster {
8
- constructor(a) { }
9
- monfunc() {
10
- return "mon";
11
- }
12
- }
13
- class Monster1 {
14
- constructor(a) { }
15
- m1num = 123;
16
- monfunc1() {
17
- return "mon1";
18
- }
19
- }
20
- const OtherMonster = {
21
- init() {
22
- let mon = new Monster(123);
23
- let mon1 = new Monster1(223);
24
- let om = {
25
- om: "123", mon
26
- };
27
- return (0, backup_1.composeClassFull)(om, mon, mon1);
28
- }
29
- };
30
- let om = OtherMonster.init(); //?
31
- om.monfunc(); //?
32
- om.monfunc1(); //?
33
- om.m1num; //?
34
- const BASE_MAX = { 攻击: 24, 生命: 54, 防御: 16, 暴击: 5, 暴击伤害: 5, 攻击加成: 3.8, 生命加成: 3.8, 防御加成: 3.8 };
35
- const 精调前 = [
36
- { 攻击: 17, 生命: 0, 防御: 0, 暴击: 0, 暴击伤害: 3.5, 攻击加成: 3.0, 生命加成: 0, 防御加成: 3.4 }, // 霰弹 专用消焰器
37
- { 攻击: 19, 生命: 0, 防御: 0, 暴击: 4.5, 暴击伤害: 4.5, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 }, // 霰弹 专用消音器
38
- { 攻击: 21, 生命: 0, 防御: 10, 暴击: 0, 暴击伤害: 0, 攻击加成: 3.8, 生命加成: 0, 防御加成: 3.0 }, // 机枪 重型制退器
39
- { 攻击: 17, 生命: 48, 防御: 14, 暴击: 0, 暴击伤害: 0, 攻击加成: 2.6, 生命加成: 0, 防御加成: 0 }, // 冲锋 消焰器攻击头
40
- { 攻击: 23, 生命: 0, 防御: 0, 暴击: 5, 暴击伤害: 0, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 }, // 狙击 异位打击 快拆战术手电
41
- { 攻击: 17, 生命: 53, 防御: 0, 暴击: 0, 暴击伤害: 0, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 }, // 霰弹 减伤支援 钢化铆钉
42
- { 攻击: 21, 生命: 0, 防御: 0, 暴击: 3.5, 暴击伤害: 0, 攻击加成: 3.0, 生命加成: 0, 防御加成: 0 }, // 冲锋 异位打击 内瞄式红点
43
- { 攻击: 17, 生命: 0, 防御: 3.8, 暴击: 0, 暴击伤害: 0, 攻击加成: 2.6, 生命加成: 0, 防御加成: 0 }, // 机枪 双重对策 镭射插件
44
- { 攻击: 19, 生命: 38, 防御: 0, 暴击: 0, 暴击伤害: 0, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 }, // 机枪 双重对策 折叠脚架
45
- ];
46
- const 精调后 = [
47
- { 攻击: 26, 生命: 0, 防御: 0, 暴击: 0, 暴击伤害: 8.1, 攻击加成: 7.5, 生命加成: 0, 防御加成: 5.8 }, // 霰弹 专用消焰器
48
- { 攻击: 31, 生命: 0, 防御: 0, 暴击: 10.4, 暴击伤害: 10.4, 攻击加成: 7.5, 生命加成: 0, 防御加成: 0 }, // 霰弹 专用消音器
49
- { 攻击: 49, 生命: 0, 防御: 17, 暴击: 0, 暴击伤害: 0, 攻击加成: 7.6, 生命加成: 0, 防御加成: 6.9 }, // 机枪 重型制退器
50
- { 攻击: 46, 生命: 116, 防御: 27, 暴击: 0, 暴击伤害: 0, 攻击加成: 5.0, 生命加成: 0, 防御加成: 0 }, // 冲锋 消焰器攻击头
51
- { 攻击: 42, 生命: 0, 防御: 0, 暴击: 11.5, 暴击伤害: 0, 攻击加成: 6.8, 生命加成: 0, 防御加成: 0 }, // 狙击 异位打击 快拆战术
52
- { 攻击: 34, 生命: 101, 防御: 0, 暴击: 0, 暴击伤害: 0, 攻击加成: 6.5, 生命加成: 0, 防御加成: 0 }, // 霰弹 减伤支援 钢化铆钉
53
- { 攻击: 38, 生命: 0, 防御: 0, 暴击: 8.4, 暴击伤害: 0, 攻击加成: 4.8, 生命加成: 0, 防御加成: 0 }, // 冲锋 异位打击 内瞄式红
54
- { 攻击: 43, 生命: 0, 防御: 8.0, 暴击: 0, 暴击伤害: 0, 攻击加成: 7.3, 生命加成: 0, 防御加成: 0 }, // 机枪 双重对策 镭射插件
55
- { 攻击: 42, 生命: 54, 防御: 0, 暴击: 0, 暴击伤害: 0, 攻击加成: 6.2, 生命加成: 0, 防御加成: 0 }, // 机枪 双重对策 折叠脚架
56
- ];
57
- const Pointify = (ed) => UtilFunctions_1.UtilFunc.mapEntries(ed, (k, v) => v ? v / BASE_MAX[k] : 0);
58
- const Sump = (ed) => Object.values(ed).reduce((r, v) => r + v);
59
- const pipeFunc = UtilFP_1.UtilFP.flow(Pointify, Sump);
60
- const Display = (list) => list.reduce((r, v) => `${r}\t${v.toFixed(2)}`, "").trim();
61
- const pre = 精调前.map((v) => pipeFunc(v));
62
- const aft = 精调后.map((v) => pipeFunc(v));
63
- const div = pre.map((dv, i) => aft[i] / dv);
64
- Display(pre); //?
65
- Display(aft); //?
66
- Display(div); //?
67
- // 定义一个函数,它将作为构造函数
68
- function MyObject() {
69
- // @ts-ignore
70
- this.a = 123;
71
- }
72
- let asloop = [
73
- {
74
- type: "effect_of_condition",
75
- id: "loop",
76
- effect: [
77
- { if: { math: ["i", ">", "0"] },
78
- then: [
79
- { u_message: "hello world" },
80
- { math: ["i", "-=", "1"] },
81
- { run_eocs: "loop" },
82
- ] }
83
- ]
84
- },
85
- {
86
- type: "effect_of_condition",
87
- id: "main",
88
- effect: [
89
- { math: ["i", "=", "10"] },
90
- { run_eocs: "loop" }
91
- ]
92
- }
93
- ];
94
- let asaloop = [
95
- {
96
- type: "effect_of_condition",
97
- id: "loop",
98
- effect: [
99
- { u_message: "hello world" }
100
- ]
101
- },
102
- {
103
- type: "effect_of_condition",
104
- id: "main",
105
- effect: [
106
- {
107
- run_eoc_with: "efl",
108
- variables: {
109
- i: "0",
110
- length: "10",
111
- eoc: "loop"
112
- }
113
- }
114
- ]
115
- }
116
- ];
117
- const testa = {
118
- _a: 123
119
- };
120
- Object.defineProperty(testa, 'a', {
121
- get: () => 1,
122
- set: function (value) {
123
- console.log('Set:', value);
124
- },
125
- enumerable: true
126
- });
127
- Object.defineProperty(testa, 'c', {
128
- value: 123,
129
- writable: true,
130
- enumerable: true,
131
- configurable: true
132
- });
133
- testa.constructor.prototype; //?
134
- testa; //?
135
- let testkeys = [];
136
- for (let k in testa)
137
- testkeys.push(k);
138
- testkeys; //?
139
- const a = "123";
@@ -1 +0,0 @@
1
- export {};
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path = require("path");
4
- const UtilFileTools_1 = require("../UtilFileTools");
5
- // 将字符串转换为十六进制
6
- function stringToHex(str) {
7
- const buf = Buffer.from(str, 'utf8');
8
- return buf.toString('hex');
9
- }
10
- // 将十六进制转换为字符串
11
- function hexToString(hex) {
12
- const buf = Buffer.from(hex, 'hex');
13
- return buf.toString('utf8');
14
- }
15
- // 示例
16
- let str = "Hello World";
17
- let hex = "0B0000002D";
18
- console.log(stringToHex(str)); // 输出字符串对应的十六进制
19
- console.log(hexToString(hex)); // 输出十六进制对应的字符串
20
- hexToString("556E6974794653"); //?
21
- /**
22
- 首先我有一个文件夹./in
23
- 我在里面存放了一些整合加密的二进制文件,文件名符合正则/.*\.bk/
24
- 我需要你帮我写解密程序,将其解密并分离为单独的文件,接下来我告诉你解密方式:
25
- 读取文件后,我们先用split(hexToString(hex))对文本进行分割成多块,然后在每一块找到第二个"UnityFS",
26
- 再从第二个UnityFS的开头截取到每一块的末尾
27
- 我举一个例子,假设我们有一段分割完成的文本块 "112233 UnityFS sasasd UnityFS我需要的内容"
28
- 那么它截取完成之后应该是"UnityFS我需要的内容"
29
- 最后,我们在将所有截取完成的文本块作为文件输出到./out/{filename}
30
- 文件名就是 {原文件名+块编号.bs}
31
- 开始写吧
32
- **/
33
- path.parse("123.bs").name; //?
34
- let filepath = "F:\\Sosarciel\\SosarcielCore\\NodeJs\\utils\\src";
35
- UtilFileTools_1.UtilFT.fileSearchGlob(`${filepath}/**/*.ts`, "**/test/**/*.ts"); //?
@@ -1,23 +0,0 @@
1
- import { UtilFunc } from '@';
2
- import { test, expect } from '@jest/globals';
3
-
4
- test('queueProc function', async () => {
5
- const results:number[] = [];
6
- const expectedResults:number[] = [];
7
- const tasks = Array.from({length: 10}, (_, i) => {
8
- const result = Math.floor(Math.random() * 100); // 随机生成结果
9
- expectedResults.push(result);
10
- return async () => {
11
- await UtilFunc.sleep(Math.random() * 800); // 随机延迟
12
- results.push(result);
13
- };
14
- });
15
- console.log("结果应该为:",expectedResults);
16
-
17
- // 同时启动所有任务,但由于 queueProc 的设计,它们应该按顺序完成
18
- const promises = tasks.map(task => UtilFunc.queueProc('test', task));
19
- await Promise.all(promises);
20
-
21
- // 检查结果是否按顺序
22
- expect(results).toEqual(expectedResults);
23
- },10000);
@@ -1,38 +0,0 @@
1
- import { Completed, Failed, PromiseStat, PromiseVerifyFn, Success, UtilFunc } from "@";
2
- import { test, expect } from '@jest/globals';
3
-
4
-
5
-
6
-
7
- const timeList = [8000,1000,1000000] as const;
8
- const resList = [Success,Failed,Failed] as const;
9
- let index = 0;
10
-
11
- // 模拟的异步函数,有一定几率失败
12
- async function mockAsyncFunction() {
13
- return new Promise<Success|Failed>((resolve, reject) => {
14
- let delay = timeList[index];
15
- let result = resList[index];
16
- console.log('当前预期 延迟:',delay,' 结果:',result);
17
- setTimeout(() => {
18
- resolve(result);
19
- }, delay);
20
- index++;
21
- });
22
- }
23
-
24
- // 验证函数,只有当结果为 "Success" 时才认为成功
25
- function mockVerifyFunction(result:Success|Failed):PromiseStat {
26
- return result === Success ? Success : Failed;
27
- }
28
-
29
- // 测试 repeatPromise 函数
30
- test('repeatPromise', async () => {
31
- const repeatCount = 3;
32
- const awaitTime = 5;
33
- console.log("重试次数:",repeatCount," 超时时间:",awaitTime)
34
- const result = await UtilFunc.repeatPromise(
35
- mockAsyncFunction, mockVerifyFunction,
36
- repeatCount, awaitTime);
37
- expect(result).toBe(Success);
38
- },10000);
package/jest/jest.test.ts DELETED
@@ -1,46 +0,0 @@
1
- import { test, expect } from '@jest/globals';
2
- // main.test.ts
3
- const add = (a: number, b: number): number => a + b;
4
-
5
- test('1+2等于3', () => {
6
- expect(add(1, 2)).toBe(3);
7
- });
8
- test('console.log test', () => {
9
- const consoleSpy = jest.spyOn(console, 'log');
10
-
11
- // 这里是你的函数,它会打印 "成功" 或 "失败"
12
- function yourFunction() {
13
- console.log('成功');
14
- }
15
-
16
- yourFunction();
17
-
18
- expect(consoleSpy).toHaveBeenCalledWith('成功');
19
-
20
- // 清理 spy
21
- consoleSpy.mockRestore();
22
- });
23
-
24
- test('mult console.log test', () => {
25
- const consoleSpy = jest.spyOn(console, 'log');
26
-
27
- // 这里是你的函数
28
- function yourFunction() {
29
- console.log("xxxx1234");
30
- console.log("111abc22");
31
- console.log("11def");
32
- console.log("xxxxxxx");
33
- }
34
-
35
- yourFunction();
36
-
37
- // 检查 console.log 的输出中是否包含 "abc" 和 "def"
38
- const hasAbc = consoleSpy.mock.calls.some(args => args.some(arg => arg.includes('abc')));
39
- const hasDef = consoleSpy.mock.calls.some(args => args.some(arg => arg.includes('def')));
40
-
41
- expect(hasAbc).toBe(true);
42
- expect(hasDef).toBe(true);
43
-
44
- // 清理 spy
45
- consoleSpy.mockRestore();
46
- });
@@ -1,134 +0,0 @@
1
- import { assertThisAs } from "@src/backup";
2
- import { Mixinable, UtilFP, UtilFunc } from ".."
3
- import { Writable } from "stream";
4
-
5
- type MixinA = Mixinable<A>;
6
- class A implements MixinA{
7
- anum = 1;
8
- constructor(n=1){this.anum=n}
9
- getNum = ()=>this.anum;
10
- /**A的函数 */
11
- getA=()=>this;
12
- readonly MIXIN_KEY = "__a" as const;
13
- static MIXIN_FIELDS = ['getNum','getA','anum'] as const;
14
- readonly MIXIN_FIELDS = A.MIXIN_FIELDS;
15
- }
16
- class B implements Mixinable<B>{
17
- private text = "B的text";
18
- getText = ()=>this.text;
19
- /**B的函数 */
20
- getB = ()=> this;
21
- /**B的静态函数 */
22
- static getNewB = ()=>new B();
23
- /**保留的函数 */
24
- privateFunc(){
25
- console.log()
26
- }
27
- readonly MIXIN_KEY = "__b" as const;
28
- static readonly MIXIN_FIELDS = ['getText','getB'] as const;
29
- readonly MIXIN_FIELDS = B.MIXIN_FIELDS;
30
- }
31
- class _C {
32
- static create(){
33
- return new _C() as C;
34
- }
35
- private constructor() {
36
- composeC(this)
37
- }
38
- getC(this:C){return this};
39
- testFunc(this:C){
40
- console.log(this);
41
- return 2;
42
- }
43
- readonly MIXIN_KEY = "__c" as const;
44
- static readonly MIXIN_FIELDS = [
45
- ...A.MIXIN_FIELDS,
46
- ...B.MIXIN_FIELDS,
47
- 'getC','__a'
48
- ] as const;
49
- readonly MIXIN_FIELDS = C.MIXIN_FIELDS;
50
- }
51
- function composeC(obj:_C){
52
- let ob1 = UtilFunc.composeMixinable(obj,new B(),new A());
53
- let ob3 = UtilFP.bindTo('bindFunc',()=>"这是动态绑定的函数",ob1);
54
- return ob3;
55
- }
56
- export type C = ReturnType<typeof composeC>;
57
- export const C = _C;
58
-
59
- const insc:C=C.create();//?
60
- console.log(insc.__a)
61
- insc.getC().testFunc()//?
62
- insc.getNum()//?
63
- insc.anum//?
64
- insc.__a = new A(2);
65
- insc.getNum()//?
66
- insc.anum//?
67
- insc.testFunc();//?
68
- insc.getText();//?
69
- insc.getB().getText()//?
70
- insc.bindFunc()//?
71
-
72
- class _D{
73
- private constructor(){};
74
- static create(){
75
- return composeD(new _D());
76
- }
77
- #d = 123;
78
- }
79
- function composeD(obj:_D){
80
- let ob1 = UtilFunc.composeMixinable(obj,C.create());
81
- let ob3 = UtilFP.bindTo('bindFunc',()=>"这是动态绑定的函数",ob1);
82
- return ob3;
83
- }
84
- export type D = ReturnType<typeof composeD>;
85
- export const D = _D;
86
-
87
- let insd:D = D.create();
88
- insd//?
89
- insd.getB()//?
90
- insd.getNum()//?
91
- insd.__a = new A(3);
92
- insd.getNum()//?
93
-
94
-
95
-
96
- type jo = {
97
- a?:number,
98
- b?:string,
99
- c:number,
100
- }
101
- let jot = {
102
- c:1
103
- } as jo;
104
- UtilFunc.initObject(jot,{
105
- c:()=>console.log("缺少c"+insd.getNum())
106
- })
107
- jot//?
108
-
109
-
110
- type IfUndefined<T, Y, N> = T extends undefined ? Y : N;
111
-
112
- type RequiredOnly<T> = {
113
- [K in (keyof T) as
114
- T[K] extends Exclude<T[K],undefined>
115
- ? K
116
- : never
117
- ]: T[K]
118
- };
119
-
120
-
121
- type WithPrefix<T,P extends string> = {
122
- [K in (keyof T) as
123
- K extends string
124
- ? `${P}_${K}`
125
- : K
126
- ]: T[K]
127
- };
128
-
129
- type a= {
130
- abc:123
131
- def?:1
132
- }
133
- type d = RequiredOnly<a>;
134
- type b = WithPrefix<a,"prefix">;
@@ -1,5 +0,0 @@
1
- import { C } from "./composeTest";
2
-
3
-
4
-
5
- let a:C = C.create();
@@ -1,29 +0,0 @@
1
- import { Failed, PromiseStat, PromiseVerifyFn, Success, 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" ? Success : 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/src/test/test.ts DELETED
@@ -1,167 +0,0 @@
1
- import { UtilFP } from "@src/UtilFP";
2
- import { UtilFunc } from "@src/UtilFunctions";
3
- import { ComposedClass, FixedLengthTuple, FuncPropNames } from "@src/UtilInterfaces";
4
- import { ComposedFullClassMult, composeClassFull } from "@src/backup";
5
-
6
-
7
- // 使用示例
8
- class Monster{
9
- constructor(a:number){}
10
- monfunc(){
11
- return "mon"
12
- }
13
- }
14
- class Monster1{
15
- constructor(a:number){}
16
- m1num=123;
17
- monfunc1(){
18
- return "mon1"
19
- }
20
- }
21
- type OtherMonster = ComposedFullClassMult<{
22
- om:string
23
- mon:Monster
24
- },[Monster,Monster1]>
25
- const OtherMonster = {
26
- init(){
27
- let mon = new Monster(123);
28
- let mon1 = new Monster1(223);
29
- let om = {
30
- om:"123",mon
31
- }
32
- return composeClassFull(om,mon,mon1);
33
- }
34
- }
35
-
36
- let om = OtherMonster.init();//?
37
- om.monfunc();//?
38
- om.monfunc1();//?
39
- om.m1num//?
40
-
41
- type ExtData = {
42
- 攻击 : number;
43
- 生命 : number;
44
- 防御 : number;
45
- 暴击 : number;
46
- 暴击伤害 : number;
47
- 攻击加成 : number;
48
- 生命加成 : number;
49
- 防御加成 : number;
50
- };
51
- const BASE_MAX = { 攻击: 24, 生命: 54, 防御: 16, 暴击: 5, 暴击伤害: 5, 攻击加成: 3.8, 生命加成: 3.8, 防御加成: 3.8 }
52
- const 精调前 = [
53
- { 攻击 : 17, 生命: 0 , 防御: 0 , 暴击: 0 , 暴击伤害: 3.5 , 攻击加成: 3.0, 生命加成: 0, 防御加成: 3.4 } , // 霰弹 专用消焰器
54
- { 攻击 : 19, 生命: 0 , 防御: 0 , 暴击: 4.5 , 暴击伤害: 4.5 , 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 } , // 霰弹 专用消音器
55
- { 攻击 : 21, 生命: 0 , 防御: 10 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 3.8, 生命加成: 0, 防御加成: 3.0 } , // 机枪 重型制退器
56
- { 攻击 : 17, 生命: 48 , 防御: 14 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 2.6, 生命加成: 0, 防御加成: 0 } , // 冲锋 消焰器攻击头
57
- { 攻击 : 23, 生命: 0 , 防御: 0 , 暴击: 5 , 暴击伤害: 0 , 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 } , // 狙击 异位打击 快拆战术手电
58
- { 攻击 : 17, 生命: 53 , 防御: 0 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 } , // 霰弹 减伤支援 钢化铆钉
59
- { 攻击 : 21, 生命: 0 , 防御: 0 , 暴击: 3.5 , 暴击伤害: 0 , 攻击加成: 3.0, 生命加成: 0, 防御加成: 0 } , // 冲锋 异位打击 内瞄式红点
60
- { 攻击 : 17, 生命: 0 , 防御: 3.8, 暴击: 0 , 暴击伤害: 0 , 攻击加成: 2.6, 生命加成: 0, 防御加成: 0 } , // 机枪 双重对策 镭射插件
61
- { 攻击 : 19, 生命: 38 , 防御: 0 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 } , // 机枪 双重对策 折叠脚架
62
- ] as const;
63
- const 精调后 = [
64
- { 攻击 : 26, 生命: 0 , 防御: 0 , 暴击: 0 , 暴击伤害: 8.1 , 攻击加成: 7.5, 生命加成: 0, 防御加成: 5.8 } , // 霰弹 专用消焰器
65
- { 攻击 : 31, 生命: 0 , 防御: 0 , 暴击: 10.4, 暴击伤害: 10.4, 攻击加成: 7.5, 生命加成: 0, 防御加成: 0 } , // 霰弹 专用消音器
66
- { 攻击 : 49, 生命: 0 , 防御: 17 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 7.6, 生命加成: 0, 防御加成: 6.9 } , // 机枪 重型制退器
67
- { 攻击 : 46, 生命: 116, 防御: 27 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 5.0, 生命加成: 0, 防御加成: 0 } , // 冲锋 消焰器攻击头
68
- { 攻击 : 42, 生命: 0 , 防御: 0 , 暴击: 11.5, 暴击伤害: 0 , 攻击加成: 6.8, 生命加成: 0, 防御加成: 0 } , // 狙击 异位打击 快拆战术
69
- { 攻击 : 34, 生命: 101, 防御: 0 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 6.5, 生命加成: 0, 防御加成: 0 } , // 霰弹 减伤支援 钢化铆钉
70
- { 攻击 : 38, 生命: 0 , 防御: 0 , 暴击: 8.4 , 暴击伤害: 0 , 攻击加成: 4.8, 生命加成: 0, 防御加成: 0 } , // 冲锋 异位打击 内瞄式红
71
- { 攻击 : 43, 生命: 0 , 防御: 8.0, 暴击: 0 , 暴击伤害: 0 , 攻击加成: 7.3, 生命加成: 0, 防御加成: 0 } , // 机枪 双重对策 镭射插件
72
- { 攻击 : 42, 生命: 54 , 防御: 0 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 6.2, 生命加成: 0, 防御加成: 0 } , // 机枪 双重对策 折叠脚架
73
- ] as const;
74
- const Pointify = (ed:ExtData)=>
75
- UtilFunc.mapEntries(ed,(k,v)=> v ? v / BASE_MAX[k] : 0 );
76
- const Sump = (ed:ExtData)=> Object.values(ed).reduce((r,v)=>r+v);
77
- const pipeFunc = UtilFP.flow(Pointify,Sump);
78
- const Display = (list:number[])=>list.reduce((r,v)=>`${r}\t${v.toFixed(2)}`,"").trim();
79
- const pre = 精调前.map((v)=>pipeFunc(v));
80
- const aft = 精调后.map((v)=>pipeFunc(v));
81
- const div = pre.map((dv,i)=>aft[i]/dv);
82
- Display(pre)//?
83
- Display(aft)//?
84
- Display(div)//?
85
-
86
-
87
- interface obja {
88
- a: number;
89
- }
90
- // 定义一个函数,它将作为构造函数
91
- function MyObject() {
92
- // @ts-ignore
93
- this.a = 123;
94
- }
95
-
96
-
97
- let asloop = [
98
- {
99
- type:"effect_of_condition",
100
- id:"loop",
101
- effect:[
102
- {if:{math:["i",">","0"]},
103
- then:[
104
- {u_message:"hello world"},
105
- {math:["i","-=","1"]},
106
- {run_eocs:"loop"},
107
- ]}
108
- ]
109
- },
110
- {
111
- type:"effect_of_condition",
112
- id:"main",
113
- effect:[
114
- {math:["i","=","10"]},
115
- {run_eocs:"loop"}
116
- ]
117
- }
118
- ]
119
- let asaloop = [
120
- {
121
- type:"effect_of_condition",
122
- id:"loop",
123
- effect:[
124
- {u_message:"hello world"}
125
- ]
126
- },
127
- {
128
- type:"effect_of_condition",
129
- id:"main",
130
- effect:[
131
- {
132
- run_eoc_with:"efl",
133
- variables:{
134
- i:"0",
135
- length:"10",
136
- eoc:"loop"
137
- }
138
- }
139
- ]
140
- }
141
- ]
142
-
143
-
144
- const testa = {
145
- _a: 123
146
- }
147
- Object.defineProperty(testa, 'a', {
148
- get: () =>1,
149
- set: function(value) {
150
- console.log('Set:', value);
151
- },
152
- enumerable: true
153
- });
154
- Object.defineProperty(testa, 'c', {
155
- value: 123,
156
- writable: true,
157
- enumerable: true,
158
- configurable: true
159
- });
160
- testa.constructor.prototype//?
161
- testa//?
162
- let testkeys:any = [];
163
- for(let k in testa)
164
- testkeys.push(k)
165
- testkeys//?
166
-
167
- const a = "123";
package/src/test/test2.ts DELETED
@@ -1,39 +0,0 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
3
- import { UtilFT } from "@src/UtilFileTools";
4
-
5
- // 将字符串转换为十六进制
6
- function stringToHex(str:string) {
7
- const buf = Buffer.from(str, 'utf8');
8
- return buf.toString('hex');
9
- }
10
-
11
- // 将十六进制转换为字符串
12
- function hexToString(hex:string) {
13
- const buf = Buffer.from(hex, 'hex');
14
- return buf.toString('utf8');
15
- }
16
-
17
- // 示例
18
- let str = "Hello World";
19
- let hex = "0B0000002D";
20
-
21
- console.log(stringToHex(str)); // 输出字符串对应的十六进制
22
- console.log(hexToString(hex)); // 输出十六进制对应的字符串
23
- hexToString("556E6974794653")//?
24
- /**
25
- 首先我有一个文件夹./in
26
- 我在里面存放了一些整合加密的二进制文件,文件名符合正则/.*\.bk/
27
- 我需要你帮我写解密程序,将其解密并分离为单独的文件,接下来我告诉你解密方式:
28
- 读取文件后,我们先用split(hexToString(hex))对文本进行分割成多块,然后在每一块找到第二个"UnityFS",
29
- 再从第二个UnityFS的开头截取到每一块的末尾
30
- 我举一个例子,假设我们有一段分割完成的文本块 "112233 UnityFS sasasd UnityFS我需要的内容"
31
- 那么它截取完成之后应该是"UnityFS我需要的内容"
32
- 最后,我们在将所有截取完成的文本块作为文件输出到./out/{filename}
33
- 文件名就是 {原文件名+块编号.bs}
34
- 开始写吧
35
- **/
36
- path.parse("123.bs").name;//?
37
-
38
- let filepath = "F:\\Sosarciel\\SosarcielCore\\NodeJs\\utils\\src"
39
- UtilFT.fileSearchGlob(`${filepath}/**/*.ts`,"**/test/**/*.ts");//?