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.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +81 -0
  3. package/dist/base.d.ts +184 -0
  4. package/dist/extend.d.ts +64 -0
  5. package/dist/function.d.ts +49 -0
  6. package/dist/index.d.ts +5 -150
  7. package/dist/member.d.ts +16 -0
  8. package/dist/mixin.d.ts +96 -0
  9. package/dist/tsdoc-metadata.json +11 -0
  10. package/dist/type-tls.d.ts +450 -0
  11. package/dist/type-tls.es.js +137 -134
  12. package/dist/type-tls.iife.js +1 -0
  13. package/dist/type-tls.umd.js +1 -1
  14. package/doc/index.md +12 -0
  15. package/doc/type-tls.anyfunction.md +13 -0
  16. package/doc/type-tls.classtype._new_.md +22 -0
  17. package/doc/type-tls.classtype.md +20 -0
  18. package/doc/type-tls.createdefinemixin.md +23 -0
  19. package/doc/type-tls.createextendtarget.md +30 -0
  20. package/doc/type-tls.createmixintarget.md +30 -0
  21. package/doc/type-tls.createtargetextend.md +30 -0
  22. package/doc/type-tls.createtargetmixin.md +30 -0
  23. package/doc/type-tls.defineextend.md +31 -0
  24. package/doc/type-tls.definemixin.md +31 -0
  25. package/doc/type-tls.exacttype.md +34 -0
  26. package/doc/type-tls.exacttypename.md +34 -0
  27. package/doc/type-tls.extendtarget.md +31 -0
  28. package/doc/type-tls.getexacttypenameof.md +26 -0
  29. package/doc/type-tls.getexacttypeof.md +26 -0
  30. package/doc/type-tls.getnameoftype.md +24 -0
  31. package/doc/type-tls.gettypebyname.md +24 -0
  32. package/doc/type-tls.gettypenameof.md +30 -0
  33. package/doc/type-tls.gettypeof.md +38 -0
  34. package/doc/type-tls.isanonymousfunction.md +35 -0
  35. package/doc/type-tls.isarraylike.md +25 -0
  36. package/doc/type-tls.isarrowfunction.md +24 -0
  37. package/doc/type-tls.isasyncfunction.md +28 -0
  38. package/doc/type-tls.isasyncgeneratorfunction.md +24 -0
  39. package/doc/type-tls.isbasetype.md +28 -0
  40. package/doc/type-tls.isgeneratorfunction.md +28 -0
  41. package/doc/type-tls.isidentifier.md +24 -0
  42. package/doc/type-tls.isiterable.md +24 -0
  43. package/doc/type-tls.isiterator.md +24 -0
  44. package/doc/type-tls.isobject.md +30 -0
  45. package/doc/type-tls.loosetype.md +13 -0
  46. package/doc/type-tls.loosetypename.md +13 -0
  47. package/doc/type-tls.md +65 -0
  48. package/doc/type-tls.methodparams.md +15 -0
  49. package/doc/type-tls.methodreturntype.md +15 -0
  50. package/doc/type-tls.mixin_4.md +33 -0
  51. package/doc/type-tls.mixintarget.md +31 -0
  52. package/doc/type-tls.optional.md +13 -0
  53. package/doc/type-tls.optionalboolean.md +15 -0
  54. package/doc/type-tls.replace.md +13 -0
  55. package/doc/type-tls.replacenull.md +15 -0
  56. package/doc/type-tls.replaceundefined.md +15 -0
  57. package/doc/type-tls.replacevoid.md +15 -0
  58. package/doc/type-tls.targetextend.md +31 -0
  59. package/doc/type-tls.targetmixin.md +31 -0
  60. package/doc/type-tls.typeofreturntype.md +13 -0
  61. package/package.json +28 -23
  62. package/dist/type-tls.cjs.js +0 -165
@@ -0,0 +1,31 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [type-tls](./type-tls.md) &gt; [mixinTarget](./type-tls.mixintarget.md)
4
+
5
+ ## mixinTarget() function
6
+
7
+ 混合目标
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ export declare function mixinTarget<T, M>(target: T, m: M & ThisType<T & M>): M & ThisType<T & M> & T;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ | Parameter | Type | Description |
18
+ | --- | --- | --- |
19
+ | target | T | 混合的目标,用作 this 的类型 |
20
+ | m | M &amp; ThisType&lt;T &amp; M&gt; | 混合对象,会自动更改其this的类型 |
21
+
22
+ <b>Returns:</b>
23
+
24
+ M &amp; ThisType&lt;T &amp; M&gt; &amp; T
25
+
26
+ 返回混合后的 target 对象
27
+
28
+ ## Remarks
29
+
30
+ 会执行对 CEarth 类的扩展操作。 与 [targetMixin()](./type-tls.targetmixin.md) 的区别仅仅是返回类型不一样。
31
+
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [type-tls](./type-tls.md) &gt; [Optional](./type-tls.optional.md)
4
+
5
+ ## Optional type
6
+
7
+ 将某个类型变为可选的类型
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ export declare type Optional<T> = T | null | undefined;
13
+ ```
@@ -0,0 +1,15 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [type-tls](./type-tls.md) &gt; [OptionalBoolean](./type-tls.optionalboolean.md)
4
+
5
+ ## OptionalBoolean type
6
+
7
+ 可选的布尔类型
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ export declare type OptionalBoolean = Optional<boolean>;
13
+ ```
14
+ <b>References:</b> [Optional](./type-tls.optional.md)
15
+
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [type-tls](./type-tls.md) &gt; [Replace](./type-tls.replace.md)
4
+
5
+ ## Replace type
6
+
7
+ 可将源类型 SourType 中的 类型 MatchType 替换为 新的类型 NewType
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ export declare type Replace<SourType, MatchType, NewType> = SourType extends MatchType ? NewType : SourType;
13
+ ```
@@ -0,0 +1,15 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [type-tls](./type-tls.md) &gt; [ReplaceNull](./type-tls.replacenull.md)
4
+
5
+ ## ReplaceNull type
6
+
7
+ 可将源类型 SourType 中的 null 替换为 新的类型 NewType
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ export declare type ReplaceNull<SourType, NewType> = Replace<SourType, null, NewType>;
13
+ ```
14
+ <b>References:</b> [Replace](./type-tls.replace.md)
15
+
@@ -0,0 +1,15 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [type-tls](./type-tls.md) &gt; [ReplaceUndefined](./type-tls.replaceundefined.md)
4
+
5
+ ## ReplaceUndefined type
6
+
7
+ 可将源类型 SourType 中的 undefined 替换为 新的类型 NewType
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ export declare type ReplaceUndefined<SourType, NewType> = Replace<SourType, undefined, NewType>;
13
+ ```
14
+ <b>References:</b> [Replace](./type-tls.replace.md)
15
+
@@ -0,0 +1,15 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [type-tls](./type-tls.md) &gt; [ReplaceVoid](./type-tls.replacevoid.md)
4
+
5
+ ## ReplaceVoid type
6
+
7
+ 可将源类型 SourType 中的代表空的类型 void \| undefined \| null 替换为 新的类型 NewType
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ export declare type ReplaceVoid<SourType, NewType> = Replace<SourType, void | undefined | null, NewType>;
13
+ ```
14
+ <b>References:</b> [Replace](./type-tls.replace.md)
15
+
@@ -0,0 +1,31 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [type-tls](./type-tls.md) &gt; [targetExtend](./type-tls.targetextend.md)
4
+
5
+ ## targetExtend() function
6
+
7
+ 扩展目标
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ export declare function targetExtend<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E>): E & ThisType<InstanceType<C> & E>;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ | Parameter | Type | Description |
18
+ | --- | --- | --- |
19
+ | cla | C | 扩展的目标,也用作 this 的类型 |
20
+ | ext | E &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt; | 扩展描述对象,会自动更改其this的类型 |
21
+
22
+ <b>Returns:</b>
23
+
24
+ E &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt;
25
+
26
+ 返回注入了 this 类型的 ext 对象本身
27
+
28
+ ## Remarks
29
+
30
+ 与 [defineExtend()](./type-tls.defineextend.md) 的区别是:`targetExtend` 会执行对 cla 的扩展操作,而 [defineExtend()](./type-tls.defineextend.md) 不会
31
+
@@ -0,0 +1,31 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [type-tls](./type-tls.md) &gt; [targetMixin](./type-tls.targetmixin.md)
4
+
5
+ ## targetMixin() function
6
+
7
+ 混合目标
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ export declare function targetMixin<T, M>(target: T, m: M & ThisType<T & M>): M & ThisType<T & M>;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ | Parameter | Type | Description |
18
+ | --- | --- | --- |
19
+ | target | T | 混合的目标,用作 this 的类型 |
20
+ | m | M &amp; ThisType&lt;T &amp; M&gt; | 混合对象,会自动更改其this的类型 |
21
+
22
+ <b>Returns:</b>
23
+
24
+ M &amp; ThisType&lt;T &amp; M&gt;
25
+
26
+ 返回注入了 this 类型的 mixin 对象本身
27
+
28
+ ## Remarks
29
+
30
+ 与 [defineMixin()](./type-tls.definemixin.md) 的区别是:`targetMixin` 会执行对 target 的混合操作,而 [defineMixin()](./type-tls.definemixin.md) 不会
31
+
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [type-tls](./type-tls.md) &gt; [TypeOfReturnType](./type-tls.typeofreturntype.md)
4
+
5
+ ## TypeOfReturnType type
6
+
7
+ typeof 的返回类型
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ export declare type TypeOfReturnType = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
13
+ ```
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "type-tls",
3
- "version": "2.1.0",
4
- "description": "type-tls 封装了与类型相关的工具,比如获取数据的类型 或 类型名字、判断数据的类型 等",
5
- "main": "dist/type-tls.cjs.js",
3
+ "version": "2.3.0",
4
+ "description": "type-tls 封装了与类型相关的工具,比如:获取数据的类型 或 类型名字、判断数据的类型 等",
5
+ "main": "dist/type-tls.umd.js",
6
6
  "module": "dist/type-tls.es.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "sideEffects": false,
@@ -11,6 +11,10 @@
11
11
  "type": "git",
12
12
  "url": "https://github.com/GuoBinyong/type-tls"
13
13
  },
14
+ "bugs": {
15
+ "url": "https://github.com/GuoBinyong/type-tls/issues",
16
+ "email": "guobinyong@qq.com"
17
+ },
14
18
  "keywords": [
15
19
  "type",
16
20
  "typeof",
@@ -18,31 +22,32 @@
18
22
  "instanceof",
19
23
  "类型"
20
24
  ],
21
- "author": "郭斌勇",
22
- "license": "ISC",
25
+ "author": {
26
+ "name": "郭斌勇",
27
+ "email": "guobinyong@qq.com"
28
+ },
29
+ "license": "MIT",
23
30
  "files": [
24
31
  "dist/[^.]*",
25
- "types/[^.]*"
32
+ "types/[^.]*",
33
+ "docs/[^.]*",
34
+ "doc/[^.]*"
26
35
  ],
27
36
  "scripts": {
28
- "build": "rollup -c",
29
- "dev": "rollup -c -w",
30
- "test": "node test/test.ts",
31
- "pretest": "npm run build"
37
+ "dev": "vite",
38
+ "build": "vite build",
39
+ "bunch": "vite build --mode bunch",
40
+ "preview": "vite preview",
41
+ "api": "api-extractor run -c api-extractor.jsonc -l -v",
42
+ "doc": "npm run api ; api-documenter markdown -i ./temp -o doc"
32
43
  },
33
44
  "devDependencies": {
34
- "@rollup/plugin-commonjs": "^11.1.0",
35
- "@rollup/plugin-node-resolve": "^7.1.3",
36
- "@rollup/plugin-typescript": "^4.1.2",
37
- "@typescript-eslint/eslint-plugin": "^3.0.0",
38
- "@typescript-eslint/parser": "^3.0.0",
39
- "eslint": "^7.0.0",
40
- "package-tls": "^1.0.2",
41
- "path": "^0.12.7",
42
- "rollup": "^2.7.2",
43
- "rollup-plugin-terser": "^6.1.0",
44
- "ts-node": "^8.9.1",
45
- "tslib": "^2.0.0",
46
- "typescript": "^3.8.3"
45
+ "@microsoft/api-documenter": "^7.17.15",
46
+ "@microsoft/api-extractor": "^7.24.1",
47
+ "build-tls": "^1.3.11",
48
+ "dts-bundle-generator": "^6.12.0",
49
+ "package-tls": "^1.2.2",
50
+ "typescript": "^4.5.4",
51
+ "vite": "^2.9.9"
47
52
  }
48
53
  }
@@ -1,165 +0,0 @@
1
-
2
- /*
3
- type-tls v2.1.0
4
- author: 郭斌勇
5
- license: ISC
6
- homepage: https://github.com/GuoBinyong/type-tls#readme
7
- repository: https://github.com/GuoBinyong/type-tls
8
- description: type-tls 封装了与类型相关的工具,比如获取数据的类型 或 类型名字、判断数据的类型 等
9
- */
10
-
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- /**
16
- * 判断目标是否是对象类型
17
- * @param target : any 目标对象
18
- *
19
- * 仅通过 target instanceof Object 判断是不行的,因为 对于 Object.create(null) 创建的对象 通过 ` Object.create(null) instanceof Object ` 来判断 返回的是 false
20
- * 即:通过 Object.create(null) 创建的对象是不被 instanceof 认为是继续于 Object 的
21
- *
22
- * typeof null 也返回 "object"
23
- */
24
- function isObject(target) {
25
- // return target instanceof Object || typeof target === "object"
26
- var tarType = typeof target;
27
- return target && (tarType === "object" || tarType === "function");
28
- }
29
- /**
30
- * 获取 inst 的宽松类型
31
- * @param inst : any
32
- * @returns LooseType inst 的类型
33
- *
34
- *
35
- *
36
- * 注意:
37
- * 本方法返回的结果如下:
38
- * undefined :undefined
39
- * null : null
40
- * function : Function
41
- * 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
42
- * 其它任何类型的实例 : 返回该实例的构造函数 或 包装对象的构造函数
43
- *
44
- */
45
- function getTypeOf(inst) {
46
- var typeInfo = inst;
47
- if (inst != null) {
48
- typeInfo = inst.constructor;
49
- if (typeInfo == undefined) {
50
- typeInfo = typeof inst;
51
- }
52
- }
53
- return typeInfo;
54
- }
55
- /**
56
- * 获取 类型的字符串表示
57
- * @param t
58
- * @return ExactTypeName
59
- */
60
- function getNameOfType(t) {
61
- switch (t) {
62
- case undefined: return "undefined";
63
- case null: return "null";
64
- }
65
- let tType = typeof t;
66
- switch (tType) {
67
- case "function": return t.name;
68
- case "string": return t;
69
- default: return tType;
70
- }
71
- }
72
- /**
73
- * 根据类型的名字获取类型
74
- * @param typeName
75
- */
76
- function getTypeByName(typeName) {
77
- return globalThis[typeName];
78
- }
79
- /**
80
- * 获取 inst 的类型字符串
81
- * @param inst : any
82
- * @returns string inst 的类型字符串
83
- *
84
- *
85
- *
86
- * 注意:
87
- * 本方法返回的结果如下:
88
- * undefined :"undefined"
89
- * null : "null"
90
- * 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
91
- * 其它任何类型的实例 : 返回该实例的构造函数 或 包装对象的构造函数 的函数名字
92
- *
93
- */
94
- function getTypeNameOf(inst) {
95
- let t = getTypeOf(inst);
96
- return getNameOfType(t);
97
- }
98
- /**
99
- * 获取 inst 的精确类型
100
- * @param inst : any
101
- * @returns ExactType inst 的类型
102
- */
103
- function getExactTypeOf(inst) {
104
- if (inst == null || isObject(inst)) {
105
- return getTypeOf(inst);
106
- }
107
- return (typeof inst);
108
- }
109
- /**
110
- * 获取 inst 的精确类型的字符串表示
111
- * @param inst : any
112
- * @returns ExactTypeName inst 的类型字符串
113
- */
114
- function getExactTypeNameOf(inst) {
115
- var t = getExactTypeOf(inst);
116
- return getNameOfType(t);
117
- }
118
- /**
119
- * 判断 data 是否是 基本类型
120
- * @param data
121
- *
122
- * 基本类型 是指 那些不是 对象类型的类型,即,除了 object 和 function 类型以外,其它的都是基本类型,null 也算怎是 基本类型
123
- */
124
- function isBaseType(data) {
125
- var typeStr = typeof data;
126
- return data == null || (typeStr !== "object" && typeStr !== "function");
127
- }
128
- /**
129
- * isArrayLike(target)
130
- * 判断 target 是否为 类数组对象
131
- * @param target : any 目标
132
- * @returns boolean
133
- */
134
- function isArrayLike(target) {
135
- let length = target && target.length;
136
- return Number.isInteger(target.length) && length >= 0;
137
- }
138
- /**
139
- * 判断 目标 是否是可迭代的对象,即 实现了 可迭代协议
140
- * @param target : any
141
- * @return {boolean}
142
- */
143
- function isIterable(target) {
144
- return target && (typeof target[Symbol.iterator] === "function");
145
- }
146
- /**
147
- * 判断 目标 是否是迭代器,即 实现了 迭代器协议
148
- * @param target : any
149
- * @return {boolean}
150
- */
151
- function isIterator(target) {
152
- return target && (typeof target.next === "function");
153
- }
154
-
155
- exports.getExactTypeNameOf = getExactTypeNameOf;
156
- exports.getExactTypeOf = getExactTypeOf;
157
- exports.getNameOfType = getNameOfType;
158
- exports.getTypeByName = getTypeByName;
159
- exports.getTypeNameOf = getTypeNameOf;
160
- exports.getTypeOf = getTypeOf;
161
- exports.isArrayLike = isArrayLike;
162
- exports.isBaseType = isBaseType;
163
- exports.isIterable = isIterable;
164
- exports.isIterator = isIterator;
165
- exports.isObject = isObject;