type-tls 2.2.1 → 2.4.1
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/async.d.ts +31 -0
- package/dist/base.d.ts +184 -0
- package/dist/buffer.d.ts +1 -0
- package/dist/extend.d.ts +86 -0
- package/dist/function.d.ts +49 -0
- package/dist/index.d.ts +6 -184
- package/dist/member.d.ts +16 -0
- package/dist/mixin.d.ts +96 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/type-tls.d.ts +303 -3
- package/dist/type-tls.es.js +109 -1
- package/dist/type-tls.iife.js +1 -1
- package/dist/type-tls.umd.js +1 -1
- package/doc/index.md +1 -1
- package/doc/type-tls.anyfunction.md +13 -0
- package/doc/type-tls.classtype._new_.md +22 -0
- package/doc/type-tls.classtype.md +20 -0
- package/doc/type-tls.createdefinemixin.md +23 -0
- package/doc/type-tls.createextendtarget.md +30 -0
- package/doc/type-tls.createmixintarget.md +30 -0
- package/doc/type-tls.createtargetextend.md +30 -0
- package/doc/type-tls.createtargetmixin.md +30 -0
- package/doc/type-tls.defineextend.md +35 -0
- package/doc/type-tls.definemixin.md +31 -0
- package/doc/type-tls.extendtarget.md +31 -0
- package/doc/type-tls.isanonymousfunction.md +35 -0
- package/doc/type-tls.isarrowfunction.md +24 -0
- package/doc/type-tls.isasyncfunction.md +28 -0
- package/doc/type-tls.isasyncgeneratorfunction.md +24 -0
- package/doc/type-tls.isgeneratorfunction.md +28 -0
- package/doc/type-tls.isidentifier.md +24 -0
- package/doc/type-tls.md +32 -6
- package/doc/type-tls.methodparams.md +15 -0
- package/doc/type-tls.methodreturntype.md +15 -0
- package/doc/type-tls.mixin_4.md +33 -0
- package/doc/type-tls.mixintarget.md +31 -0
- package/doc/type-tls.privatememberofextend._constructor.md +22 -0
- package/doc/type-tls.privatememberofextend.md +20 -0
- package/doc/type-tls.resolvedata.md +18 -0
- package/doc/type-tls.targetextend.md +31 -0
- package/doc/type-tls.targetmixin.md +31 -0
- package/doc/type-tls.waitasyncable.md +30 -0
- package/doc/type-tls.waitasyncablecallback.md +13 -0
- package/doc/type-tls.waitasyncablereturn.md +13 -0
- package/package.json +5 -3
package/dist/type-tls.d.ts
CHANGED
|
@@ -1,10 +1,98 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 表示任意的函数类型
|
|
3
|
+
*/
|
|
4
|
+
export declare type AnyFunction = (...args: any) => any;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 类的类型、构造函数的类型
|
|
8
|
+
*
|
|
9
|
+
* @typeParam Arg - 构建函数的参数类型
|
|
10
|
+
* @typeParam Instance - 构建函数的返回的实例类型
|
|
11
|
+
*/
|
|
12
|
+
export declare interface ClassType<Arg extends any[] = any[], Instance = any> {
|
|
13
|
+
new (...args: Arg): Instance;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 创建定义混合的类型便利函数
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* 它返回的便利函数的功能与 {@link defineMixin} 的功能一样,唯一区别是不再需要接收 target 参数了
|
|
21
|
+
*
|
|
22
|
+
* @returns 可以用于 定义混合的 类型便利函数
|
|
23
|
+
*/
|
|
24
|
+
export declare function createDefineMixin<T>(): <M>(target: T, mixin: M & ThisType<T & M>) => M & ThisType<T & M>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 创建用于扩展目标工具函数
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* 它返回的便利函数的功能与 {@link extendTarget} 的功能一样,唯一区别是不再需要接收 cla 参数了
|
|
31
|
+
*
|
|
32
|
+
* @param cla - 扩展的目标,也用作 this 的类型
|
|
33
|
+
* @returns 可以用于 扩展目标 的便利函数
|
|
34
|
+
*/
|
|
35
|
+
export declare function createExtendTarget<C extends ClassType>(cla: C): <E>(ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>) => ClassType<ConstructorParameters<C>, E & ThisType<InstanceType<C> & E>>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 创建用于混合目标工具函数
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* 它返回的便利函数的功能与 {@link mixinTarget} 的功能一样,唯一区别是不再需要接收 target 参数了
|
|
42
|
+
*
|
|
43
|
+
* @returns 可以用于 混合目标 的便利函数
|
|
44
|
+
*/
|
|
45
|
+
export declare function createMixinTarget<T>(target: T): <M>(m: M & ThisType<T & M>) => M & ThisType<T & M> & T;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 创建用于扩展目标的便捷函数
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* 它返回的便利函数的功能与 {@link targetExtend} 的功能一样,唯一区别是不再需要接收 cla 参数了
|
|
52
|
+
*
|
|
53
|
+
* @param cla - 扩展的目标,也用作 this 的类型
|
|
54
|
+
* @returns 可以用于 扩展目标 的便利函数
|
|
55
|
+
*/
|
|
56
|
+
export declare function createTargetExtend<C extends ClassType>(cla: C): <E>(ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>) => E & ThisType<C & E>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 创建用于混合目标的便捷函数
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* 它返回的便利函数的功能与 {@link targetMixin} 的功能一样,唯一区别是不再需要接收 target 参数了
|
|
63
|
+
*
|
|
64
|
+
* @param target - 混合的目标,用作 this 的类型
|
|
65
|
+
* @returns 可以用于 混合目标 的便利函数
|
|
66
|
+
*/
|
|
67
|
+
export declare function createTargetMixin<T>(target: T): <M>(m: M & ThisType<T & M>) => M & ThisType<T & M>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 定义扩展的类型便利函数
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* 它会更改 ext 中方法的this指向为 cla & ext,不会真的执行扩展操作。
|
|
74
|
+
*
|
|
75
|
+
* 其中 ext._constructor 会被保存在 cla._constructors 属性中,它是一个数组。
|
|
76
|
+
*
|
|
77
|
+
* cla 需要在自己的构建函数中逐个调用 cla._constructors 中的函数
|
|
78
|
+
*
|
|
79
|
+
* @param cla - 扩展的目标,用作 this 的类型
|
|
80
|
+
* @param ext - 描述扩展内容的对象,会自动更改其this的类型
|
|
81
|
+
* @returns 返回注入了 this 类型的 ext 对象本身
|
|
82
|
+
*/
|
|
83
|
+
export declare function defineExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>): E & ThisType<C & E>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 定义混合的类型便利函数
|
|
87
|
+
*
|
|
3
88
|
* @remarks
|
|
4
|
-
*
|
|
89
|
+
* 它会更改 mixin 中方法的this指向为 target & mixin,不会真的执行混合操作
|
|
5
90
|
*
|
|
6
|
-
* @
|
|
91
|
+
* @param target - 混合的目标,用作 this 的类型
|
|
92
|
+
* @param mixin - 混合对象,会自动更改其this的类型
|
|
93
|
+
* @returns 返回注入了 this 类型的 mixin 对象本身
|
|
7
94
|
*/
|
|
95
|
+
export declare function defineMixin<T, M>(target: T, mixin: M & ThisType<T & M>): M & ThisType<T & M>;
|
|
8
96
|
|
|
9
97
|
/**
|
|
10
98
|
* 精确类型
|
|
@@ -56,6 +144,19 @@ export declare type ExactType = LooseType | Exclude<TypeOfReturnType, "undefined
|
|
|
56
144
|
*/
|
|
57
145
|
export declare type ExactTypeName = LooseTypeName | Exclude<TypeOfReturnType, "undefined" | "function" | "object">;
|
|
58
146
|
|
|
147
|
+
/**
|
|
148
|
+
* 扩展目标
|
|
149
|
+
*
|
|
150
|
+
* @remarks
|
|
151
|
+
* 会执行对 CEarth 类的扩展操作。
|
|
152
|
+
* 与 {@link targetExtend} 的区别仅仅是返回类型不一样。
|
|
153
|
+
*
|
|
154
|
+
* @param cla - 扩展的目标,也用作 this 的类型
|
|
155
|
+
* @param ext - 扩展对象,会自动更改其this的类型
|
|
156
|
+
* @returns 返回扩展后的 cla 对象
|
|
157
|
+
*/
|
|
158
|
+
export declare function extendTarget<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>): ClassType<ConstructorParameters<C>, E & ThisType<InstanceType<C> & E>>;
|
|
159
|
+
|
|
59
160
|
/**
|
|
60
161
|
* 获取 inst 的精确类型的字符串表示
|
|
61
162
|
* @param inst
|
|
@@ -120,6 +221,22 @@ export declare function getTypeNameOf(inst: any): LooseTypeName;
|
|
|
120
221
|
*/
|
|
121
222
|
export declare function getTypeOf(inst: any): LooseType;
|
|
122
223
|
|
|
224
|
+
/**
|
|
225
|
+
* 判断是否是匿名函数
|
|
226
|
+
*
|
|
227
|
+
* @remarks
|
|
228
|
+
* 判断函数在被定义时是否是通过匿名函数来定义的。
|
|
229
|
+
* 匿名函数是指声明函数时没有写名字的函数。
|
|
230
|
+
* 注意:即使是匿名函数,函数对象上的 name 属性也可能是有值的,因为 js解析器 会自动将 函数表达式函数变量的名字作为匿名函数的名字,如下:
|
|
231
|
+
* ```ts
|
|
232
|
+
* var funName = function(){};
|
|
233
|
+
* ```
|
|
234
|
+
* 其中的匿名函数对象的 name 属性的值会是 `funName`
|
|
235
|
+
*
|
|
236
|
+
* 如果 函数对象上的 name 属性的值为 `""`,函数一定是匿名函数。
|
|
237
|
+
*/
|
|
238
|
+
export declare function isAnonymousFunction(fun: Function): boolean;
|
|
239
|
+
|
|
123
240
|
/**
|
|
124
241
|
* 判断 target 是否为 类数组对象
|
|
125
242
|
* @param target - 目标
|
|
@@ -127,6 +244,26 @@ export declare function getTypeOf(inst: any): LooseType;
|
|
|
127
244
|
*/
|
|
128
245
|
export declare function isArrayLike(target: any): boolean;
|
|
129
246
|
|
|
247
|
+
/**
|
|
248
|
+
* 判断函数是否是箭头函数
|
|
249
|
+
* @param fun - 被判断的函数
|
|
250
|
+
*/
|
|
251
|
+
export declare function isArrowFunction(fun: Function): boolean;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* 判断函数是否是 async 异步函数
|
|
255
|
+
* @remarks
|
|
256
|
+
* 异步函数 不包含 异步生成器函数 AsyncGeneratorFunction
|
|
257
|
+
* @param fun - 被判断的函数
|
|
258
|
+
*/
|
|
259
|
+
export declare function isAsyncFunction(fun: Function): boolean;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* 判断函数是否是异步生成器函数
|
|
263
|
+
* @param fun - 被判断的函数
|
|
264
|
+
*/
|
|
265
|
+
export declare function isAsyncGeneratorFunction(fun: Function): boolean;
|
|
266
|
+
|
|
130
267
|
/**
|
|
131
268
|
* 判断 data 是否是 基本类型
|
|
132
269
|
* @remarks
|
|
@@ -135,6 +272,21 @@ export declare function isArrayLike(target: any): boolean;
|
|
|
135
272
|
*/
|
|
136
273
|
export declare function isBaseType(data: any): boolean;
|
|
137
274
|
|
|
275
|
+
/**
|
|
276
|
+
* 判断函数是否是生成器函数
|
|
277
|
+
*
|
|
278
|
+
* @remarks
|
|
279
|
+
* 生成器函数 不包含 异步生成器函数 AsyncGeneratorFunction
|
|
280
|
+
* @param fun - 被判断的函数
|
|
281
|
+
*/
|
|
282
|
+
export declare function isGeneratorFunction(fun: Function): boolean;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* 判断 code 是否是有校的 js 标识符
|
|
286
|
+
* @param code - 标识符的字符串
|
|
287
|
+
*/
|
|
288
|
+
export declare function isIdentifier(code: string): boolean;
|
|
289
|
+
|
|
138
290
|
/**
|
|
139
291
|
* 判断 目标 是否是可迭代的对象,即 实现了 可迭代协议
|
|
140
292
|
* @param target - 目标
|
|
@@ -170,6 +322,74 @@ export declare type LooseType = undefined | null | Function | "object";
|
|
|
170
322
|
*/
|
|
171
323
|
export declare type LooseTypeName = "undefined" | "null" | "Function" | "object" | string;
|
|
172
324
|
|
|
325
|
+
/**
|
|
326
|
+
* 获取对象的方法的某个参数的类型
|
|
327
|
+
*
|
|
328
|
+
* @typeParam Obj - 对象
|
|
329
|
+
* @typeParam Method - 对象方法的名字
|
|
330
|
+
* @typeParam ParamIndex - 参数的索引个数
|
|
331
|
+
*/
|
|
332
|
+
export declare type MethodParams<Obj, Method extends keyof Obj, ParamIndex extends number> = Obj[Method] extends AnyFunction ? Parameters<Obj[Method]>[ParamIndex] : never;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* 获取对象的方法的返回的类型
|
|
336
|
+
*
|
|
337
|
+
* @typeParam Obj - 对象
|
|
338
|
+
* @typeParam Method - 对象方法的名字
|
|
339
|
+
*/
|
|
340
|
+
export declare type MethodReturnType<Obj, Method extends keyof Obj> = Obj[Method] extends AnyFunction ? ReturnType<Obj[Method]> : never;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* 混合
|
|
344
|
+
* @internal
|
|
345
|
+
*/
|
|
346
|
+
export declare function mixin<T, S>(target: T, source: S): T & S;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* 混合
|
|
350
|
+
* @internal
|
|
351
|
+
*/
|
|
352
|
+
export declare function mixin<T, S1, S2>(target: T, source1: S1, source2: S2): T & S1 & S2;
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* 混合
|
|
356
|
+
* @internal
|
|
357
|
+
*/
|
|
358
|
+
export declare function mixin<T, S1, S2, S3>(target: T, source1: S1, source2: S2, source3: S3): T & S1 & S2 & S3;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* 混合
|
|
362
|
+
* @internal
|
|
363
|
+
*/
|
|
364
|
+
export declare function mixin<T, S1, S2, S3, S4>(target: T, source1: S1, source2: S2, source3: S3, source4: S3): T & S1 & S2 & S3 & S4;
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* 混合
|
|
368
|
+
*
|
|
369
|
+
* @remarks
|
|
370
|
+
* 将 source 的所有成员混入 target 对象中。
|
|
371
|
+
*
|
|
372
|
+
* 与 `Object.assign()` 的功能类似,不同的是 `mixin()` 会在 target 对象中 保持 source 对象属性的 PropertyDescriptors
|
|
373
|
+
*
|
|
374
|
+
* @param target - 目标对象,所有 源对象 的属性都要被混入进到 目标对象中
|
|
375
|
+
* @param sources - 源对象,所有 源对象 的属性都要被混入进到 目标对象中
|
|
376
|
+
* @returns 混入后的 target
|
|
377
|
+
*/
|
|
378
|
+
export declare function mixin(target: any, ...sources: any[]): any;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* 混合目标
|
|
382
|
+
*
|
|
383
|
+
* @remarks
|
|
384
|
+
* 会执行对 CEarth 类的扩展操作。
|
|
385
|
+
* 与 {@link targetMixin} 的区别仅仅是返回类型不一样。
|
|
386
|
+
*
|
|
387
|
+
* @param target - 混合的目标,用作 this 的类型
|
|
388
|
+
* @param m - 混合对象,会自动更改其this的类型
|
|
389
|
+
* @returns 返回混合后的 target 对象
|
|
390
|
+
*/
|
|
391
|
+
export declare function mixinTarget<T, M>(target: T, m: M & ThisType<T & M>): M & ThisType<T & M> & T;
|
|
392
|
+
|
|
173
393
|
/**
|
|
174
394
|
* 将某个类型变为可选的类型
|
|
175
395
|
*/
|
|
@@ -180,6 +400,25 @@ export declare type Optional<T> = T | null | undefined;
|
|
|
180
400
|
*/
|
|
181
401
|
export declare type OptionalBoolean = Optional<boolean>;
|
|
182
402
|
|
|
403
|
+
/**
|
|
404
|
+
* 用于定义扩展选项中的私有成员
|
|
405
|
+
*/
|
|
406
|
+
export declare interface PrivateMemberOfExtend<TargetType extends new (...args: any) => any> {
|
|
407
|
+
/**
|
|
408
|
+
* 扩展类中用于定义在创建实例时的初始化的方法
|
|
409
|
+
* @remarks
|
|
410
|
+
* 该方法会在创建实例时自动执行,并将构建函数接收到的参数透传给方方法。
|
|
411
|
+
*
|
|
412
|
+
* 注意:
|
|
413
|
+
* _constructor 会被保存在 目标类中的 _constructors 属性中,它是一个数组。
|
|
414
|
+
*
|
|
415
|
+
* 目标类 需要在自己的构建函数中逐个调用 cla._constructors 中的函数
|
|
416
|
+
*
|
|
417
|
+
* @param args
|
|
418
|
+
*/
|
|
419
|
+
_constructor?: (...args: (TargetType extends new (...args: infer A) => any ? A : never)) => void;
|
|
420
|
+
}
|
|
421
|
+
|
|
183
422
|
/**
|
|
184
423
|
* 可将源类型 SourType 中的 类型 MatchType 替换为 新的类型 NewType
|
|
185
424
|
*/
|
|
@@ -200,9 +439,70 @@ export declare type ReplaceUndefined<SourType, NewType> = Replace<SourType, unde
|
|
|
200
439
|
*/
|
|
201
440
|
export declare type ReplaceVoid<SourType, NewType> = Replace<SourType, void | undefined | null, NewType>;
|
|
202
441
|
|
|
442
|
+
/**
|
|
443
|
+
* 获取 Promise 解决的类型的值
|
|
444
|
+
* @remarks
|
|
445
|
+
* 对于非 Promise 类型的值,返回原类型本身
|
|
446
|
+
*/
|
|
447
|
+
export declare type ResolveData<P> = P extends Promise<infer D> ? D : P;
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* 扩展目标
|
|
451
|
+
*
|
|
452
|
+
* @remarks
|
|
453
|
+
* 与 {@link defineExtend} 的区别是:`targetExtend` 会执行对 cla 的扩展操作,而 {@link defineExtend} 不会
|
|
454
|
+
*
|
|
455
|
+
*
|
|
456
|
+
* @param cla - 扩展的目标,也用作 this 的类型
|
|
457
|
+
* @param ext - 扩展描述对象,会自动更改其this的类型
|
|
458
|
+
* @returns 返回注入了 this 类型的 ext 对象本身
|
|
459
|
+
*/
|
|
460
|
+
export declare function targetExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>): E & ThisType<InstanceType<C> & E>;
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* 混合目标
|
|
464
|
+
*
|
|
465
|
+
* @remarks
|
|
466
|
+
* 与 {@link defineMixin} 的区别是:`targetMixin` 会执行对 target 的混合操作,而 {@link defineMixin} 不会
|
|
467
|
+
*
|
|
468
|
+
*
|
|
469
|
+
* @param target - 混合的目标,用作 this 的类型
|
|
470
|
+
* @param m - 混合对象,会自动更改其this的类型
|
|
471
|
+
* @returns 返回注入了 this 类型的 mixin 对象本身
|
|
472
|
+
*/
|
|
473
|
+
export declare function targetMixin<T, M>(target: T, m: M & ThisType<T & M>): M & ThisType<T & M>;
|
|
474
|
+
|
|
203
475
|
/**
|
|
204
476
|
* typeof 的返回类型
|
|
205
477
|
*/
|
|
206
478
|
export declare type TypeOfReturnType = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
|
207
479
|
|
|
480
|
+
/**
|
|
481
|
+
* 等待可异步的结果
|
|
482
|
+
*
|
|
483
|
+
* @remarks
|
|
484
|
+
* 当 asyncable 为同步值时,会同步调用 callback。
|
|
485
|
+
* 当 asyncable 为异步值时,会等待 asyncable 解决后再调用 callback。
|
|
486
|
+
*
|
|
487
|
+
* @param asyncable - 可异步的结果
|
|
488
|
+
* @param callback
|
|
489
|
+
* @returns
|
|
490
|
+
*/
|
|
491
|
+
export declare function waitAsyncable<Result, Return>(asyncable: Result, callback: WaitAsyncableCallback<Result, Return>): WaitAsyncableReturn<Result, Return>;
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* waitAsyncable 的回调函数的类型
|
|
495
|
+
* @param result - 同步的结果
|
|
496
|
+
* @param rejected - 异步是否被拒绝
|
|
497
|
+
*/
|
|
498
|
+
export declare interface WaitAsyncableCallback<Result, Return> {
|
|
499
|
+
(result: ResolveData<Result>, rejected: false): Return;
|
|
500
|
+
(result: undefined, rejected: true, reason: any): Return;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* waitAsyncable 的返回值的类型
|
|
505
|
+
*/
|
|
506
|
+
export declare type WaitAsyncableReturn<Result, Return> = Return extends Promise<any> ? Return : (Result extends Promise<any> ? Promise<Return> : Return);
|
|
507
|
+
|
|
208
508
|
export { }
|
package/dist/type-tls.es.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var _a, _b, _c;
|
|
1
2
|
function isObject(target) {
|
|
2
3
|
var tarType = typeof target;
|
|
3
4
|
return target && (tarType === "object" || tarType === "function");
|
|
@@ -60,4 +61,111 @@ function isIterable(target) {
|
|
|
60
61
|
function isIterator(target) {
|
|
61
62
|
return target && typeof target.next === "function";
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
+
function mixin(target, ...sources) {
|
|
65
|
+
for (const s of sources) {
|
|
66
|
+
const propDes = Object.getOwnPropertyDescriptors(s);
|
|
67
|
+
Object.defineProperties(target, propDes);
|
|
68
|
+
}
|
|
69
|
+
return target;
|
|
70
|
+
}
|
|
71
|
+
function defineMixin(target, mixin2) {
|
|
72
|
+
return mixin2;
|
|
73
|
+
}
|
|
74
|
+
function createDefineMixin() {
|
|
75
|
+
return function defineMixin2(target, mixin2) {
|
|
76
|
+
return mixin2;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function targetMixin(target, m) {
|
|
80
|
+
mixin(target, m);
|
|
81
|
+
return m;
|
|
82
|
+
}
|
|
83
|
+
function createTargetMixin(target) {
|
|
84
|
+
return function targetMixin2(m) {
|
|
85
|
+
mixin(target, m);
|
|
86
|
+
return m;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function mixinTarget(target, m) {
|
|
90
|
+
mixin(target, m);
|
|
91
|
+
return target;
|
|
92
|
+
}
|
|
93
|
+
function createMixinTarget(target) {
|
|
94
|
+
return function mixinTarget2(m) {
|
|
95
|
+
mixin(target, m);
|
|
96
|
+
return target;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function defineExtend(cla, ext) {
|
|
100
|
+
return ext;
|
|
101
|
+
}
|
|
102
|
+
function targetExtend(cla, ext) {
|
|
103
|
+
var _a2;
|
|
104
|
+
mixin(cla.prototype, ext);
|
|
105
|
+
const _constructor = ext._constructor;
|
|
106
|
+
if (typeof _constructor === "function") {
|
|
107
|
+
const target = cla;
|
|
108
|
+
const _constructors = (_a2 = target._constructors) != null ? _a2 : target._constructors = [];
|
|
109
|
+
_constructors.push(_constructor);
|
|
110
|
+
}
|
|
111
|
+
return ext;
|
|
112
|
+
}
|
|
113
|
+
function createTargetExtend(cla) {
|
|
114
|
+
return function classExtend(ext) {
|
|
115
|
+
targetExtend(cla, ext);
|
|
116
|
+
return ext;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function extendTarget(cla, ext) {
|
|
120
|
+
targetExtend(cla, ext);
|
|
121
|
+
return cla;
|
|
122
|
+
}
|
|
123
|
+
function createExtendTarget(cla) {
|
|
124
|
+
return function extendTarget2(ext) {
|
|
125
|
+
targetExtend(cla, ext);
|
|
126
|
+
return cla;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
const jsIdentifier = /^[A-Za-z_$]+[\w$]*$/;
|
|
130
|
+
function isIdentifier(code) {
|
|
131
|
+
return jsIdentifier.test(code);
|
|
132
|
+
}
|
|
133
|
+
const arrowFunctionRegExpOfFunString = /(^\s*(async\s+)?\s*(\b[A-Za-z_$]+[\w$]*\b)\s*=>)|(^\s*(async\s+)?\s*\(\s*(\b[A-Za-z_$]+[\w$]*\b)?\s*(,\s*(\b[A-Za-z_$]+[\w$]*\b)\s*)*\)\s*=>)/;
|
|
134
|
+
function isArrowFunction(fun) {
|
|
135
|
+
const funStr = fun.toString();
|
|
136
|
+
return arrowFunctionRegExpOfFunString.test(funStr);
|
|
137
|
+
}
|
|
138
|
+
const AsyncFun = (_a = globalThis.AsyncFunction) != null ? _a : async function() {
|
|
139
|
+
}.constructor;
|
|
140
|
+
function isAsyncFunction(fun) {
|
|
141
|
+
return fun instanceof AsyncFun;
|
|
142
|
+
}
|
|
143
|
+
const GeneratorFun = (_b = globalThis.GeneratorFunction) != null ? _b : function* () {
|
|
144
|
+
}.constructor;
|
|
145
|
+
function isGeneratorFunction(fun) {
|
|
146
|
+
return fun instanceof GeneratorFun;
|
|
147
|
+
}
|
|
148
|
+
const AsyncGeneratorFun = (_c = globalThis.AsyncGeneratorFunction) != null ? _c : async function* () {
|
|
149
|
+
}.constructor;
|
|
150
|
+
function isAsyncGeneratorFunction(fun) {
|
|
151
|
+
return fun instanceof AsyncGeneratorFun;
|
|
152
|
+
}
|
|
153
|
+
const funNameRegExpOfFunString = /(^\s*(async\s+)?function\s*(\s|\*)\s*)[A-Za-z_$]+[\w$]*(\s*\()/;
|
|
154
|
+
function isAnonymousFunction(fun) {
|
|
155
|
+
if (fun.name) {
|
|
156
|
+
const funStr = fun.toString();
|
|
157
|
+
return !funNameRegExpOfFunString.test(funStr);
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
function waitAsyncable(asyncable, callback) {
|
|
162
|
+
if (asyncable instanceof Promise) {
|
|
163
|
+
return asyncable.then((syncRes) => {
|
|
164
|
+
return callback(syncRes, false);
|
|
165
|
+
}, (reason) => {
|
|
166
|
+
return callback(void 0, true, reason);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return callback(asyncable, false);
|
|
170
|
+
}
|
|
171
|
+
export { createDefineMixin, createExtendTarget, createMixinTarget, createTargetExtend, createTargetMixin, defineExtend, defineMixin, extendTarget, getExactTypeNameOf, getExactTypeOf, getNameOfType, getTypeByName, getTypeNameOf, getTypeOf, isAnonymousFunction, isArrayLike, isArrowFunction, isAsyncFunction, isAsyncGeneratorFunction, isBaseType, isGeneratorFunction, isIdentifier, isIterable, isIterator, isObject, mixin, mixinTarget, targetExtend, targetMixin, waitAsyncable };
|
package/dist/type-tls.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var typeTls=function(
|
|
1
|
+
var typeTls=function(e){var y,g,T;"use strict";function a(n){var t=typeof n;return n&&(t==="object"||t==="function")}function o(n){var t=n;return n!=null&&(t=n.constructor,t==null&&(t=typeof n)),t}function f(n){switch(n){case void 0:return"undefined";case null:return"null"}let t=typeof n;switch(t){case"function":return n.name;case"string":return n;default:return t}}function d(n){return globalThis[n]}function A(n){let t=o(n);return f(t)}function s(n){return n==null||a(n)?o(n):typeof n}function b(n){var t=s(n);return f(t)}function m(n){var t=typeof n;return n==null||t!=="object"&&t!=="function"}function F(n){let t=n&&n.length;return Number.isInteger(n.length)&&t>=0}function O(n){return n&&typeof n[Symbol.iterator]=="function"}function E(n){return n&&typeof n.next=="function"}function i(n,...t){for(const r of t){const c=Object.getOwnPropertyDescriptors(r);Object.defineProperties(n,c)}return n}function M(n,t){return t}function w(){return function(t,r){return r}}function _(n,t){return i(n,t),t}function h(n){return function(r){return i(n,r),r}}function $(n,t){return i(n,t),n}function v(n){return function(r){return i(n,r),n}}function N(n,t){return t}function u(n,t){var c;i(n.prototype,t);const r=t._constructor;if(typeof r=="function"){const l=n;((c=l._constructors)!=null?c:l._constructors=[]).push(r)}return t}function S(n){return function(r){return u(n,r),r}}function I(n,t){return u(n,t),n}function j(n){return function(r){return u(n,r),n}}const G=/^[A-Za-z_$]+[\w$]*$/;function p(n){return G.test(n)}const z=/(^\s*(async\s+)?\s*(\b[A-Za-z_$]+[\w$]*\b)\s*=>)|(^\s*(async\s+)?\s*\(\s*(\b[A-Za-z_$]+[\w$]*\b)?\s*(,\s*(\b[A-Za-z_$]+[\w$]*\b)\s*)*\)\s*=>)/;function Z(n){const t=n.toString();return z.test(t)}const B=(y=globalThis.AsyncFunction)!=null?y:async function(){}.constructor;function D(n){return n instanceof B}const P=(g=globalThis.GeneratorFunction)!=null?g:function*(){}.constructor;function x(n){return n instanceof P}const L=(T=globalThis.AsyncGeneratorFunction)!=null?T:async function*(){}.constructor;function R(n){return n instanceof L}const k=/(^\s*(async\s+)?function\s*(\s|\*)\s*)[A-Za-z_$]+[\w$]*(\s*\()/;function q(n){if(n.name){const t=n.toString();return!k.test(t)}return!0}function C(n,t){return n instanceof Promise?n.then(r=>t(r,!1),r=>t(void 0,!0,r)):t(n,!1)}return e.createDefineMixin=w,e.createExtendTarget=j,e.createMixinTarget=v,e.createTargetExtend=S,e.createTargetMixin=h,e.defineExtend=N,e.defineMixin=M,e.extendTarget=I,e.getExactTypeNameOf=b,e.getExactTypeOf=s,e.getNameOfType=f,e.getTypeByName=d,e.getTypeNameOf=A,e.getTypeOf=o,e.isAnonymousFunction=q,e.isArrayLike=F,e.isArrowFunction=Z,e.isAsyncFunction=D,e.isAsyncGeneratorFunction=R,e.isBaseType=m,e.isGeneratorFunction=x,e.isIdentifier=p,e.isIterable=O,e.isIterator=E,e.isObject=a,e.mixin=i,e.mixinTarget=$,e.targetExtend=u,e.targetMixin=_,e.waitAsyncable=C,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),e}({});
|
package/dist/type-tls.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(e,r){typeof exports=="object"&&typeof module!="undefined"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(e=typeof globalThis!="undefined"?globalThis:e||self,r(e.typeTls={}))})(this,function(e){var y,g,d;"use strict";function r(n){var t=typeof n;return n&&(t==="object"||t==="function")}function f(n){var t=n;return n!=null&&(t=n.constructor,t==null&&(t=typeof n)),t}function s(n){switch(n){case void 0:return"undefined";case null:return"null"}let t=typeof n;switch(t){case"function":return n.name;case"string":return n;default:return t}}function l(n){return globalThis[n]}function m(n){let t=f(n);return s(t)}function a(n){return n==null||r(n)?f(n):typeof n}function b(n){var t=a(n);return s(t)}function A(n){var t=typeof n;return n==null||t!=="object"&&t!=="function"}function F(n){let t=n&&n.length;return Number.isInteger(n.length)&&t>=0}function O(n){return n&&typeof n[Symbol.iterator]=="function"}function p(n){return n&&typeof n.next=="function"}function u(n,...t){for(const i of t){const o=Object.getOwnPropertyDescriptors(i);Object.defineProperties(n,o)}return n}function E(n,t){return t}function h(){return function(t,i){return i}}function M(n,t){return u(n,t),t}function w(n){return function(i){return u(n,i),i}}function _(n,t){return u(n,t),n}function $(n){return function(i){return u(n,i),n}}function N(n,t){return t}function c(n,t){var o;u(n.prototype,t);const i=t._constructor;if(typeof i=="function"){const T=n;((o=T._constructors)!=null?o:T._constructors=[]).push(i)}return t}function S(n){return function(i){return c(n,i),i}}function j(n,t){return c(n,t),n}function v(n){return function(i){return c(n,i),n}}const I=/^[A-Za-z_$]+[\w$]*$/;function G(n){return I.test(n)}const x=/(^\s*(async\s+)?\s*(\b[A-Za-z_$]+[\w$]*\b)\s*=>)|(^\s*(async\s+)?\s*\(\s*(\b[A-Za-z_$]+[\w$]*\b)?\s*(,\s*(\b[A-Za-z_$]+[\w$]*\b)\s*)*\)\s*=>)/;function z(n){const t=n.toString();return x.test(t)}const Z=(y=globalThis.AsyncFunction)!=null?y:async function(){}.constructor;function B(n){return n instanceof Z}const D=(g=globalThis.GeneratorFunction)!=null?g:function*(){}.constructor;function P(n){return n instanceof D}const L=(d=globalThis.AsyncGeneratorFunction)!=null?d:async function*(){}.constructor;function R(n){return n instanceof L}const k=/(^\s*(async\s+)?function\s*(\s|\*)\s*)[A-Za-z_$]+[\w$]*(\s*\()/;function q(n){if(n.name){const t=n.toString();return!k.test(t)}return!0}function C(n,t){return n instanceof Promise?n.then(i=>t(i,!1),i=>t(void 0,!0,i)):t(n,!1)}e.createDefineMixin=h,e.createExtendTarget=v,e.createMixinTarget=$,e.createTargetExtend=S,e.createTargetMixin=w,e.defineExtend=N,e.defineMixin=E,e.extendTarget=j,e.getExactTypeNameOf=b,e.getExactTypeOf=a,e.getNameOfType=s,e.getTypeByName=l,e.getTypeNameOf=m,e.getTypeOf=f,e.isAnonymousFunction=q,e.isArrayLike=F,e.isArrowFunction=z,e.isAsyncFunction=B,e.isAsyncGeneratorFunction=R,e.isBaseType=A,e.isGeneratorFunction=P,e.isIdentifier=G,e.isIterable=O,e.isIterator=p,e.isObject=r,e.mixin=u,e.mixinTarget=_,e.targetExtend=c,e.targetMixin=M,e.waitAsyncable=C,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/doc/index.md
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [type-tls](./type-tls.md) > [AnyFunction](./type-tls.anyfunction.md)
|
|
4
|
+
|
|
5
|
+
## AnyFunction type
|
|
6
|
+
|
|
7
|
+
表示任意的函数类型
|
|
8
|
+
|
|
9
|
+
<b>Signature:</b>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export declare type AnyFunction = (...args: any) => any;
|
|
13
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [type-tls](./type-tls.md) > [ClassType](./type-tls.classtype.md) > [(new)](./type-tls.classtype._new_.md)
|
|
4
|
+
|
|
5
|
+
## ClassType.(new)
|
|
6
|
+
|
|
7
|
+
<b>Signature:</b>
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
new (...args: Arg): Instance;
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Parameters
|
|
14
|
+
|
|
15
|
+
| Parameter | Type | Description |
|
|
16
|
+
| --- | --- | --- |
|
|
17
|
+
| args | Arg | |
|
|
18
|
+
|
|
19
|
+
<b>Returns:</b>
|
|
20
|
+
|
|
21
|
+
Instance
|
|
22
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [type-tls](./type-tls.md) > [ClassType](./type-tls.classtype.md)
|
|
4
|
+
|
|
5
|
+
## ClassType interface
|
|
6
|
+
|
|
7
|
+
类的类型、构造函数的类型
|
|
8
|
+
|
|
9
|
+
<b>Signature:</b>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export interface ClassType<Arg extends any[] = any[], Instance = any>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Methods
|
|
16
|
+
|
|
17
|
+
| Method | Description |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| [(new)(args)](./type-tls.classtype._new_.md) | |
|
|
20
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [type-tls](./type-tls.md) > [createDefineMixin](./type-tls.createdefinemixin.md)
|
|
4
|
+
|
|
5
|
+
## createDefineMixin() function
|
|
6
|
+
|
|
7
|
+
创建定义混合的类型便利函数
|
|
8
|
+
|
|
9
|
+
<b>Signature:</b>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export declare function createDefineMixin<T>(): <M>(target: T, mixin: M & ThisType<T & M>) => M & ThisType<T & M>;
|
|
13
|
+
```
|
|
14
|
+
<b>Returns:</b>
|
|
15
|
+
|
|
16
|
+
<M>(target: T, mixin: M & ThisType<T & M>) => M & ThisType<T & M>
|
|
17
|
+
|
|
18
|
+
可以用于 定义混合的 类型便利函数
|
|
19
|
+
|
|
20
|
+
## Remarks
|
|
21
|
+
|
|
22
|
+
它返回的便利函数的功能与 [defineMixin()](./type-tls.definemixin.md) 的功能一样,唯一区别是不再需要接收 target 参数了
|
|
23
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [type-tls](./type-tls.md) > [createExtendTarget](./type-tls.createextendtarget.md)
|
|
4
|
+
|
|
5
|
+
## createExtendTarget() function
|
|
6
|
+
|
|
7
|
+
创建用于扩展目标工具函数
|
|
8
|
+
|
|
9
|
+
<b>Signature:</b>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export declare function createExtendTarget<C extends ClassType>(cla: C): <E>(ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>) => ClassType<ConstructorParameters<C>, E & ThisType<InstanceType<C> & E>>;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
| Parameter | Type | Description |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| cla | C | 扩展的目标,也用作 this 的类型 |
|
|
20
|
+
|
|
21
|
+
<b>Returns:</b>
|
|
22
|
+
|
|
23
|
+
<E>(ext: E & ThisType<InstanceType<C> & E> & [PrivateMemberOfExtend](./type-tls.privatememberofextend.md)<!-- --><C>) => [ClassType](./type-tls.classtype.md)<!-- --><ConstructorParameters<C>, E & ThisType<InstanceType<C> & E>>
|
|
24
|
+
|
|
25
|
+
可以用于 扩展目标 的便利函数
|
|
26
|
+
|
|
27
|
+
## Remarks
|
|
28
|
+
|
|
29
|
+
它返回的便利函数的功能与 [extendTarget()](./type-tls.extendtarget.md) 的功能一样,唯一区别是不再需要接收 cla 参数了
|
|
30
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [type-tls](./type-tls.md) > [createMixinTarget](./type-tls.createmixintarget.md)
|
|
4
|
+
|
|
5
|
+
## createMixinTarget() function
|
|
6
|
+
|
|
7
|
+
创建用于混合目标工具函数
|
|
8
|
+
|
|
9
|
+
<b>Signature:</b>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export declare function createMixinTarget<T>(target: T): <M>(m: M & ThisType<T & M>) => M & ThisType<T & M> & T;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
| Parameter | Type | Description |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| target | T | |
|
|
20
|
+
|
|
21
|
+
<b>Returns:</b>
|
|
22
|
+
|
|
23
|
+
<M>(m: M & ThisType<T & M>) => M & ThisType<T & M> & T
|
|
24
|
+
|
|
25
|
+
可以用于 混合目标 的便利函数
|
|
26
|
+
|
|
27
|
+
## Remarks
|
|
28
|
+
|
|
29
|
+
它返回的便利函数的功能与 [mixinTarget()](./type-tls.mixintarget.md) 的功能一样,唯一区别是不再需要接收 target 参数了
|
|
30
|
+
|