type-tls 2.3.0 → 2.4.2

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.
@@ -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, Return> = Return extends Promise<any> ? Return : (Result extends Promise<any> ? Promise<Return> : Return);
11
+ /**
12
+ * waitAsyncable 的回调函数的类型
13
+ * @param result - 同步的结果
14
+ * @param rejected - 异步是否被拒绝
15
+ */
16
+ export declare type WaitAsyncableCallback<Result, Return> = (result: Result | undefined, rejected: boolean, error: any) => 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<Result, Return>;
@@ -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
@@ -3,3 +3,4 @@ export * from './mixin';
3
3
  export * from './extend';
4
4
  export * from './function';
5
5
  export * from './member';
6
+ export * from './async';
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.28.5"
8
+ "packageVersion": "7.28.3"
9
9
  }
10
10
  ]
11
11
  }
@@ -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<Result, Return>;
492
+
493
+ /**
494
+ * waitAsyncable 的回调函数的类型
495
+ * @param result - 同步的结果
496
+ * @param rejected - 异步是否被拒绝
497
+ */
498
+ export declare type WaitAsyncableCallback<Result, Return> = (result: Result | undefined, rejected: boolean, error: any) => Return;
499
+
500
+ /**
501
+ * waitAsyncable 的返回值的类型
502
+ */
503
+ export declare type WaitAsyncableReturn<Result, Return> = Return extends Promise<any> ? Return : (Result extends Promise<any> ? Promise<Return> : Return);
504
+
450
505
  export { }
@@ -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 targetExtend2(ext) {
108
- mixin(cla.prototype, ext);
114
+ return function classExtend(ext) {
115
+ targetExtend(cla, ext);
109
116
  return ext;
110
117
  };
111
118
  }
112
119
  function extendTarget(cla, ext) {
113
- mixin(cla.prototype, ext);
120
+ targetExtend(cla, ext);
114
121
  return cla;
115
122
  }
116
123
  function createExtendTarget(cla) {
117
124
  return function extendTarget2(ext) {
118
- mixin(cla.prototype, ext);
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
- 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 };
161
+ function waitAsyncable(asyncable, callback) {
162
+ if (asyncable instanceof Promise) {
163
+ return asyncable.then((syncRes) => {
164
+ return callback(syncRes, false, void 0);
165
+ }, (error) => {
166
+ return callback(void 0, true, error);
167
+ });
168
+ }
169
+ return callback(asyncable, false, void 0);
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 };
@@ -1 +1 @@
1
- var typeTls=function(e){var a,s,y;"use strict";function o(n){var t=typeof n;return n&&(t==="object"||t==="function")}function u(n){var t=n;return n!=null&&(t=n.constructor,t==null&&(t=typeof n)),t}function c(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 g(n){return globalThis[n]}function T(n){let t=u(n);return c(t)}function f(n){return n==null||o(n)?u(n):typeof n}function l(n){var t=f(n);return c(t)}function d(n){var t=typeof n;return n==null||t!=="object"&&t!=="function"}function b(n){let t=n&&n.length;return Number.isInteger(n.length)&&t>=0}function m(n){return n&&typeof n[Symbol.iterator]=="function"}function A(n){return n&&typeof n.next=="function"}function i(n,...t){for(const r of t){const R=Object.getOwnPropertyDescriptors(r);Object.defineProperties(n,R)}return n}function F(n,t){return t}function O(){return function(t,r){return r}}function E(n,t){return i(n,t),t}function M(n){return function(r){return i(n,r),r}}function p(n,t){return i(n,t),n}function w(n){return function(r){return i(n,r),n}}function $(n,t){return t}function N(n,t){return i(n.prototype,t),t}function S(n){return function(r){return i(n.prototype,r),r}}function h(n,t){return i(n.prototype,t),n}function v(n){return function(r){return i(n.prototype,r),n}}const I=/^[A-Za-z_$]+[\w$]*$/;function j(n){return I.test(n)}const G=/(^\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 _(n){const t=n.toString();return G.test(t)}const z=(a=globalThis.AsyncFunction)!=null?a:async function(){}.constructor;function Z(n){return n instanceof z}const x=(s=globalThis.GeneratorFunction)!=null?s:function*(){}.constructor;function B(n){return n instanceof x}const D=(y=globalThis.AsyncGeneratorFunction)!=null?y:async function*(){}.constructor;function P(n){return n instanceof D}const k=/(^\s*(async\s+)?function\s*(\s|\*)\s*)[A-Za-z_$]+[\w$]*(\s*\()/;function L(n){if(n.name){const t=n.toString();return!k.test(t)}return!0}return e.createDefineMixin=O,e.createExtendTarget=v,e.createMixinTarget=w,e.createTargetExtend=S,e.createTargetMixin=M,e.defineExtend=$,e.defineMixin=F,e.extendTarget=h,e.getExactTypeNameOf=l,e.getExactTypeOf=f,e.getNameOfType=c,e.getTypeByName=g,e.getTypeNameOf=T,e.getTypeOf=u,e.isAnonymousFunction=L,e.isArrayLike=b,e.isArrowFunction=_,e.isAsyncFunction=Z,e.isAsyncGeneratorFunction=P,e.isBaseType=d,e.isGeneratorFunction=B,e.isIdentifier=j,e.isIterable=m,e.isIterator=A,e.isObject=o,e.mixin=i,e.mixinTarget=p,e.targetExtend=N,e.targetMixin=E,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),e}({});
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 l(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 v(n){return function(r){return i(n,r),r}}function h(n,t){return i(n,t),n}function $(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 d=n;((c=d._constructors)!=null?c:d._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,void 0),r=>t(void 0,!0,r)):t(n,!1,void 0)}return e.createDefineMixin=w,e.createExtendTarget=j,e.createMixinTarget=$,e.createTargetExtend=S,e.createTargetMixin=v,e.defineExtend=N,e.defineMixin=M,e.extendTarget=I,e.getExactTypeNameOf=b,e.getExactTypeOf=s,e.getNameOfType=f,e.getTypeByName=l,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=h,e.targetExtend=u,e.targetMixin=_,e.waitAsyncable=C,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),e}({});
@@ -1 +1 @@
1
- (function(t,u){typeof exports=="object"&&typeof module!="undefined"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(t=typeof globalThis!="undefined"?globalThis:t||self,u(t.typeTls={}))})(this,function(t){var a,s,y;"use strict";function u(n){var e=typeof n;return n&&(e==="object"||e==="function")}function c(n){var e=n;return n!=null&&(e=n.constructor,e==null&&(e=typeof n)),e}function o(n){switch(n){case void 0:return"undefined";case null:return"null"}let e=typeof n;switch(e){case"function":return n.name;case"string":return n;default:return e}}function g(n){return globalThis[n]}function T(n){let e=c(n);return o(e)}function f(n){return n==null||u(n)?c(n):typeof n}function d(n){var e=f(n);return o(e)}function l(n){var e=typeof n;return n==null||e!=="object"&&e!=="function"}function b(n){let e=n&&n.length;return Number.isInteger(n.length)&&e>=0}function m(n){return n&&typeof n[Symbol.iterator]=="function"}function p(n){return n&&typeof n.next=="function"}function r(n,...e){for(const i of e){const R=Object.getOwnPropertyDescriptors(i);Object.defineProperties(n,R)}return n}function A(n,e){return e}function F(){return function(e,i){return i}}function O(n,e){return r(n,e),e}function E(n){return function(i){return r(n,i),i}}function M(n,e){return r(n,e),n}function h(n){return function(i){return r(n,i),n}}function w(n,e){return e}function $(n,e){return r(n.prototype,e),e}function N(n){return function(i){return r(n.prototype,i),i}}function S(n,e){return r(n.prototype,e),n}function j(n){return function(i){return r(n.prototype,i),n}}const I=/^[A-Za-z_$]+[\w$]*$/;function v(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 G(n){const e=n.toString();return x.test(e)}const _=(a=globalThis.AsyncFunction)!=null?a:async function(){}.constructor;function z(n){return n instanceof _}const Z=(s=globalThis.GeneratorFunction)!=null?s:function*(){}.constructor;function B(n){return n instanceof Z}const D=(y=globalThis.AsyncGeneratorFunction)!=null?y:async function*(){}.constructor;function P(n){return n instanceof D}const k=/(^\s*(async\s+)?function\s*(\s|\*)\s*)[A-Za-z_$]+[\w$]*(\s*\()/;function L(n){if(n.name){const e=n.toString();return!k.test(e)}return!0}t.createDefineMixin=F,t.createExtendTarget=j,t.createMixinTarget=h,t.createTargetExtend=N,t.createTargetMixin=E,t.defineExtend=w,t.defineMixin=A,t.extendTarget=S,t.getExactTypeNameOf=d,t.getExactTypeOf=f,t.getNameOfType=o,t.getTypeByName=g,t.getTypeNameOf=T,t.getTypeOf=c,t.isAnonymousFunction=L,t.isArrayLike=b,t.isArrowFunction=G,t.isAsyncFunction=z,t.isAsyncGeneratorFunction=P,t.isBaseType=l,t.isGeneratorFunction=B,t.isIdentifier=v,t.isIterable=m,t.isIterator=p,t.isObject=u,t.mixin=r,t.mixinTarget=M,t.targetExtend=$,t.targetMixin=O,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
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 v(n){return function(i){return u(n,i),n}}function $(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 N(n){return function(i){return c(n,i),i}}function S(n,t){return c(n,t),n}function j(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,void 0),i=>t(void 0,!0,i)):t(n,!1,void 0)}e.createDefineMixin=h,e.createExtendTarget=j,e.createMixinTarget=v,e.createTargetExtend=N,e.createTargetMixin=w,e.defineExtend=$,e.defineMixin=E,e.extendTarget=S,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
- &lt;E&gt;(ext: E &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt;) =&gt; [ClassType](./type-tls.classtype.md)<!-- -->&lt;ConstructorParameters&lt;C&gt;, E &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt;&gt;
23
+ &lt;E&gt;(ext: E &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt; &amp; [PrivateMemberOfExtend](./type-tls.privatememberofextend.md)<!-- -->&lt;C&gt;) =&gt; [ClassType](./type-tls.classtype.md)<!-- -->&lt;ConstructorParameters&lt;C&gt;, E &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt;&gt;
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
- &lt;E&gt;(ext: E &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt;) =&gt; E &amp; ThisType&lt;C &amp; E&gt;
23
+ &lt;E&gt;(ext: E &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt; &amp; [PrivateMemberOfExtend](./type-tls.privatememberofextend.md)<!-- -->&lt;C&gt;) =&gt; E &amp; ThisType&lt;C &amp; E&gt;
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 &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt; | 描述扩展内容的对象,会自动更改其this的类型 |
20
+ | ext | E &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt; &amp; [PrivateMemberOfExtend](./type-tls.privatememberofextend.md)<!-- -->&lt;C&gt; | 描述扩展内容的对象,会自动更改其this的类型 |
21
21
 
22
22
  <b>Returns:</b>
23
23
 
@@ -27,5 +27,9 @@ E &amp; ThisType&lt;C &amp; E&gt;
27
27
 
28
28
  ## Remarks
29
29
 
30
- 它会更改 ext 中方法的this指向为 cla &amp; ext,不会真的执行扩展操作
30
+ 它会更改 ext 中方法的this指向为 cla &amp; 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 &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt; | 扩展对象,会自动更改其this的类型 |
20
+ | ext | E &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt; &amp; [PrivateMemberOfExtend](./type-tls.privatememberofextend.md)<!-- -->&lt;C&gt; | 扩展对象,会自动更改其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) &gt; [type-tls](./type-tls.md) &gt; [PrivateMemberOfExtend](./type-tls.privatememberofextend.md) &gt; [\_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) &gt; [type-tls](./type-tls.md) &gt; [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) =&gt; any ? A : never)) =&gt; 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) &gt; [type-tls](./type-tls.md) &gt; [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 &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt; | 扩展描述对象,会自动更改其this的类型 |
20
+ | ext | E &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt; &amp; [PrivateMemberOfExtend](./type-tls.privatememberofextend.md)<!-- -->&lt;C&gt; | 扩展描述对象,会自动更改其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) &gt; [type-tls](./type-tls.md) &gt; [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<Result, Return>;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ | Parameter | Type | Description |
18
+ | --- | --- | --- |
19
+ | asyncable | Result | 可异步的结果 |
20
+ | callback | [WaitAsyncableCallback](./type-tls.waitasyncablecallback.md)<!-- -->&lt;Result, Return&gt; | |
21
+
22
+ <b>Returns:</b>
23
+
24
+ [WaitAsyncableReturn](./type-tls.waitasyncablereturn.md)<!-- -->&lt;Result, Return&gt;
25
+
26
+
27
+ ## Remarks
28
+
29
+ 当 asyncable 为同步值时,会同步调用 callback。 当 asyncable 为异步值时,会等待 asyncable 解决后再调用 callback。
30
+
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [type-tls](./type-tls.md) &gt; [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: Result | undefined, rejected: boolean, error: any) => Return;
13
+ ```
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [type-tls](./type-tls.md) &gt; [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, Return> = Return extends Promise<any> ? Return : (Result extends Promise<any> ? Promise<Return> : Return);
13
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-tls",
3
- "version": "2.3.0",
3
+ "version": "2.4.2",
4
4
  "description": "type-tls 封装了与类型相关的工具,比如:获取数据的类型 或 类型名字、判断数据的类型 等",
5
5
  "main": "dist/type-tls.umd.js",
6
6
  "module": "dist/type-tls.es.js",