@zwa73/utils 1.0.46 → 1.0.49
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/UtilClass.d.ts +36 -0
- package/dist/UtilClass.js +53 -1
- package/dist/UtilCom.js +6 -6
- package/dist/UtilDecorators.d.ts +8 -12
- package/dist/UtilDecorators.js +75 -13
- package/dist/UtilFileTools.d.ts +12 -2
- package/dist/UtilFileTools.js +23 -9
- package/dist/UtilFunctions.d.ts +74 -14
- package/dist/UtilFunctions.js +156 -37
- package/dist/UtilInterfaces.d.ts +22 -9
- package/dist/test/test.d.ts +1 -0
- package/dist/test/test.js +187 -0
- package/dist/test/test2.d.ts +1 -0
- package/dist/test/test2.js +35 -0
- package/package.json +4 -2
- package/postinstall.js +39 -0
- package/publish.bat +1 -1
- package/src/UtilClass.ts +68 -0
- package/src/UtilCom.ts +7 -7
- package/src/UtilDecorators.ts +66 -12
- package/src/UtilFileTools.ts +21 -9
- package/src/UtilFunctions.ts +212 -39
- package/src/UtilInterfaces.ts +56 -11
- package/src/test/test.ts +223 -0
- package/src/test/test2.ts +40 -0
- package/tsconfig.json +2 -0
package/dist/UtilFunctions.js
CHANGED
|
@@ -93,6 +93,7 @@ var UtilFunc;
|
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
UtilFunc.exec = exec;
|
|
96
|
+
/**永不完成的Promise单例 */
|
|
96
97
|
const NeverResolvedPromise = new Promise(() => { });
|
|
97
98
|
/**获得一个永不完成的Promise单例 */
|
|
98
99
|
function getNeverResolvedPromise() {
|
|
@@ -103,11 +104,14 @@ var UtilFunc;
|
|
|
103
104
|
* @async
|
|
104
105
|
* @param {PromiseProcFn<T>} [procFn] - 发起函数
|
|
105
106
|
* @param {PromiseVerifyFn<T>} [verifyFn] - 验证函数
|
|
106
|
-
* @param {number} [repeatCount]
|
|
107
|
-
* @param {number} [repeatTime]
|
|
108
|
-
* @returns {Promise<T|null>}
|
|
107
|
+
* @param {number} [repeatCount] - 重试次数
|
|
108
|
+
* @param {number} [repeatTime] - 超时时间/秒 最小为10秒
|
|
109
|
+
* @returns {Promise<T|null>} - 结果 null 为全部失败/超时
|
|
109
110
|
*/
|
|
110
111
|
async function repeatPromise(procFn, verifyFn, repeatCount = 3, repeatTime = 180) {
|
|
112
|
+
//计时
|
|
113
|
+
const timeflag = "repeatPromise " + UtilFunc.genUUID();
|
|
114
|
+
UtilLogger_1.SLogger.time(timeflag);
|
|
111
115
|
//转换为毫秒
|
|
112
116
|
const hasRepeatTime = (repeatTime >= 10);
|
|
113
117
|
if (hasRepeatTime)
|
|
@@ -130,58 +134,173 @@ var UtilFunc;
|
|
|
130
134
|
resolveFn = null;
|
|
131
135
|
};
|
|
132
136
|
//进行中的请求
|
|
133
|
-
const plist =
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
137
|
+
const plist = [];
|
|
138
|
+
//开始处理
|
|
139
|
+
try {
|
|
140
|
+
for (let i = 0; i < repeatCount;) {
|
|
141
|
+
UtilLogger_1.SLogger.info(`开始第 ${i + 1} 次 repeatPromise`);
|
|
142
|
+
//创建当前任务
|
|
143
|
+
if (plist.length < i + 1) {
|
|
144
|
+
plist.push(procFn().then(result => ({ result, stat: verifyFn(result), index: i })));
|
|
145
|
+
}
|
|
146
|
+
//创建定时器
|
|
147
|
+
if (timerP == null) {
|
|
148
|
+
timerP = new Promise(function (resolve, rejecte) {
|
|
149
|
+
resolveFn = resolve;
|
|
150
|
+
timer = setTimeout(() => resolve("Timeout"), hasRepeatTime ? repeatTime : Infinity); //无限制则无限时间
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
//等待完成
|
|
154
|
+
const currObj = await Promise.race([...plist, timerP]);
|
|
155
|
+
//超时处理
|
|
156
|
+
if (currObj == "Timeout") {
|
|
157
|
+
UtilLogger_1.SLogger.warn(`第 ${i + 1} 次 repeatPromise 超时 ${repeatTime} ms 开始重试`);
|
|
158
|
+
clearTimer();
|
|
159
|
+
i++;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
156
162
|
const poststat = await currObj.stat;
|
|
157
163
|
switch (poststat) {
|
|
158
164
|
case "Completed": //完成
|
|
159
|
-
UtilLogger_1.SLogger.info(
|
|
160
|
-
|
|
165
|
+
UtilLogger_1.SLogger.info(`第 ${currObj.index + 1} 次 repeatPromise 成功`);
|
|
166
|
+
//非当前
|
|
167
|
+
if (currObj.index != i)
|
|
168
|
+
UtilLogger_1.SLogger.info(`成功的 promise 非当前 promise 考虑增大重试间隔\n当前index: ${i}\n当前间隔: ${repeatTime}`);
|
|
161
169
|
return currObj.result;
|
|
162
170
|
case "Terminated": //终止
|
|
163
|
-
UtilLogger_1.SLogger.warn(
|
|
164
|
-
clearTimer();
|
|
171
|
+
UtilLogger_1.SLogger.warn(`第 ${currObj.index + 1} 次 repeatPromise 终止 停止重试`);
|
|
165
172
|
return currObj.result;
|
|
166
173
|
case "Failed": //验证失败
|
|
174
|
+
//抛弃失败
|
|
175
|
+
plist[currObj.index] = UtilFunc.getNeverResolvedPromise();
|
|
167
176
|
//是当前
|
|
168
177
|
if (currObj.index == i) {
|
|
169
|
-
UtilLogger_1.SLogger.warn(
|
|
178
|
+
UtilLogger_1.SLogger.warn(`第 ${currObj.index + 1} 次 repeatPromise 失败 开始重试`);
|
|
170
179
|
clearTimer();
|
|
171
180
|
i++;
|
|
172
181
|
continue;
|
|
173
182
|
}
|
|
174
183
|
//非当前
|
|
175
|
-
UtilLogger_1.SLogger.warn(
|
|
176
|
-
//抛弃失败
|
|
177
|
-
plist[currObj.index] = UtilFunc.getNeverResolvedPromise();
|
|
184
|
+
UtilLogger_1.SLogger.warn(`第 ${currObj.index + 1} 次 repeatPromise 失败`);
|
|
178
185
|
continue;
|
|
179
186
|
}
|
|
180
187
|
}
|
|
188
|
+
//全部失败或超时则返回null
|
|
189
|
+
UtilLogger_1.SLogger.warn(`${repeatCount} 次 repeatPromise 尝试均失败`);
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
catch (err) {
|
|
193
|
+
UtilLogger_1.SLogger.warn(`repeatPromise 发生错误`, err);
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
//清理
|
|
198
|
+
clearTimer();
|
|
199
|
+
UtilLogger_1.SLogger.timeEnd(timeflag);
|
|
181
200
|
}
|
|
182
|
-
clearTimer();
|
|
183
|
-
//全部失败或超时则返回null
|
|
184
|
-
return null;
|
|
185
201
|
}
|
|
186
202
|
UtilFunc.repeatPromise = repeatPromise;
|
|
203
|
+
/**柯里化转换
|
|
204
|
+
* @param {T} fn - 将要转换的函数
|
|
205
|
+
* @returns {CurryFunc<T>} 柯里化的函数
|
|
206
|
+
*/
|
|
207
|
+
function curry(fn) {
|
|
208
|
+
return (function curried(...args) {
|
|
209
|
+
if (args.length >= fn.length)
|
|
210
|
+
return fn(...args);
|
|
211
|
+
return (...restArgs) => curried(...args, ...restArgs);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
UtilFunc.curry = curry;
|
|
215
|
+
/**函数组合
|
|
216
|
+
* 从右到左执行
|
|
217
|
+
* @param {Function[]} funcs - 待组合的函数
|
|
218
|
+
* @returns {(arg: any)=>any} 组合完成的函数
|
|
219
|
+
*/
|
|
220
|
+
function compose(...funcs) {
|
|
221
|
+
return (arg) => funcs.reduceRight((value, func) => func(value), arg);
|
|
222
|
+
}
|
|
223
|
+
UtilFunc.compose = compose;
|
|
224
|
+
/**函数管道
|
|
225
|
+
* 从左到右执行
|
|
226
|
+
* @param {((arg: T) => T)} funcs - 待组合的函数
|
|
227
|
+
* @returns {((arg: T) => T)} 组合完成的函数
|
|
228
|
+
*/
|
|
229
|
+
function pipeline(...funcs) {
|
|
230
|
+
return (arg) => {
|
|
231
|
+
return funcs.reduce((value, func) => func(value), arg);
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
UtilFunc.pipeline = pipeline;
|
|
235
|
+
/**部分类组合
|
|
236
|
+
* 将mixin的部分字段混入base
|
|
237
|
+
* @param base - 基础类
|
|
238
|
+
* @param mixin - 目标类
|
|
239
|
+
* @param fields - 需要混入的字段
|
|
240
|
+
* @returns - 混合完成的类
|
|
241
|
+
*/
|
|
242
|
+
function composePartClass(base, mixin, ...fields) {
|
|
243
|
+
const compObj = base;
|
|
244
|
+
for (const fd of fields) {
|
|
245
|
+
Object.defineProperty(compObj, fd, {
|
|
246
|
+
get: () => mixin[fd],
|
|
247
|
+
set: (value) => { mixin[fd] = value; },
|
|
248
|
+
enumerable: true,
|
|
249
|
+
//writable: true ,
|
|
250
|
+
configurable: true
|
|
251
|
+
});
|
|
252
|
+
//(compObj as any)[fd] = (mixin[fd] as any).bind(mixin);
|
|
253
|
+
}
|
|
254
|
+
return compObj;
|
|
255
|
+
}
|
|
256
|
+
UtilFunc.composePartClass = composePartClass;
|
|
257
|
+
/**类组合
|
|
258
|
+
* 将mixinList每个成员的字段混入base
|
|
259
|
+
* @param base - 基础类
|
|
260
|
+
* @param mixinList - 目标类
|
|
261
|
+
* @returns - 混合完成的类
|
|
262
|
+
*/
|
|
263
|
+
function composeClass(base, ...mixinList) {
|
|
264
|
+
let obj = base;
|
|
265
|
+
for (let mixin of mixinList) {
|
|
266
|
+
let propks = Object.getOwnPropertyNames(mixin.constructor.prototype);
|
|
267
|
+
for (const key of propks) {
|
|
268
|
+
if (key != "constructor") {
|
|
269
|
+
Object.defineProperty(obj, key, {
|
|
270
|
+
get: () => mixin[key],
|
|
271
|
+
set: (value) => { mixin[key] = value; },
|
|
272
|
+
enumerable: true,
|
|
273
|
+
//writable: true,
|
|
274
|
+
configurable: true
|
|
275
|
+
});
|
|
276
|
+
//obj[key] = (mixin as any)[key];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
for (const key in mixin) {
|
|
280
|
+
Object.defineProperty(obj, key, {
|
|
281
|
+
get: () => mixin[key],
|
|
282
|
+
set: (value) => { mixin[key] = value; },
|
|
283
|
+
enumerable: true,
|
|
284
|
+
//writable: true ,
|
|
285
|
+
configurable: true
|
|
286
|
+
});
|
|
287
|
+
//obj[key] = (mixin as any)[key];
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return obj;
|
|
291
|
+
}
|
|
292
|
+
UtilFunc.composeClass = composeClass;
|
|
293
|
+
/**对对象的每个属性应用映射函数,并返回一个新的对象。
|
|
294
|
+
* @template T - 对象的类型
|
|
295
|
+
* @param obj - 要处理的对象
|
|
296
|
+
* @param mapper - 映射函数,接受一个值和一个键,返回一个新的值
|
|
297
|
+
* @returns - 一个新的对象,它的属性是原对象的属性经过映射函数处理后的结果
|
|
298
|
+
*/
|
|
299
|
+
function mapObject(obj, mapper) {
|
|
300
|
+
return Object.entries(obj).reduce((result, [key, value]) => {
|
|
301
|
+
result[key] = mapper(key, value);
|
|
302
|
+
return result;
|
|
303
|
+
}, {});
|
|
304
|
+
}
|
|
305
|
+
UtilFunc.mapObject = mapObject;
|
|
187
306
|
})(UtilFunc = exports.UtilFunc || (exports.UtilFunc = {}));
|
package/dist/UtilInterfaces.d.ts
CHANGED
|
@@ -54,15 +54,6 @@ type ExclusiveRecursive<B, T, K extends string[], R extends unknown[] = []> = R[
|
|
|
54
54
|
export type ExclusiveRecord<B, T, K extends string[], TMP = ExclusiveRecursive<B, T, K>> = TMP[keyof TMP];
|
|
55
55
|
/**符合JObject约束的互斥表 */
|
|
56
56
|
export type ExclusiveJObject<B extends JObject, T extends JToken, K extends string[], TMP extends JArray = ExclusiveRecursive<B, T, K>> = TMP[number];
|
|
57
|
-
/**进行中的请求 */
|
|
58
|
-
export type ProcessingPromise<T> = {
|
|
59
|
-
/**主体请求 */
|
|
60
|
-
result: T;
|
|
61
|
-
/**请求状态 */
|
|
62
|
-
stat: PromiseStat | Promise<PromiseStat>;
|
|
63
|
-
/**请求下标/序号 */
|
|
64
|
-
index: number;
|
|
65
|
-
};
|
|
66
57
|
/**请求完成状态 成功/失败/终止
|
|
67
58
|
* 成功/终止 将直接返回
|
|
68
59
|
* 失败 将重试
|
|
@@ -72,4 +63,26 @@ export type PromiseStat = "Completed" | "Failed" | "Terminated";
|
|
|
72
63
|
export type PromiseVerifyFn<T> = (obj: T) => Promise<PromiseStat> | PromiseStat;
|
|
73
64
|
/**发起promise的函数 */
|
|
74
65
|
export type PromiseProcFn<T> = () => Promise<T>;
|
|
66
|
+
/**类型中任意函数的字符串名称 */
|
|
67
|
+
export type FuncPropNames<T> = {
|
|
68
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
|
|
69
|
+
}[keyof T];
|
|
70
|
+
/**部分组合的类
|
|
71
|
+
* @template {Base} - 基类
|
|
72
|
+
* @template {Mixin} - 待混入的类
|
|
73
|
+
* @template {PropKeys} - 需要混入的成员key
|
|
74
|
+
*/
|
|
75
|
+
export type ComposedPartClass<Base extends object, Mixin extends object, PropKeys extends keyof Mixin> = Base & Pick<Mixin, PropKeys>;
|
|
76
|
+
/**组合的类 嵌套变体 */
|
|
77
|
+
export type ComposedPartClassMult<Base extends object, Mixin1 extends object = {}, PropKeys1 extends keyof Mixin1 = keyof Mixin1, Mixin2 extends object = {}, PropKeys2 extends keyof Mixin2 = keyof Mixin2, Mixin3 extends object = {}, PropKeys3 extends keyof Mixin3 = keyof Mixin3, Mixin4 extends object = {}, PropKeys4 extends keyof Mixin4 = keyof Mixin4, Mixin5 extends object = {}, PropKeys5 extends keyof Mixin5 = keyof Mixin5, Mixin6 extends object = {}, PropKeys6 extends keyof Mixin6 = keyof Mixin6> = ComposedPartClass<ComposedPartClass<ComposedPartClass<ComposedPartClass<ComposedPartClass<ComposedPartClass<Base, Mixin1, PropKeys1>, Mixin2, PropKeys2>, Mixin3, PropKeys3>, Mixin4, PropKeys4>, Mixin5, PropKeys5>, Mixin6, PropKeys6>;
|
|
78
|
+
/**组合的类
|
|
79
|
+
* @template {Base} - 基类
|
|
80
|
+
* @template {Mixin} - 待混入的类
|
|
81
|
+
*/
|
|
82
|
+
export type ComposedClass<Base extends object, Mixin extends object> = Base & Mixin;
|
|
83
|
+
/**组合的类 多组合变体
|
|
84
|
+
* @template {Base} - 基类
|
|
85
|
+
* @template {MixinList}- 待混入的类型数组
|
|
86
|
+
*/
|
|
87
|
+
export type ComposedClassMult<Base extends object, MixinList extends object[]> = MixinList extends [infer Mixin, ...infer Rest] ? Mixin extends object ? Rest extends object[] ? ComposedClassMult<ComposedClass<Base, Mixin>, Rest> : Base : Base : Base;
|
|
75
88
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const UtilFunctions_1 = require("../UtilFunctions");
|
|
4
|
+
const compKeys = ["getData", "getA"];
|
|
5
|
+
class A {
|
|
6
|
+
abc = 223;
|
|
7
|
+
/**A的getData */
|
|
8
|
+
getData() {
|
|
9
|
+
return this.abc;
|
|
10
|
+
}
|
|
11
|
+
/**获取A */
|
|
12
|
+
getA() {
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
class C {
|
|
17
|
+
abc = 3333;
|
|
18
|
+
/**A的getData */
|
|
19
|
+
resetData() {
|
|
20
|
+
return this.abc;
|
|
21
|
+
}
|
|
22
|
+
/**获取C */
|
|
23
|
+
getC() {
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
/**获取C */
|
|
27
|
+
getC1() {
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class B {
|
|
32
|
+
_bc;
|
|
33
|
+
constructor() {
|
|
34
|
+
const tb = this;
|
|
35
|
+
this._bc = UtilFunctions_1.UtilFunc.composePartClass(tb, new A(), ...compKeys);
|
|
36
|
+
}
|
|
37
|
+
static init() {
|
|
38
|
+
return new B()._bc;
|
|
39
|
+
}
|
|
40
|
+
/**B的getData */
|
|
41
|
+
getData1() { return "BGetdata"; }
|
|
42
|
+
getTest() { return this._bc.getData(); }
|
|
43
|
+
}
|
|
44
|
+
const BComp = {
|
|
45
|
+
init() {
|
|
46
|
+
return B.init();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
let c = BComp.init();
|
|
50
|
+
console.log(1);
|
|
51
|
+
let d = c.getData(); //?
|
|
52
|
+
c.getA;
|
|
53
|
+
c.getData1(); //?
|
|
54
|
+
c.getTest(); //?
|
|
55
|
+
let r3 = null;
|
|
56
|
+
class Monster {
|
|
57
|
+
constructor(a) { }
|
|
58
|
+
monfunc() {
|
|
59
|
+
return "mon";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
class Monster1 {
|
|
63
|
+
constructor(a) { }
|
|
64
|
+
m1num = 123;
|
|
65
|
+
monfunc1() {
|
|
66
|
+
return "mon1";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const OtherMonster = {
|
|
70
|
+
init() {
|
|
71
|
+
let mon = new Monster(123);
|
|
72
|
+
let mon1 = new Monster1(223);
|
|
73
|
+
let om = {
|
|
74
|
+
om: "123", mon
|
|
75
|
+
};
|
|
76
|
+
return UtilFunctions_1.UtilFunc.composeClass(om, mon, mon1);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
let om = OtherMonster.init(); //?
|
|
80
|
+
om.monfunc(); //?
|
|
81
|
+
om.monfunc1(); //?
|
|
82
|
+
om.m1num; //?
|
|
83
|
+
const BASE_MAX = { 攻击: 24, 生命: 54, 防御: 16, 暴击: 5, 暴击伤害: 5, 攻击加成: 3.8, 生命加成: 3.8, 防御加成: 3.8 };
|
|
84
|
+
const 精调前 = [
|
|
85
|
+
{ 攻击: 17, 生命: 0, 防御: 0, 暴击: 0, 暴击伤害: 3.5, 攻击加成: 3.0, 生命加成: 0, 防御加成: 3.4 },
|
|
86
|
+
{ 攻击: 19, 生命: 0, 防御: 0, 暴击: 4.5, 暴击伤害: 4.5, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 },
|
|
87
|
+
{ 攻击: 21, 生命: 0, 防御: 10, 暴击: 0, 暴击伤害: 0, 攻击加成: 3.8, 生命加成: 0, 防御加成: 3.0 },
|
|
88
|
+
{ 攻击: 17, 生命: 48, 防御: 14, 暴击: 0, 暴击伤害: 0, 攻击加成: 2.6, 生命加成: 0, 防御加成: 0 },
|
|
89
|
+
{ 攻击: 23, 生命: 0, 防御: 0, 暴击: 5, 暴击伤害: 0, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 },
|
|
90
|
+
{ 攻击: 17, 生命: 53, 防御: 0, 暴击: 0, 暴击伤害: 0, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 },
|
|
91
|
+
{ 攻击: 21, 生命: 0, 防御: 0, 暴击: 3.5, 暴击伤害: 0, 攻击加成: 3.0, 生命加成: 0, 防御加成: 0 },
|
|
92
|
+
{ 攻击: 17, 生命: 0, 防御: 3.8, 暴击: 0, 暴击伤害: 0, 攻击加成: 2.6, 生命加成: 0, 防御加成: 0 },
|
|
93
|
+
{ 攻击: 19, 生命: 38, 防御: 0, 暴击: 0, 暴击伤害: 0, 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 }, // 机枪 双重对策 折叠脚架
|
|
94
|
+
];
|
|
95
|
+
const 精调后 = [
|
|
96
|
+
{ 攻击: 26, 生命: 0, 防御: 0, 暴击: 0, 暴击伤害: 8.1, 攻击加成: 7.5, 生命加成: 0, 防御加成: 5.8 },
|
|
97
|
+
{ 攻击: 31, 生命: 0, 防御: 0, 暴击: 10.4, 暴击伤害: 10.4, 攻击加成: 7.5, 生命加成: 0, 防御加成: 0 },
|
|
98
|
+
{ 攻击: 49, 生命: 0, 防御: 17, 暴击: 0, 暴击伤害: 0, 攻击加成: 7.6, 生命加成: 0, 防御加成: 6.9 },
|
|
99
|
+
{ 攻击: 46, 生命: 116, 防御: 27, 暴击: 0, 暴击伤害: 0, 攻击加成: 5.0, 生命加成: 0, 防御加成: 0 },
|
|
100
|
+
{ 攻击: 42, 生命: 0, 防御: 0, 暴击: 11.5, 暴击伤害: 0, 攻击加成: 6.8, 生命加成: 0, 防御加成: 0 },
|
|
101
|
+
{ 攻击: 34, 生命: 101, 防御: 0, 暴击: 0, 暴击伤害: 0, 攻击加成: 6.5, 生命加成: 0, 防御加成: 0 },
|
|
102
|
+
{ 攻击: 38, 生命: 0, 防御: 0, 暴击: 8.4, 暴击伤害: 0, 攻击加成: 4.8, 生命加成: 0, 防御加成: 0 },
|
|
103
|
+
{ 攻击: 43, 生命: 0, 防御: 8.0, 暴击: 0, 暴击伤害: 0, 攻击加成: 7.3, 生命加成: 0, 防御加成: 0 },
|
|
104
|
+
{ 攻击: 42, 生命: 54, 防御: 0, 暴击: 0, 暴击伤害: 0, 攻击加成: 6.2, 生命加成: 0, 防御加成: 0 }, // 机枪 双重对策 折叠脚架
|
|
105
|
+
];
|
|
106
|
+
const Pointify = (ed) => UtilFunctions_1.UtilFunc.mapObject(ed, (k, v) => v ? v / BASE_MAX[k] : 0);
|
|
107
|
+
const Sump = (ed) => Object.values(ed).reduce((r, v) => r + v);
|
|
108
|
+
const pipeFunc = UtilFunctions_1.UtilFunc.pipeline(Pointify, Sump);
|
|
109
|
+
const Display = (list) => list.reduce((r, v) => `${r}\t${v.toFixed(2)}`, "").trim();
|
|
110
|
+
const pre = 精调前.map((v) => pipeFunc(v));
|
|
111
|
+
const aft = 精调后.map((v) => pipeFunc(v));
|
|
112
|
+
const div = pre.map((dv, i) => aft[i] / dv);
|
|
113
|
+
Display(pre); //?
|
|
114
|
+
Display(aft); //?
|
|
115
|
+
Display(div); //?
|
|
116
|
+
// 定义一个函数,它将作为构造函数
|
|
117
|
+
function MyObject() {
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
this.a = 123;
|
|
120
|
+
}
|
|
121
|
+
let asloop = [
|
|
122
|
+
{
|
|
123
|
+
type: "effect_of_condition",
|
|
124
|
+
id: "loop",
|
|
125
|
+
effect: [
|
|
126
|
+
{ if: { math: ["i", ">", "0"] },
|
|
127
|
+
then: [
|
|
128
|
+
{ u_message: "hello world" },
|
|
129
|
+
{ math: ["i", "-=", "1"] },
|
|
130
|
+
{ run_eocs: "loop" },
|
|
131
|
+
] }
|
|
132
|
+
]
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
type: "effect_of_condition",
|
|
136
|
+
id: "main",
|
|
137
|
+
effect: [
|
|
138
|
+
{ math: ["i", "=", "10"] },
|
|
139
|
+
{ run_eocs: "loop" }
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
];
|
|
143
|
+
let asaloop = [
|
|
144
|
+
{
|
|
145
|
+
type: "effect_of_condition",
|
|
146
|
+
id: "loop",
|
|
147
|
+
effect: [
|
|
148
|
+
{ u_message: "hello world" }
|
|
149
|
+
]
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
type: "effect_of_condition",
|
|
153
|
+
id: "main",
|
|
154
|
+
effect: [
|
|
155
|
+
{
|
|
156
|
+
run_eoc_with: "efl",
|
|
157
|
+
variables: {
|
|
158
|
+
i: "0",
|
|
159
|
+
length: "10",
|
|
160
|
+
eoc: "loop"
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
];
|
|
166
|
+
const testa = {
|
|
167
|
+
_a: 123
|
|
168
|
+
};
|
|
169
|
+
Object.defineProperty(testa, 'a', {
|
|
170
|
+
get: () => 1,
|
|
171
|
+
set: function (value) {
|
|
172
|
+
console.log('Set:', value);
|
|
173
|
+
},
|
|
174
|
+
enumerable: true
|
|
175
|
+
});
|
|
176
|
+
Object.defineProperty(testa, 'c', {
|
|
177
|
+
value: 123,
|
|
178
|
+
writable: true,
|
|
179
|
+
enumerable: true,
|
|
180
|
+
configurable: true
|
|
181
|
+
});
|
|
182
|
+
testa.constructor.prototype; //?
|
|
183
|
+
testa; //?
|
|
184
|
+
let testkeys = [];
|
|
185
|
+
for (let k in testa)
|
|
186
|
+
testkeys.push(k);
|
|
187
|
+
testkeys; //?
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
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"); //?
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zwa73/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.49",
|
|
4
4
|
"description": "my utils",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "node test"
|
|
7
|
+
"test": "node test",
|
|
8
|
+
"postinstall": "node postinstall.js"
|
|
8
9
|
},
|
|
9
10
|
"keywords": [
|
|
10
11
|
"zwa73"
|
|
@@ -16,6 +17,7 @@
|
|
|
16
17
|
"esm": "^3.2.25",
|
|
17
18
|
"esm-resolve": "^1.0.8",
|
|
18
19
|
"fluent-ffmpeg": "^2.1.2",
|
|
20
|
+
"glob": "^10.3.10",
|
|
19
21
|
"html-entities": "^2.3.3",
|
|
20
22
|
"http-proxy-agent": "^5.0.0",
|
|
21
23
|
"https-proxy-agent": "^5.0.1",
|
package/postinstall.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const currentVersion = require('./package.json').version;
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { UtilFT } = require("./index");
|
|
4
|
+
const dataPath = path.join(__dirname,"..","version.json");
|
|
5
|
+
UtilFT.ensurePathExists(dataPath);
|
|
6
|
+
let dataTable = UtilFT.loadJSONFileSync(dataPath,{});
|
|
7
|
+
dataTable.utils = dataTable.utils??{};
|
|
8
|
+
let prevVersion = dataTable.utils.version;
|
|
9
|
+
dataTable.utils.version = currentVersion;
|
|
10
|
+
|
|
11
|
+
console.log(`${currentVersion} 版本已安装`);
|
|
12
|
+
|
|
13
|
+
// 将版本号转换为可以比较的数字
|
|
14
|
+
function versionToNumber(version) {
|
|
15
|
+
if(version==undefined) return 0;
|
|
16
|
+
return version.split('.').map(Number).reduce((acc, val) => acc * 1000 + val);
|
|
17
|
+
}
|
|
18
|
+
//提示表
|
|
19
|
+
const infoTable = {
|
|
20
|
+
"1.0.17":"fileSearch 函数进入 UtilFT 命名空间",
|
|
21
|
+
"1.0.47":"UtilFT.fileSearch 函数与返回值发生变动, 请使用fileSearchRegex 或 fileSearchGlob"
|
|
22
|
+
}
|
|
23
|
+
//显示提示
|
|
24
|
+
function showUpgradeMessages(prevVersion, currentVersion, infoTable) {
|
|
25
|
+
let prevVersionNumber = versionToNumber(prevVersion);
|
|
26
|
+
let currentVersionNumber = versionToNumber(currentVersion);
|
|
27
|
+
// 遍历infoTable中的所有版本
|
|
28
|
+
for (let version in infoTable) {
|
|
29
|
+
let versionNumber = versionToNumber(version);
|
|
30
|
+
// 如果用户的上一个版本低于这个版本,而当前版本高于或等于这个版本
|
|
31
|
+
if (versionNumber > prevVersionNumber && versionNumber <= currentVersionNumber) {
|
|
32
|
+
// 显示这个版本的提示信息
|
|
33
|
+
console.log(infoTable[version]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 使用这个函数来显示升级信息
|
|
39
|
+
showUpgradeMessages(prevVersion, currentVersion, infoTable);
|
package/publish.bat
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
npm publish --access public
|
|
1
|
+
call npm publish --access public
|
|
2
2
|
pause
|
package/src/UtilClass.ts
CHANGED
|
@@ -981,3 +981,71 @@ class SKVC {
|
|
|
981
981
|
|
|
982
982
|
constructor() {}
|
|
983
983
|
}
|
|
984
|
+
|
|
985
|
+
/**函数组合器 */
|
|
986
|
+
export class Composer<Result,PreArg = Result> {
|
|
987
|
+
/**组合函数列表 */
|
|
988
|
+
private funcs: Function[] = [];
|
|
989
|
+
private constructor(){};
|
|
990
|
+
/**添加单个参数与返回值不同的函数 */
|
|
991
|
+
public static push<Result,Arg>(func: (arg: Arg) => Result): Composer<Result,Arg>;
|
|
992
|
+
/**添加多个参数与返回值相同的函数 */
|
|
993
|
+
public static push<Result>(func:((arg: Result) => Result), ...funcs: ((arg: Result) => Result)[]): Composer<Result>;
|
|
994
|
+
public static push(...funcs: Function[]){
|
|
995
|
+
const newComposer = new Composer<any>();
|
|
996
|
+
newComposer.funcs = [...funcs];
|
|
997
|
+
return newComposer;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/**添加单个参数与返回值不同的函数 */
|
|
1001
|
+
public push<T>(func: (arg: T) => PreArg): Composer<Result,T>;
|
|
1002
|
+
/**添加多个参数与返回值相同的函数 */
|
|
1003
|
+
public push(func:((arg: Result) => Result), ...funcs: ((arg: PreArg) => PreArg)[]): Composer<Result,PreArg>;
|
|
1004
|
+
public push(...funcs: Function[]): Composer<Result,any> {
|
|
1005
|
+
const newComposer = new Composer<Result>();
|
|
1006
|
+
newComposer.funcs = [...this.funcs, ...funcs];
|
|
1007
|
+
return newComposer;
|
|
1008
|
+
}
|
|
1009
|
+
/**组合函数 */
|
|
1010
|
+
public compose():(arg:PreArg)=>Result {
|
|
1011
|
+
return (arg:PreArg) => this.funcs.reduceRight((value, func) => func(value), arg) as any as Result;
|
|
1012
|
+
}
|
|
1013
|
+
/**直接调用 */
|
|
1014
|
+
public invoke(arg:PreArg):Result {
|
|
1015
|
+
return this.funcs.reduceRight((value, func) => func(value), arg) as any as Result;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
/**函数管道器 */
|
|
1019
|
+
export class Piper<Arg, Result = Arg> {
|
|
1020
|
+
/**管道函数列表 */
|
|
1021
|
+
private funcs: Function[] = [];
|
|
1022
|
+
private constructor(){};
|
|
1023
|
+
/**添加单个参数与返回值不同的函数 */
|
|
1024
|
+
public static pipe<Arg, Result>(func: (arg: Arg) => Result): Piper<Arg, Result>;
|
|
1025
|
+
/**添加多个参数与返回值相同的函数 */
|
|
1026
|
+
public static pipe<Arg>(func:((arg: Arg) => Arg), ...funcs: ((arg: Arg) => Arg)[]): Piper<Arg>;
|
|
1027
|
+
public static pipe(...funcs: Function[]){
|
|
1028
|
+
const newPiper = new Piper<any>();
|
|
1029
|
+
newPiper.funcs = [...funcs];
|
|
1030
|
+
return newPiper;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/**添加单个参数与返回值不同的函数 */
|
|
1034
|
+
public pipe<T>(func: (arg: Result) => T): Piper<Arg, T>;
|
|
1035
|
+
/**添加多个参数与返回值相同的函数 */
|
|
1036
|
+
public pipe(func:((arg: Result) => Result), ...funcs: ((arg: Result) => Result)[]): Piper<Arg, Result>;
|
|
1037
|
+
public pipe(...funcs: Function[]): Piper<Arg, any> {
|
|
1038
|
+
const newPiper = new Piper<Arg>();
|
|
1039
|
+
newPiper.funcs = [...this.funcs, ...funcs];
|
|
1040
|
+
return newPiper;
|
|
1041
|
+
}
|
|
1042
|
+
/**管道函数 */
|
|
1043
|
+
public pipeline():(arg:Arg)=>Result {
|
|
1044
|
+
return (arg:Arg) => this.funcs.reduce((value, func) => func(value), arg) as any as Result;
|
|
1045
|
+
}
|
|
1046
|
+
/**直接调用 */
|
|
1047
|
+
public invoke(arg:Arg):Result {
|
|
1048
|
+
return this.funcs.reduce((value, func) => func(value), arg) as any as Result;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
|