type-tls 2.1.0 → 2.3.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/LICENSE +21 -0
- package/README.md +81 -0
- package/dist/base.d.ts +184 -0
- package/dist/extend.d.ts +64 -0
- package/dist/function.d.ts +49 -0
- package/dist/index.d.ts +5 -150
- package/dist/member.d.ts +16 -0
- package/dist/mixin.d.ts +96 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/type-tls.d.ts +450 -0
- package/dist/type-tls.es.js +137 -134
- package/dist/type-tls.iife.js +1 -0
- package/dist/type-tls.umd.js +1 -1
- package/doc/index.md +12 -0
- package/doc/type-tls.anyfunction.md +13 -0
- package/doc/type-tls.classtype._new_.md +22 -0
- package/doc/type-tls.classtype.md +20 -0
- package/doc/type-tls.createdefinemixin.md +23 -0
- package/doc/type-tls.createextendtarget.md +30 -0
- package/doc/type-tls.createmixintarget.md +30 -0
- package/doc/type-tls.createtargetextend.md +30 -0
- package/doc/type-tls.createtargetmixin.md +30 -0
- package/doc/type-tls.defineextend.md +31 -0
- package/doc/type-tls.definemixin.md +31 -0
- package/doc/type-tls.exacttype.md +34 -0
- package/doc/type-tls.exacttypename.md +34 -0
- package/doc/type-tls.extendtarget.md +31 -0
- package/doc/type-tls.getexacttypenameof.md +26 -0
- package/doc/type-tls.getexacttypeof.md +26 -0
- package/doc/type-tls.getnameoftype.md +24 -0
- package/doc/type-tls.gettypebyname.md +24 -0
- package/doc/type-tls.gettypenameof.md +30 -0
- package/doc/type-tls.gettypeof.md +38 -0
- package/doc/type-tls.isanonymousfunction.md +35 -0
- package/doc/type-tls.isarraylike.md +25 -0
- package/doc/type-tls.isarrowfunction.md +24 -0
- package/doc/type-tls.isasyncfunction.md +28 -0
- package/doc/type-tls.isasyncgeneratorfunction.md +24 -0
- package/doc/type-tls.isbasetype.md +28 -0
- package/doc/type-tls.isgeneratorfunction.md +28 -0
- package/doc/type-tls.isidentifier.md +24 -0
- package/doc/type-tls.isiterable.md +24 -0
- package/doc/type-tls.isiterator.md +24 -0
- package/doc/type-tls.isobject.md +30 -0
- package/doc/type-tls.loosetype.md +13 -0
- package/doc/type-tls.loosetypename.md +13 -0
- package/doc/type-tls.md +65 -0
- package/doc/type-tls.methodparams.md +15 -0
- package/doc/type-tls.methodreturntype.md +15 -0
- package/doc/type-tls.mixin_4.md +33 -0
- package/doc/type-tls.mixintarget.md +31 -0
- package/doc/type-tls.optional.md +13 -0
- package/doc/type-tls.optionalboolean.md +15 -0
- package/doc/type-tls.replace.md +13 -0
- package/doc/type-tls.replacenull.md +15 -0
- package/doc/type-tls.replaceundefined.md +15 -0
- package/doc/type-tls.replacevoid.md +15 -0
- package/doc/type-tls.targetextend.md +31 -0
- package/doc/type-tls.targetmixin.md +31 -0
- package/doc/type-tls.typeofreturntype.md +13 -0
- package/package.json +28 -23
- package/dist/type-tls.cjs.js +0 -165
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 郭斌勇
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
[API接口文档]: ./doc/index.md
|
|
2
|
+
|
|
3
|
+
[GitHub仓库]: https://github.com/GuoBinyong/type-tls
|
|
4
|
+
[发行地址]: https://github.com/GuoBinyong/type-tls/releases
|
|
5
|
+
[issues]: https://github.com/GuoBinyong/type-tls/issues
|
|
6
|
+
|
|
7
|
+
[码云仓库]: https://gitee.com/guobinyong/type-tls
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
> 目录
|
|
12
|
+
|
|
13
|
+
- [1. 简介](#1-简介)
|
|
14
|
+
- [2. 安装方式](#2-安装方式)
|
|
15
|
+
- [2.1. 方式1:通过 npm 安装](#21-方式1通过-npm-安装)
|
|
16
|
+
- [2.2. 方式3:通过`<script>`标签引入](#22-方式3通过script标签引入)
|
|
17
|
+
- [3. API接口文档](#3-api接口文档)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# 1. 简介
|
|
23
|
+
在使用 TypeScript 封装库时,如果希望设计更智能的 TypeScript 类型推导,则往往需要大量的类型相关的操作,type-tls 就提供了常用的类型操作的工具,比如:获取数据的类型 或 类型名字、判断数据的类型、还有一些 Type 工具。
|
|
24
|
+
|
|
25
|
+
**详情请看:**
|
|
26
|
+
- 主页:<https://github.com/GuoBinyong/type-tls>
|
|
27
|
+
- [GitHub仓库][]
|
|
28
|
+
- [码云仓库][]
|
|
29
|
+
- [教程][]
|
|
30
|
+
- [API接口文档][]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
**如果您在使用的过程中遇到了问题,或者有好的建议和想法,您都可以通过以下方式联系我,期待与您的交流:**
|
|
34
|
+
- 给该仓库提交 [issues][]
|
|
35
|
+
- 给我 Pull requests
|
|
36
|
+
- 邮箱:<guobinyong@qq.com>
|
|
37
|
+
- QQ:guobinyong@qq.com
|
|
38
|
+
- 微信:keyanzhe
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# 2. 安装方式
|
|
45
|
+
目前,安装方式有以下几种:
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## 2.1. 方式1:通过 npm 安装
|
|
49
|
+
```
|
|
50
|
+
npm install type-tls
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## 2.2. 方式3:通过`<script>`标签引入
|
|
57
|
+
您可直接从项目的 [发行地址][] 中下载以 `.iife.js` 作为缀的文件,然后使用如下代码引用 和 使用 type-tls:
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
1. 引用 type-tls
|
|
61
|
+
```
|
|
62
|
+
<script src="path/to/package/type-tls.iife.js"></script>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
2. 使用全局的 `TypeTls`
|
|
66
|
+
```
|
|
67
|
+
<script>
|
|
68
|
+
// 使用全局的 TypeTls
|
|
69
|
+
</script>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
# 3. API接口文档
|
|
73
|
+
详情跳转至[API接口文档][]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
--------------------
|
|
78
|
+
|
|
79
|
+
> 有您的支持,我会在开源的道路上,越走越远
|
|
80
|
+
|
|
81
|
+

|
package/dist/base.d.ts
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
* 可将源类型 SourType 中的 类型 MatchType 替换为 新的类型 NewType
|
|
171
|
+
*/
|
|
172
|
+
export declare type Replace<SourType, MatchType, NewType> = SourType extends MatchType ? NewType : SourType;
|
|
173
|
+
/**
|
|
174
|
+
* 可将源类型 SourType 中的 undefined 替换为 新的类型 NewType
|
|
175
|
+
*/
|
|
176
|
+
export declare type ReplaceUndefined<SourType, NewType> = Replace<SourType, undefined, NewType>;
|
|
177
|
+
/**
|
|
178
|
+
* 可将源类型 SourType 中的 null 替换为 新的类型 NewType
|
|
179
|
+
*/
|
|
180
|
+
export declare type ReplaceNull<SourType, NewType> = Replace<SourType, null, NewType>;
|
|
181
|
+
/**
|
|
182
|
+
* 可将源类型 SourType 中的代表空的类型 void | undefined | null 替换为 新的类型 NewType
|
|
183
|
+
*/
|
|
184
|
+
export declare type ReplaceVoid<SourType, NewType> = Replace<SourType, void | undefined | null, NewType>;
|
package/dist/extend.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 类的类型、构造函数的类型
|
|
3
|
+
*
|
|
4
|
+
* @typeParam Arg - 构建函数的参数类型
|
|
5
|
+
* @typeParam Instance - 构建函数的返回的实例类型
|
|
6
|
+
*/
|
|
7
|
+
export interface ClassType<Arg extends any[] = any[], Instance = any> {
|
|
8
|
+
new (...args: Arg): Instance;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 定义扩展的类型便利函数
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* 它会更改 ext 中方法的this指向为 cla & ext,不会真的执行扩展操作
|
|
15
|
+
*
|
|
16
|
+
* @param cla - 扩展的目标,用作 this 的类型
|
|
17
|
+
* @param ext - 描述扩展内容的对象,会自动更改其this的类型
|
|
18
|
+
* @returns 返回注入了 this 类型的 ext 对象本身
|
|
19
|
+
*/
|
|
20
|
+
export declare function defineExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E>): E & ThisType<C & E>;
|
|
21
|
+
/**
|
|
22
|
+
* 扩展目标
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* 与 {@link defineExtend} 的区别是:`targetExtend` 会执行对 cla 的扩展操作,而 {@link defineExtend} 不会
|
|
26
|
+
*
|
|
27
|
+
*
|
|
28
|
+
* @param cla - 扩展的目标,也用作 this 的类型
|
|
29
|
+
* @param ext - 扩展描述对象,会自动更改其this的类型
|
|
30
|
+
* @returns 返回注入了 this 类型的 ext 对象本身
|
|
31
|
+
*/
|
|
32
|
+
export declare function targetExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E>): E & ThisType<InstanceType<C> & E>;
|
|
33
|
+
/**
|
|
34
|
+
* 创建用于扩展目标的便捷函数
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* 它返回的便利函数的功能与 {@link targetExtend} 的功能一样,唯一区别是不再需要接收 cla 参数了
|
|
38
|
+
*
|
|
39
|
+
* @param cla - 扩展的目标,也用作 this 的类型
|
|
40
|
+
* @returns 可以用于 扩展目标 的便利函数
|
|
41
|
+
*/
|
|
42
|
+
export declare function createTargetExtend<C extends ClassType>(cla: C): <E>(ext: E & ThisType<InstanceType<C> & E>) => E & ThisType<C & E>;
|
|
43
|
+
/**
|
|
44
|
+
* 扩展目标
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* 会执行对 CEarth 类的扩展操作。
|
|
48
|
+
* 与 {@link targetExtend} 的区别仅仅是返回类型不一样。
|
|
49
|
+
*
|
|
50
|
+
* @param cla - 扩展的目标,也用作 this 的类型
|
|
51
|
+
* @param ext - 扩展对象,会自动更改其this的类型
|
|
52
|
+
* @returns 返回扩展后的 cla 对象
|
|
53
|
+
*/
|
|
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>>;
|
|
55
|
+
/**
|
|
56
|
+
* 创建用于扩展目标工具函数
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* 它返回的便利函数的功能与 {@link extendTarget} 的功能一样,唯一区别是不再需要接收 cla 参数了
|
|
60
|
+
*
|
|
61
|
+
* @param cla - 扩展的目标,也用作 this 的类型
|
|
62
|
+
* @returns 可以用于 扩展目标 的便利函数
|
|
63
|
+
*/
|
|
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>>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判断 code 是否是有校的 js 标识符
|
|
3
|
+
* @param code - 标识符的字符串
|
|
4
|
+
*/
|
|
5
|
+
export declare function isIdentifier(code: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* 判断函数是否是箭头函数
|
|
8
|
+
* @param fun - 被判断的函数
|
|
9
|
+
*/
|
|
10
|
+
export declare function isArrowFunction(fun: Function): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* 判断函数是否是 async 异步函数
|
|
13
|
+
* @remarks
|
|
14
|
+
* 异步函数 不包含 异步生成器函数 AsyncGeneratorFunction
|
|
15
|
+
* @param fun - 被判断的函数
|
|
16
|
+
*/
|
|
17
|
+
export declare function isAsyncFunction(fun: Function): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* 判断函数是否是生成器函数
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* 生成器函数 不包含 异步生成器函数 AsyncGeneratorFunction
|
|
23
|
+
* @param fun - 被判断的函数
|
|
24
|
+
*/
|
|
25
|
+
export declare function isGeneratorFunction(fun: Function): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* 判断函数是否是异步生成器函数
|
|
28
|
+
* @param fun - 被判断的函数
|
|
29
|
+
*/
|
|
30
|
+
export declare function isAsyncGeneratorFunction(fun: Function): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 判断是否是匿名函数
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* 判断函数在被定义时是否是通过匿名函数来定义的。
|
|
36
|
+
* 匿名函数是指声明函数时没有写名字的函数。
|
|
37
|
+
* 注意:即使是匿名函数,函数对象上的 name 属性也可能是有值的,因为 js解析器 会自动将 函数表达式函数变量的名字作为匿名函数的名字,如下:
|
|
38
|
+
* ```ts
|
|
39
|
+
* var funName = function(){};
|
|
40
|
+
* ```
|
|
41
|
+
* 其中的匿名函数对象的 name 属性的值会是 `funName`
|
|
42
|
+
*
|
|
43
|
+
* 如果 函数对象上的 name 属性的值为 `""`,函数一定是匿名函数。
|
|
44
|
+
*/
|
|
45
|
+
export declare function isAnonymousFunction(fun: Function): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* 表示任意的函数类型
|
|
48
|
+
*/
|
|
49
|
+
export declare type AnyFunction = (...args: any) => any;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,150 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* 即:通过 Object.create(null) 创建的对象是不被 instanceof 认为是继续于 Object 的
|
|
7
|
-
*
|
|
8
|
-
* typeof null 也返回 "object"
|
|
9
|
-
*/
|
|
10
|
-
export declare function isObject(target: any): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* typeof 的返回类型
|
|
13
|
-
*/
|
|
14
|
-
export declare type TypeOfReturnType = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
|
15
|
-
/**
|
|
16
|
-
* 宽松的类型
|
|
17
|
-
*/
|
|
18
|
-
export declare type LooseType = undefined | null | Function | "object";
|
|
19
|
-
/**
|
|
20
|
-
* 宽松类型的字符串表示
|
|
21
|
-
*/
|
|
22
|
-
export declare type LooseTypeName = "undefined" | "null" | "Function" | "object" | string;
|
|
23
|
-
/**
|
|
24
|
-
* 精确类型
|
|
25
|
-
*
|
|
26
|
-
* 在精准类型中认为 JavaScript 的原始类型(非对象类型) 与 其对应的 包装类型(类类型)是不同的类型,即:
|
|
27
|
-
* number 和 Number、string 和 String、boolean 和 Boolean 等 是不同的类型;
|
|
28
|
-
* 对于原始类型,返回的结果 会与 typeof 返回的结果一样;
|
|
29
|
-
* 但,对于 undefined 和 null 会返回其自身值(即 undefined 和 null)作为类型值
|
|
30
|
-
*
|
|
31
|
-
* 各种类型的值 与 该方法的返回值 的映射如下:
|
|
32
|
-
* undefined :undefined
|
|
33
|
-
* null : null
|
|
34
|
-
* string : "string"
|
|
35
|
-
* number : "number"
|
|
36
|
-
* bigint : "bigint"
|
|
37
|
-
* boolean : "boolean"
|
|
38
|
-
* symbol : "symbol"
|
|
39
|
-
* function : Function
|
|
40
|
-
* 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
|
|
41
|
-
* 其它任何类型的实例 : 返回该实例的构造函数
|
|
42
|
-
*/
|
|
43
|
-
export declare type ExactType = LooseType | Exclude<TypeOfReturnType, "undefined" | "function" | "object">;
|
|
44
|
-
/**
|
|
45
|
-
* 精确类型的字符串表示
|
|
46
|
-
*
|
|
47
|
-
* 在精准类型中认为 JavaScript 的原始类型(非对象类型) 与 其对应的 包装类型(类类型)是不同的类型,即:
|
|
48
|
-
* number 和 Number、string 和 String、boolean 和 Boolean 等 是不同的类型;
|
|
49
|
-
* 对于原始类型,返回的结果 会与 typeof 返回的结果一样;
|
|
50
|
-
* 但,对于 null 会返回 "null"
|
|
51
|
-
*
|
|
52
|
-
* 各种类型的值 与 该方法的返回值 的映射如下:
|
|
53
|
-
* undefined :"undefined"
|
|
54
|
-
* null : "null"
|
|
55
|
-
* function : "Function"
|
|
56
|
-
* string : "string"
|
|
57
|
-
* number : "number"
|
|
58
|
-
* bigint : "bigint"
|
|
59
|
-
* boolean : "boolean"
|
|
60
|
-
* symbol : "symbol"
|
|
61
|
-
* 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
|
|
62
|
-
* 其它任何类型的实例 : 返回该实例的构造函数的名字
|
|
63
|
-
*/
|
|
64
|
-
export declare type ExactTypeName = LooseTypeName | Exclude<TypeOfReturnType, "undefined" | "function" | "object">;
|
|
65
|
-
/**
|
|
66
|
-
* 获取 inst 的宽松类型
|
|
67
|
-
* @param inst : any
|
|
68
|
-
* @returns LooseType inst 的类型
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* 注意:
|
|
73
|
-
* 本方法返回的结果如下:
|
|
74
|
-
* undefined :undefined
|
|
75
|
-
* null : null
|
|
76
|
-
* function : Function
|
|
77
|
-
* 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
|
|
78
|
-
* 其它任何类型的实例 : 返回该实例的构造函数 或 包装对象的构造函数
|
|
79
|
-
*
|
|
80
|
-
*/
|
|
81
|
-
export declare function getTypeOf(inst: any): LooseType;
|
|
82
|
-
/**
|
|
83
|
-
* 获取 类型的字符串表示
|
|
84
|
-
* @param t
|
|
85
|
-
* @return ExactTypeName
|
|
86
|
-
*/
|
|
87
|
-
export declare function getNameOfType(t: ExactType): ExactTypeName;
|
|
88
|
-
/**
|
|
89
|
-
* 根据类型的名字获取类型
|
|
90
|
-
* @param typeName
|
|
91
|
-
*/
|
|
92
|
-
export declare function getTypeByName(typeName: string): Function | undefined;
|
|
93
|
-
/**
|
|
94
|
-
* 获取 inst 的类型字符串
|
|
95
|
-
* @param inst : any
|
|
96
|
-
* @returns string inst 的类型字符串
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* 注意:
|
|
101
|
-
* 本方法返回的结果如下:
|
|
102
|
-
* undefined :"undefined"
|
|
103
|
-
* null : "null"
|
|
104
|
-
* 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
|
|
105
|
-
* 其它任何类型的实例 : 返回该实例的构造函数 或 包装对象的构造函数 的函数名字
|
|
106
|
-
*
|
|
107
|
-
*/
|
|
108
|
-
export declare function getTypeNameOf(inst: any): LooseTypeName;
|
|
109
|
-
/**
|
|
110
|
-
* 获取 inst 的精确类型
|
|
111
|
-
* @param inst : any
|
|
112
|
-
* @returns ExactType inst 的类型
|
|
113
|
-
*/
|
|
114
|
-
export declare function getExactTypeOf(inst: any): ExactType;
|
|
115
|
-
/**
|
|
116
|
-
* 获取 inst 的精确类型的字符串表示
|
|
117
|
-
* @param inst : any
|
|
118
|
-
* @returns ExactTypeName inst 的类型字符串
|
|
119
|
-
*/
|
|
120
|
-
export declare function getExactTypeNameOf(inst: any): ExactTypeName;
|
|
121
|
-
/**
|
|
122
|
-
* 判断 data 是否是 基本类型
|
|
123
|
-
* @param data
|
|
124
|
-
*
|
|
125
|
-
* 基本类型 是指 那些不是 对象类型的类型,即,除了 object 和 function 类型以外,其它的都是基本类型,null 也算怎是 基本类型
|
|
126
|
-
*/
|
|
127
|
-
export declare function isBaseType(data: any): boolean;
|
|
128
|
-
/**
|
|
129
|
-
* isArrayLike(target)
|
|
130
|
-
* 判断 target 是否为 类数组对象
|
|
131
|
-
* @param target : any 目标
|
|
132
|
-
* @returns boolean
|
|
133
|
-
*/
|
|
134
|
-
export declare function isArrayLike(target: any): boolean;
|
|
135
|
-
/**
|
|
136
|
-
* 判断 目标 是否是可迭代的对象,即 实现了 可迭代协议
|
|
137
|
-
* @param target : any
|
|
138
|
-
* @return {boolean}
|
|
139
|
-
*/
|
|
140
|
-
export declare function isIterable(target: any): boolean;
|
|
141
|
-
/**
|
|
142
|
-
* 判断 目标 是否是迭代器,即 实现了 迭代器协议
|
|
143
|
-
* @param target : any
|
|
144
|
-
* @return {boolean}
|
|
145
|
-
*/
|
|
146
|
-
export declare function isIterator(target: any): boolean;
|
|
147
|
-
/**
|
|
148
|
-
* 可选的布尔类型
|
|
149
|
-
*/
|
|
150
|
-
export declare type OptionalBoolean = boolean | null | undefined;
|
|
1
|
+
export * from './base';
|
|
2
|
+
export * from './mixin';
|
|
3
|
+
export * from './extend';
|
|
4
|
+
export * from './function';
|
|
5
|
+
export * from './member';
|
package/dist/member.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AnyFunction } from "./function";
|
|
2
|
+
/**
|
|
3
|
+
* 获取对象的方法的某个参数的类型
|
|
4
|
+
*
|
|
5
|
+
* @typeParam Obj - 对象
|
|
6
|
+
* @typeParam Method - 对象方法的名字
|
|
7
|
+
* @typeParam ParamIndex - 参数的索引个数
|
|
8
|
+
*/
|
|
9
|
+
export declare type MethodParams<Obj, Method extends keyof Obj, ParamIndex extends number> = Obj[Method] extends AnyFunction ? Parameters<Obj[Method]>[ParamIndex] : never;
|
|
10
|
+
/**
|
|
11
|
+
* 获取对象的方法的返回的类型
|
|
12
|
+
*
|
|
13
|
+
* @typeParam Obj - 对象
|
|
14
|
+
* @typeParam Method - 对象方法的名字
|
|
15
|
+
*/
|
|
16
|
+
export declare type MethodReturnType<Obj, Method extends keyof Obj> = Obj[Method] extends AnyFunction ? ReturnType<Obj[Method]> : never;
|
package/dist/mixin.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 混合
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare function mixin<T, S>(target: T, source: S): T & S;
|
|
6
|
+
/**
|
|
7
|
+
* 混合
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare function mixin<T, S1, S2>(target: T, source1: S1, source2: S2): T & S1 & S2;
|
|
11
|
+
/**
|
|
12
|
+
* 混合
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export declare function mixin<T, S1, S2, S3>(target: T, source1: S1, source2: S2, source3: S3): T & S1 & S2 & S3;
|
|
16
|
+
/**
|
|
17
|
+
* 混合
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function mixin<T, S1, S2, S3, S4>(target: T, source1: S1, source2: S2, source3: S3, source4: S3): T & S1 & S2 & S3 & S4;
|
|
21
|
+
/**
|
|
22
|
+
* 混合
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* 将 source 的所有成员混入 target 对象中。
|
|
26
|
+
*
|
|
27
|
+
* 与 `Object.assign()` 的功能类似,不同的是 `mixin()` 会在 target 对象中 保持 source 对象属性的 PropertyDescriptors
|
|
28
|
+
*
|
|
29
|
+
* @param target - 目标对象,所有 源对象 的属性都要被混入进到 目标对象中
|
|
30
|
+
* @param sources - 源对象,所有 源对象 的属性都要被混入进到 目标对象中
|
|
31
|
+
* @returns 混入后的 target
|
|
32
|
+
*/
|
|
33
|
+
export declare function mixin(target: any, ...sources: any[]): any;
|
|
34
|
+
/**
|
|
35
|
+
* 定义混合的类型便利函数
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* 它会更改 mixin 中方法的this指向为 target & mixin,不会真的执行混合操作
|
|
39
|
+
*
|
|
40
|
+
* @param target - 混合的目标,用作 this 的类型
|
|
41
|
+
* @param mixin - 混合对象,会自动更改其this的类型
|
|
42
|
+
* @returns 返回注入了 this 类型的 mixin 对象本身
|
|
43
|
+
*/
|
|
44
|
+
export declare function defineMixin<T, M>(target: T, mixin: M & ThisType<T & M>): M & ThisType<T & M>;
|
|
45
|
+
/**
|
|
46
|
+
* 创建定义混合的类型便利函数
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* 它返回的便利函数的功能与 {@link defineMixin} 的功能一样,唯一区别是不再需要接收 target 参数了
|
|
50
|
+
*
|
|
51
|
+
* @returns 可以用于 定义混合的 类型便利函数
|
|
52
|
+
*/
|
|
53
|
+
export declare function createDefineMixin<T>(): <M>(target: T, mixin: M & ThisType<T & M>) => M & ThisType<T & M>;
|
|
54
|
+
/**
|
|
55
|
+
* 混合目标
|
|
56
|
+
*
|
|
57
|
+
* @remarks
|
|
58
|
+
* 与 {@link defineMixin} 的区别是:`targetMixin` 会执行对 target 的混合操作,而 {@link defineMixin} 不会
|
|
59
|
+
*
|
|
60
|
+
*
|
|
61
|
+
* @param target - 混合的目标,用作 this 的类型
|
|
62
|
+
* @param m - 混合对象,会自动更改其this的类型
|
|
63
|
+
* @returns 返回注入了 this 类型的 mixin 对象本身
|
|
64
|
+
*/
|
|
65
|
+
export declare function targetMixin<T, M>(target: T, m: M & ThisType<T & M>): M & ThisType<T & M>;
|
|
66
|
+
/**
|
|
67
|
+
* 创建用于混合目标的便捷函数
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* 它返回的便利函数的功能与 {@link targetMixin} 的功能一样,唯一区别是不再需要接收 target 参数了
|
|
71
|
+
*
|
|
72
|
+
* @param target - 混合的目标,用作 this 的类型
|
|
73
|
+
* @returns 可以用于 混合目标 的便利函数
|
|
74
|
+
*/
|
|
75
|
+
export declare function createTargetMixin<T>(target: T): <M>(m: M & ThisType<T & M>) => M & ThisType<T & M>;
|
|
76
|
+
/**
|
|
77
|
+
* 混合目标
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* 会执行对 CEarth 类的扩展操作。
|
|
81
|
+
* 与 {@link targetMixin} 的区别仅仅是返回类型不一样。
|
|
82
|
+
*
|
|
83
|
+
* @param target - 混合的目标,用作 this 的类型
|
|
84
|
+
* @param m - 混合对象,会自动更改其this的类型
|
|
85
|
+
* @returns 返回混合后的 target 对象
|
|
86
|
+
*/
|
|
87
|
+
export declare function mixinTarget<T, M>(target: T, m: M & ThisType<T & M>): M & ThisType<T & M> & T;
|
|
88
|
+
/**
|
|
89
|
+
* 创建用于混合目标工具函数
|
|
90
|
+
*
|
|
91
|
+
* @remarks
|
|
92
|
+
* 它返回的便利函数的功能与 {@link mixinTarget} 的功能一样,唯一区别是不再需要接收 target 参数了
|
|
93
|
+
*
|
|
94
|
+
* @returns 可以用于 混合目标 的便利函数
|
|
95
|
+
*/
|
|
96
|
+
export declare function createMixinTarget<T>(target: T): <M>(m: M & ThisType<T & M>) => M & ThisType<T & M> & T;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.28.5"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|