type-tls 2.7.0 → 3.1.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.
Files changed (101) hide show
  1. package/dist/async.d.ts +28 -0
  2. package/dist/base.d.ts +261 -0
  3. package/dist/buffer.d.ts +1 -0
  4. package/dist/function.d.ts +49 -0
  5. package/dist/index.d.ts +6 -630
  6. package/dist/member.d.ts +21 -0
  7. package/dist/other.d.ts +25 -0
  8. package/dist/tsdoc-metadata.json +1 -1
  9. package/dist/type-tls.d.ts +36 -312
  10. package/dist/type-tls.iife.js +1 -1
  11. package/dist/type-tls.js +125 -0
  12. package/dist/type-tls.umd.cjs +1 -0
  13. package/doc/api/index.md +20 -3
  14. package/doc/api/type-tls.anyfunction.md +2 -2
  15. package/doc/api/type-tls.arrayitemtype.md +2 -2
  16. package/doc/api/type-tls.bitflagequaltesttype.getequalfun.md +52 -0
  17. package/doc/api/type-tls.bitflagequaltesttype.md +37 -0
  18. package/doc/api/type-tls.exacttype.md +3 -3
  19. package/doc/api/type-tls.exacttypename.md +3 -3
  20. package/doc/api/type-tls.getexacttypenameof.md +32 -5
  21. package/doc/api/type-tls.getexacttypeof.md +32 -5
  22. package/doc/api/type-tls.getnameoftype.md +34 -5
  23. package/doc/api/type-tls.gettypebyname.md +34 -5
  24. package/doc/api/type-tls.gettypenameof.md +32 -5
  25. package/doc/api/type-tls.gettypeof.md +32 -5
  26. package/doc/api/type-tls.isanonymousfunction.md +32 -5
  27. package/doc/api/type-tls.isarraylike.md +34 -5
  28. package/doc/api/type-tls.isarrowfunction.md +34 -5
  29. package/doc/api/type-tls.isasyncfunction.md +34 -5
  30. package/doc/api/type-tls.isasyncgeneratorfunction.md +34 -5
  31. package/doc/api/type-tls.isbasetype.md +34 -5
  32. package/doc/api/type-tls.isgeneratorfunction.md +34 -5
  33. package/doc/api/type-tls.isidentifier.md +34 -5
  34. package/doc/api/type-tls.isiterable.md +34 -5
  35. package/doc/api/type-tls.isiterator.md +34 -5
  36. package/doc/api/type-tls.isobject.md +34 -5
  37. package/doc/api/type-tls.keyofcontainsvalue.md +3 -3
  38. package/doc/api/type-tls.keyofnoncontainsvalue.md +3 -3
  39. package/doc/api/type-tls.keyofnonvalue.md +3 -3
  40. package/doc/api/type-tls.keyofvalue.md +3 -3
  41. package/doc/api/type-tls.loosetype.md +2 -2
  42. package/doc/api/type-tls.loosetypename.md +2 -2
  43. package/doc/api/type-tls.md +593 -83
  44. package/doc/api/type-tls.methodparams.md +3 -3
  45. package/doc/api/type-tls.methodreturntype.md +3 -3
  46. package/doc/api/type-tls.optional.md +2 -2
  47. package/doc/api/type-tls.optionalboolean.md +3 -3
  48. package/doc/api/type-tls.pickcontainsvalue.md +4 -4
  49. package/doc/api/type-tls.pickmethod.md +3 -3
  50. package/doc/api/type-tls.picknoncontainsvalue.md +4 -4
  51. package/doc/api/type-tls.picknonvalue.md +4 -4
  52. package/doc/api/type-tls.pickproperty.md +3 -3
  53. package/doc/api/type-tls.pickvalue.md +4 -4
  54. package/doc/api/type-tls.replace.md +2 -2
  55. package/doc/api/type-tls.replacenull.md +3 -3
  56. package/doc/api/type-tls.replaceundefined.md +3 -3
  57. package/doc/api/type-tls.replacevoid.md +3 -3
  58. package/doc/api/type-tls.resolvedata.md +2 -2
  59. package/doc/api/type-tls.twolayerpartial.md +20 -0
  60. package/doc/api/type-tls.typedarray.md +11 -0
  61. package/doc/api/type-tls.typeofreturntype.md +2 -2
  62. package/doc/api/type-tls.waitasyncable.md +48 -6
  63. package/doc/api/type-tls.waitasyncablecallback.md +3 -3
  64. package/doc/api/type-tls.waitasyncablereturn.md +2 -2
  65. package/package.json +32 -15
  66. package/dist/type-tls.mjs +0 -214
  67. package/dist/type-tls.umd.js +0 -1
  68. package/doc/api/type-tls.axis.getcrossaxiss.md +0 -32
  69. package/doc/api/type-tls.axis.md +0 -22
  70. package/doc/api/type-tls.axis.toindex.md +0 -25
  71. package/doc/api/type-tls.axis.tokey.md +0 -25
  72. package/doc/api/type-tls.axis4.getcrossaxiss.md +0 -32
  73. package/doc/api/type-tls.axis4.md +0 -22
  74. package/doc/api/type-tls.axis4.toindex.md +0 -25
  75. package/doc/api/type-tls.axis4.tokey.md +0 -25
  76. package/doc/api/type-tls.axis4name.md +0 -13
  77. package/doc/api/type-tls.axisname.md +0 -13
  78. package/doc/api/type-tls.classtype._new_.md +0 -22
  79. package/doc/api/type-tls.classtype.md +0 -20
  80. package/doc/api/type-tls.createdefinemixin.md +0 -23
  81. package/doc/api/type-tls.createextendtarget.md +0 -30
  82. package/doc/api/type-tls.createmixintarget.md +0 -30
  83. package/doc/api/type-tls.createtargetextend.md +0 -30
  84. package/doc/api/type-tls.createtargetmixin.md +0 -30
  85. package/doc/api/type-tls.defineextend.md +0 -35
  86. package/doc/api/type-tls.definemixin.md +0 -31
  87. package/doc/api/type-tls.extendtarget.md +0 -31
  88. package/doc/api/type-tls.ivector.md +0 -15
  89. package/doc/api/type-tls.ivector2.md +0 -21
  90. package/doc/api/type-tls.ivector2.x.md +0 -11
  91. package/doc/api/type-tls.ivector2.y.md +0 -11
  92. package/doc/api/type-tls.ivector3.md +0 -21
  93. package/doc/api/type-tls.ivector3.z.md +0 -11
  94. package/doc/api/type-tls.ivector4.md +0 -21
  95. package/doc/api/type-tls.ivector4.w.md +0 -11
  96. package/doc/api/type-tls.mixin_4.md +0 -33
  97. package/doc/api/type-tls.mixintarget.md +0 -31
  98. package/doc/api/type-tls.privatememberofextend._constructor.md +0 -22
  99. package/doc/api/type-tls.privatememberofextend.md +0 -20
  100. package/doc/api/type-tls.targetextend.md +0 -31
  101. package/doc/api/type-tls.targetmixin.md +0 -31
@@ -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>;
@@ -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;