type-tls 3.2.1 → 3.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/dist/index.d.ts CHANGED
@@ -4,3 +4,5 @@ export * from './member';
4
4
  export * from './async';
5
5
  export * from './buffer';
6
6
  export * from "./other";
7
+ export * from './vector';
8
+ export * from './size';
package/dist/member.d.ts CHANGED
@@ -26,6 +26,15 @@ export type ArrayItemType<Arr> = Arr extends (infer Item)[] ? Item : never;
26
26
  * 如果 ItemOrArray 不是数组,则转为数组类型 ItemOrArray[]
27
27
  */
28
28
  export type FormatAsArray<ItemOrArray> = ItemOrArray extends any[] ? ItemOrArray : ItemOrArray[];
29
+ /**
30
+ * 格式化为数组格式
31
+ * @remarks
32
+ * 如果 value 是数组,则保持不变
33
+ * 如果 value 不是数组,则转为数组类型
34
+ * @param value
35
+ * @returns
36
+ */
37
+ export declare function formatAsArray<V>(value: V): FormatAsArray<V>;
29
38
  /**
30
39
  * 格式化对象成员为数组格式
31
40
  * @remarks
@@ -35,3 +44,12 @@ export type FormatAsArray<ItemOrArray> = ItemOrArray extends any[] ? ItemOrArray
35
44
  export type FormatMemberAsArray<D> = {
36
45
  [K in keyof D]: FormatAsArray<D[K]>;
37
46
  };
47
+ /**
48
+ * 格式化对象成员为数组格式
49
+ * @remarks
50
+ * 如果 成员 是数组,则保持不变
51
+ * 如果 成员 不是数组,则转为数组类型
52
+ *
53
+ * @returns 返回来的 data 对象,此方法会改变原对象 data,耗会生成新的对象
54
+ */
55
+ export declare function formatMemberAsArray<D extends {}>(data: D): FormatMemberAsArray<D>;
package/dist/size.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 二维尺寸
3
+ */
4
+ export interface Size2 {
5
+ width: number;
6
+ height: number;
7
+ }
8
+ /**
9
+ * 三维尺寸
10
+ */
11
+ export interface Size3 extends Size2 {
12
+ depth: number;
13
+ }
@@ -1 +1 @@
1
- var TypeTls=function(e){"use strict";function f(n){var t=typeof n;return n&&(t==="object"||t==="function")}function o(n){var t=n;return n!=null&&(t=n.constructor,t==null&&(t=typeof n)),t}function s(n){switch(n){case void 0:return"undefined";case null:return"null"}let t=typeof n;switch(t){case"function":return n.name;case"string":return n;default:return t}}function y(n){return globalThis[n]}function l(n){let t=o(n);return s(t)}function a(n){return n==null||f(n)?o(n):typeof n}function g(n){var t=a(n);return s(t)}function T(n){var t=typeof n;return n==null||t!=="object"&&t!=="function"}function F(n){let t=n&&n.length;return Number.isInteger(n.length)&&t>=0}function A(n){return n&&typeof n[Symbol.iterator]=="function"}function b(n){return n&&typeof n.next=="function"}const m=/^[A-Za-z_$]+[\w$]*$/;function O(n){return m.test(n)}const d=/(^\s*(async\s+)?\s*(\b[A-Za-z_$]+[\w$]*\b)\s*=>)|(^\s*(async\s+)?\s*\(\s*(\b[A-Za-z_$]+[\w$]*\b)?\s*(,\s*(\b[A-Za-z_$]+[\w$]*\b)\s*)*\)\s*=>)/;function w(n){const t=n.toString();return d.test(t)}const h=globalThis.AsyncFunction??(async function(){}).constructor;function v(n){return n instanceof h}const E=globalThis.GeneratorFunction??(function*(){}).constructor;function $(n){return n instanceof E}const N=globalThis.AsyncGeneratorFunction??(async function*(){}).constructor;function S(n){return n instanceof N}const q=/(^\s*(async\s+)?function\s*(\s|\*)\s*)[A-Za-z_$]+[\w$]*(\s*\()/;function I(n){if(n.name){const t=n.toString();return!q.test(t)}return!0}function G(n,t){return n instanceof Promise?n.then(i=>t(i,!1,void 0),i=>t(void 0,!0,i)):t(n,!1,void 0)}return e.BitFlagEqualTestType=(n=>(n.equal="equal",n.intersect="intersect",n.intersectEqual="intersectEqual",n))(e.BitFlagEqualTestType||{}),(n=>{function t(i){let c;switch(i){case"equal":c=(u,r)=>u===r;case"intersect":c=(u,r)=>u&r;default:c=(u,r)=>(u&r)===u}return c}n.getEqualFun=t})(e.BitFlagEqualTestType||(e.BitFlagEqualTestType={})),e.getExactTypeNameOf=g,e.getExactTypeOf=a,e.getNameOfType=s,e.getTypeByName=y,e.getTypeNameOf=l,e.getTypeOf=o,e.isAnonymousFunction=I,e.isArrayLike=F,e.isArrowFunction=w,e.isAsyncFunction=v,e.isAsyncGeneratorFunction=S,e.isBaseType=T,e.isGeneratorFunction=$,e.isIdentifier=O,e.isIterable=A,e.isIterator=b,e.isObject=f,e.waitAsyncable=G,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});
1
+ var TypeTls=function(e){"use strict";function f(n){var t=typeof n;return n&&(t==="object"||t==="function")}function o(n){var t=n;return n!=null&&(t=n.constructor,t==null&&(t=typeof n)),t}function s(n){switch(n){case void 0:return"undefined";case null:return"null"}let t=typeof n;switch(t){case"function":return n.name;case"string":return n;default:return t}}function y(n){return globalThis[n]}function l(n){let t=o(n);return s(t)}function a(n){return n==null||f(n)?o(n):typeof n}function A(n){var t=a(n);return s(t)}function g(n){var t=typeof n;return n==null||t!=="object"&&t!=="function"}function T(n){let t=n&&n.length;return Number.isInteger(n.length)&&t>=0}function m(n){return n&&typeof n[Symbol.iterator]=="function"}function F(n){return n&&typeof n.next=="function"}const b=/^[A-Za-z_$]+[\w$]*$/;function O(n){return b.test(n)}const w=/(^\s*(async\s+)?\s*(\b[A-Za-z_$]+[\w$]*\b)\s*=>)|(^\s*(async\s+)?\s*\(\s*(\b[A-Za-z_$]+[\w$]*\b)?\s*(,\s*(\b[A-Za-z_$]+[\w$]*\b)\s*)*\)\s*=>)/;function d(n){const t=n.toString();return w.test(t)}const h=globalThis.AsyncFunction??(async function(){}).constructor;function E(n){return n instanceof h}const $=globalThis.GeneratorFunction??(function*(){}).constructor;function N(n){return n instanceof $}const S=globalThis.AsyncGeneratorFunction??(async function*(){}).constructor;function q(n){return n instanceof S}const v=/(^\s*(async\s+)?function\s*(\s|\*)\s*)[A-Za-z_$]+[\w$]*(\s*\()/;function I(n){if(n.name){const t=n.toString();return!v.test(t)}return!0}function G(n){return Array.isArray(n)?n:n==null?[]:[n]}function j(n){for(const[t,r]of Object.entries(n))n[t]=Array.isArray(r)?r:r==null?[]:[r];return n}function p(n,t){return n instanceof Promise?n.then(r=>t(r,!1,void 0),r=>t(void 0,!0,r)):t(n,!1,void 0)}return e.BitFlagEqualTestType=(n=>(n.equal="equal",n.intersect="intersect",n.intersectEqual="intersectEqual",n))(e.BitFlagEqualTestType||{}),(n=>{function t(r){let c;switch(r){case"equal":c=(u,i)=>u===i;case"intersect":c=(u,i)=>u&i;default:c=(u,i)=>(u&i)===u}return c}n.getEqualFun=t})(e.BitFlagEqualTestType||(e.BitFlagEqualTestType={})),e.formatAsArray=G,e.formatMemberAsArray=j,e.getExactTypeNameOf=A,e.getExactTypeOf=a,e.getNameOfType=s,e.getTypeByName=y,e.getTypeNameOf=l,e.getTypeOf=o,e.isAnonymousFunction=I,e.isArrayLike=T,e.isArrowFunction=d,e.isAsyncFunction=E,e.isAsyncGeneratorFunction=q,e.isBaseType=g,e.isGeneratorFunction=N,e.isIdentifier=O,e.isIterable=m,e.isIterator=F,e.isObject=f,e.waitAsyncable=p,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});
package/dist/type-tls.js CHANGED
@@ -23,17 +23,17 @@ function s(n) {
23
23
  return t;
24
24
  }
25
25
  }
26
- function b(n) {
26
+ function m(n) {
27
27
  return globalThis[n];
28
28
  }
29
- function h(n) {
29
+ function F(n) {
30
30
  let t = i(n);
31
31
  return s(t);
32
32
  }
33
33
  function a(n) {
34
34
  return n == null || f(n) ? i(n) : typeof n;
35
35
  }
36
- function m(n) {
36
+ function h(n) {
37
37
  var t = a(n);
38
38
  return s(t);
39
39
  }
@@ -45,58 +45,66 @@ function $(n) {
45
45
  let t = n && n.length;
46
46
  return Number.isInteger(n.length) && t >= 0;
47
47
  }
48
- function d(n) {
48
+ function O(n) {
49
49
  return n && typeof n[Symbol.iterator] == "function";
50
50
  }
51
- function v(n) {
51
+ function T(n) {
52
52
  return n && typeof n.next == "function";
53
53
  }
54
- const l = /^[A-Za-z_$]+[\w$]*$/;
55
- function T(n) {
56
- return l.test(n);
54
+ const y = /^[A-Za-z_$]+[\w$]*$/;
55
+ function d(n) {
56
+ return y.test(n);
57
57
  }
58
- const y = /(^\s*(async\s+)?\s*(\b[A-Za-z_$]+[\w$]*\b)\s*=>)|(^\s*(async\s+)?\s*\(\s*(\b[A-Za-z_$]+[\w$]*\b)?\s*(,\s*(\b[A-Za-z_$]+[\w$]*\b)\s*)*\)\s*=>)/;
59
- function O(n) {
58
+ const l = /(^\s*(async\s+)?\s*(\b[A-Za-z_$]+[\w$]*\b)\s*=>)|(^\s*(async\s+)?\s*\(\s*(\b[A-Za-z_$]+[\w$]*\b)?\s*(,\s*(\b[A-Za-z_$]+[\w$]*\b)\s*)*\)\s*=>)/;
59
+ function v(n) {
60
60
  const t = n.toString();
61
- return y.test(t);
61
+ return l.test(t);
62
62
  }
63
- const p = globalThis.AsyncFunction ?? (async function() {
63
+ const A = globalThis.AsyncFunction ?? (async function() {
64
64
  }).constructor;
65
65
  function S(n) {
66
- return n instanceof p;
66
+ return n instanceof A;
67
67
  }
68
- const g = globalThis.GeneratorFunction ?? (function* () {
68
+ const p = globalThis.GeneratorFunction ?? (function* () {
69
69
  }).constructor;
70
70
  function q(n) {
71
- return n instanceof g;
71
+ return n instanceof p;
72
72
  }
73
- const A = globalThis.AsyncGeneratorFunction ?? (async function* () {
73
+ const g = globalThis.AsyncGeneratorFunction ?? (async function* () {
74
74
  }).constructor;
75
75
  function x(n) {
76
- return n instanceof A;
76
+ return n instanceof g;
77
77
  }
78
- const F = /(^\s*(async\s+)?function\s*(\s|\*)\s*)[A-Za-z_$]+[\w$]*(\s*\()/;
78
+ const b = /(^\s*(async\s+)?function\s*(\s|\*)\s*)[A-Za-z_$]+[\w$]*(\s*\()/;
79
79
  function E(n) {
80
80
  if (n.name) {
81
81
  const t = n.toString();
82
- return !F.test(t);
82
+ return !b.test(t);
83
83
  }
84
84
  return !0;
85
85
  }
86
- function G(n, t) {
87
- return n instanceof Promise ? n.then((r) => t(r, !1, void 0), (r) => t(void 0, !0, r)) : t(n, !1, void 0);
86
+ function G(n) {
87
+ return Array.isArray(n) ? n : n == null ? [] : [n];
88
+ }
89
+ function I(n) {
90
+ for (const [t, e] of Object.entries(n))
91
+ n[t] = Array.isArray(e) ? e : e == null ? [] : [e];
92
+ return n;
93
+ }
94
+ function N(n, t) {
95
+ return n instanceof Promise ? n.then((e) => t(e, !1, void 0), (e) => t(void 0, !0, e)) : t(n, !1, void 0);
88
96
  }
89
97
  var c = /* @__PURE__ */ ((n) => (n.equal = "equal", n.intersect = "intersect", n.intersectEqual = "intersectEqual", n))(c || {});
90
98
  ((n) => {
91
- function t(r) {
99
+ function t(e) {
92
100
  let o;
93
- switch (r) {
101
+ switch (e) {
94
102
  case "equal":
95
- o = (e, u) => e === u;
103
+ o = (r, u) => r === u;
96
104
  case "intersect":
97
- o = (e, u) => e & u;
105
+ o = (r, u) => r & u;
98
106
  default:
99
- o = (e, u) => (e & u) === e;
107
+ o = (r, u) => (r & u) === r;
100
108
  }
101
109
  return o;
102
110
  }
@@ -104,22 +112,24 @@ var c = /* @__PURE__ */ ((n) => (n.equal = "equal", n.intersect = "intersect", n
104
112
  })(c || (c = {}));
105
113
  export {
106
114
  c as BitFlagEqualTestType,
107
- m as getExactTypeNameOf,
115
+ G as formatAsArray,
116
+ I as formatMemberAsArray,
117
+ h as getExactTypeNameOf,
108
118
  a as getExactTypeOf,
109
119
  s as getNameOfType,
110
- b as getTypeByName,
111
- h as getTypeNameOf,
120
+ m as getTypeByName,
121
+ F as getTypeNameOf,
112
122
  i as getTypeOf,
113
123
  E as isAnonymousFunction,
114
124
  $ as isArrayLike,
115
- O as isArrowFunction,
125
+ v as isArrowFunction,
116
126
  S as isAsyncFunction,
117
127
  x as isAsyncGeneratorFunction,
118
128
  w as isBaseType,
119
129
  q as isGeneratorFunction,
120
- T as isIdentifier,
121
- d as isIterable,
122
- v as isIterator,
130
+ d as isIdentifier,
131
+ O as isIterable,
132
+ T as isIterator,
123
133
  f as isObject,
124
- G as waitAsyncable
134
+ N as waitAsyncable
125
135
  };
@@ -1 +1 @@
1
- (function(t,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(t=typeof globalThis<"u"?globalThis:t||self,i(t.TypeTls={}))})(this,function(t){"use strict";function i(n){var e=typeof n;return n&&(e==="object"||e==="function")}function s(n){var e=n;return n!=null&&(e=n.constructor,e==null&&(e=typeof n)),e}function f(n){switch(n){case void 0:return"undefined";case null:return"null"}let e=typeof n;switch(e){case"function":return n.name;case"string":return n;default:return e}}function y(n){return globalThis[n]}function l(n){let e=s(n);return f(e)}function a(n){return n==null||i(n)?s(n):typeof n}function g(n){var e=a(n);return f(e)}function T(n){var e=typeof n;return n==null||e!=="object"&&e!=="function"}function d(n){let e=n&&n.length;return Number.isInteger(n.length)&&e>=0}function F(n){return n&&typeof n[Symbol.iterator]=="function"}function A(n){return n&&typeof n.next=="function"}const b=/^[A-Za-z_$]+[\w$]*$/;function m(n){return b.test(n)}const p=/(^\s*(async\s+)?\s*(\b[A-Za-z_$]+[\w$]*\b)\s*=>)|(^\s*(async\s+)?\s*\(\s*(\b[A-Za-z_$]+[\w$]*\b)?\s*(,\s*(\b[A-Za-z_$]+[\w$]*\b)\s*)*\)\s*=>)/;function O(n){const e=n.toString();return p.test(e)}const h=globalThis.AsyncFunction??(async function(){}).constructor;function w(n){return n instanceof h}const E=globalThis.GeneratorFunction??(function*(){}).constructor;function $(n){return n instanceof E}const v=globalThis.AsyncGeneratorFunction??(async function*(){}).constructor;function N(n){return n instanceof v}const S=/(^\s*(async\s+)?function\s*(\s|\*)\s*)[A-Za-z_$]+[\w$]*(\s*\()/;function q(n){if(n.name){const e=n.toString();return!S.test(e)}return!0}function I(n,e){return n instanceof Promise?n.then(r=>e(r,!1,void 0),r=>e(void 0,!0,r)):e(n,!1,void 0)}t.BitFlagEqualTestType=(n=>(n.equal="equal",n.intersect="intersect",n.intersectEqual="intersectEqual",n))(t.BitFlagEqualTestType||{}),(n=>{function e(r){let o;switch(r){case"equal":o=(u,c)=>u===c;case"intersect":o=(u,c)=>u&c;default:o=(u,c)=>(u&c)===u}return o}n.getEqualFun=e})(t.BitFlagEqualTestType||(t.BitFlagEqualTestType={})),t.getExactTypeNameOf=g,t.getExactTypeOf=a,t.getNameOfType=f,t.getTypeByName=y,t.getTypeNameOf=l,t.getTypeOf=s,t.isAnonymousFunction=q,t.isArrayLike=d,t.isArrowFunction=O,t.isAsyncFunction=w,t.isAsyncGeneratorFunction=N,t.isBaseType=T,t.isGeneratorFunction=$,t.isIdentifier=m,t.isIterable=F,t.isIterator=A,t.isObject=i,t.waitAsyncable=I,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
1
+ (function(t,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(t=typeof globalThis<"u"?globalThis:t||self,i(t.TypeTls={}))})(this,function(t){"use strict";function i(n){var e=typeof n;return n&&(e==="object"||e==="function")}function s(n){var e=n;return n!=null&&(e=n.constructor,e==null&&(e=typeof n)),e}function f(n){switch(n){case void 0:return"undefined";case null:return"null"}let e=typeof n;switch(e){case"function":return n.name;case"string":return n;default:return e}}function y(n){return globalThis[n]}function l(n){let e=s(n);return f(e)}function a(n){return n==null||i(n)?s(n):typeof n}function A(n){var e=a(n);return f(e)}function g(n){var e=typeof n;return n==null||e!=="object"&&e!=="function"}function T(n){let e=n&&n.length;return Number.isInteger(n.length)&&e>=0}function m(n){return n&&typeof n[Symbol.iterator]=="function"}function b(n){return n&&typeof n.next=="function"}const F=/^[A-Za-z_$]+[\w$]*$/;function d(n){return F.test(n)}const O=/(^\s*(async\s+)?\s*(\b[A-Za-z_$]+[\w$]*\b)\s*=>)|(^\s*(async\s+)?\s*\(\s*(\b[A-Za-z_$]+[\w$]*\b)?\s*(,\s*(\b[A-Za-z_$]+[\w$]*\b)\s*)*\)\s*=>)/;function h(n){const e=n.toString();return O.test(e)}const p=globalThis.AsyncFunction??(async function(){}).constructor;function w(n){return n instanceof p}const E=globalThis.GeneratorFunction??(function*(){}).constructor;function $(n){return n instanceof E}const N=globalThis.AsyncGeneratorFunction??(async function*(){}).constructor;function S(n){return n instanceof N}const q=/(^\s*(async\s+)?function\s*(\s|\*)\s*)[A-Za-z_$]+[\w$]*(\s*\()/;function I(n){if(n.name){const e=n.toString();return!q.test(e)}return!0}function j(n){return Array.isArray(n)?n:n==null?[]:[n]}function v(n){for(const[e,r]of Object.entries(n))n[e]=Array.isArray(r)?r:r==null?[]:[r];return n}function G(n,e){return n instanceof Promise?n.then(r=>e(r,!1,void 0),r=>e(void 0,!0,r)):e(n,!1,void 0)}t.BitFlagEqualTestType=(n=>(n.equal="equal",n.intersect="intersect",n.intersectEqual="intersectEqual",n))(t.BitFlagEqualTestType||{}),(n=>{function e(r){let c;switch(r){case"equal":c=(u,o)=>u===o;case"intersect":c=(u,o)=>u&o;default:c=(u,o)=>(u&o)===u}return c}n.getEqualFun=e})(t.BitFlagEqualTestType||(t.BitFlagEqualTestType={})),t.formatAsArray=j,t.formatMemberAsArray=v,t.getExactTypeNameOf=A,t.getExactTypeOf=a,t.getNameOfType=f,t.getTypeByName=y,t.getTypeNameOf=l,t.getTypeOf=s,t.isAnonymousFunction=I,t.isArrayLike=T,t.isArrowFunction=h,t.isAsyncFunction=w,t.isAsyncGeneratorFunction=S,t.isBaseType=g,t.isGeneratorFunction=$,t.isIdentifier=d,t.isIterable=m,t.isIterator=b,t.isObject=i,t.waitAsyncable=G,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 二维向量
3
+ */
4
+ export interface IVector2 {
5
+ x: number;
6
+ y: number;
7
+ }
8
+ /**
9
+ * 三维向量
10
+ */
11
+ export interface IVector3 extends IVector2 {
12
+ z: number;
13
+ }
14
+ /**
15
+ * 四维向量
16
+ */
17
+ export interface IVector4 extends IVector3 {
18
+ w: number;
19
+ }
20
+ /**
21
+ * 向量
22
+ */
23
+ export type IVector = IVector2 | IVector3 | IVector4;
@@ -45,6 +45,28 @@ Description
45
45
  </th></tr></thead>
46
46
  <tbody><tr><td>
47
47
 
48
+ [formatAsArray(value)](./type-tls.formatasarray.md)
49
+
50
+
51
+ </td><td>
52
+
53
+ 格式化为数组格式
54
+
55
+
56
+ </td></tr>
57
+ <tr><td>
58
+
59
+ [formatMemberAsArray(data)](./type-tls.formatmemberasarray.md)
60
+
61
+
62
+ </td><td>
63
+
64
+ 格式化对象成员为数组格式
65
+
66
+
67
+ </td></tr>
68
+ <tr><td>
69
+
48
70
  [getExactTypeNameOf(inst)](./type-tls.getexacttypenameof.md)
49
71
 
50
72
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-tls",
3
- "version": "3.2.1",
3
+ "version": "3.3.0",
4
4
  "description": "type-tls 封装了与类型相关的工具,比如:获取数据的类型 或 类型名字、判断数据的类型 等",
5
5
  "main": "./dist/type-tls.umd.cjs",
6
6
  "module": "./dist/type-tls.js",
@@ -1,11 +0,0 @@
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.52.7"
9
- }
10
- ]
11
- }
@@ -1,445 +0,0 @@
1
- /**
2
- * 表示任意的函数类型
3
- */
4
- export declare type AnyFunction = (...args: any) => any;
5
-
6
- /**
7
- * 获取数组元素的类型
8
- * @typeParam Arr 数组
9
- */
10
- export declare type ArrayItemType<Arr> = Arr extends (infer Item)[] ? Item : never;
11
-
12
- /**
13
- * 位标志相等测试
14
- */
15
- export declare enum BitFlagEqualTestType {
16
- /**
17
- * 相等:A === B
18
- */
19
- equal = "equal",// "相等"
20
- /**
21
- * 相交:A & B
22
- */
23
- intersect = "intersect",// "相交"
24
- /**
25
- * 交等:A & B === A
26
- */
27
- intersectEqual = "intersectEqual"
28
- }
29
-
30
- export declare namespace BitFlagEqualTestType {
31
- /**
32
- * 获取 位标志相等测试的函数
33
- * @param testType 默认 intersectEqual
34
- * @returns
35
- */
36
- export function getEqualFun(testType?: BitFlagEqualTestType | null): (a: number, b: number) => number | boolean;
37
- }
38
-
39
- /**
40
- * 精确类型
41
- *
42
- * @remarks
43
- * 在精准类型中认为 JavaScript 的原始类型(非对象类型) 与 其对应的 包装类型(类类型)是不同的类型,即:
44
- * number 和 Number、string 和 String、boolean 和 Boolean 等 是不同的类型;
45
- * 对于原始类型,返回的结果 会与 typeof 返回的结果一样;
46
- * 但,对于 undefined 和 null 会返回其自身值(即 undefined 和 null)作为类型值
47
- *
48
- * 各种类型的值 与 该方法的返回值 的映射如下:
49
- * ```
50
- * undefined :undefined
51
- * null : null
52
- * string : "string"
53
- * number : "number"
54
- * bigint : "bigint"
55
- * boolean : "boolean"
56
- * symbol : "symbol"
57
- * function : Function
58
- * 没有原型的对象(如:通过 `Object.create(null)` 创建的对象) : "object"
59
- * 其它任何类型的实例 : 返回该实例的构造函数
60
- * ```
61
- */
62
- export declare type ExactType = LooseType | Exclude<TypeOfReturnType, "undefined" | "function" | "object">;
63
-
64
- /**
65
- * 精确类型的字符串表示
66
- *
67
- * @remarks
68
- * 在精准类型中认为 JavaScript 的原始类型(非对象类型) 与 其对应的 包装类型(类类型)是不同的类型,即:
69
- * number 和 Number、string 和 String、boolean 和 Boolean 等 是不同的类型;
70
- * 对于原始类型,返回的结果 会与 typeof 返回的结果一样;
71
- * 但,对于 null 会返回 "null"
72
- *
73
- * 各种类型的值 与 该方法的返回值 的映射如下:
74
- * ```
75
- * undefined :"undefined"
76
- * null : "null"
77
- * function : "Function"
78
- * string : "string"
79
- * number : "number"
80
- * bigint : "bigint"
81
- * boolean : "boolean"
82
- * symbol : "symbol"
83
- * 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
84
- * 其它任何类型的实例 : 返回该实例的构造函数的名字
85
- * ```
86
- */
87
- export declare type ExactTypeName = LooseTypeName | Exclude<TypeOfReturnType, "undefined" | "function" | "object">;
88
-
89
- /**
90
- * 格式化为数组格式
91
- * @remarks
92
- * 如果 ItemOrArray 是数组,则保持不变
93
- * 如果 ItemOrArray 不是数组,则转为数组类型 ItemOrArray[]
94
- */
95
- export declare type FormatAsArray<ItemOrArray> = ItemOrArray extends any[] ? ItemOrArray : ItemOrArray[];
96
-
97
- /**
98
- * 格式化对象成员为数组格式
99
- * @remarks
100
- * 如果 成员 是数组,则保持不变
101
- * 如果 成员 不是数组,则转为数组类型
102
- */
103
- export declare type FormatMemberAsArray<D> = {
104
- [K in keyof D]: FormatAsArray<D[K]>;
105
- };
106
-
107
- /**
108
- * 获取 inst 的精确类型的字符串表示
109
- * @param inst
110
- * @returns inst 的类型字符串
111
- */
112
- export declare function getExactTypeNameOf(inst: any): ExactTypeName;
113
-
114
- /**
115
- * 获取 inst 的精确类型
116
- * @param inst
117
- * @returns inst 的类型
118
- */
119
- export declare function getExactTypeOf(inst: any): ExactType;
120
-
121
- /**
122
- * 获取 类型的字符串表示
123
- *
124
- * @param t - 一个 ExactType 类型的值
125
- * @return t 的字符串表示的类型
126
- */
127
- export declare function getNameOfType(t: ExactType): ExactTypeName;
128
-
129
- /**
130
- * 根据类型的名字获取其对应的类
131
- * @param typeName - 类型的名字
132
- */
133
- export declare function getTypeByName(typeName: string): Function | undefined;
134
-
135
- /**
136
- * 获取 inst 的类型字符串
137
- *
138
- * @remarks
139
- * 注意:
140
- * 本方法返回的结果如下:
141
- * undefined :"undefined"
142
- * null : "null"
143
- * 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
144
- * 其它任何类型的实例 : 返回该实例的构造函数 或 包装对象的构造函数 的函数名字
145
- *
146
- * @param inst
147
- * @returns inst 的类型字符串
148
- */
149
- export declare function getTypeNameOf(inst: any): LooseTypeName;
150
-
151
- /**
152
- * 获取 inst 的宽松类型
153
- *
154
- * @remarks
155
- * 注意:
156
- * 本方法返回的结果如下:
157
- * ```
158
- * undefined :undefined
159
- * null : null
160
- * function : Function
161
- * 没有原型的对象(如:通过 Object.create(null) 创建的对象) : "object"
162
- * 其它任何类型的实例 : 返回该实例的构造函数 或 包装对象的构造函数
163
- * ```
164
- *
165
- *
166
- * @param inst
167
- * @returns inst 的类型
168
- */
169
- export declare function getTypeOf(inst: any): LooseType;
170
-
171
- /**
172
- * 判断是否是匿名函数
173
- *
174
- * @remarks
175
- * 判断函数在被定义时是否是通过匿名函数来定义的。
176
- * 匿名函数是指声明函数时没有写名字的函数。
177
- * 注意:即使是匿名函数,函数对象上的 name 属性也可能是有值的,因为 js解析器 会自动将 函数表达式函数变量的名字作为匿名函数的名字,如下:
178
- * ```ts
179
- * var funName = function(){};
180
- * ```
181
- * 其中的匿名函数对象的 name 属性的值会是 `funName`
182
- *
183
- * 如果 函数对象上的 name 属性的值为 `""`,函数一定是匿名函数。
184
- */
185
- export declare function isAnonymousFunction(fun: Function): boolean;
186
-
187
- /**
188
- * 判断 target 是否为 类数组对象
189
- * @param target - 目标
190
- * @returns
191
- */
192
- export declare function isArrayLike(target: any): boolean;
193
-
194
- /**
195
- * 判断函数是否是箭头函数
196
- * @param fun - 被判断的函数
197
- */
198
- export declare function isArrowFunction(fun: Function): boolean;
199
-
200
- /**
201
- * 判断函数是否是 async 异步函数
202
- * @remarks
203
- * 异步函数 不包含 异步生成器函数 AsyncGeneratorFunction
204
- * @param fun - 被判断的函数
205
- */
206
- export declare function isAsyncFunction(fun: Function): boolean;
207
-
208
- /**
209
- * 判断函数是否是异步生成器函数
210
- * @param fun - 被判断的函数
211
- */
212
- export declare function isAsyncGeneratorFunction(fun: Function): boolean;
213
-
214
- /**
215
- * 判断 data 是否是 基本类型
216
- * @remarks
217
- * 基本类型 是指 那些不是 对象类型的类型,即,除了 object 和 function 类型以外,其它的都是基本类型,null 也算怎是 基本类型
218
- * @param data - 任意类型的值
219
- */
220
- export declare function isBaseType(data: any): boolean;
221
-
222
- /**
223
- * 判断函数是否是生成器函数
224
- *
225
- * @remarks
226
- * 生成器函数 不包含 异步生成器函数 AsyncGeneratorFunction
227
- * @param fun - 被判断的函数
228
- */
229
- export declare function isGeneratorFunction(fun: Function): boolean;
230
-
231
- /**
232
- * 判断 code 是否是有校的 js 标识符
233
- * @param code - 标识符的字符串
234
- */
235
- export declare function isIdentifier(code: string): boolean;
236
-
237
- /**
238
- * 判断 目标 是否是可迭代的对象,即 实现了 可迭代协议
239
- * @param target - 目标
240
- */
241
- export declare function isIterable(target: any): boolean;
242
-
243
- /**
244
- * 判断 目标 是否是迭代器,即 实现了 迭代器协议
245
- * @param target - 目标
246
- */
247
- export declare function isIterator(target: any): boolean;
248
-
249
- /**
250
- * 判断目标是否是对象类型
251
- *
252
- * @remarks
253
- * 仅通过 target instanceof Object 判断是不行的,因为 对于 Object.create(null) 创建的对象 通过 ` Object.create(null) instanceof Object ` 来判断 返回的是 false
254
- * 即:通过 Object.create(null) 创建的对象是不被 instanceof 认为是继续于 Object 的
255
- *
256
- * typeof null 也返回 "object"
257
- *
258
- * @param target : any 目标对象
259
- */
260
- export declare function isObject(target: any): boolean;
261
-
262
- /**
263
- * 获取值类型包含指定类型的所有 key
264
- *
265
- * @typeParam Target - 目标对象
266
- * @typeParam Value - 要获取的key的对应值应包含的类型
267
- */
268
- export declare type KeyOfContainsValue<Target, Value> = {
269
- [K in keyof Target]: Value extends Target[K] ? K : never;
270
- }[keyof Target];
271
-
272
- /**
273
- * 获取值类型不应包含指定类型的所有 key
274
- *
275
- * @typeParam Target - 目标对象
276
- * @typeParam Value - 不应包含的值的类型
277
- */
278
- export declare type KeyOfNonContainsValue<Target, Value> = {
279
- [K in keyof Target]: Value extends Target[K] ? never : K;
280
- }[keyof Target];
281
-
282
- /**
283
- * 获取值类型不是指定类型的所有 key
284
- *
285
- * @typeParam Target - 目标对象
286
- * @typeParam Value - 被排除的值的类型
287
- */
288
- export declare type KeyOfNonValue<Target, Value> = {
289
- [K in keyof Target]: Target[K] extends Value ? never : K;
290
- }[keyof Target];
291
-
292
- /**
293
- * 获取值类型为指定类型的所有 key
294
- *
295
- * @typeParam Target - 目标对象
296
- * @typeParam Value - 要获取的key的对应值的类型
297
- */
298
- export declare type KeyOfValue<Target, Value> = {
299
- [K in keyof Target]: Target[K] extends Value ? K : never;
300
- }[keyof Target];
301
-
302
- /**
303
- * 宽松的类型
304
- */
305
- export declare type LooseType = undefined | null | Function | "object";
306
-
307
- /**
308
- * 宽松类型的字符串表示
309
- */
310
- export declare type LooseTypeName = "undefined" | "null" | "Function" | "object" | string;
311
-
312
- /**
313
- * 获取对象的方法的某个参数的类型
314
- *
315
- * @typeParam Obj - 对象
316
- * @typeParam Method - 对象方法的名字
317
- * @typeParam ParamIndex - 参数的索引个数
318
- */
319
- export declare type MethodParams<Obj, Method extends keyof Obj, ParamIndex extends number> = Obj[Method] extends AnyFunction ? Parameters<Obj[Method]>[ParamIndex] : never;
320
-
321
- /**
322
- * 获取对象的方法的返回的类型
323
- *
324
- * @typeParam Obj - 对象
325
- * @typeParam Method - 对象方法的名字
326
- */
327
- export declare type MethodReturnType<Obj, Method extends keyof Obj> = Obj[Method] extends AnyFunction ? ReturnType<Obj[Method]> : never;
328
-
329
- /**
330
- * 将某个类型变为可选的类型
331
- */
332
- export declare type Optional<T> = T | null | undefined;
333
-
334
- /**
335
- * 可选的布尔类型
336
- */
337
- export declare type OptionalBoolean = Optional<boolean>;
338
-
339
- /**
340
- * 从 Target 中挑选出那些成员值的类型包含 Value 类型的成员
341
- */
342
- export declare type PickContainsValue<Target, Value> = {
343
- [P in KeyOfContainsValue<Target, Value>]: Target[P];
344
- };
345
-
346
- /**
347
- * 从 Target 中挑选出方法
348
- */
349
- export declare type PickMethod<Target> = PickValue<Target, AnyFunction>;
350
-
351
- /**
352
- * 从 Target 中挑选出那些成员值的类型不包含 Value 类型的成员
353
- */
354
- export declare type PickNonContainsValue<Target, Value> = {
355
- [P in KeyOfNonContainsValue<Target, Value>]: Target[P];
356
- };
357
-
358
- /**
359
- * 从 Target 中挑选出那些成员值不是 Value 的类型的成员
360
- */
361
- export declare type PickNonValue<Target, Value> = {
362
- [P in KeyOfNonValue<Target, Value>]: Target[P];
363
- };
364
-
365
- /**
366
- * 从 Target 中挑选出属性
367
- */
368
- export declare type PickProperty<Target> = PickNonValue<Target, AnyFunction>;
369
-
370
- /**
371
- * 从 T 中挑选出那些成员值为 Value 的类型的成员
372
- */
373
- export declare type PickValue<Target, Value> = {
374
- [P in KeyOfValue<Target, Value>]: Target[P];
375
- };
376
-
377
- /**
378
- * 可将源类型 SourType 中的 类型 MatchType 替换为 新的类型 NewType
379
- */
380
- export declare type Replace<SourType, MatchType, NewType> = SourType extends MatchType ? NewType : SourType;
381
-
382
- /**
383
- * 可将源类型 SourType 中的 null 替换为 新的类型 NewType
384
- */
385
- export declare type ReplaceNull<SourType, NewType> = Replace<SourType, null, NewType>;
386
-
387
- /**
388
- * 可将源类型 SourType 中的 undefined 替换为 新的类型 NewType
389
- */
390
- export declare type ReplaceUndefined<SourType, NewType> = Replace<SourType, undefined, NewType>;
391
-
392
- /**
393
- * 可将源类型 SourType 中的代表空的类型 void | undefined | null 替换为 新的类型 NewType
394
- */
395
- export declare type ReplaceVoid<SourType, NewType> = Replace<SourType, void | undefined | null, NewType>;
396
-
397
- /**
398
- * 获取 Promise 解决的类型的值
399
- * @remarks
400
- * 对于非 Promise 类型的值,返回原类型本身
401
- */
402
- export declare type ResolveData<P> = P extends Promise<infer D> ? D : P;
403
-
404
- /**
405
- * 将 T 及其对象成员属性值都改为 Partial 类型
406
- * @remarks
407
- * 比 Partial 又深入的一层
408
- */
409
- export declare type TwoLayerPartial<T> = {
410
- [P in keyof T]?: Partial<T[P]>;
411
- };
412
-
413
- export declare type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | BigInt64Array | BigUint64Array | Float32Array | Float64Array;
414
-
415
- /**
416
- * typeof 的返回类型
417
- */
418
- export declare type TypeOfReturnType = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
419
-
420
- /**
421
- * 等待可异步的结果
422
- *
423
- * @remarks
424
- * 当 asyncable 为同步值时,会同步调用 callback。
425
- * 当 asyncable 为异步值时,会等待 asyncable 解决后再调用 callback。
426
- *
427
- * @param asyncable - 可异步的结果
428
- * @param callback
429
- * @returns
430
- */
431
- export declare function waitAsyncable<Result, Return>(asyncable: Result, callback: WaitAsyncableCallback<Result, Return>): WaitAsyncableReturn<Result, Return>;
432
-
433
- /**
434
- * waitAsyncable 的回调函数的类型
435
- * @param result - 同步的结果
436
- * @param rejected - 异步是否被拒绝
437
- */
438
- export declare type WaitAsyncableCallback<Result, Return> = (result: ResolveData<Result> | undefined, rejected: boolean, error: any) => Return;
439
-
440
- /**
441
- * waitAsyncable 的返回值的类型
442
- */
443
- export declare type WaitAsyncableReturn<Result, Return> = Return extends Promise<any> ? Return : (Result extends Promise<any> ? Promise<Return> : Return);
444
-
445
- export { }