type-tls 2.4.3 → 2.4.5
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/README.md +9 -3
- package/dist/index.d.ts +501 -6
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/type-tls.d.ts +63 -16
- package/dist/type-tls.mjs +180 -0
- package/dist/type-tls.umd.js +1 -1
- package/doc/{index.md → api/index.md} +1 -1
- package/doc/api/type-tls.arrayitemtype.md +13 -0
- package/doc/api/type-tls.keyofcontainsvalue.md +15 -0
- package/doc/api/type-tls.keyofnoncontainsvalue.md +15 -0
- package/doc/api/type-tls.keyofnonvalue.md +15 -0
- package/doc/{type-tls.keyofvalue.md → api/type-tls.keyofvalue.md} +1 -1
- package/doc/{type-tls.md → api/type-tls.md} +10 -0
- package/doc/{type-tls.waitasyncablecallback.md → api/type-tls.waitasyncablecallback.md} +3 -1
- package/doc//346/225/231/347/250/213.md +7 -0
- package/package.json +12 -12
- package/dist/async.d.ts +0 -28
- package/dist/base.d.ts +0 -190
- package/dist/buffer.d.ts +0 -1
- package/dist/extend.d.ts +0 -86
- package/dist/function.d.ts +0 -49
- package/dist/member.d.ts +0 -16
- package/dist/mixin.d.ts +0 -96
- package/dist/type-tls.es.js +0 -171
- /package/doc/{type-tls.anyfunction.md → api/type-tls.anyfunction.md} +0 -0
- /package/doc/{type-tls.classtype._new_.md → api/type-tls.classtype._new_.md} +0 -0
- /package/doc/{type-tls.classtype.md → api/type-tls.classtype.md} +0 -0
- /package/doc/{type-tls.createdefinemixin.md → api/type-tls.createdefinemixin.md} +0 -0
- /package/doc/{type-tls.createextendtarget.md → api/type-tls.createextendtarget.md} +0 -0
- /package/doc/{type-tls.createmixintarget.md → api/type-tls.createmixintarget.md} +0 -0
- /package/doc/{type-tls.createtargetextend.md → api/type-tls.createtargetextend.md} +0 -0
- /package/doc/{type-tls.createtargetmixin.md → api/type-tls.createtargetmixin.md} +0 -0
- /package/doc/{type-tls.defineextend.md → api/type-tls.defineextend.md} +0 -0
- /package/doc/{type-tls.definemixin.md → api/type-tls.definemixin.md} +0 -0
- /package/doc/{type-tls.exacttype.md → api/type-tls.exacttype.md} +0 -0
- /package/doc/{type-tls.exacttypename.md → api/type-tls.exacttypename.md} +0 -0
- /package/doc/{type-tls.extendtarget.md → api/type-tls.extendtarget.md} +0 -0
- /package/doc/{type-tls.getexacttypenameof.md → api/type-tls.getexacttypenameof.md} +0 -0
- /package/doc/{type-tls.getexacttypeof.md → api/type-tls.getexacttypeof.md} +0 -0
- /package/doc/{type-tls.getnameoftype.md → api/type-tls.getnameoftype.md} +0 -0
- /package/doc/{type-tls.gettypebyname.md → api/type-tls.gettypebyname.md} +0 -0
- /package/doc/{type-tls.gettypenameof.md → api/type-tls.gettypenameof.md} +0 -0
- /package/doc/{type-tls.gettypeof.md → api/type-tls.gettypeof.md} +0 -0
- /package/doc/{type-tls.isanonymousfunction.md → api/type-tls.isanonymousfunction.md} +0 -0
- /package/doc/{type-tls.isarraylike.md → api/type-tls.isarraylike.md} +0 -0
- /package/doc/{type-tls.isarrowfunction.md → api/type-tls.isarrowfunction.md} +0 -0
- /package/doc/{type-tls.isasyncfunction.md → api/type-tls.isasyncfunction.md} +0 -0
- /package/doc/{type-tls.isasyncgeneratorfunction.md → api/type-tls.isasyncgeneratorfunction.md} +0 -0
- /package/doc/{type-tls.isbasetype.md → api/type-tls.isbasetype.md} +0 -0
- /package/doc/{type-tls.isgeneratorfunction.md → api/type-tls.isgeneratorfunction.md} +0 -0
- /package/doc/{type-tls.isidentifier.md → api/type-tls.isidentifier.md} +0 -0
- /package/doc/{type-tls.isiterable.md → api/type-tls.isiterable.md} +0 -0
- /package/doc/{type-tls.isiterator.md → api/type-tls.isiterator.md} +0 -0
- /package/doc/{type-tls.isobject.md → api/type-tls.isobject.md} +0 -0
- /package/doc/{type-tls.loosetype.md → api/type-tls.loosetype.md} +0 -0
- /package/doc/{type-tls.loosetypename.md → api/type-tls.loosetypename.md} +0 -0
- /package/doc/{type-tls.methodparams.md → api/type-tls.methodparams.md} +0 -0
- /package/doc/{type-tls.methodreturntype.md → api/type-tls.methodreturntype.md} +0 -0
- /package/doc/{type-tls.mixin_4.md → api/type-tls.mixin_4.md} +0 -0
- /package/doc/{type-tls.mixintarget.md → api/type-tls.mixintarget.md} +0 -0
- /package/doc/{type-tls.optional.md → api/type-tls.optional.md} +0 -0
- /package/doc/{type-tls.optionalboolean.md → api/type-tls.optionalboolean.md} +0 -0
- /package/doc/{type-tls.privatememberofextend._constructor.md → api/type-tls.privatememberofextend._constructor.md} +0 -0
- /package/doc/{type-tls.privatememberofextend.md → api/type-tls.privatememberofextend.md} +0 -0
- /package/doc/{type-tls.replace.md → api/type-tls.replace.md} +0 -0
- /package/doc/{type-tls.replacenull.md → api/type-tls.replacenull.md} +0 -0
- /package/doc/{type-tls.replaceundefined.md → api/type-tls.replaceundefined.md} +0 -0
- /package/doc/{type-tls.replacevoid.md → api/type-tls.replacevoid.md} +0 -0
- /package/doc/{type-tls.resolvedata.md → api/type-tls.resolvedata.md} +0 -0
- /package/doc/{type-tls.targetextend.md → api/type-tls.targetextend.md} +0 -0
- /package/doc/{type-tls.targetmixin.md → api/type-tls.targetmixin.md} +0 -0
- /package/doc/{type-tls.typeofreturntype.md → api/type-tls.typeofreturntype.md} +0 -0
- /package/doc/{type-tls.waitasyncable.md → api/type-tls.waitasyncable.md} +0 -0
- /package/doc/{type-tls.waitasyncablereturn.md → api/type-tls.waitasyncablereturn.md} +0 -0
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
[
|
|
1
|
+
[教程]: ./doc/教程.md
|
|
2
|
+
[API接口文档]: ./doc/api/index.md
|
|
2
3
|
|
|
3
4
|
[GitHub仓库]: https://github.com/GuoBinyong/type-tls
|
|
4
5
|
[发行地址]: https://github.com/GuoBinyong/type-tls/releases
|
|
@@ -14,7 +15,8 @@
|
|
|
14
15
|
- [2. 安装方式](#2-安装方式)
|
|
15
16
|
- [2.1. 方式1:通过 npm 安装](#21-方式1通过-npm-安装)
|
|
16
17
|
- [2.2. 方式3:通过`<script>`标签引入](#22-方式3通过script标签引入)
|
|
17
|
-
- [3.
|
|
18
|
+
- [3. 教程](#3-教程)
|
|
19
|
+
- [4. API接口文档](#4-api接口文档)
|
|
18
20
|
|
|
19
21
|
|
|
20
22
|
|
|
@@ -46,6 +48,7 @@
|
|
|
46
48
|
|
|
47
49
|
|
|
48
50
|
## 2.1. 方式1:通过 npm 安装
|
|
51
|
+
通过 npm (或 yarn、pnpm 等包管理器)安装
|
|
49
52
|
```
|
|
50
53
|
npm install type-tls
|
|
51
54
|
```
|
|
@@ -69,7 +72,10 @@ npm install type-tls
|
|
|
69
72
|
</script>
|
|
70
73
|
```
|
|
71
74
|
|
|
72
|
-
# 3.
|
|
75
|
+
# 3. 教程
|
|
76
|
+
详情跳转至[教程][]
|
|
77
|
+
|
|
78
|
+
# 4. API接口文档
|
|
73
79
|
详情跳转至[API接口文档][]
|
|
74
80
|
|
|
75
81
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,501 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 处理类型相关的工具
|
|
3
|
+
* @remarks
|
|
4
|
+
* type-tls 封装了与类型相关的工具,比如获取数据的类型 或 类型名字、判断数据的类型 等
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 判断目标是否是对象类型
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* 仅通过 target instanceof Object 判断是不行的,因为 对于 Object.create(null) 创建的对象 通过 ` Object.create(null) instanceof Object ` 来判断 返回的是 false
|
|
13
|
+
* 即:通过 Object.create(null) 创建的对象是不被 instanceof 认为是继续于 Object 的
|
|
14
|
+
*
|
|
15
|
+
* typeof null 也返回 "object"
|
|
16
|
+
*
|
|
17
|
+
* @param target : any 目标对象
|
|
18
|
+
*/
|
|
19
|
+
export declare function isObject(target: any): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* typeof 的返回类型
|
|
22
|
+
*/
|
|
23
|
+
export declare type TypeOfReturnType = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
|
24
|
+
/**
|
|
25
|
+
* 宽松的类型
|
|
26
|
+
*/
|
|
27
|
+
export declare type LooseType = undefined | null | Function | "object";
|
|
28
|
+
/**
|
|
29
|
+
* 宽松类型的字符串表示
|
|
30
|
+
*/
|
|
31
|
+
export declare type LooseTypeName = "undefined" | "null" | "Function" | "object" | string;
|
|
32
|
+
/**
|
|
33
|
+
* 精确类型
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* 在精准类型中认为 JavaScript 的原始类型(非对象类型) 与 其对应的 包装类型(类类型)是不同的类型,即:
|
|
37
|
+
* number 和 Number、string 和 String、boolean 和 Boolean 等 是不同的类型;
|
|
38
|
+
* 对于原始类型,返回的结果 会与 typeof 返回的结果一样;
|
|
39
|
+
* 但,对于 undefined 和 null 会返回其自身值(即 undefined 和 null)作为类型值
|
|
40
|
+
*
|
|
41
|
+
* 各种类型的值 与 该方法的返回值 的映射如下:
|
|
42
|
+
* ```
|
|
43
|
+
* undefined :undefined
|
|
44
|
+
* null : null
|
|
45
|
+
* string : "string"
|
|
46
|
+
* number : "number"
|
|
47
|
+
* bigint : "bigint"
|
|
48
|
+
* boolean : "boolean"
|
|
49
|
+
* symbol : "symbol"
|
|
50
|
+
* function : Function
|
|
51
|
+
* 没有原型的对象(如:通过 `Object.create(null)` 创建的对象) : "object"
|
|
52
|
+
* 其它任何类型的实例 : 返回该实例的构造函数
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare type ExactType = LooseType | Exclude<TypeOfReturnType, "undefined" | "function" | "object">;
|
|
56
|
+
/**
|
|
57
|
+
* 精确类型的字符串表示
|
|
58
|
+
*
|
|
59
|
+
* @remarks
|
|
60
|
+
* 在精准类型中认为 JavaScript 的原始类型(非对象类型) 与 其对应的 包装类型(类类型)是不同的类型,即:
|
|
61
|
+
* number 和 Number、string 和 String、boolean 和 Boolean 等 是不同的类型;
|
|
62
|
+
* 对于原始类型,返回的结果 会与 typeof 返回的结果一样;
|
|
63
|
+
* 但,对于 null 会返回 "null"
|
|
64
|
+
*
|
|
65
|
+
* 各种类型的值 与 该方法的返回值 的映射如下:
|
|
66
|
+
* ```
|
|
67
|
+
* undefined :"undefined"
|
|
68
|
+
* null : "null"
|
|
69
|
+
* function : "Function"
|
|
70
|
+
* string : "string"
|
|
71
|
+
* number : "number"
|
|
72
|
+
* bigint : "bigint"
|
|
73
|
+
* boolean : "boolean"
|
|
74
|
+
* symbol : "symbol"
|
|
75
|
+
* 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
|
|
76
|
+
* 其它任何类型的实例 : 返回该实例的构造函数的名字
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare type ExactTypeName = LooseTypeName | Exclude<TypeOfReturnType, "undefined" | "function" | "object">;
|
|
80
|
+
/**
|
|
81
|
+
* 获取 inst 的宽松类型
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* 注意:
|
|
85
|
+
* 本方法返回的结果如下:
|
|
86
|
+
* ```
|
|
87
|
+
* undefined :undefined
|
|
88
|
+
* null : null
|
|
89
|
+
* function : Function
|
|
90
|
+
* 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
|
|
91
|
+
* 其它任何类型的实例 : 返回该实例的构造函数 或 包装对象的构造函数
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
*
|
|
95
|
+
* @param inst
|
|
96
|
+
* @returns inst 的类型
|
|
97
|
+
*/
|
|
98
|
+
export declare function getTypeOf(inst: any): LooseType;
|
|
99
|
+
/**
|
|
100
|
+
* 获取 类型的字符串表示
|
|
101
|
+
*
|
|
102
|
+
* @param t - 一个 ExactType 类型的值
|
|
103
|
+
* @return t 的字符串表示的类型
|
|
104
|
+
*/
|
|
105
|
+
export declare function getNameOfType(t: ExactType): ExactTypeName;
|
|
106
|
+
/**
|
|
107
|
+
* 根据类型的名字获取其对应的类
|
|
108
|
+
* @param typeName - 类型的名字
|
|
109
|
+
*/
|
|
110
|
+
export declare function getTypeByName(typeName: string): Function | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* 获取 inst 的类型字符串
|
|
113
|
+
*
|
|
114
|
+
* @remarks
|
|
115
|
+
* 注意:
|
|
116
|
+
* 本方法返回的结果如下:
|
|
117
|
+
* undefined :"undefined"
|
|
118
|
+
* null : "null"
|
|
119
|
+
* 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
|
|
120
|
+
* 其它任何类型的实例 : 返回该实例的构造函数 或 包装对象的构造函数 的函数名字
|
|
121
|
+
*
|
|
122
|
+
* @param inst
|
|
123
|
+
* @returns inst 的类型字符串
|
|
124
|
+
*/
|
|
125
|
+
export declare function getTypeNameOf(inst: any): LooseTypeName;
|
|
126
|
+
/**
|
|
127
|
+
* 获取 inst 的精确类型
|
|
128
|
+
* @param inst
|
|
129
|
+
* @returns inst 的类型
|
|
130
|
+
*/
|
|
131
|
+
export declare function getExactTypeOf(inst: any): ExactType;
|
|
132
|
+
/**
|
|
133
|
+
* 获取 inst 的精确类型的字符串表示
|
|
134
|
+
* @param inst
|
|
135
|
+
* @returns inst 的类型字符串
|
|
136
|
+
*/
|
|
137
|
+
export declare function getExactTypeNameOf(inst: any): ExactTypeName;
|
|
138
|
+
/**
|
|
139
|
+
* 判断 data 是否是 基本类型
|
|
140
|
+
* @remarks
|
|
141
|
+
* 基本类型 是指 那些不是 对象类型的类型,即,除了 object 和 function 类型以外,其它的都是基本类型,null 也算怎是 基本类型
|
|
142
|
+
* @param data - 任意类型的值
|
|
143
|
+
*/
|
|
144
|
+
export declare function isBaseType(data: any): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* 判断 target 是否为 类数组对象
|
|
147
|
+
* @param target - 目标
|
|
148
|
+
* @returns
|
|
149
|
+
*/
|
|
150
|
+
export declare function isArrayLike(target: any): boolean;
|
|
151
|
+
/**
|
|
152
|
+
* 判断 目标 是否是可迭代的对象,即 实现了 可迭代协议
|
|
153
|
+
* @param target - 目标
|
|
154
|
+
*/
|
|
155
|
+
export declare function isIterable(target: any): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* 判断 目标 是否是迭代器,即 实现了 迭代器协议
|
|
158
|
+
* @param target - 目标
|
|
159
|
+
*/
|
|
160
|
+
export declare function isIterator(target: any): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* 将某个类型变为可选的类型
|
|
163
|
+
*/
|
|
164
|
+
export declare type Optional<T> = T | null | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* 可选的布尔类型
|
|
167
|
+
*/
|
|
168
|
+
export declare type OptionalBoolean = Optional<boolean>;
|
|
169
|
+
/**
|
|
170
|
+
* 获取值类型为指定类型的所有 key
|
|
171
|
+
*
|
|
172
|
+
* @typeParam Target - 目标对象
|
|
173
|
+
* @typeParam Value - 要获取的key的对应值的类型
|
|
174
|
+
*/
|
|
175
|
+
export declare type KeyOfValue<Target, Value> = {
|
|
176
|
+
[K in keyof Target]: Target[K] extends Value ? K : never;
|
|
177
|
+
}[keyof Target];
|
|
178
|
+
/**
|
|
179
|
+
* 获取值类型不是指定类型的所有 key
|
|
180
|
+
*
|
|
181
|
+
* @typeParam Target - 目标对象
|
|
182
|
+
* @typeParam Value - 被排除的值的类型
|
|
183
|
+
*/
|
|
184
|
+
export declare type KeyOfNonValue<Target, Value> = {
|
|
185
|
+
[K in keyof Target]: Target[K] extends Value ? never : K;
|
|
186
|
+
}[keyof Target];
|
|
187
|
+
/**
|
|
188
|
+
* 获取值类型包含指定类型的所有 key
|
|
189
|
+
*
|
|
190
|
+
* @typeParam Target - 目标对象
|
|
191
|
+
* @typeParam Value - 要获取的key的对应值应包含的类型
|
|
192
|
+
*/
|
|
193
|
+
export declare type KeyOfContainsValue<Target, Value> = {
|
|
194
|
+
[K in keyof Target]: Value extends Target[K] ? K : never;
|
|
195
|
+
}[keyof Target];
|
|
196
|
+
/**
|
|
197
|
+
* 获取值类型不应包含指定类型的所有 key
|
|
198
|
+
*
|
|
199
|
+
* @typeParam Target - 目标对象
|
|
200
|
+
* @typeParam Value - 不应包含的值的类型
|
|
201
|
+
*/
|
|
202
|
+
export declare type KeyOfNonContainsValue<Target, Value> = {
|
|
203
|
+
[K in keyof Target]: Value extends Target[K] ? never : K;
|
|
204
|
+
}[keyof Target];
|
|
205
|
+
/**
|
|
206
|
+
* 可将源类型 SourType 中的 类型 MatchType 替换为 新的类型 NewType
|
|
207
|
+
*/
|
|
208
|
+
export declare type Replace<SourType, MatchType, NewType> = SourType extends MatchType ? NewType : SourType;
|
|
209
|
+
/**
|
|
210
|
+
* 可将源类型 SourType 中的 undefined 替换为 新的类型 NewType
|
|
211
|
+
*/
|
|
212
|
+
export declare type ReplaceUndefined<SourType, NewType> = Replace<SourType, undefined, NewType>;
|
|
213
|
+
/**
|
|
214
|
+
* 可将源类型 SourType 中的 null 替换为 新的类型 NewType
|
|
215
|
+
*/
|
|
216
|
+
export declare type ReplaceNull<SourType, NewType> = Replace<SourType, null, NewType>;
|
|
217
|
+
/**
|
|
218
|
+
* 可将源类型 SourType 中的代表空的类型 void | undefined | null 替换为 新的类型 NewType
|
|
219
|
+
*/
|
|
220
|
+
export declare type ReplaceVoid<SourType, NewType> = Replace<SourType, void | undefined | null, NewType>;
|
|
221
|
+
/**
|
|
222
|
+
* 混合
|
|
223
|
+
* @internal
|
|
224
|
+
*/
|
|
225
|
+
export declare function mixin<T, S>(target: T, source: S): T & S;
|
|
226
|
+
/**
|
|
227
|
+
* 混合
|
|
228
|
+
* @internal
|
|
229
|
+
*/
|
|
230
|
+
export declare function mixin<T, S1, S2>(target: T, source1: S1, source2: S2): T & S1 & S2;
|
|
231
|
+
/**
|
|
232
|
+
* 混合
|
|
233
|
+
* @internal
|
|
234
|
+
*/
|
|
235
|
+
export declare function mixin<T, S1, S2, S3>(target: T, source1: S1, source2: S2, source3: S3): T & S1 & S2 & S3;
|
|
236
|
+
/**
|
|
237
|
+
* 混合
|
|
238
|
+
* @internal
|
|
239
|
+
*/
|
|
240
|
+
export declare function mixin<T, S1, S2, S3, S4>(target: T, source1: S1, source2: S2, source3: S3, source4: S3): T & S1 & S2 & S3 & S4;
|
|
241
|
+
/**
|
|
242
|
+
* 混合
|
|
243
|
+
*
|
|
244
|
+
* @remarks
|
|
245
|
+
* 将 source 的所有成员混入 target 对象中。
|
|
246
|
+
*
|
|
247
|
+
* 与 `Object.assign()` 的功能类似,不同的是 `mixin()` 会在 target 对象中 保持 source 对象属性的 PropertyDescriptors
|
|
248
|
+
*
|
|
249
|
+
* @param target - 目标对象,所有 源对象 的属性都要被混入进到 目标对象中
|
|
250
|
+
* @param sources - 源对象,所有 源对象 的属性都要被混入进到 目标对象中
|
|
251
|
+
* @returns 混入后的 target
|
|
252
|
+
*/
|
|
253
|
+
export declare function mixin(target: any, ...sources: any[]): any;
|
|
254
|
+
/**
|
|
255
|
+
* 定义混合的类型便利函数
|
|
256
|
+
*
|
|
257
|
+
* @remarks
|
|
258
|
+
* 它会更改 mixin 中方法的this指向为 target & mixin,不会真的执行混合操作
|
|
259
|
+
*
|
|
260
|
+
* @param target - 混合的目标,用作 this 的类型
|
|
261
|
+
* @param mixin - 混合对象,会自动更改其this的类型
|
|
262
|
+
* @returns 返回注入了 this 类型的 mixin 对象本身
|
|
263
|
+
*/
|
|
264
|
+
export declare function defineMixin<T, M>(target: T, mixin: M & ThisType<T & M>): M & ThisType<T & M>;
|
|
265
|
+
/**
|
|
266
|
+
* 创建定义混合的类型便利函数
|
|
267
|
+
*
|
|
268
|
+
* @remarks
|
|
269
|
+
* 它返回的便利函数的功能与 {@link defineMixin} 的功能一样,唯一区别是不再需要接收 target 参数了
|
|
270
|
+
*
|
|
271
|
+
* @returns 可以用于 定义混合的 类型便利函数
|
|
272
|
+
*/
|
|
273
|
+
export declare function createDefineMixin<T>(): <M>(target: T, mixin: M & ThisType<T & M>) => M & ThisType<T & M>;
|
|
274
|
+
/**
|
|
275
|
+
* 混合目标
|
|
276
|
+
*
|
|
277
|
+
* @remarks
|
|
278
|
+
* 与 {@link defineMixin} 的区别是:`targetMixin` 会执行对 target 的混合操作,而 {@link defineMixin} 不会
|
|
279
|
+
*
|
|
280
|
+
*
|
|
281
|
+
* @param target - 混合的目标,用作 this 的类型
|
|
282
|
+
* @param m - 混合对象,会自动更改其this的类型
|
|
283
|
+
* @returns 返回注入了 this 类型的 mixin 对象本身
|
|
284
|
+
*/
|
|
285
|
+
export declare function targetMixin<T, M>(target: T, m: M & ThisType<T & M>): M & ThisType<T & M>;
|
|
286
|
+
/**
|
|
287
|
+
* 创建用于混合目标的便捷函数
|
|
288
|
+
*
|
|
289
|
+
* @remarks
|
|
290
|
+
* 它返回的便利函数的功能与 {@link targetMixin} 的功能一样,唯一区别是不再需要接收 target 参数了
|
|
291
|
+
*
|
|
292
|
+
* @param target - 混合的目标,用作 this 的类型
|
|
293
|
+
* @returns 可以用于 混合目标 的便利函数
|
|
294
|
+
*/
|
|
295
|
+
export declare function createTargetMixin<T>(target: T): <M>(m: M & ThisType<T & M>) => M & ThisType<T & M>;
|
|
296
|
+
/**
|
|
297
|
+
* 混合目标
|
|
298
|
+
*
|
|
299
|
+
* @remarks
|
|
300
|
+
* 会执行对 CEarth 类的扩展操作。
|
|
301
|
+
* 与 {@link targetMixin} 的区别仅仅是返回类型不一样。
|
|
302
|
+
*
|
|
303
|
+
* @param target - 混合的目标,用作 this 的类型
|
|
304
|
+
* @param m - 混合对象,会自动更改其this的类型
|
|
305
|
+
* @returns 返回混合后的 target 对象
|
|
306
|
+
*/
|
|
307
|
+
export declare function mixinTarget<T, M>(target: T, m: M & ThisType<T & M>): M & ThisType<T & M> & T;
|
|
308
|
+
/**
|
|
309
|
+
* 创建用于混合目标工具函数
|
|
310
|
+
*
|
|
311
|
+
* @remarks
|
|
312
|
+
* 它返回的便利函数的功能与 {@link mixinTarget} 的功能一样,唯一区别是不再需要接收 target 参数了
|
|
313
|
+
*
|
|
314
|
+
* @returns 可以用于 混合目标 的便利函数
|
|
315
|
+
*/
|
|
316
|
+
export declare function createMixinTarget<T>(target: T): <M>(m: M & ThisType<T & M>) => M & ThisType<T & M> & T;
|
|
317
|
+
/**
|
|
318
|
+
* 类的类型、构造函数的类型
|
|
319
|
+
*
|
|
320
|
+
* @typeParam Arg - 构建函数的参数类型
|
|
321
|
+
* @typeParam Instance - 构建函数的返回的实例类型
|
|
322
|
+
*/
|
|
323
|
+
export interface ClassType<Arg extends any[] = any[], Instance = any> {
|
|
324
|
+
new (...args: Arg): Instance;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* 用于定义扩展选项中的私有成员
|
|
328
|
+
*/
|
|
329
|
+
export interface PrivateMemberOfExtend<TargetType extends new (...args: any) => any> {
|
|
330
|
+
/**
|
|
331
|
+
* 扩展类中用于定义在创建实例时的初始化的方法
|
|
332
|
+
* @remarks
|
|
333
|
+
* 该方法会在创建实例时自动执行,并将构建函数接收到的参数透传给方方法。
|
|
334
|
+
*
|
|
335
|
+
* 注意:
|
|
336
|
+
* _constructor 会被保存在 目标类中的 _constructors 属性中,它是一个数组。
|
|
337
|
+
*
|
|
338
|
+
* 目标类 需要在自己的构建函数中逐个调用 cla._constructors 中的函数
|
|
339
|
+
*
|
|
340
|
+
* @param args
|
|
341
|
+
*/
|
|
342
|
+
_constructor?: (...args: (TargetType extends new (...args: infer A) => any ? A : never)) => void;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* 定义扩展的类型便利函数
|
|
346
|
+
*
|
|
347
|
+
* @remarks
|
|
348
|
+
* 它会更改 ext 中方法的this指向为 cla & ext,不会真的执行扩展操作。
|
|
349
|
+
*
|
|
350
|
+
* 其中 ext._constructor 会被保存在 cla._constructors 属性中,它是一个数组。
|
|
351
|
+
*
|
|
352
|
+
* cla 需要在自己的构建函数中逐个调用 cla._constructors 中的函数
|
|
353
|
+
*
|
|
354
|
+
* @param cla - 扩展的目标,用作 this 的类型
|
|
355
|
+
* @param ext - 描述扩展内容的对象,会自动更改其this的类型
|
|
356
|
+
* @returns 返回注入了 this 类型的 ext 对象本身
|
|
357
|
+
*/
|
|
358
|
+
export declare function defineExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>): E & ThisType<C & E>;
|
|
359
|
+
/**
|
|
360
|
+
* 扩展目标
|
|
361
|
+
*
|
|
362
|
+
* @remarks
|
|
363
|
+
* 与 {@link defineExtend} 的区别是:`targetExtend` 会执行对 cla 的扩展操作,而 {@link defineExtend} 不会
|
|
364
|
+
*
|
|
365
|
+
*
|
|
366
|
+
* @param cla - 扩展的目标,也用作 this 的类型
|
|
367
|
+
* @param ext - 扩展描述对象,会自动更改其this的类型
|
|
368
|
+
* @returns 返回注入了 this 类型的 ext 对象本身
|
|
369
|
+
*/
|
|
370
|
+
export declare function targetExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>): E & ThisType<InstanceType<C> & E>;
|
|
371
|
+
/**
|
|
372
|
+
* 创建用于扩展目标的便捷函数
|
|
373
|
+
*
|
|
374
|
+
* @remarks
|
|
375
|
+
* 它返回的便利函数的功能与 {@link targetExtend} 的功能一样,唯一区别是不再需要接收 cla 参数了
|
|
376
|
+
*
|
|
377
|
+
* @param cla - 扩展的目标,也用作 this 的类型
|
|
378
|
+
* @returns 可以用于 扩展目标 的便利函数
|
|
379
|
+
*/
|
|
380
|
+
export declare function createTargetExtend<C extends ClassType>(cla: C): <E>(ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtend<C>) => E & ThisType<C & E>;
|
|
381
|
+
/**
|
|
382
|
+
* 扩展目标
|
|
383
|
+
*
|
|
384
|
+
* @remarks
|
|
385
|
+
* 会执行对 CEarth 类的扩展操作。
|
|
386
|
+
* 与 {@link targetExtend} 的区别仅仅是返回类型不一样。
|
|
387
|
+
*
|
|
388
|
+
* @param cla - 扩展的目标,也用作 this 的类型
|
|
389
|
+
* @param ext - 扩展对象,会自动更改其this的类型
|
|
390
|
+
* @returns 返回扩展后的 cla 对象
|
|
391
|
+
*/
|
|
392
|
+
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>>;
|
|
393
|
+
/**
|
|
394
|
+
* 创建用于扩展目标工具函数
|
|
395
|
+
*
|
|
396
|
+
* @remarks
|
|
397
|
+
* 它返回的便利函数的功能与 {@link extendTarget} 的功能一样,唯一区别是不再需要接收 cla 参数了
|
|
398
|
+
*
|
|
399
|
+
* @param cla - 扩展的目标,也用作 this 的类型
|
|
400
|
+
* @returns 可以用于 扩展目标 的便利函数
|
|
401
|
+
*/
|
|
402
|
+
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>>;
|
|
403
|
+
/**
|
|
404
|
+
* 判断 code 是否是有校的 js 标识符
|
|
405
|
+
* @param code - 标识符的字符串
|
|
406
|
+
*/
|
|
407
|
+
export declare function isIdentifier(code: string): boolean;
|
|
408
|
+
/**
|
|
409
|
+
* 判断函数是否是箭头函数
|
|
410
|
+
* @param fun - 被判断的函数
|
|
411
|
+
*/
|
|
412
|
+
export declare function isArrowFunction(fun: Function): boolean;
|
|
413
|
+
/**
|
|
414
|
+
* 判断函数是否是 async 异步函数
|
|
415
|
+
* @remarks
|
|
416
|
+
* 异步函数 不包含 异步生成器函数 AsyncGeneratorFunction
|
|
417
|
+
* @param fun - 被判断的函数
|
|
418
|
+
*/
|
|
419
|
+
export declare function isAsyncFunction(fun: Function): boolean;
|
|
420
|
+
/**
|
|
421
|
+
* 判断函数是否是生成器函数
|
|
422
|
+
*
|
|
423
|
+
* @remarks
|
|
424
|
+
* 生成器函数 不包含 异步生成器函数 AsyncGeneratorFunction
|
|
425
|
+
* @param fun - 被判断的函数
|
|
426
|
+
*/
|
|
427
|
+
export declare function isGeneratorFunction(fun: Function): boolean;
|
|
428
|
+
/**
|
|
429
|
+
* 判断函数是否是异步生成器函数
|
|
430
|
+
* @param fun - 被判断的函数
|
|
431
|
+
*/
|
|
432
|
+
export declare function isAsyncGeneratorFunction(fun: Function): boolean;
|
|
433
|
+
/**
|
|
434
|
+
* 判断是否是匿名函数
|
|
435
|
+
*
|
|
436
|
+
* @remarks
|
|
437
|
+
* 判断函数在被定义时是否是通过匿名函数来定义的。
|
|
438
|
+
* 匿名函数是指声明函数时没有写名字的函数。
|
|
439
|
+
* 注意:即使是匿名函数,函数对象上的 name 属性也可能是有值的,因为 js解析器 会自动将 函数表达式函数变量的名字作为匿名函数的名字,如下:
|
|
440
|
+
* ```ts
|
|
441
|
+
* var funName = function(){};
|
|
442
|
+
* ```
|
|
443
|
+
* 其中的匿名函数对象的 name 属性的值会是 `funName`
|
|
444
|
+
*
|
|
445
|
+
* 如果 函数对象上的 name 属性的值为 `""`,函数一定是匿名函数。
|
|
446
|
+
*/
|
|
447
|
+
export declare function isAnonymousFunction(fun: Function): boolean;
|
|
448
|
+
/**
|
|
449
|
+
* 表示任意的函数类型
|
|
450
|
+
*/
|
|
451
|
+
export declare type AnyFunction = (...args: any) => any;
|
|
452
|
+
/**
|
|
453
|
+
* 获取对象的方法的某个参数的类型
|
|
454
|
+
*
|
|
455
|
+
* @typeParam Obj - 对象
|
|
456
|
+
* @typeParam Method - 对象方法的名字
|
|
457
|
+
* @typeParam ParamIndex - 参数的索引个数
|
|
458
|
+
*/
|
|
459
|
+
export declare type MethodParams<Obj, Method extends keyof Obj, ParamIndex extends number> = Obj[Method] extends AnyFunction ? Parameters<Obj[Method]>[ParamIndex] : never;
|
|
460
|
+
/**
|
|
461
|
+
* 获取对象的方法的返回的类型
|
|
462
|
+
*
|
|
463
|
+
* @typeParam Obj - 对象
|
|
464
|
+
* @typeParam Method - 对象方法的名字
|
|
465
|
+
*/
|
|
466
|
+
export declare type MethodReturnType<Obj, Method extends keyof Obj> = Obj[Method] extends AnyFunction ? ReturnType<Obj[Method]> : never;
|
|
467
|
+
/**
|
|
468
|
+
* 获取数组元素的类型
|
|
469
|
+
* @typeParam Arr 数组
|
|
470
|
+
*/
|
|
471
|
+
export declare type ArrayItemType<Arr> = Arr extends (infer Item)[] ? Item : never;
|
|
472
|
+
/**
|
|
473
|
+
* 获取 Promise 解决的类型的值
|
|
474
|
+
* @remarks
|
|
475
|
+
* 对于非 Promise 类型的值,返回原类型本身
|
|
476
|
+
*/
|
|
477
|
+
export declare type ResolveData<P> = P extends Promise<infer D> ? D : P;
|
|
478
|
+
/**
|
|
479
|
+
* waitAsyncable 的返回值的类型
|
|
480
|
+
*/
|
|
481
|
+
export declare type WaitAsyncableReturn<Result, Return> = Return extends Promise<any> ? Return : (Result extends Promise<any> ? Promise<Return> : Return);
|
|
482
|
+
/**
|
|
483
|
+
* waitAsyncable 的回调函数的类型
|
|
484
|
+
* @param result - 同步的结果
|
|
485
|
+
* @param rejected - 异步是否被拒绝
|
|
486
|
+
*/
|
|
487
|
+
export declare type WaitAsyncableCallback<Result, Return> = (result: ResolveData<Result> | undefined, rejected: boolean, error: any) => Return;
|
|
488
|
+
/**
|
|
489
|
+
* 等待可异步的结果
|
|
490
|
+
*
|
|
491
|
+
* @remarks
|
|
492
|
+
* 当 asyncable 为同步值时,会同步调用 callback。
|
|
493
|
+
* 当 asyncable 为异步值时,会等待 asyncable 解决后再调用 callback。
|
|
494
|
+
*
|
|
495
|
+
* @param asyncable - 可异步的结果
|
|
496
|
+
* @param callback
|
|
497
|
+
* @returns
|
|
498
|
+
*/
|
|
499
|
+
export declare function waitAsyncable<Result, Return>(asyncable: Result, callback: WaitAsyncableCallback<Result, Return>): WaitAsyncableReturn<Result, Return>;
|
|
500
|
+
|
|
501
|
+
export {};
|
package/dist/tsdoc-metadata.json
CHANGED
package/dist/type-tls.d.ts
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 处理类型相关的工具
|
|
3
|
+
* @remarks
|
|
4
|
+
* type-tls 封装了与类型相关的工具,比如获取数据的类型 或 类型名字、判断数据的类型 等
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
|
|
1
9
|
/**
|
|
2
10
|
* 表示任意的函数类型
|
|
3
11
|
*/
|
|
4
12
|
export declare type AnyFunction = (...args: any) => any;
|
|
5
13
|
|
|
14
|
+
/**
|
|
15
|
+
* 获取数组元素的类型
|
|
16
|
+
* @typeParam Arr 数组
|
|
17
|
+
*/
|
|
18
|
+
export declare type ArrayItemType<Arr> = Arr extends (infer Item)[] ? Item : never;
|
|
19
|
+
|
|
6
20
|
/**
|
|
7
21
|
* 类的类型、构造函数的类型
|
|
8
22
|
*
|
|
@@ -10,7 +24,7 @@ export declare type AnyFunction = (...args: any) => any;
|
|
|
10
24
|
* @typeParam Instance - 构建函数的返回的实例类型
|
|
11
25
|
*/
|
|
12
26
|
export declare interface ClassType<Arg extends any[] = any[], Instance = any> {
|
|
13
|
-
|
|
27
|
+
new (...args: Arg): Instance;
|
|
14
28
|
}
|
|
15
29
|
|
|
16
30
|
/**
|
|
@@ -312,11 +326,44 @@ export declare function isIterator(target: any): boolean;
|
|
|
312
326
|
*/
|
|
313
327
|
export declare function isObject(target: any): boolean;
|
|
314
328
|
|
|
329
|
+
/**
|
|
330
|
+
* 获取值类型包含指定类型的所有 key
|
|
331
|
+
*
|
|
332
|
+
* @typeParam Target - 目标对象
|
|
333
|
+
* @typeParam Value - 要获取的key的对应值应包含的类型
|
|
334
|
+
*/
|
|
335
|
+
export declare type KeyOfContainsValue<Target, Value> = {
|
|
336
|
+
[K in keyof Target]: Value extends Target[K] ? K : never;
|
|
337
|
+
}[keyof Target];
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* 获取值类型不应包含指定类型的所有 key
|
|
341
|
+
*
|
|
342
|
+
* @typeParam Target - 目标对象
|
|
343
|
+
* @typeParam Value - 不应包含的值的类型
|
|
344
|
+
*/
|
|
345
|
+
export declare type KeyOfNonContainsValue<Target, Value> = {
|
|
346
|
+
[K in keyof Target]: Value extends Target[K] ? never : K;
|
|
347
|
+
}[keyof Target];
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* 获取值类型不是指定类型的所有 key
|
|
351
|
+
*
|
|
352
|
+
* @typeParam Target - 目标对象
|
|
353
|
+
* @typeParam Value - 被排除的值的类型
|
|
354
|
+
*/
|
|
355
|
+
export declare type KeyOfNonValue<Target, Value> = {
|
|
356
|
+
[K in keyof Target]: Target[K] extends Value ? never : K;
|
|
357
|
+
}[keyof Target];
|
|
358
|
+
|
|
315
359
|
/**
|
|
316
360
|
* 获取值类型为指定类型的所有 key
|
|
361
|
+
*
|
|
362
|
+
* @typeParam Target - 目标对象
|
|
363
|
+
* @typeParam Value - 要获取的key的对应值的类型
|
|
317
364
|
*/
|
|
318
365
|
export declare type KeyOfValue<Target, Value> = {
|
|
319
|
-
|
|
366
|
+
[K in keyof Target]: Target[K] extends Value ? K : never;
|
|
320
367
|
}[keyof Target];
|
|
321
368
|
|
|
322
369
|
/**
|
|
@@ -411,19 +458,19 @@ export declare type OptionalBoolean = Optional<boolean>;
|
|
|
411
458
|
* 用于定义扩展选项中的私有成员
|
|
412
459
|
*/
|
|
413
460
|
export declare interface PrivateMemberOfExtend<TargetType extends new (...args: any) => any> {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
461
|
+
/**
|
|
462
|
+
* 扩展类中用于定义在创建实例时的初始化的方法
|
|
463
|
+
* @remarks
|
|
464
|
+
* 该方法会在创建实例时自动执行,并将构建函数接收到的参数透传给方方法。
|
|
465
|
+
*
|
|
466
|
+
* 注意:
|
|
467
|
+
* _constructor 会被保存在 目标类中的 _constructors 属性中,它是一个数组。
|
|
468
|
+
*
|
|
469
|
+
* 目标类 需要在自己的构建函数中逐个调用 cla._constructors 中的函数
|
|
470
|
+
*
|
|
471
|
+
* @param args
|
|
472
|
+
*/
|
|
473
|
+
_constructor?: (...args: (TargetType extends new (...args: infer A) => any ? A : never)) => void;
|
|
427
474
|
}
|
|
428
475
|
|
|
429
476
|
/**
|
|
@@ -502,7 +549,7 @@ export declare function waitAsyncable<Result, Return>(asyncable: Result, callbac
|
|
|
502
549
|
* @param result - 同步的结果
|
|
503
550
|
* @param rejected - 异步是否被拒绝
|
|
504
551
|
*/
|
|
505
|
-
export declare type WaitAsyncableCallback<Result, Return> = (result: Result | undefined, rejected: boolean, error: any) => Return;
|
|
552
|
+
export declare type WaitAsyncableCallback<Result, Return> = (result: ResolveData<Result> | undefined, rejected: boolean, error: any) => Return;
|
|
506
553
|
|
|
507
554
|
/**
|
|
508
555
|
* waitAsyncable 的返回值的类型
|