type-tls 2.3.0 → 2.4.0
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 +28 -0
- package/dist/buffer.d.ts +1 -0
- package/dist/extend.d.ts +28 -6
- package/dist/index.d.ts +1 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/type-tls.d.ts +61 -6
- package/dist/type-tls.es.js +22 -5
- package/dist/type-tls.iife.js +1 -1
- package/dist/type-tls.umd.js +1 -1
- package/doc/type-tls.createextendtarget.md +2 -2
- package/doc/type-tls.createtargetextend.md +2 -2
- package/doc/type-tls.defineextend.md +7 -3
- package/doc/type-tls.extendtarget.md +2 -2
- package/doc/type-tls.md +5 -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 +2 -2
- package/doc/type-tls.waitasyncable.md +30 -0
- package/doc/type-tls.waitasyncablecallback.md +15 -0
- package/doc/type-tls.waitasyncablereturn.md +13 -0
- package/package.json +1 -1
package/dist/async.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取 Promise 解决的类型的值
|
|
3
|
+
* @remarks
|
|
4
|
+
* 对于非 Promise 类型的值,返回原类型本身
|
|
5
|
+
*/
|
|
6
|
+
export declare type ResolveData<P> = P extends Promise<infer D> ? D : P;
|
|
7
|
+
/**
|
|
8
|
+
* waitAsyncable 的返回值的类型
|
|
9
|
+
*/
|
|
10
|
+
export declare type WaitAsyncableReturn<Result> = Result extends Promise<any> ? Result : Promise<Result> | Result;
|
|
11
|
+
/**
|
|
12
|
+
* waitAsyncable 的回调函数的类型
|
|
13
|
+
* @param result - 同步的结果
|
|
14
|
+
* @param rejected - 异步是否被拒绝
|
|
15
|
+
*/
|
|
16
|
+
export declare type WaitAsyncableCallback<Result, Return> = (result: ResolveData<Result> | null | undefined, rejected: boolean) => Return;
|
|
17
|
+
/**
|
|
18
|
+
* 等待可异步的结果
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* 当 asyncable 为同步值时,会同步调用 callback。
|
|
22
|
+
* 当 asyncable 为异步值时,会等待 asyncable 解决后再调用 callback。
|
|
23
|
+
*
|
|
24
|
+
* @param asyncable - 可异步的结果
|
|
25
|
+
* @param callback
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export declare function waitAsyncable<Result, Return>(asyncable: Result, callback: WaitAsyncableCallback<Result, Return>): WaitAsyncableReturn<Return>;
|
package/dist/buffer.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | BigInt64Array | BigUint64Array | Float32Array | Float64Array;
|
package/dist/extend.d.ts
CHANGED
|
@@ -7,17 +7,39 @@
|
|
|
7
7
|
export interface ClassType<Arg extends any[] = any[], Instance = any> {
|
|
8
8
|
new (...args: Arg): Instance;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* 用于定义扩展选项中的私有成员
|
|
12
|
+
*/
|
|
13
|
+
export interface PrivateMemberOfExtend<TargetType extends new (...args: any) => any> {
|
|
14
|
+
/**
|
|
15
|
+
* 扩展类中用于定义在创建实例时的初始化的方法
|
|
16
|
+
* @remarks
|
|
17
|
+
* 该方法会在创建实例时自动执行,并将构建函数接收到的参数透传给方方法。
|
|
18
|
+
*
|
|
19
|
+
* 注意:
|
|
20
|
+
* _constructor 会被保存在 目标类中的 _constructors 属性中,它是一个数组。
|
|
21
|
+
*
|
|
22
|
+
* 目标类 需要在自己的构建函数中逐个调用 cla._constructors 中的函数
|
|
23
|
+
*
|
|
24
|
+
* @param args
|
|
25
|
+
*/
|
|
26
|
+
_constructor?: (...args: (TargetType extends new (...args: infer A) => any ? A : never)) => void;
|
|
27
|
+
}
|
|
10
28
|
/**
|
|
11
29
|
* 定义扩展的类型便利函数
|
|
12
30
|
*
|
|
13
31
|
* @remarks
|
|
14
|
-
* 它会更改 ext 中方法的this指向为 cla & ext
|
|
32
|
+
* 它会更改 ext 中方法的this指向为 cla & ext,不会真的执行扩展操作。
|
|
33
|
+
*
|
|
34
|
+
* 其中 ext._constructor 会被保存在 cla._constructors 属性中,它是一个数组。
|
|
35
|
+
*
|
|
36
|
+
* cla 需要在自己的构建函数中逐个调用 cla._constructors 中的函数
|
|
15
37
|
*
|
|
16
38
|
* @param cla - 扩展的目标,用作 this 的类型
|
|
17
39
|
* @param ext - 描述扩展内容的对象,会自动更改其this的类型
|
|
18
40
|
* @returns 返回注入了 this 类型的 ext 对象本身
|
|
19
41
|
*/
|
|
20
|
-
export declare function defineExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E>): E & ThisType<C & E>;
|
|
42
|
+
export declare function defineExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>): E & ThisType<C & E>;
|
|
21
43
|
/**
|
|
22
44
|
* 扩展目标
|
|
23
45
|
*
|
|
@@ -29,7 +51,7 @@ export declare function defineExtend<C extends ClassType, E>(cla: C, ext: E & Th
|
|
|
29
51
|
* @param ext - 扩展描述对象,会自动更改其this的类型
|
|
30
52
|
* @returns 返回注入了 this 类型的 ext 对象本身
|
|
31
53
|
*/
|
|
32
|
-
export declare function targetExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E>): E & ThisType<InstanceType<C> & E>;
|
|
54
|
+
export declare function targetExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>): E & ThisType<InstanceType<C> & E>;
|
|
33
55
|
/**
|
|
34
56
|
* 创建用于扩展目标的便捷函数
|
|
35
57
|
*
|
|
@@ -39,7 +61,7 @@ export declare function targetExtend<C extends ClassType, E>(cla: C, ext: E & Th
|
|
|
39
61
|
* @param cla - 扩展的目标,也用作 this 的类型
|
|
40
62
|
* @returns 可以用于 扩展目标 的便利函数
|
|
41
63
|
*/
|
|
42
|
-
export declare function createTargetExtend<C extends ClassType>(cla: C): <E>(ext: E & ThisType<InstanceType<C> & E>) => E & ThisType<C & E>;
|
|
64
|
+
export declare function createTargetExtend<C extends ClassType>(cla: C): <E>(ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>) => E & ThisType<C & E>;
|
|
43
65
|
/**
|
|
44
66
|
* 扩展目标
|
|
45
67
|
*
|
|
@@ -51,7 +73,7 @@ export declare function createTargetExtend<C extends ClassType>(cla: C): <E>(ext
|
|
|
51
73
|
* @param ext - 扩展对象,会自动更改其this的类型
|
|
52
74
|
* @returns 返回扩展后的 cla 对象
|
|
53
75
|
*/
|
|
54
|
-
export declare function extendTarget<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E>): ClassType<ConstructorParameters<C>, E & ThisType<InstanceType<C> & E>>;
|
|
76
|
+
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>>;
|
|
55
77
|
/**
|
|
56
78
|
* 创建用于扩展目标工具函数
|
|
57
79
|
*
|
|
@@ -61,4 +83,4 @@ export declare function extendTarget<C extends ClassType, E>(cla: C, ext: E & Th
|
|
|
61
83
|
* @param cla - 扩展的目标,也用作 this 的类型
|
|
62
84
|
* @returns 可以用于 扩展目标 的便利函数
|
|
63
85
|
*/
|
|
64
|
-
export declare function createExtendTarget<C extends ClassType>(cla: C): <E>(ext: E & ThisType<InstanceType<C> & E>) => ClassType<ConstructorParameters<C>, E & ThisType<InstanceType<C> & E>>;
|
|
86
|
+
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>>;
|
package/dist/index.d.ts
CHANGED
package/dist/tsdoc-metadata.json
CHANGED
package/dist/type-tls.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare function createDefineMixin<T>(): <M>(target: T, mixin: M & ThisTy
|
|
|
32
32
|
* @param cla - 扩展的目标,也用作 this 的类型
|
|
33
33
|
* @returns 可以用于 扩展目标 的便利函数
|
|
34
34
|
*/
|
|
35
|
-
export declare function createExtendTarget<C extends ClassType>(cla: C): <E>(ext: E & ThisType<InstanceType<C> & E>) => ClassType<ConstructorParameters<C>, E & ThisType<InstanceType<C> & E>>;
|
|
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
36
|
|
|
37
37
|
/**
|
|
38
38
|
* 创建用于混合目标工具函数
|
|
@@ -53,7 +53,7 @@ export declare function createMixinTarget<T>(target: T): <M>(m: M & ThisType<T &
|
|
|
53
53
|
* @param cla - 扩展的目标,也用作 this 的类型
|
|
54
54
|
* @returns 可以用于 扩展目标 的便利函数
|
|
55
55
|
*/
|
|
56
|
-
export declare function createTargetExtend<C extends ClassType>(cla: C): <E>(ext: E & ThisType<InstanceType<C> & E>) => E & ThisType<C & E>;
|
|
56
|
+
export declare function createTargetExtend<C extends ClassType>(cla: C): <E>(ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>) => E & ThisType<C & E>;
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* 创建用于混合目标的便捷函数
|
|
@@ -70,13 +70,17 @@ export declare function createTargetMixin<T>(target: T): <M>(m: M & ThisType<T &
|
|
|
70
70
|
* 定义扩展的类型便利函数
|
|
71
71
|
*
|
|
72
72
|
* @remarks
|
|
73
|
-
* 它会更改 ext 中方法的this指向为 cla & ext
|
|
73
|
+
* 它会更改 ext 中方法的this指向为 cla & ext,不会真的执行扩展操作。
|
|
74
|
+
*
|
|
75
|
+
* 其中 ext._constructor 会被保存在 cla._constructors 属性中,它是一个数组。
|
|
76
|
+
*
|
|
77
|
+
* cla 需要在自己的构建函数中逐个调用 cla._constructors 中的函数
|
|
74
78
|
*
|
|
75
79
|
* @param cla - 扩展的目标,用作 this 的类型
|
|
76
80
|
* @param ext - 描述扩展内容的对象,会自动更改其this的类型
|
|
77
81
|
* @returns 返回注入了 this 类型的 ext 对象本身
|
|
78
82
|
*/
|
|
79
|
-
export declare function defineExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E>): E & ThisType<C & E>;
|
|
83
|
+
export declare function defineExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>): E & ThisType<C & E>;
|
|
80
84
|
|
|
81
85
|
/**
|
|
82
86
|
* 定义混合的类型便利函数
|
|
@@ -151,7 +155,7 @@ export declare type ExactTypeName = LooseTypeName | Exclude<TypeOfReturnType, "u
|
|
|
151
155
|
* @param ext - 扩展对象,会自动更改其this的类型
|
|
152
156
|
* @returns 返回扩展后的 cla 对象
|
|
153
157
|
*/
|
|
154
|
-
export declare function extendTarget<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E>): ClassType<ConstructorParameters<C>, E & ThisType<InstanceType<C> & E>>;
|
|
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>>;
|
|
155
159
|
|
|
156
160
|
/**
|
|
157
161
|
* 获取 inst 的精确类型的字符串表示
|
|
@@ -396,6 +400,25 @@ export declare type Optional<T> = T | null | undefined;
|
|
|
396
400
|
*/
|
|
397
401
|
export declare type OptionalBoolean = Optional<boolean>;
|
|
398
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
|
+
|
|
399
422
|
/**
|
|
400
423
|
* 可将源类型 SourType 中的 类型 MatchType 替换为 新的类型 NewType
|
|
401
424
|
*/
|
|
@@ -416,6 +439,13 @@ export declare type ReplaceUndefined<SourType, NewType> = Replace<SourType, unde
|
|
|
416
439
|
*/
|
|
417
440
|
export declare type ReplaceVoid<SourType, NewType> = Replace<SourType, void | undefined | null, NewType>;
|
|
418
441
|
|
|
442
|
+
/**
|
|
443
|
+
* 获取 Promise 解决的类型的值
|
|
444
|
+
* @remarks
|
|
445
|
+
* 对于非 Promise 类型的值,返回原类型本身
|
|
446
|
+
*/
|
|
447
|
+
export declare type ResolveData<P> = P extends Promise<infer D> ? D : P;
|
|
448
|
+
|
|
419
449
|
/**
|
|
420
450
|
* 扩展目标
|
|
421
451
|
*
|
|
@@ -427,7 +457,7 @@ export declare type ReplaceVoid<SourType, NewType> = Replace<SourType, void | un
|
|
|
427
457
|
* @param ext - 扩展描述对象,会自动更改其this的类型
|
|
428
458
|
* @returns 返回注入了 this 类型的 ext 对象本身
|
|
429
459
|
*/
|
|
430
|
-
export declare function targetExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E>): E & ThisType<InstanceType<C> & E>;
|
|
460
|
+
export declare function targetExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>): E & ThisType<InstanceType<C> & E>;
|
|
431
461
|
|
|
432
462
|
/**
|
|
433
463
|
* 混合目标
|
|
@@ -447,4 +477,29 @@ export declare function targetMixin<T, M>(target: T, m: M & ThisType<T & M>): M
|
|
|
447
477
|
*/
|
|
448
478
|
export declare type TypeOfReturnType = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
|
449
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<Return>;
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* waitAsyncable 的回调函数的类型
|
|
495
|
+
* @param result - 同步的结果
|
|
496
|
+
* @param rejected - 异步是否被拒绝
|
|
497
|
+
*/
|
|
498
|
+
export declare type WaitAsyncableCallback<Result, Return> = (result: ResolveData<Result> | null | undefined, rejected: boolean) => Return;
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* waitAsyncable 的返回值的类型
|
|
502
|
+
*/
|
|
503
|
+
export declare type WaitAsyncableReturn<Result> = Result extends Promise<any> ? Result : Promise<Result> | Result;
|
|
504
|
+
|
|
450
505
|
export { }
|
package/dist/type-tls.es.js
CHANGED
|
@@ -100,22 +100,29 @@ function defineExtend(cla, ext) {
|
|
|
100
100
|
return ext;
|
|
101
101
|
}
|
|
102
102
|
function targetExtend(cla, ext) {
|
|
103
|
+
var _a2;
|
|
103
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
|
+
}
|
|
104
111
|
return ext;
|
|
105
112
|
}
|
|
106
113
|
function createTargetExtend(cla) {
|
|
107
|
-
return function
|
|
108
|
-
|
|
114
|
+
return function classExtend(ext) {
|
|
115
|
+
targetExtend(cla, ext);
|
|
109
116
|
return ext;
|
|
110
117
|
};
|
|
111
118
|
}
|
|
112
119
|
function extendTarget(cla, ext) {
|
|
113
|
-
|
|
120
|
+
targetExtend(cla, ext);
|
|
114
121
|
return cla;
|
|
115
122
|
}
|
|
116
123
|
function createExtendTarget(cla) {
|
|
117
124
|
return function extendTarget2(ext) {
|
|
118
|
-
|
|
125
|
+
targetExtend(cla, ext);
|
|
119
126
|
return cla;
|
|
120
127
|
};
|
|
121
128
|
}
|
|
@@ -151,4 +158,14 @@ function isAnonymousFunction(fun) {
|
|
|
151
158
|
}
|
|
152
159
|
return true;
|
|
153
160
|
}
|
|
154
|
-
|
|
161
|
+
function waitAsyncable(asyncable, callback) {
|
|
162
|
+
if (asyncable instanceof Promise) {
|
|
163
|
+
return asyncable.then((syncRes) => {
|
|
164
|
+
return callback(syncRes, false);
|
|
165
|
+
}, () => {
|
|
166
|
+
return callback(void 0, true);
|
|
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(e){var
|
|
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),()=>t(void 0,!0)):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),()=>t(void 0,!0)):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"}})});
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
export declare function createExtendTarget<C extends ClassType>(cla: C): <E>(ext: E & ThisType<InstanceType<C> & E>) => ClassType<ConstructorParameters<C>, E & ThisType<InstanceType<C> & E>>;
|
|
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
13
|
```
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
@@ -20,7 +20,7 @@ export declare function createExtendTarget<C extends ClassType>(cla: C): <E>(ext
|
|
|
20
20
|
|
|
21
21
|
<b>Returns:</b>
|
|
22
22
|
|
|
23
|
-
<E>(ext: E & ThisType<InstanceType<C> & E>) => [ClassType](./type-tls.classtype.md)<!-- --><ConstructorParameters<C>, E & ThisType<InstanceType<C> & E>>
|
|
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
24
|
|
|
25
25
|
可以用于 扩展目标 的便利函数
|
|
26
26
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
export declare function createTargetExtend<C extends ClassType>(cla: C): <E>(ext: E & ThisType<InstanceType<C> & E>) => E & ThisType<C & E>;
|
|
12
|
+
export declare function createTargetExtend<C extends ClassType>(cla: C): <E>(ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>) => E & ThisType<C & E>;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
@@ -20,7 +20,7 @@ export declare function createTargetExtend<C extends ClassType>(cla: C): <E>(ext
|
|
|
20
20
|
|
|
21
21
|
<b>Returns:</b>
|
|
22
22
|
|
|
23
|
-
<E>(ext: E & ThisType<InstanceType<C> & E>) => E & ThisType<C & E>
|
|
23
|
+
<E>(ext: E & ThisType<InstanceType<C> & E> & [PrivateMemberOfExtend](./type-tls.privatememberofextend.md)<!-- --><C>) => E & ThisType<C & E>
|
|
24
24
|
|
|
25
25
|
可以用于 扩展目标 的便利函数
|
|
26
26
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
export declare function defineExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E>): E & ThisType<C & E>;
|
|
12
|
+
export declare function defineExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>): E & ThisType<C & E>;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
@@ -17,7 +17,7 @@ export declare function defineExtend<C extends ClassType, E>(cla: C, ext: E & Th
|
|
|
17
17
|
| Parameter | Type | Description |
|
|
18
18
|
| --- | --- | --- |
|
|
19
19
|
| cla | C | 扩展的目标,用作 this 的类型 |
|
|
20
|
-
| ext | E & ThisType<InstanceType<C> & E> | 描述扩展内容的对象,会自动更改其this的类型 |
|
|
20
|
+
| ext | E & ThisType<InstanceType<C> & E> & [PrivateMemberOfExtend](./type-tls.privatememberofextend.md)<!-- --><C> | 描述扩展内容的对象,会自动更改其this的类型 |
|
|
21
21
|
|
|
22
22
|
<b>Returns:</b>
|
|
23
23
|
|
|
@@ -27,5 +27,9 @@ E & ThisType<C & E>
|
|
|
27
27
|
|
|
28
28
|
## Remarks
|
|
29
29
|
|
|
30
|
-
它会更改 ext 中方法的this指向为 cla & ext
|
|
30
|
+
它会更改 ext 中方法的this指向为 cla & ext,不会真的执行扩展操作。
|
|
31
|
+
|
|
32
|
+
其中 ext.\_constructor 会被保存在 cla.\_constructors 属性中,它是一个数组。
|
|
33
|
+
|
|
34
|
+
cla 需要在自己的构建函数中逐个调用 cla.\_constructors 中的函数
|
|
31
35
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
export declare function extendTarget<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E>): ClassType<ConstructorParameters<C>, E & ThisType<InstanceType<C> & E>>;
|
|
12
|
+
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>>;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
@@ -17,7 +17,7 @@ export declare function extendTarget<C extends ClassType, E>(cla: C, ext: E & Th
|
|
|
17
17
|
| Parameter | Type | Description |
|
|
18
18
|
| --- | --- | --- |
|
|
19
19
|
| cla | C | 扩展的目标,也用作 this 的类型 |
|
|
20
|
-
| ext | E & ThisType<InstanceType<C> & E> | 扩展对象,会自动更改其this的类型 |
|
|
20
|
+
| ext | E & ThisType<InstanceType<C> & E> & [PrivateMemberOfExtend](./type-tls.privatememberofextend.md)<!-- --><C> | 扩展对象,会自动更改其this的类型 |
|
|
21
21
|
|
|
22
22
|
<b>Returns:</b>
|
|
23
23
|
|
package/doc/type-tls.md
CHANGED
|
@@ -37,12 +37,14 @@
|
|
|
37
37
|
| [mixinTarget(target, m)](./type-tls.mixintarget.md) | 混合目标 |
|
|
38
38
|
| [targetExtend(cla, ext)](./type-tls.targetextend.md) | 扩展目标 |
|
|
39
39
|
| [targetMixin(target, m)](./type-tls.targetmixin.md) | 混合目标 |
|
|
40
|
+
| [waitAsyncable(asyncable, callback)](./type-tls.waitasyncable.md) | 等待可异步的结果 |
|
|
40
41
|
|
|
41
42
|
## Interfaces
|
|
42
43
|
|
|
43
44
|
| Interface | Description |
|
|
44
45
|
| --- | --- |
|
|
45
46
|
| [ClassType](./type-tls.classtype.md) | 类的类型、构造函数的类型 |
|
|
47
|
+
| [PrivateMemberOfExtend](./type-tls.privatememberofextend.md) | 用于定义扩展选项中的私有成员 |
|
|
46
48
|
|
|
47
49
|
## Type Aliases
|
|
48
50
|
|
|
@@ -61,5 +63,8 @@
|
|
|
61
63
|
| [ReplaceNull](./type-tls.replacenull.md) | 可将源类型 SourType 中的 null 替换为 新的类型 NewType |
|
|
62
64
|
| [ReplaceUndefined](./type-tls.replaceundefined.md) | 可将源类型 SourType 中的 undefined 替换为 新的类型 NewType |
|
|
63
65
|
| [ReplaceVoid](./type-tls.replacevoid.md) | 可将源类型 SourType 中的代表空的类型 void \| undefined \| null 替换为 新的类型 NewType |
|
|
66
|
+
| [ResolveData](./type-tls.resolvedata.md) | 获取 Promise 解决的类型的值 |
|
|
64
67
|
| [TypeOfReturnType](./type-tls.typeofreturntype.md) | typeof 的返回类型 |
|
|
68
|
+
| [WaitAsyncableCallback](./type-tls.waitasyncablecallback.md) | waitAsyncable 的回调函数的类型 |
|
|
69
|
+
| [WaitAsyncableReturn](./type-tls.waitasyncablereturn.md) | waitAsyncable 的返回值的类型 |
|
|
65
70
|
|
|
@@ -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) > [PrivateMemberOfExtend](./type-tls.privatememberofextend.md) > [\_constructor](./type-tls.privatememberofextend._constructor.md)
|
|
4
|
+
|
|
5
|
+
## PrivateMemberOfExtend.\_constructor property
|
|
6
|
+
|
|
7
|
+
扩展类中用于定义在创建实例时的初始化的方法
|
|
8
|
+
|
|
9
|
+
<b>Signature:</b>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
_constructor?: (...args: (TargetType extends new (...args: infer A) => any ? A : never)) => void;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Remarks
|
|
16
|
+
|
|
17
|
+
该方法会在创建实例时自动执行,并将构建函数接收到的参数透传给方方法。
|
|
18
|
+
|
|
19
|
+
注意: \_constructor 会被保存在 目标类中的 \_constructors 属性中,它是一个数组。
|
|
20
|
+
|
|
21
|
+
目标类 需要在自己的构建函数中逐个调用 cla.\_constructors 中的函数
|
|
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) > [PrivateMemberOfExtend](./type-tls.privatememberofextend.md)
|
|
4
|
+
|
|
5
|
+
## PrivateMemberOfExtend interface
|
|
6
|
+
|
|
7
|
+
用于定义扩展选项中的私有成员
|
|
8
|
+
|
|
9
|
+
<b>Signature:</b>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export interface PrivateMemberOfExtend<TargetType extends new (...args: any) => any>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Properties
|
|
16
|
+
|
|
17
|
+
| Property | Modifiers | Type | Description |
|
|
18
|
+
| --- | --- | --- | --- |
|
|
19
|
+
| [\_constructor?](./type-tls.privatememberofextend._constructor.md) | | (...args: (TargetType extends new (...args: infer A) => any ? A : never)) => void | <i>(Optional)</i> 扩展类中用于定义在创建实例时的初始化的方法 |
|
|
20
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [type-tls](./type-tls.md) > [ResolveData](./type-tls.resolvedata.md)
|
|
4
|
+
|
|
5
|
+
## ResolveData type
|
|
6
|
+
|
|
7
|
+
获取 Promise 解决的类型的值
|
|
8
|
+
|
|
9
|
+
<b>Signature:</b>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export declare type ResolveData<P> = P extends Promise<infer D> ? D : P;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Remarks
|
|
16
|
+
|
|
17
|
+
对于非 Promise 类型的值,返回原类型本身
|
|
18
|
+
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
export declare function targetExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E>): E & ThisType<InstanceType<C> & E>;
|
|
12
|
+
export declare function targetExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>): E & ThisType<InstanceType<C> & E>;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
@@ -17,7 +17,7 @@ export declare function targetExtend<C extends ClassType, E>(cla: C, ext: E & Th
|
|
|
17
17
|
| Parameter | Type | Description |
|
|
18
18
|
| --- | --- | --- |
|
|
19
19
|
| cla | C | 扩展的目标,也用作 this 的类型 |
|
|
20
|
-
| ext | E & ThisType<InstanceType<C> & E> | 扩展描述对象,会自动更改其this的类型 |
|
|
20
|
+
| ext | E & ThisType<InstanceType<C> & E> & [PrivateMemberOfExtend](./type-tls.privatememberofextend.md)<!-- --><C> | 扩展描述对象,会自动更改其this的类型 |
|
|
21
21
|
|
|
22
22
|
<b>Returns:</b>
|
|
23
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) > [waitAsyncable](./type-tls.waitasyncable.md)
|
|
4
|
+
|
|
5
|
+
## waitAsyncable() function
|
|
6
|
+
|
|
7
|
+
等待可异步的结果
|
|
8
|
+
|
|
9
|
+
<b>Signature:</b>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export declare function waitAsyncable<Result, Return>(asyncable: Result, callback: WaitAsyncableCallback<Result, Return>): WaitAsyncableReturn<Return>;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
| Parameter | Type | Description |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| asyncable | Result | 可异步的结果 |
|
|
20
|
+
| callback | [WaitAsyncableCallback](./type-tls.waitasyncablecallback.md)<!-- --><Result, Return> | |
|
|
21
|
+
|
|
22
|
+
<b>Returns:</b>
|
|
23
|
+
|
|
24
|
+
[WaitAsyncableReturn](./type-tls.waitasyncablereturn.md)<!-- --><Return>
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## Remarks
|
|
28
|
+
|
|
29
|
+
当 asyncable 为同步值时,会同步调用 callback。 当 asyncable 为异步值时,会等待 asyncable 解决后再调用 callback。
|
|
30
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [type-tls](./type-tls.md) > [WaitAsyncableCallback](./type-tls.waitasyncablecallback.md)
|
|
4
|
+
|
|
5
|
+
## WaitAsyncableCallback type
|
|
6
|
+
|
|
7
|
+
waitAsyncable 的回调函数的类型
|
|
8
|
+
|
|
9
|
+
<b>Signature:</b>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export declare type WaitAsyncableCallback<Result, Return> = (result: ResolveData<Result> | null | undefined, rejected: boolean) => Return;
|
|
13
|
+
```
|
|
14
|
+
<b>References:</b> [ResolveData](./type-tls.resolvedata.md)
|
|
15
|
+
|
|
@@ -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) > [WaitAsyncableReturn](./type-tls.waitasyncablereturn.md)
|
|
4
|
+
|
|
5
|
+
## WaitAsyncableReturn type
|
|
6
|
+
|
|
7
|
+
waitAsyncable 的返回值的类型
|
|
8
|
+
|
|
9
|
+
<b>Signature:</b>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export declare type WaitAsyncableReturn<Result> = Result extends Promise<any> ? Result : Promise<Result> | Result;
|
|
13
|
+
```
|