@zwa73/utils 1.0.47 → 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.
@@ -1,5 +1,5 @@
1
1
  import * as crypto from "crypto";
2
- import { JToken, PromiseProcFn, PromiseStat, PromiseVerifyFn } from "./UtilInterfaces";
2
+ import { ComposedClass, ComposedClassMult, ComposedPartClass as ComposedPartClass, FuncPropNames, JToken, PromiseProcFn, PromiseStat, PromiseVerifyFn } from "./UtilInterfaces";
3
3
  import * as cp from "child_process";
4
4
  import { SLogger } from "./UtilLogger";
5
5
 
@@ -92,6 +92,7 @@ export function exec(command: string) {
92
92
  });
93
93
  }
94
94
 
95
+ /**永不完成的Promise单例 */
95
96
  const NeverResolvedPromise = new Promise(()=>{});
96
97
  /**获得一个永不完成的Promise单例 */
97
98
  export function getNeverResolvedPromise<T>():Promise<T>{
@@ -112,9 +113,9 @@ type ProcessingPromise<T> = {
112
113
  * @async
113
114
  * @param {PromiseProcFn<T>} [procFn] - 发起函数
114
115
  * @param {PromiseVerifyFn<T>} [verifyFn] - 验证函数
115
- * @param {number} [repeatCount] - 重试次数
116
- * @param {number} [repeatTime] - 超时时间/秒 最小为10秒
117
- * @returns {Promise<T|null>} - 结果 null 为全部失败/超时
116
+ * @param {number} [repeatCount] - 重试次数
117
+ * @param {number} [repeatTime] - 超时时间/秒 最小为10秒
118
+ * @returns {Promise<T|null>} - 结果 null 为全部失败/超时
118
119
  */
119
120
  export async function repeatPromise<T>(procFn:PromiseProcFn<T>,verifyFn?:PromiseVerifyFn<T>,
120
121
  repeatCount:number=3,repeatTime:number=180):Promise<T|null>{
@@ -215,5 +216,150 @@ export async function repeatPromise<T>(procFn:PromiseProcFn<T>,verifyFn?:Promise
215
216
  }
216
217
  }
217
218
 
219
+
220
+ /**柯里化函数类型 */
221
+ type CurryFunc<T, PrevArgs extends any[] = []> = T extends (...args: infer Args) => infer Result
222
+ ? Args extends [infer Arg, ...infer RestArgs]
223
+ ? RestArgs extends []
224
+ ? ((...args: [...PrevArgs, Arg]) => Result )
225
+ : ((...args: [...PrevArgs, Arg]) => CurryFunc<(...rest:RestArgs) => Result> )
226
+ & (CurryFunc<(...args: RestArgs) => Result, [...PrevArgs, Arg]>)
227
+ : Args extends []
228
+ ? () => Result
229
+ : never
230
+ : never;
231
+
232
+ /**柯里化转换
233
+ * @param {T} fn - 将要转换的函数
234
+ * @returns {CurryFunc<T>} 柯里化的函数
235
+ */
236
+ export function curry<T extends (...args: any[]) => any>(fn: T): CurryFunc<T> {
237
+ return (function curried(...args: any[]) {
238
+ if (args.length >= fn.length)
239
+ return fn(...args);
240
+ return (...restArgs: any[]) => curried(...args, ...restArgs);
241
+ }) as CurryFunc<T>;
242
+ }
243
+ /**
244
+ let sumvoid = ()=>10;
245
+ let a = curry(sumvoid);//?
246
+ console.log(a());
247
+ let sum = (a:number,b:string,c:number,d:boolean)=>a+b+c+d;
248
+ let sumCu = curry(sum);//?
249
+ let suma = sumCu(1)("ss");//?
250
+ let sumb = sumCu(1,"1")(2);//?
251
+ let sumc = sumCu(4);//?
252
+ let sumz = sumCu(1,"b",3)(false);//?
253
+ console.log(suma(2,true));
254
+ console.log(sumb(true));
255
+ console.log(sumc("s",3,false));
256
+ */
257
+ /**可组合的函数 */
258
+ type CompFunc<T = any, R = any> = (arg: T) => R;
259
+ /**函数组合 从右到左执行 */
260
+ export function compose<T>(...fs: CompFunc<T, T>[]): CompFunc<T, T>;
261
+ export function compose<T, R>(f1: CompFunc<T, R>): CompFunc<T, R>;
262
+ export function compose<T, R, R1>(f2: CompFunc<R, R1>, f1: CompFunc<T, R>): CompFunc<T, R1>;
263
+ export function compose<T, R, R1, R2>(f3: CompFunc<R1, R2>, f2: CompFunc<R, R1>, f1: CompFunc<T, R>): CompFunc<T, R2>;
264
+ export function compose<T, R, R1, R2, R3>(f4: CompFunc<R2, R3>, f3: CompFunc<R1, R2>, f2: CompFunc<R, R1>, f1: CompFunc<T, R>): CompFunc<T, R3>;
265
+ export function compose<T, R, R1, R2, R3, R4>(f5: CompFunc<R3, R4>,f4: CompFunc<R2, R3>, f3: CompFunc<R1, R2>, f2: CompFunc<R, R1>, f1: CompFunc<T, R>): CompFunc<T, R4>;
266
+ /**函数组合
267
+ * 从右到左执行
268
+ * @param {Function[]} funcs - 待组合的函数
269
+ * @returns {(arg: any)=>any} 组合完成的函数
270
+ */
271
+ export function compose(...funcs: Function[]) {
272
+ return (arg: any) => funcs.reduceRight((value, func) => func(value), arg);
273
+ }
274
+ /**函数管道 从左到右执行 */
275
+ export function pipeline<T>(...fs: CompFunc<T, T>[]): CompFunc<T, T>;
276
+ export function pipeline<T, R>(f1: CompFunc<T, R>): CompFunc<T, R>;
277
+ export function pipeline<T, R, R1>(f1: CompFunc<T, R>, f2: CompFunc<R, R1>): CompFunc<T, R1>;
278
+ export function pipeline<T, R, R1, R2>(f1: CompFunc<T, R>, f2: CompFunc<R, R1>, f3: CompFunc<R1, R2>): CompFunc<T, R2>;
279
+ export function pipeline<T, R, R1, R2, R3>(f1: CompFunc<T, R>, f2: CompFunc<R, R1>, f3: CompFunc<R1, R2>, f4: CompFunc<R2, R3>): CompFunc<T, R3>;
280
+ export function pipeline<T, R, R1, R2, R3, R4>(f1: CompFunc<T, R>, f2: CompFunc<R, R1>, f3: CompFunc<R1, R2>, f4: CompFunc<R2, R3>, f5: CompFunc<R3, R4>): CompFunc<T, R4>;
281
+ /**函数管道
282
+ * 从左到右执行
283
+ * @param {((arg: T) => T)} funcs - 待组合的函数
284
+ * @returns {((arg: T) => T)} 组合完成的函数
285
+ */
286
+ export function pipeline<T>(...funcs: ((arg: T) => T)[]): (arg: T) => T {
287
+ return (arg: T): T => {
288
+ return funcs.reduce((value, func) => func(value), arg);
289
+ };
290
+ }
291
+
292
+ /**部分类组合
293
+ * 将mixin的部分字段混入base
294
+ * @param base - 基础类
295
+ * @param mixin - 目标类
296
+ * @param fields - 需要混入的字段
297
+ * @returns - 混合完成的类
298
+ */
299
+ export function composePartClass<Base extends object,Mixin extends object>
300
+ (base:Base,mixin:Mixin,...fields:(keyof Mixin)[]):ComposedPartClass<Base,Mixin,keyof Mixin>{
301
+ const compObj = base as any;
302
+ for(const fd of fields){
303
+ Object.defineProperty(compObj, fd, {
304
+ get: ()=>mixin[fd],
305
+ set: (value)=>{mixin[fd] = value},
306
+ enumerable:true ,
307
+ //writable: true ,
308
+ configurable: true
309
+ });
310
+ //(compObj as any)[fd] = (mixin[fd] as any).bind(mixin);
311
+ }
312
+ return compObj;
313
+ }
314
+ /**类组合
315
+ * 将mixinList每个成员的字段混入base
316
+ * @param base - 基础类
317
+ * @param mixinList - 目标类
318
+ * @returns - 混合完成的类
319
+ */
320
+ export function composeClass<Base extends object,MixinList extends object[]>
321
+ (base:Base,...mixinList:MixinList):ComposedClassMult<Base,MixinList>{
322
+ let obj = base as any;
323
+ for(let mixin of mixinList as any){
324
+ let propks = Object.getOwnPropertyNames(mixin.constructor.prototype)
325
+ for(const key of propks){
326
+ if(key != "constructor"){
327
+ Object.defineProperty(obj, key, {
328
+ get: ()=>mixin[key],
329
+ set: (value)=>{mixin[key] = value},
330
+ enumerable:true,
331
+ //writable: true,
332
+ configurable: true
333
+ });
334
+ //obj[key] = (mixin as any)[key];
335
+ }
336
+ }
337
+ for(const key in mixin){
338
+ Object.defineProperty(obj, key, {
339
+ get: ()=>mixin[key],
340
+ set: (value)=>{mixin[key] = value},
341
+ enumerable:true ,
342
+ //writable: true ,
343
+ configurable: true
344
+ });
345
+ //obj[key] = (mixin as any)[key];
346
+ }
347
+ }
348
+ return obj;
349
+ }
350
+
351
+ /**对对象的每个属性应用映射函数,并返回一个新的对象。
352
+ * @template T - 对象的类型
353
+ * @param obj - 要处理的对象
354
+ * @param mapper - 映射函数,接受一个值和一个键,返回一个新的值
355
+ * @returns - 一个新的对象,它的属性是原对象的属性经过映射函数处理后的结果
356
+ */
357
+ export function mapObject<T extends Object>
358
+ (obj: T, mapper: (key: keyof T, value: T[keyof T]) => T[keyof T]): T {
359
+ return Object.entries(obj).reduce((result, [key, value]) => {
360
+ result[key as keyof T] = mapper(key as keyof T, value);
361
+ return result;
362
+ }, {} as T);
218
363
  }
219
364
 
365
+ }
@@ -80,4 +80,59 @@ export type PromiseStat = "Completed"|"Failed"|"Terminated";
80
80
  /**promise验证函数 */
81
81
  export type PromiseVerifyFn<T> = (obj:T)=>Promise<PromiseStat>|PromiseStat;
82
82
  /**发起promise的函数 */
83
- export type PromiseProcFn<T> = ()=>Promise<T>;
83
+ export type PromiseProcFn<T> = ()=>Promise<T>;
84
+
85
+ /**类型中任意函数的字符串名称 */
86
+ export type FuncPropNames<T> = {
87
+ [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
88
+ }[keyof T];
89
+
90
+ /**部分组合的类
91
+ * @template {Base} - 基类
92
+ * @template {Mixin} - 待混入的类
93
+ * @template {PropKeys} - 需要混入的成员key
94
+ */
95
+ export type ComposedPartClass<Base extends object, Mixin extends object, PropKeys extends keyof Mixin> =
96
+ Base & Pick<Mixin, PropKeys>;
97
+
98
+ /**组合的类 嵌套变体 */
99
+ export type ComposedPartClassMult<Base extends object,
100
+ Mixin1 extends object = {}, PropKeys1 extends keyof Mixin1 = keyof Mixin1,
101
+ Mixin2 extends object = {}, PropKeys2 extends keyof Mixin2 = keyof Mixin2,
102
+ Mixin3 extends object = {}, PropKeys3 extends keyof Mixin3 = keyof Mixin3,
103
+ Mixin4 extends object = {}, PropKeys4 extends keyof Mixin4 = keyof Mixin4,
104
+ Mixin5 extends object = {}, PropKeys5 extends keyof Mixin5 = keyof Mixin5,
105
+ Mixin6 extends object = {}, PropKeys6 extends keyof Mixin6 = keyof Mixin6> =
106
+ ComposedPartClass<ComposedPartClass<ComposedPartClass<
107
+ ComposedPartClass<ComposedPartClass<ComposedPartClass<
108
+ Base,
109
+ Mixin1,PropKeys1>,Mixin2,PropKeys2>,Mixin3,PropKeys3>,
110
+ Mixin4,PropKeys4>,Mixin5,PropKeys5>,Mixin6,PropKeys6>
111
+
112
+ /**递归多组合 仅单key有效 */
113
+ type ComposedClassOnceKey<Base extends object,Data extends [object,string][]> =
114
+ Data extends [[infer Mixin extends object, infer FuncKeys], ...infer Rest]
115
+ ? FuncKeys extends FuncPropNames<Mixin>
116
+ ? Rest extends [any, any][]
117
+ ? ComposedClassOnceKey<ComposedPartClass<Base, Mixin, FuncKeys>,Rest>
118
+ : Base
119
+ : Base
120
+ : Base;
121
+
122
+ /**组合的类
123
+ * @template {Base} - 基类
124
+ * @template {Mixin} - 待混入的类
125
+ */
126
+ export type ComposedClass<Base extends object,Mixin extends object> = Base&Mixin;
127
+ /**组合的类 多组合变体
128
+ * @template {Base} - 基类
129
+ * @template {MixinList}- 待混入的类型数组
130
+ */
131
+ export type ComposedClassMult<Base extends object,MixinList extends object[]> =
132
+ MixinList extends [infer Mixin, ...infer Rest]
133
+ ? Mixin extends object
134
+ ? Rest extends object[]
135
+ ? ComposedClassMult<ComposedClass<Base,Mixin>,Rest>
136
+ : Base
137
+ : Base
138
+ : Base;
@@ -0,0 +1,223 @@
1
+ import { UtilFunc } from "../UtilFunctions";
2
+ import { ComposedClassMult, ComposedPartClass, ComposedPartClassMult, FixedLengthTuple, FuncPropNames } from "../UtilInterfaces";
3
+
4
+ const compKeys = ["getData","getA"] as const;
5
+
6
+ class A {
7
+ abc=223;
8
+ /**A的getData */
9
+ getData(){
10
+ return this.abc
11
+ }
12
+ /**获取A */
13
+ getA(){
14
+ return this;
15
+ }
16
+ }
17
+ class C {
18
+ abc=3333;
19
+ /**A的getData */
20
+ resetData(){
21
+ return this.abc
22
+ }
23
+ /**获取C */
24
+ getC(){
25
+ return this;
26
+ }
27
+ /**获取C */
28
+ private getC1(){
29
+ return this;
30
+ }
31
+ }
32
+ class B{
33
+ private _bc:BComp;
34
+ private constructor(){
35
+ const tb:B = this;
36
+ this._bc = UtilFunc.composePartClass(tb, new A(), ...compKeys);
37
+ }
38
+ static init(){
39
+ return new B()._bc;
40
+ }
41
+ /**B的getData */
42
+ getData1(){return "BGetdata"}
43
+ getTest(){return this._bc.getData()}
44
+ }
45
+ type BComp = ComposedPartClass<B, A, typeof compKeys[number]>;
46
+ const BComp = {
47
+ init(){
48
+ return B.init();
49
+ }
50
+ }
51
+
52
+ let c:BComp = BComp.init();
53
+ console.log(1);
54
+ let d = c.getData();//?
55
+ c.getA
56
+ c.getData1();//?
57
+ c.getTest();//?
58
+
59
+ // 使用示例
60
+ type R3 = ComposedPartClassMult<B, A, "getData"|"getA", C>
61
+ let r3:R3 = null as any;
62
+
63
+
64
+
65
+ class Monster{
66
+ constructor(a:number){}
67
+ monfunc(){
68
+ return "mon"
69
+ }
70
+ }
71
+ class Monster1{
72
+ constructor(a:number){}
73
+ m1num=123;
74
+ monfunc1(){
75
+ return "mon1"
76
+ }
77
+ }
78
+ type OtherMonster = ComposedClassMult<{
79
+ om:string
80
+ mon:Monster
81
+ },[Monster,Monster1]>
82
+ const OtherMonster = {
83
+ init():OtherMonster{
84
+ let mon = new Monster(123);
85
+ let mon1 = new Monster1(223);
86
+ let om = {
87
+ om:"123",mon
88
+ }
89
+ return UtilFunc.composeClass(om,mon,mon1);
90
+ }
91
+ }
92
+
93
+ let om = OtherMonster.init();//?
94
+ om.monfunc();//?
95
+ om.monfunc1();//?
96
+ om.m1num//?
97
+
98
+ type ExtData = {
99
+ 攻击 : number;
100
+ 生命 : number;
101
+ 防御 : number;
102
+ 暴击 : number;
103
+ 暴击伤害 : number;
104
+ 攻击加成 : number;
105
+ 生命加成 : number;
106
+ 防御加成 : number;
107
+ };
108
+ const BASE_MAX = { 攻击: 24, 生命: 54, 防御: 16, 暴击: 5, 暴击伤害: 5, 攻击加成: 3.8, 生命加成: 3.8, 防御加成: 3.8 }
109
+ const 精调前 = [
110
+ { 攻击 : 17, 生命: 0 , 防御: 0 , 暴击: 0 , 暴击伤害: 3.5 , 攻击加成: 3.0, 生命加成: 0, 防御加成: 3.4 } , // 霰弹 专用消焰器
111
+ { 攻击 : 19, 生命: 0 , 防御: 0 , 暴击: 4.5 , 暴击伤害: 4.5 , 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 } , // 霰弹 专用消音器
112
+ { 攻击 : 21, 生命: 0 , 防御: 10 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 3.8, 生命加成: 0, 防御加成: 3.0 } , // 机枪 重型制退器
113
+ { 攻击 : 17, 生命: 48 , 防御: 14 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 2.6, 生命加成: 0, 防御加成: 0 } , // 冲锋 消焰器攻击头
114
+ { 攻击 : 23, 生命: 0 , 防御: 0 , 暴击: 5 , 暴击伤害: 0 , 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 } , // 狙击 异位打击 快拆战术手电
115
+ { 攻击 : 17, 生命: 53 , 防御: 0 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 } , // 霰弹 减伤支援 钢化铆钉
116
+ { 攻击 : 21, 生命: 0 , 防御: 0 , 暴击: 3.5 , 暴击伤害: 0 , 攻击加成: 3.0, 生命加成: 0, 防御加成: 0 } , // 冲锋 异位打击 内瞄式红点
117
+ { 攻击 : 17, 生命: 0 , 防御: 3.8, 暴击: 0 , 暴击伤害: 0 , 攻击加成: 2.6, 生命加成: 0, 防御加成: 0 } , // 机枪 双重对策 镭射插件
118
+ { 攻击 : 19, 生命: 38 , 防御: 0 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 3.4, 生命加成: 0, 防御加成: 0 } , // 机枪 双重对策 折叠脚架
119
+ ] as const;
120
+ const 精调后 = [
121
+ { 攻击 : 26, 生命: 0 , 防御: 0 , 暴击: 0 , 暴击伤害: 8.1 , 攻击加成: 7.5, 生命加成: 0, 防御加成: 5.8 } , // 霰弹 专用消焰器
122
+ { 攻击 : 31, 生命: 0 , 防御: 0 , 暴击: 10.4, 暴击伤害: 10.4, 攻击加成: 7.5, 生命加成: 0, 防御加成: 0 } , // 霰弹 专用消音器
123
+ { 攻击 : 49, 生命: 0 , 防御: 17 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 7.6, 生命加成: 0, 防御加成: 6.9 } , // 机枪 重型制退器
124
+ { 攻击 : 46, 生命: 116, 防御: 27 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 5.0, 生命加成: 0, 防御加成: 0 } , // 冲锋 消焰器攻击头
125
+ { 攻击 : 42, 生命: 0 , 防御: 0 , 暴击: 11.5, 暴击伤害: 0 , 攻击加成: 6.8, 生命加成: 0, 防御加成: 0 } , // 狙击 异位打击 快拆战术
126
+ { 攻击 : 34, 生命: 101, 防御: 0 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 6.5, 生命加成: 0, 防御加成: 0 } , // 霰弹 减伤支援 钢化铆钉
127
+ { 攻击 : 38, 生命: 0 , 防御: 0 , 暴击: 8.4 , 暴击伤害: 0 , 攻击加成: 4.8, 生命加成: 0, 防御加成: 0 } , // 冲锋 异位打击 内瞄式红
128
+ { 攻击 : 43, 生命: 0 , 防御: 8.0, 暴击: 0 , 暴击伤害: 0 , 攻击加成: 7.3, 生命加成: 0, 防御加成: 0 } , // 机枪 双重对策 镭射插件
129
+ { 攻击 : 42, 生命: 54 , 防御: 0 , 暴击: 0 , 暴击伤害: 0 , 攻击加成: 6.2, 生命加成: 0, 防御加成: 0 } , // 机枪 双重对策 折叠脚架
130
+ ] as const;
131
+ const Pointify = (ed:ExtData)=>
132
+ UtilFunc.mapObject(ed,(k,v)=> v ? v / BASE_MAX[k] : 0 );
133
+ const Sump = (ed:ExtData)=> Object.values(ed).reduce((r,v)=>r+v);
134
+ const pipeFunc = UtilFunc.pipeline(Pointify,Sump);
135
+ const Display = (list:number[])=>list.reduce((r,v)=>`${r}\t${v.toFixed(2)}`,"").trim();
136
+ const pre = 精调前.map((v)=>pipeFunc(v));
137
+ const aft = 精调后.map((v)=>pipeFunc(v));
138
+ const div = pre.map((dv,i)=>aft[i]/dv);
139
+ Display(pre)//?
140
+ Display(aft)//?
141
+ Display(div)//?
142
+
143
+
144
+ interface obja {
145
+ a: number;
146
+ }
147
+ // 定义一个函数,它将作为构造函数
148
+ function MyObject() {
149
+ // @ts-ignore
150
+ this.a = 123;
151
+ }
152
+
153
+
154
+ let asloop = [
155
+ {
156
+ type:"effect_of_condition",
157
+ id:"loop",
158
+ effect:[
159
+ {if:{math:["i",">","0"]},
160
+ then:[
161
+ {u_message:"hello world"},
162
+ {math:["i","-=","1"]},
163
+ {run_eocs:"loop"},
164
+ ]}
165
+ ]
166
+ },
167
+ {
168
+ type:"effect_of_condition",
169
+ id:"main",
170
+ effect:[
171
+ {math:["i","=","10"]},
172
+ {run_eocs:"loop"}
173
+ ]
174
+ }
175
+ ]
176
+ let asaloop = [
177
+ {
178
+ type:"effect_of_condition",
179
+ id:"loop",
180
+ effect:[
181
+ {u_message:"hello world"}
182
+ ]
183
+ },
184
+ {
185
+ type:"effect_of_condition",
186
+ id:"main",
187
+ effect:[
188
+ {
189
+ run_eoc_with:"efl",
190
+ variables:{
191
+ i:"0",
192
+ length:"10",
193
+ eoc:"loop"
194
+ }
195
+ }
196
+ ]
197
+ }
198
+ ]
199
+
200
+
201
+ const testa = {
202
+ _a: 123
203
+ }
204
+ Object.defineProperty(testa, 'a', {
205
+ get: () =>1,
206
+ set: function(value) {
207
+ console.log('Set:', value);
208
+ },
209
+ enumerable: true
210
+ });
211
+ Object.defineProperty(testa, 'c', {
212
+ value: 123,
213
+ writable: true,
214
+ enumerable: true,
215
+ configurable: true
216
+ });
217
+ testa.constructor.prototype//?
218
+ testa//?
219
+ let testkeys:any = [];
220
+ for(let k in testa)
221
+ testkeys.push(k)
222
+ testkeys//?
223
+
@@ -0,0 +1,40 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import { globSync } from "glob";
4
+ import { UtilFT } from "../UtilFileTools";
5
+
6
+ // 将字符串转换为十六进制
7
+ function stringToHex(str:string) {
8
+ const buf = Buffer.from(str, 'utf8');
9
+ return buf.toString('hex');
10
+ }
11
+
12
+ // 将十六进制转换为字符串
13
+ function hexToString(hex:string) {
14
+ const buf = Buffer.from(hex, 'hex');
15
+ return buf.toString('utf8');
16
+ }
17
+
18
+ // 示例
19
+ let str = "Hello World";
20
+ let hex = "0B0000002D";
21
+
22
+ console.log(stringToHex(str)); // 输出字符串对应的十六进制
23
+ console.log(hexToString(hex)); // 输出十六进制对应的字符串
24
+ hexToString("556E6974794653")//?
25
+ /**
26
+ 首先我有一个文件夹./in
27
+ 我在里面存放了一些整合加密的二进制文件,文件名符合正则/.*\.bk/
28
+ 我需要你帮我写解密程序,将其解密并分离为单独的文件,接下来我告诉你解密方式:
29
+ 读取文件后,我们先用split(hexToString(hex))对文本进行分割成多块,然后在每一块找到第二个"UnityFS",
30
+ 再从第二个UnityFS的开头截取到每一块的末尾
31
+ 我举一个例子,假设我们有一段分割完成的文本块 "112233 UnityFS sasasd UnityFS我需要的内容"
32
+ 那么它截取完成之后应该是"UnityFS我需要的内容"
33
+ 最后,我们在将所有截取完成的文本块作为文件输出到./out/{filename}
34
+ 文件名就是 {原文件名+块编号.bs}
35
+ 开始写吧
36
+ **/
37
+ path.parse("123.bs").name;//?
38
+
39
+ let filepath = "F:\\Sosarciel\\SosarcielCore\\NodeJs\\utils\\src"
40
+ UtilFT.fileSearchGlob(`${filepath}/**/*.ts`,"**/test/**/*.ts");//?
package/tsconfig.json CHANGED
@@ -7,6 +7,8 @@
7
7
  "outDir": "./dist",
8
8
  "declaration": true,
9
9
  "baseUrl": ".",
10
+ "emitDecoratorMetadata": true,
11
+ "experimentalDecorators": true,
10
12
  "paths": {
11
13
  "@/*": ["./*"],
12
14
  "DataController": ["./src/DataController"],