@zwa73/utils 1.0.107 → 1.0.108
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/UtilFileTools.d.ts +4 -4
- package/dist/UtilFileTools.js +8 -8
- package/dist/UtilFunctions.d.ts +3 -3
- package/dist/UtilFunctions.js +12 -8
- package/dist/UtilInterfaces.d.ts +6 -5
- package/package.json +1 -1
- package/src/UtilFileTools.ts +8 -8
- package/src/UtilFunctions.ts +15 -11
- package/src/UtilInterfaces.ts +8 -8
package/dist/UtilFileTools.d.ts
CHANGED
|
@@ -98,21 +98,21 @@ export declare namespace UtilFT {
|
|
|
98
98
|
*/
|
|
99
99
|
function writeJSONFile(filePath: string, token: JToken): Promise<void>;
|
|
100
100
|
/**搜索路径符合正则表达式的文件
|
|
101
|
-
* @param
|
|
101
|
+
* @param dir - 起始目录
|
|
102
102
|
* @param traitRegex - 正则表达式
|
|
103
103
|
* @param opt - 可选参数
|
|
104
104
|
* @param opt.relative - 搜索子目录
|
|
105
105
|
* @returns 文件名路径数组
|
|
106
106
|
*/
|
|
107
|
-
function fileSearchRegex(
|
|
107
|
+
function fileSearchRegex(dir: string, traitRegex: string, opt?: FileSearchRegexOpt): string[];
|
|
108
108
|
/**搜索符合Glob匹配的文件
|
|
109
|
-
* @param
|
|
109
|
+
* @param dir - 起始目录
|
|
110
110
|
* @param globPattern - glob匹配
|
|
111
111
|
* @param opt - 可选参数
|
|
112
112
|
* @param opt.ignore - 忽略的文件
|
|
113
113
|
* @returns 文件绝对路径数组
|
|
114
114
|
*/
|
|
115
|
-
function fileSearchGlob(
|
|
115
|
+
function fileSearchGlob(dir: string, globPattern: string | string[], opt?: FileSearchGlobOpt): string[];
|
|
116
116
|
/**
|
|
117
117
|
* @deprecated 请使用 fileSearchRegex 或 fileSearchGlob
|
|
118
118
|
*/
|
package/dist/UtilFileTools.js
CHANGED
|
@@ -194,19 +194,19 @@ var UtilFT;
|
|
|
194
194
|
}
|
|
195
195
|
UtilFT.writeJSONFile = writeJSONFile;
|
|
196
196
|
/**搜索路径符合正则表达式的文件
|
|
197
|
-
* @param
|
|
197
|
+
* @param dir - 起始目录
|
|
198
198
|
* @param traitRegex - 正则表达式
|
|
199
199
|
* @param opt - 可选参数
|
|
200
200
|
* @param opt.relative - 搜索子目录
|
|
201
201
|
* @returns 文件名路径数组
|
|
202
202
|
*/
|
|
203
|
-
function fileSearchRegex(
|
|
203
|
+
function fileSearchRegex(dir, traitRegex, opt) {
|
|
204
204
|
const relative = opt?.relative ?? true;
|
|
205
205
|
const outArray = [];
|
|
206
|
-
const subFiles = fs.readdirSync(
|
|
206
|
+
const subFiles = fs.readdirSync(dir, { withFileTypes: true });
|
|
207
207
|
const regex = new RegExp(traitRegex);
|
|
208
208
|
for (const subFile of subFiles) {
|
|
209
|
-
const subFilePath = path.join(
|
|
209
|
+
const subFilePath = path.join(dir, subFile.name);
|
|
210
210
|
//判断是否是文件夹,递归调用
|
|
211
211
|
if (subFile.isDirectory()) {
|
|
212
212
|
if (relative)
|
|
@@ -220,16 +220,16 @@ var UtilFT;
|
|
|
220
220
|
}
|
|
221
221
|
UtilFT.fileSearchRegex = fileSearchRegex;
|
|
222
222
|
/**搜索符合Glob匹配的文件
|
|
223
|
-
* @param
|
|
223
|
+
* @param dir - 起始目录
|
|
224
224
|
* @param globPattern - glob匹配
|
|
225
225
|
* @param opt - 可选参数
|
|
226
226
|
* @param opt.ignore - 忽略的文件
|
|
227
227
|
* @returns 文件绝对路径数组
|
|
228
228
|
*/
|
|
229
|
-
function fileSearchGlob(
|
|
229
|
+
function fileSearchGlob(dir, globPattern, opt) {
|
|
230
230
|
const fixedPath = typeof globPattern === "string"
|
|
231
|
-
? path.join(
|
|
232
|
-
: globPattern.map((p) => path.join(
|
|
231
|
+
? path.join(dir, path.posix.normalize(globPattern))
|
|
232
|
+
: globPattern.map((p) => path.join(dir, path.posix.normalize(p)));
|
|
233
233
|
return (0, glob_1.globSync)(fixedPath, { ignore: opt?.ingore, absolute: true });
|
|
234
234
|
}
|
|
235
235
|
UtilFT.fileSearchGlob = fileSearchGlob;
|
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyFunc, ComposedClass, ComposedMixinable,
|
|
1
|
+
import { AnyFunc, ComposedClass, ComposedMixinable, ComposedRefMixinable, ExtractOutcome, IJData, JObject, JToken, Keyable, LiteralCheck, Matchable, MatchableFlag, Mixinable, Outcome, PromiseVerifyFn, RefMixinable, UnionToIntersection } from "./UtilInterfaces";
|
|
2
2
|
import { LogLevel } from "./UtilLogger";
|
|
3
3
|
import { FailedLike, None, StatusSymbol, Success, SuccessLike, Timeout } from "./UtilSymbol";
|
|
4
4
|
type SuccessOut<T> = Outcome<Success, T>;
|
|
@@ -83,11 +83,11 @@ export declare class UtilFunc {
|
|
|
83
83
|
*/
|
|
84
84
|
static composeClassPart<Base extends object, Mixin extends object, Field extends keyof Mixin>(base: Base, mixin: Mixin, key: string, ...fields: Field[]): ComposedClass<Base, Mixin, typeof key, Field>;
|
|
85
85
|
/**根据 MIXIN_FIELDS 自动混入
|
|
86
|
-
* @deprecated
|
|
86
|
+
* @deprecated 非必要情况下, 对class定义请使用 composeRefMixinable
|
|
87
87
|
*/
|
|
88
88
|
static composeMixinable<Base extends object, Mixins extends Mixinable<any>[]>(base: Base, ...mixins: Mixins): ComposedMixinable<Base, Mixins>;
|
|
89
89
|
/**根据 MIXIN_FIELDS 自动混入 */
|
|
90
|
-
static composeRefMixinable<Base extends object, Mixins extends RefMixinable<any, unknown>[]>(base: Base, ...mixins: Mixins):
|
|
90
|
+
static composeRefMixinable<Base extends object, Mixins extends RefMixinable<any, unknown>[]>(base: Base, ...mixins: Mixins): ComposedRefMixinable<Base, Mixins>;
|
|
91
91
|
/**对对象的每个属性应用映射函数,并返回一个新的对象。
|
|
92
92
|
* @template T - 对象的类型
|
|
93
93
|
* @param obj - 要处理的对象
|
package/dist/UtilFunctions.js
CHANGED
|
@@ -255,17 +255,21 @@ class UtilFunc {
|
|
|
255
255
|
for (const fd of fields) {
|
|
256
256
|
if (compObj[fd] !== undefined)
|
|
257
257
|
UtilLogger_1.SLogger.warn(`field: ${fd} 已存在于基础类中, 混入可能导致类型问题, 如需覆盖, 请使用 ${key}=val`);
|
|
258
|
-
//
|
|
259
|
-
// get: ()=>compObj[key][fd],
|
|
260
|
-
// set: (value)=>{compObj[key][fd] = value},
|
|
261
|
-
// enumerable:true ,
|
|
262
|
-
// //writable: true ,
|
|
263
|
-
// configurable: true
|
|
264
|
-
//});
|
|
258
|
+
//func需绑定this无法直接设置属性
|
|
265
259
|
if (typeof mixin[fd] === 'function') {
|
|
266
260
|
compObj[fd] = (...args) => compObj[key][fd](...args);
|
|
261
|
+
//#region other
|
|
262
|
+
//const memo = (...args: any[]) => compObj[key][fd](...args);
|
|
263
|
+
//Object.defineProperty(compObj, fd, {
|
|
264
|
+
// get:()=>memo,
|
|
265
|
+
// set:()=>SLogger.warn(new Error(`试图修改一个由 composeClassPart 组合的函数字段:${String(fd)}, 修改已被忽略`)),
|
|
266
|
+
// enumerable:true ,
|
|
267
|
+
// //writable: true ,
|
|
268
|
+
// configurable: true
|
|
269
|
+
//});
|
|
267
270
|
//(compObj as any)[fd] = (...args: any[]) => (mixin[fd] as any).apply(mixin, args);
|
|
268
271
|
//(compObj as any)[fd] = (mixin[fd] as any).bind(mixin);
|
|
272
|
+
//#endregion
|
|
269
273
|
}
|
|
270
274
|
else {
|
|
271
275
|
Object.defineProperty(compObj, fd, {
|
|
@@ -280,7 +284,7 @@ class UtilFunc {
|
|
|
280
284
|
return compObj;
|
|
281
285
|
}
|
|
282
286
|
/**根据 MIXIN_FIELDS 自动混入
|
|
283
|
-
* @deprecated
|
|
287
|
+
* @deprecated 非必要情况下, 对class定义请使用 composeRefMixinable
|
|
284
288
|
*/
|
|
285
289
|
static composeMixinable(base, ...mixins) {
|
|
286
290
|
let out = base;
|
package/dist/UtilInterfaces.d.ts
CHANGED
|
@@ -117,16 +117,17 @@ export type ReflectionAble<Ctor, Constraint = {}> = {
|
|
|
117
117
|
/**原型构造器 */
|
|
118
118
|
readonly CTOR: Ctor & Constraint;
|
|
119
119
|
};
|
|
120
|
-
|
|
121
|
-
* @template Ctor
|
|
120
|
+
/**可反射的 且 构造函数是可混入的类
|
|
121
|
+
* @template Ctor - 构造器类型
|
|
122
122
|
* @template Instance - 实例类型
|
|
123
123
|
* @template Constraint - 构造器约束
|
|
124
124
|
*/
|
|
125
125
|
export type RefMixinable<Ctor, Instance, Constraint = {}> = ReflectionAble<Ctor, Mixinable<Instance> & Constraint>;
|
|
126
|
-
/**自动组合可混入的类
|
|
126
|
+
/**自动组合可混入的类
|
|
127
|
+
*/
|
|
127
128
|
export type ComposedMixinable<B, Ms extends unknown[]> = Ms extends [infer M, ...infer Rest] ? M extends Mixinable<M> ? ComposedMixinable<ComposedClass<B, M, M['MIXIN_KEY'], M['MIXIN_FIELDS'][number]>, Rest> : "一个混入类没有实现 Mixinable<self>" & Error : B;
|
|
128
|
-
|
|
129
|
-
export type
|
|
129
|
+
/**自动组合 可反射的 且 构造函数是可混入的 类 */
|
|
130
|
+
export type ComposedRefMixinable<B, Ms extends unknown[]> = Ms extends [infer M, ...infer Rest] ? M extends RefMixinable<unknown, M> ? ComposedRefMixinable<ComposedClass<B, M, M['CTOR']['MIXIN_KEY'], M['CTOR']['MIXIN_FIELDS'][number]>, Rest> : "一个混入类没有实现 RefMixinable<typeof self, self>" & Error : B;
|
|
130
131
|
/** extends封装
|
|
131
132
|
* @template B - 基础类型
|
|
132
133
|
* @template T - 判断的目标类型
|
package/package.json
CHANGED
package/src/UtilFileTools.ts
CHANGED
|
@@ -228,19 +228,19 @@ export async function writeJSONFile(
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
/**搜索路径符合正则表达式的文件
|
|
231
|
-
* @param
|
|
231
|
+
* @param dir - 起始目录
|
|
232
232
|
* @param traitRegex - 正则表达式
|
|
233
233
|
* @param opt - 可选参数
|
|
234
234
|
* @param opt.relative - 搜索子目录
|
|
235
235
|
* @returns 文件名路径数组
|
|
236
236
|
*/
|
|
237
|
-
export function fileSearchRegex(
|
|
237
|
+
export function fileSearchRegex(dir: string, traitRegex: string, opt?:FileSearchRegexOpt) {
|
|
238
238
|
const relative = opt?.relative ?? true;
|
|
239
239
|
const outArray: string[] = [];
|
|
240
|
-
const subFiles = fs.readdirSync(
|
|
240
|
+
const subFiles = fs.readdirSync(dir,{withFileTypes:true});
|
|
241
241
|
const regex = new RegExp(traitRegex);
|
|
242
242
|
for (const subFile of subFiles) {
|
|
243
|
-
const subFilePath = path.join(
|
|
243
|
+
const subFilePath = path.join(dir, subFile.name);
|
|
244
244
|
//判断是否是文件夹,递归调用
|
|
245
245
|
if (subFile.isDirectory()) {
|
|
246
246
|
if(relative) outArray.push(...fileSearchRegex(path.join(subFilePath, path.sep), traitRegex));
|
|
@@ -251,16 +251,16 @@ export function fileSearchRegex(folder: string, traitRegex: string, opt?:FileSea
|
|
|
251
251
|
return outArray;
|
|
252
252
|
}
|
|
253
253
|
/**搜索符合Glob匹配的文件
|
|
254
|
-
* @param
|
|
254
|
+
* @param dir - 起始目录
|
|
255
255
|
* @param globPattern - glob匹配
|
|
256
256
|
* @param opt - 可选参数
|
|
257
257
|
* @param opt.ignore - 忽略的文件
|
|
258
258
|
* @returns 文件绝对路径数组
|
|
259
259
|
*/
|
|
260
|
-
export function fileSearchGlob(
|
|
260
|
+
export function fileSearchGlob(dir: string, globPattern:string|string[],opt?:FileSearchGlobOpt){
|
|
261
261
|
const fixedPath = typeof globPattern === "string"
|
|
262
|
-
? path.join(
|
|
263
|
-
: globPattern.map((p)=>path.join(
|
|
262
|
+
? path.join(dir,path.posix.normalize(globPattern))
|
|
263
|
+
: globPattern.map((p)=>path.join(dir,path.posix.normalize(p)));
|
|
264
264
|
return globSync(fixedPath,{ignore:opt?.ingore,absolute:true});
|
|
265
265
|
}
|
|
266
266
|
/**
|
package/src/UtilFunctions.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as crypto from "crypto";
|
|
2
|
-
import { AnyFunc, ComposedClass, ComposedMixinable,
|
|
2
|
+
import { AnyFunc, ComposedClass, ComposedMixinable, ComposedRefMixinable, ExtractOutcome, IJData, JObject, JToken, Keyable, LiteralCheck, Matchable, MatchableFlag, Mixinable, Outcome, PromiseStat, PromiseVerifyFn, RefMixinable, UnionToIntersection } from "@src/UtilInterfaces";
|
|
3
3
|
import * as cp from "child_process";
|
|
4
4
|
import { LogLevel, SLogger } from "@src/UtilLogger";
|
|
5
5
|
import { Completed, Failed, FailedLike, None, StatusSymbol, Success, SuccessLike, Terminated, Timeout } from "./UtilSymbol";
|
|
@@ -280,17 +280,21 @@ static composeClassPart
|
|
|
280
280
|
for(const fd of fields){
|
|
281
281
|
if(compObj[fd]!==undefined)
|
|
282
282
|
SLogger.warn(`field: ${fd as string} 已存在于基础类中, 混入可能导致类型问题, 如需覆盖, 请使用 ${key}=val`);
|
|
283
|
-
//
|
|
284
|
-
// get: ()=>compObj[key][fd],
|
|
285
|
-
// set: (value)=>{compObj[key][fd] = value},
|
|
286
|
-
// enumerable:true ,
|
|
287
|
-
// //writable: true ,
|
|
288
|
-
// configurable: true
|
|
289
|
-
//});
|
|
283
|
+
//func需绑定this无法直接设置属性
|
|
290
284
|
if(typeof mixin[fd] === 'function') {
|
|
291
285
|
compObj[fd] = (...args: any[]) => compObj[key][fd](...args);
|
|
286
|
+
//#region other
|
|
287
|
+
//const memo = (...args: any[]) => compObj[key][fd](...args);
|
|
288
|
+
//Object.defineProperty(compObj, fd, {
|
|
289
|
+
// get:()=>memo,
|
|
290
|
+
// set:()=>SLogger.warn(new Error(`试图修改一个由 composeClassPart 组合的函数字段:${String(fd)}, 修改已被忽略`)),
|
|
291
|
+
// enumerable:true ,
|
|
292
|
+
// //writable: true ,
|
|
293
|
+
// configurable: true
|
|
294
|
+
//});
|
|
292
295
|
//(compObj as any)[fd] = (...args: any[]) => (mixin[fd] as any).apply(mixin, args);
|
|
293
296
|
//(compObj as any)[fd] = (mixin[fd] as any).bind(mixin);
|
|
297
|
+
//#endregion
|
|
294
298
|
} else {
|
|
295
299
|
Object.defineProperty(compObj, fd, {
|
|
296
300
|
get: ()=>compObj[key][fd],
|
|
@@ -304,8 +308,8 @@ static composeClassPart
|
|
|
304
308
|
return compObj;
|
|
305
309
|
}
|
|
306
310
|
|
|
307
|
-
/**根据 MIXIN_FIELDS 自动混入
|
|
308
|
-
* @deprecated
|
|
311
|
+
/**根据 MIXIN_FIELDS 自动混入
|
|
312
|
+
* @deprecated 非必要情况下, 对class定义请使用 composeRefMixinable
|
|
309
313
|
*/
|
|
310
314
|
static composeMixinable
|
|
311
315
|
<Base extends object, Mixins extends Mixinable<any>[]>
|
|
@@ -331,7 +335,7 @@ static composeMixinable
|
|
|
331
335
|
static composeRefMixinable
|
|
332
336
|
<Base extends object, Mixins extends RefMixinable<any,unknown>[]>
|
|
333
337
|
(base:Base,...mixins:Mixins):
|
|
334
|
-
|
|
338
|
+
ComposedRefMixinable<Base,Mixins>{
|
|
335
339
|
let out = base;
|
|
336
340
|
const fieldsSet = new Set<string>();
|
|
337
341
|
for(const mixin of mixins){
|
package/src/UtilInterfaces.ts
CHANGED
|
@@ -152,8 +152,8 @@ export type ReflectionAble<Ctor,Constraint={}> = {
|
|
|
152
152
|
/**原型构造器 */
|
|
153
153
|
readonly CTOR:Ctor&Constraint
|
|
154
154
|
};
|
|
155
|
-
|
|
156
|
-
* @template Ctor
|
|
155
|
+
/**可反射的 且 构造函数是可混入的类
|
|
156
|
+
* @template Ctor - 构造器类型
|
|
157
157
|
* @template Instance - 实例类型
|
|
158
158
|
* @template Constraint - 构造器约束
|
|
159
159
|
*/
|
|
@@ -161,7 +161,8 @@ export type RefMixinable<Ctor,Instance,Constraint={}> =
|
|
|
161
161
|
ReflectionAble<Ctor,Mixinable<Instance>&Constraint>;
|
|
162
162
|
|
|
163
163
|
|
|
164
|
-
/**自动组合可混入的类
|
|
164
|
+
/**自动组合可混入的类
|
|
165
|
+
*/
|
|
165
166
|
export type ComposedMixinable<B, Ms extends unknown[]> =
|
|
166
167
|
Ms extends [infer M, ...infer Rest]
|
|
167
168
|
? M extends Mixinable<M>
|
|
@@ -169,11 +170,11 @@ export type ComposedMixinable<B, Ms extends unknown[]> =
|
|
|
169
170
|
: "一个混入类没有实现 Mixinable<self>" & Error
|
|
170
171
|
: B
|
|
171
172
|
|
|
172
|
-
|
|
173
|
-
export type
|
|
173
|
+
/**自动组合 可反射的 且 构造函数是可混入的 类 */
|
|
174
|
+
export type ComposedRefMixinable<B, Ms extends unknown[]> =
|
|
174
175
|
Ms extends [infer M, ...infer Rest]
|
|
175
176
|
? M extends RefMixinable<unknown,M>
|
|
176
|
-
?
|
|
177
|
+
? ComposedRefMixinable<ComposedClass<B,M,
|
|
177
178
|
M['CTOR']['MIXIN_KEY'],
|
|
178
179
|
M['CTOR']['MIXIN_FIELDS'][number]>,
|
|
179
180
|
Rest>
|
|
@@ -196,8 +197,7 @@ export type ExtendThen<B,T,Y,N = never> = B extends T ? Y : N;
|
|
|
196
197
|
*/
|
|
197
198
|
type UnionInclude<B,T,Y,N = never> =
|
|
198
199
|
B extends Exclude<B,T>
|
|
199
|
-
? N
|
|
200
|
-
: Y
|
|
200
|
+
? N : Y
|
|
201
201
|
/**排除可选字段 */
|
|
202
202
|
export type RequiredOnly<T> = {
|
|
203
203
|
[K in keyof T as
|