type-tls 2.7.0 → 3.0.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 -21
- package/README.md +86 -86
- package/dist/async.d.ts +28 -0
- package/dist/base.d.ts +261 -0
- package/dist/buffer.d.ts +1 -0
- package/dist/function.d.ts +49 -0
- package/dist/index.d.ts +5 -630
- package/dist/member.d.ts +21 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/type-tls.d.ts +14 -317
- package/dist/type-tls.iife.js +1 -1
- package/dist/type-tls.js +108 -0
- package/dist/type-tls.umd.cjs +1 -0
- package/doc/api/type-tls.anyfunction.md +2 -2
- package/doc/api/type-tls.arrayitemtype.md +2 -2
- package/doc/api/type-tls.exacttype.md +3 -3
- package/doc/api/type-tls.exacttypename.md +3 -3
- package/doc/api/type-tls.getexacttypenameof.md +2 -2
- package/doc/api/type-tls.getexacttypeof.md +2 -2
- package/doc/api/type-tls.getnameoftype.md +2 -2
- package/doc/api/type-tls.gettypebyname.md +2 -2
- package/doc/api/type-tls.gettypenameof.md +2 -2
- package/doc/api/type-tls.gettypeof.md +2 -2
- package/doc/api/type-tls.isanonymousfunction.md +2 -2
- package/doc/api/type-tls.isarraylike.md +2 -2
- package/doc/api/type-tls.isarrowfunction.md +2 -2
- package/doc/api/type-tls.isasyncfunction.md +2 -2
- package/doc/api/type-tls.isasyncgeneratorfunction.md +2 -2
- package/doc/api/type-tls.isbasetype.md +2 -2
- package/doc/api/type-tls.isgeneratorfunction.md +2 -2
- package/doc/api/type-tls.isidentifier.md +2 -2
- package/doc/api/type-tls.isiterable.md +2 -2
- package/doc/api/type-tls.isiterator.md +2 -2
- package/doc/api/type-tls.isobject.md +2 -2
- package/doc/api/type-tls.keyofcontainsvalue.md +3 -3
- package/doc/api/type-tls.keyofnoncontainsvalue.md +3 -3
- package/doc/api/type-tls.keyofnonvalue.md +3 -3
- package/doc/api/type-tls.keyofvalue.md +3 -3
- package/doc/api/type-tls.loosetype.md +2 -2
- package/doc/api/type-tls.loosetypename.md +2 -2
- package/doc/api/type-tls.md +2 -39
- package/doc/api/type-tls.methodparams.md +3 -3
- package/doc/api/type-tls.methodreturntype.md +3 -3
- package/doc/api/type-tls.optional.md +2 -2
- package/doc/api/type-tls.optionalboolean.md +3 -3
- package/doc/api/type-tls.pickcontainsvalue.md +4 -4
- package/doc/api/type-tls.pickmethod.md +3 -3
- package/doc/api/type-tls.picknoncontainsvalue.md +4 -4
- package/doc/api/type-tls.picknonvalue.md +4 -4
- package/doc/api/type-tls.pickproperty.md +3 -3
- package/doc/api/type-tls.pickvalue.md +4 -4
- package/doc/api/type-tls.replace.md +2 -2
- package/doc/api/type-tls.replacenull.md +3 -3
- package/doc/api/type-tls.replaceundefined.md +3 -3
- package/doc/api/type-tls.replacevoid.md +3 -3
- package/doc/api/type-tls.resolvedata.md +2 -2
- package/doc/api/type-tls.twolayerpartial.md +20 -0
- package/doc/api/type-tls.typedarray.md +11 -0
- package/doc/api/type-tls.typeofreturntype.md +2 -2
- package/doc/api/type-tls.waitasyncable.md +2 -2
- package/doc/api/type-tls.waitasyncablecallback.md +3 -3
- package/doc/api/type-tls.waitasyncablereturn.md +2 -2
- package/doc//346/225/231/347/250/213.md +6 -6
- package/package.json +20 -11
- package/dist/type-tls.mjs +0 -214
- package/dist/type-tls.umd.js +0 -1
- package/doc/api/type-tls.axis.getcrossaxiss.md +0 -32
- package/doc/api/type-tls.axis.md +0 -22
- package/doc/api/type-tls.axis.toindex.md +0 -25
- package/doc/api/type-tls.axis.tokey.md +0 -25
- package/doc/api/type-tls.axis4.getcrossaxiss.md +0 -32
- package/doc/api/type-tls.axis4.md +0 -22
- package/doc/api/type-tls.axis4.toindex.md +0 -25
- package/doc/api/type-tls.axis4.tokey.md +0 -25
- package/doc/api/type-tls.axis4name.md +0 -13
- package/doc/api/type-tls.axisname.md +0 -13
- package/doc/api/type-tls.classtype._new_.md +0 -22
- package/doc/api/type-tls.classtype.md +0 -20
- package/doc/api/type-tls.createdefinemixin.md +0 -23
- package/doc/api/type-tls.createextendtarget.md +0 -30
- package/doc/api/type-tls.createmixintarget.md +0 -30
- package/doc/api/type-tls.createtargetextend.md +0 -30
- package/doc/api/type-tls.createtargetmixin.md +0 -30
- package/doc/api/type-tls.defineextend.md +0 -35
- package/doc/api/type-tls.definemixin.md +0 -31
- package/doc/api/type-tls.extendtarget.md +0 -31
- package/doc/api/type-tls.ivector.md +0 -15
- package/doc/api/type-tls.ivector2.md +0 -21
- package/doc/api/type-tls.ivector2.x.md +0 -11
- package/doc/api/type-tls.ivector2.y.md +0 -11
- package/doc/api/type-tls.ivector3.md +0 -21
- package/doc/api/type-tls.ivector3.z.md +0 -11
- package/doc/api/type-tls.ivector4.md +0 -21
- package/doc/api/type-tls.ivector4.w.md +0 -11
- package/doc/api/type-tls.mixin_4.md +0 -33
- package/doc/api/type-tls.mixintarget.md +0 -31
- package/doc/api/type-tls.privatememberofextend._constructor.md +0 -22
- package/doc/api/type-tls.privatememberofextend.md +0 -20
- package/doc/api/type-tls.targetextend.md +0 -31
- package/doc/api/type-tls.targetmixin.md +0 -31
package/LICENSE
CHANGED
|
@@ -1,21 +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.
|
|
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
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
[教程]: ./doc/教程.md
|
|
2
|
-
[API接口文档]: ./doc/api/index.md
|
|
3
|
-
|
|
4
|
-
[GitHub仓库]: https://github.com/GuoBinyong/type-tls
|
|
5
|
-
[发行地址]: https://github.com/GuoBinyong/type-tls/releases
|
|
6
|
-
[issues]: https://github.com/GuoBinyong/type-tls/issues
|
|
7
|
-
|
|
8
|
-
[码云仓库]: https://gitee.com/guobinyong/type-tls
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
> 目录
|
|
13
|
-
|
|
14
|
-
- [1. 简介](#1-简介)
|
|
15
|
-
- [2. 安装方式](#2-安装方式)
|
|
16
|
-
- [2.1. 方式1:通过 npm 安装](#21-方式1通过-npm-安装)
|
|
17
|
-
- [2.2. 方式3:通过`<script>`标签引入](#22-方式3通过script标签引入)
|
|
18
|
-
- [3. 教程](#3-教程)
|
|
19
|
-
- [4. API接口文档](#4-api接口文档)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
# 1. 简介
|
|
25
|
-
在使用 TypeScript 封装库时,如果希望设计更智能的 TypeScript 类型推导,则往往需要大量的类型相关的操作,type-tls 就提供了常用的类型操作的工具,比如:获取数据的类型 或 类型名字、判断数据的类型、还有一些 Type 工具。
|
|
26
|
-
|
|
27
|
-
**详情请看:**
|
|
28
|
-
- 主页:<https://github.com/GuoBinyong/type-tls>
|
|
29
|
-
- [GitHub仓库][]
|
|
30
|
-
- [码云仓库][]
|
|
31
|
-
- [教程][]
|
|
32
|
-
- [API接口文档][]
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
**如果您在使用的过程中遇到了问题,或者有好的建议和想法,您都可以通过以下方式联系我,期待与您的交流:**
|
|
36
|
-
- 给该仓库提交 [issues][]
|
|
37
|
-
- 给我 Pull requests
|
|
38
|
-
- 邮箱:<guobinyong@qq.com>
|
|
39
|
-
- QQ:guobinyong@qq.com
|
|
40
|
-
- 微信:keyanzhe
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
# 2. 安装方式
|
|
47
|
-
目前,安装方式有以下几种:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
## 2.1. 方式1:通过 npm 安装
|
|
51
|
-
通过 npm (或 yarn、pnpm 等包管理器)安装
|
|
52
|
-
```
|
|
53
|
-
npm install type-tls
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
## 2.2. 方式3:通过`<script>`标签引入
|
|
60
|
-
您可直接从项目的 [发行地址][] 中下载以 `.iife.js` 作为缀的文件,然后使用如下代码引用 和 使用 type-tls:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
1. 引用 type-tls
|
|
64
|
-
```
|
|
65
|
-
<script src="path/to/package/type-tls.iife.js"></script>
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
2. 使用全局的 `TypeTls`
|
|
69
|
-
```
|
|
70
|
-
<script>
|
|
71
|
-
// 使用全局的 TypeTls
|
|
72
|
-
</script>
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
# 3. 教程
|
|
76
|
-
详情跳转至[教程][]
|
|
77
|
-
|
|
78
|
-
# 4. API接口文档
|
|
79
|
-
详情跳转至[API接口文档][]
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
--------------------
|
|
84
|
-
|
|
85
|
-
> 有您的支持,我会在开源的道路上,越走越远
|
|
86
|
-
|
|
1
|
+
[教程]: ./doc/教程.md
|
|
2
|
+
[API接口文档]: ./doc/api/index.md
|
|
3
|
+
|
|
4
|
+
[GitHub仓库]: https://github.com/GuoBinyong/type-tls
|
|
5
|
+
[发行地址]: https://github.com/GuoBinyong/type-tls/releases
|
|
6
|
+
[issues]: https://github.com/GuoBinyong/type-tls/issues
|
|
7
|
+
|
|
8
|
+
[码云仓库]: https://gitee.com/guobinyong/type-tls
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
> 目录
|
|
13
|
+
|
|
14
|
+
- [1. 简介](#1-简介)
|
|
15
|
+
- [2. 安装方式](#2-安装方式)
|
|
16
|
+
- [2.1. 方式1:通过 npm 安装](#21-方式1通过-npm-安装)
|
|
17
|
+
- [2.2. 方式3:通过`<script>`标签引入](#22-方式3通过script标签引入)
|
|
18
|
+
- [3. 教程](#3-教程)
|
|
19
|
+
- [4. API接口文档](#4-api接口文档)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# 1. 简介
|
|
25
|
+
在使用 TypeScript 封装库时,如果希望设计更智能的 TypeScript 类型推导,则往往需要大量的类型相关的操作,type-tls 就提供了常用的类型操作的工具,比如:获取数据的类型 或 类型名字、判断数据的类型、还有一些 Type 工具。
|
|
26
|
+
|
|
27
|
+
**详情请看:**
|
|
28
|
+
- 主页:<https://github.com/GuoBinyong/type-tls>
|
|
29
|
+
- [GitHub仓库][]
|
|
30
|
+
- [码云仓库][]
|
|
31
|
+
- [教程][]
|
|
32
|
+
- [API接口文档][]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
**如果您在使用的过程中遇到了问题,或者有好的建议和想法,您都可以通过以下方式联系我,期待与您的交流:**
|
|
36
|
+
- 给该仓库提交 [issues][]
|
|
37
|
+
- 给我 Pull requests
|
|
38
|
+
- 邮箱:<guobinyong@qq.com>
|
|
39
|
+
- QQ:guobinyong@qq.com
|
|
40
|
+
- 微信:keyanzhe
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# 2. 安装方式
|
|
47
|
+
目前,安装方式有以下几种:
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## 2.1. 方式1:通过 npm 安装
|
|
51
|
+
通过 npm (或 yarn、pnpm 等包管理器)安装
|
|
52
|
+
```
|
|
53
|
+
npm install type-tls
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## 2.2. 方式3:通过`<script>`标签引入
|
|
60
|
+
您可直接从项目的 [发行地址][] 中下载以 `.iife.js` 作为缀的文件,然后使用如下代码引用 和 使用 type-tls:
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
1. 引用 type-tls
|
|
64
|
+
```
|
|
65
|
+
<script src="path/to/package/type-tls.iife.js"></script>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
2. 使用全局的 `TypeTls`
|
|
69
|
+
```
|
|
70
|
+
<script>
|
|
71
|
+
// 使用全局的 TypeTls
|
|
72
|
+
</script>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
# 3. 教程
|
|
76
|
+
详情跳转至[教程][]
|
|
77
|
+
|
|
78
|
+
# 4. API接口文档
|
|
79
|
+
详情跳转至[API接口文档][]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
--------------------
|
|
84
|
+
|
|
85
|
+
> 有您的支持,我会在开源的道路上,越走越远
|
|
86
|
+
|
|
87
87
|

|
package/dist/async.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取 Promise 解决的类型的值
|
|
3
|
+
* @remarks
|
|
4
|
+
* 对于非 Promise 类型的值,返回原类型本身
|
|
5
|
+
*/
|
|
6
|
+
export type ResolveData<P> = P extends Promise<infer D> ? D : P;
|
|
7
|
+
/**
|
|
8
|
+
* waitAsyncable 的返回值的类型
|
|
9
|
+
*/
|
|
10
|
+
export 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 type WaitAsyncableCallback<Result, Return> = (result: ResolveData<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>;
|
package/dist/base.d.ts
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 处理类型相关的工具
|
|
3
|
+
* @remarks
|
|
4
|
+
* type-tls 封装了与类型相关的工具,比如获取数据的类型 或 类型名字、判断数据的类型 等
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
import { AnyFunction } from "./function";
|
|
9
|
+
/**
|
|
10
|
+
* 判断目标是否是对象类型
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* 仅通过 target instanceof Object 判断是不行的,因为 对于 Object.create(null) 创建的对象 通过 ` Object.create(null) instanceof Object ` 来判断 返回的是 false
|
|
14
|
+
* 即:通过 Object.create(null) 创建的对象是不被 instanceof 认为是继续于 Object 的
|
|
15
|
+
*
|
|
16
|
+
* typeof null 也返回 "object"
|
|
17
|
+
*
|
|
18
|
+
* @param target : any 目标对象
|
|
19
|
+
*/
|
|
20
|
+
export declare function isObject(target: any): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* typeof 的返回类型
|
|
23
|
+
*/
|
|
24
|
+
export type TypeOfReturnType = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
|
25
|
+
/**
|
|
26
|
+
* 宽松的类型
|
|
27
|
+
*/
|
|
28
|
+
export type LooseType = undefined | null | Function | "object";
|
|
29
|
+
/**
|
|
30
|
+
* 宽松类型的字符串表示
|
|
31
|
+
*/
|
|
32
|
+
export type LooseTypeName = "undefined" | "null" | "Function" | "object" | string;
|
|
33
|
+
/**
|
|
34
|
+
* 精确类型
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* 在精准类型中认为 JavaScript 的原始类型(非对象类型) 与 其对应的 包装类型(类类型)是不同的类型,即:
|
|
38
|
+
* number 和 Number、string 和 String、boolean 和 Boolean 等 是不同的类型;
|
|
39
|
+
* 对于原始类型,返回的结果 会与 typeof 返回的结果一样;
|
|
40
|
+
* 但,对于 undefined 和 null 会返回其自身值(即 undefined 和 null)作为类型值
|
|
41
|
+
*
|
|
42
|
+
* 各种类型的值 与 该方法的返回值 的映射如下:
|
|
43
|
+
* ```
|
|
44
|
+
* undefined :undefined
|
|
45
|
+
* null : null
|
|
46
|
+
* string : "string"
|
|
47
|
+
* number : "number"
|
|
48
|
+
* bigint : "bigint"
|
|
49
|
+
* boolean : "boolean"
|
|
50
|
+
* symbol : "symbol"
|
|
51
|
+
* function : Function
|
|
52
|
+
* 没有原型的对象(如:通过 `Object.create(null)` 创建的对象) : "object"
|
|
53
|
+
* 其它任何类型的实例 : 返回该实例的构造函数
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export type ExactType = LooseType | Exclude<TypeOfReturnType, "undefined" | "function" | "object">;
|
|
57
|
+
/**
|
|
58
|
+
* 精确类型的字符串表示
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* 在精准类型中认为 JavaScript 的原始类型(非对象类型) 与 其对应的 包装类型(类类型)是不同的类型,即:
|
|
62
|
+
* number 和 Number、string 和 String、boolean 和 Boolean 等 是不同的类型;
|
|
63
|
+
* 对于原始类型,返回的结果 会与 typeof 返回的结果一样;
|
|
64
|
+
* 但,对于 null 会返回 "null"
|
|
65
|
+
*
|
|
66
|
+
* 各种类型的值 与 该方法的返回值 的映射如下:
|
|
67
|
+
* ```
|
|
68
|
+
* undefined :"undefined"
|
|
69
|
+
* null : "null"
|
|
70
|
+
* function : "Function"
|
|
71
|
+
* string : "string"
|
|
72
|
+
* number : "number"
|
|
73
|
+
* bigint : "bigint"
|
|
74
|
+
* boolean : "boolean"
|
|
75
|
+
* symbol : "symbol"
|
|
76
|
+
* 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
|
|
77
|
+
* 其它任何类型的实例 : 返回该实例的构造函数的名字
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export type ExactTypeName = LooseTypeName | Exclude<TypeOfReturnType, "undefined" | "function" | "object">;
|
|
81
|
+
/**
|
|
82
|
+
* 获取 inst 的宽松类型
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* 注意:
|
|
86
|
+
* 本方法返回的结果如下:
|
|
87
|
+
* ```
|
|
88
|
+
* undefined :undefined
|
|
89
|
+
* null : null
|
|
90
|
+
* function : Function
|
|
91
|
+
* 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
|
|
92
|
+
* 其它任何类型的实例 : 返回该实例的构造函数 或 包装对象的构造函数
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
*
|
|
96
|
+
* @param inst
|
|
97
|
+
* @returns inst 的类型
|
|
98
|
+
*/
|
|
99
|
+
export declare function getTypeOf(inst: any): LooseType;
|
|
100
|
+
/**
|
|
101
|
+
* 获取 类型的字符串表示
|
|
102
|
+
*
|
|
103
|
+
* @param t - 一个 ExactType 类型的值
|
|
104
|
+
* @return t 的字符串表示的类型
|
|
105
|
+
*/
|
|
106
|
+
export declare function getNameOfType(t: ExactType): ExactTypeName;
|
|
107
|
+
/**
|
|
108
|
+
* 根据类型的名字获取其对应的类
|
|
109
|
+
* @param typeName - 类型的名字
|
|
110
|
+
*/
|
|
111
|
+
export declare function getTypeByName(typeName: string): Function | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* 获取 inst 的类型字符串
|
|
114
|
+
*
|
|
115
|
+
* @remarks
|
|
116
|
+
* 注意:
|
|
117
|
+
* 本方法返回的结果如下:
|
|
118
|
+
* undefined :"undefined"
|
|
119
|
+
* null : "null"
|
|
120
|
+
* 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
|
|
121
|
+
* 其它任何类型的实例 : 返回该实例的构造函数 或 包装对象的构造函数 的函数名字
|
|
122
|
+
*
|
|
123
|
+
* @param inst
|
|
124
|
+
* @returns inst 的类型字符串
|
|
125
|
+
*/
|
|
126
|
+
export declare function getTypeNameOf(inst: any): LooseTypeName;
|
|
127
|
+
/**
|
|
128
|
+
* 获取 inst 的精确类型
|
|
129
|
+
* @param inst
|
|
130
|
+
* @returns inst 的类型
|
|
131
|
+
*/
|
|
132
|
+
export declare function getExactTypeOf(inst: any): ExactType;
|
|
133
|
+
/**
|
|
134
|
+
* 获取 inst 的精确类型的字符串表示
|
|
135
|
+
* @param inst
|
|
136
|
+
* @returns inst 的类型字符串
|
|
137
|
+
*/
|
|
138
|
+
export declare function getExactTypeNameOf(inst: any): ExactTypeName;
|
|
139
|
+
/**
|
|
140
|
+
* 判断 data 是否是 基本类型
|
|
141
|
+
* @remarks
|
|
142
|
+
* 基本类型 是指 那些不是 对象类型的类型,即,除了 object 和 function 类型以外,其它的都是基本类型,null 也算怎是 基本类型
|
|
143
|
+
* @param data - 任意类型的值
|
|
144
|
+
*/
|
|
145
|
+
export declare function isBaseType(data: any): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* 判断 target 是否为 类数组对象
|
|
148
|
+
* @param target - 目标
|
|
149
|
+
* @returns
|
|
150
|
+
*/
|
|
151
|
+
export declare function isArrayLike(target: any): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* 判断 目标 是否是可迭代的对象,即 实现了 可迭代协议
|
|
154
|
+
* @param target - 目标
|
|
155
|
+
*/
|
|
156
|
+
export declare function isIterable(target: any): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* 判断 目标 是否是迭代器,即 实现了 迭代器协议
|
|
159
|
+
* @param target - 目标
|
|
160
|
+
*/
|
|
161
|
+
export declare function isIterator(target: any): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* 将某个类型变为可选的类型
|
|
164
|
+
*/
|
|
165
|
+
export type Optional<T> = T | null | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* 可选的布尔类型
|
|
168
|
+
*/
|
|
169
|
+
export type OptionalBoolean = Optional<boolean>;
|
|
170
|
+
/**
|
|
171
|
+
* 获取值类型为指定类型的所有 key
|
|
172
|
+
*
|
|
173
|
+
* @typeParam Target - 目标对象
|
|
174
|
+
* @typeParam Value - 要获取的key的对应值的类型
|
|
175
|
+
*/
|
|
176
|
+
export type KeyOfValue<Target, Value> = {
|
|
177
|
+
[K in keyof Target]: Target[K] extends Value ? K : never;
|
|
178
|
+
}[keyof Target];
|
|
179
|
+
/**
|
|
180
|
+
* 获取值类型不是指定类型的所有 key
|
|
181
|
+
*
|
|
182
|
+
* @typeParam Target - 目标对象
|
|
183
|
+
* @typeParam Value - 被排除的值的类型
|
|
184
|
+
*/
|
|
185
|
+
export type KeyOfNonValue<Target, Value> = {
|
|
186
|
+
[K in keyof Target]: Target[K] extends Value ? never : K;
|
|
187
|
+
}[keyof Target];
|
|
188
|
+
/**
|
|
189
|
+
* 获取值类型包含指定类型的所有 key
|
|
190
|
+
*
|
|
191
|
+
* @typeParam Target - 目标对象
|
|
192
|
+
* @typeParam Value - 要获取的key的对应值应包含的类型
|
|
193
|
+
*/
|
|
194
|
+
export type KeyOfContainsValue<Target, Value> = {
|
|
195
|
+
[K in keyof Target]: Value extends Target[K] ? K : never;
|
|
196
|
+
}[keyof Target];
|
|
197
|
+
/**
|
|
198
|
+
* 获取值类型不应包含指定类型的所有 key
|
|
199
|
+
*
|
|
200
|
+
* @typeParam Target - 目标对象
|
|
201
|
+
* @typeParam Value - 不应包含的值的类型
|
|
202
|
+
*/
|
|
203
|
+
export type KeyOfNonContainsValue<Target, Value> = {
|
|
204
|
+
[K in keyof Target]: Value extends Target[K] ? never : K;
|
|
205
|
+
}[keyof Target];
|
|
206
|
+
/**
|
|
207
|
+
* 从 T 中挑选出那些成员值为 Value 的类型的成员
|
|
208
|
+
*/
|
|
209
|
+
export type PickValue<Target, Value> = {
|
|
210
|
+
[P in KeyOfValue<Target, Value>]: Target[P];
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* 从 Target 中挑选出那些成员值不是 Value 的类型的成员
|
|
214
|
+
*/
|
|
215
|
+
export type PickNonValue<Target, Value> = {
|
|
216
|
+
[P in KeyOfNonValue<Target, Value>]: Target[P];
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* 从 Target 中挑选出那些成员值的类型包含 Value 类型的成员
|
|
220
|
+
*/
|
|
221
|
+
export type PickContainsValue<Target, Value> = {
|
|
222
|
+
[P in KeyOfContainsValue<Target, Value>]: Target[P];
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* 从 Target 中挑选出那些成员值的类型不包含 Value 类型的成员
|
|
226
|
+
*/
|
|
227
|
+
export type PickNonContainsValue<Target, Value> = {
|
|
228
|
+
[P in KeyOfNonContainsValue<Target, Value>]: Target[P];
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* 从 Target 中挑选出属性
|
|
232
|
+
*/
|
|
233
|
+
export type PickProperty<Target> = PickNonValue<Target, AnyFunction>;
|
|
234
|
+
/**
|
|
235
|
+
* 从 Target 中挑选出方法
|
|
236
|
+
*/
|
|
237
|
+
export type PickMethod<Target> = PickValue<Target, AnyFunction>;
|
|
238
|
+
/**
|
|
239
|
+
* 将 T 及其对象成员属性值都改为 Partial 类型
|
|
240
|
+
* @remarks
|
|
241
|
+
* 比 Partial 又深入的一层
|
|
242
|
+
*/
|
|
243
|
+
export type TwoLayerPartial<T> = {
|
|
244
|
+
[P in keyof T]?: Partial<T[P]>;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* 可将源类型 SourType 中的 类型 MatchType 替换为 新的类型 NewType
|
|
248
|
+
*/
|
|
249
|
+
export type Replace<SourType, MatchType, NewType> = SourType extends MatchType ? NewType : SourType;
|
|
250
|
+
/**
|
|
251
|
+
* 可将源类型 SourType 中的 undefined 替换为 新的类型 NewType
|
|
252
|
+
*/
|
|
253
|
+
export type ReplaceUndefined<SourType, NewType> = Replace<SourType, undefined, NewType>;
|
|
254
|
+
/**
|
|
255
|
+
* 可将源类型 SourType 中的 null 替换为 新的类型 NewType
|
|
256
|
+
*/
|
|
257
|
+
export type ReplaceNull<SourType, NewType> = Replace<SourType, null, NewType>;
|
|
258
|
+
/**
|
|
259
|
+
* 可将源类型 SourType 中的代表空的类型 void | undefined | null 替换为 新的类型 NewType
|
|
260
|
+
*/
|
|
261
|
+
export type ReplaceVoid<SourType, NewType> = Replace<SourType, void | undefined | null, NewType>;
|
package/dist/buffer.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | BigInt64Array | BigUint64Array | Float32Array | Float64Array;
|
|
@@ -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 type AnyFunction = (...args: any) => any;
|