@zwa73/utils 1.0.84 → 1.0.86

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.
@@ -104,6 +104,10 @@ export declare class UtilFunc {
104
104
  * @returns 处理结果
105
105
  */
106
106
  static queueProc<T>(flag: Keyable, task: (() => Promise<T>) | Promise<T>): Promise<T>;
107
+ /**队列获取目标的代办事件数
108
+ * @param flag - 队列标签
109
+ */
110
+ static queueLength(flag: Keyable): number;
107
111
  /**创建一个Outcome */
108
112
  static outcome<K extends Keyable, V>(key: K, value: V): Outcome<K, V>;
109
113
  /**处理联合值
@@ -128,6 +132,11 @@ export declare class UtilFunc {
128
132
  static isFailed<T>(tg: T): T extends Matchable<FailedLike> ? true : MatchableFlag<T> extends Exclude<MatchableFlag<T>, FailedLike> ? false : boolean;
129
133
  /**是成功的 */
130
134
  static isSuccess<T>(tg: T): T extends Matchable<SuccessLike> ? true : MatchableFlag<T> extends Exclude<MatchableFlag<T>, SuccessLike> ? false : boolean;
135
+ /**类似空值 undefined null None
136
+ * @param t - 检测目标
137
+ * @param strictLog - 应该严格等于None 否则将输出警告 但任然返回true
138
+ */
139
+ static likeNone(t: unknown, strictLog?: boolean): t is None;
131
140
  /**验证一个变量的类型是否为 T
132
141
  * @template T - 验证类型
133
142
  * @param t - 验证目标
@@ -326,6 +326,13 @@ class UtilFunc {
326
326
  tryRes();
327
327
  }
328
328
  }
329
+ /**队列获取目标的代办事件数
330
+ * @param flag - 队列标签
331
+ */
332
+ static queueLength(flag) {
333
+ const pd = this.pendingMap[flag];
334
+ return pd != null ? pd.length : 0;
335
+ }
329
336
  /**创建一个Outcome */
330
337
  static outcome(key, value) {
331
338
  return {
@@ -385,6 +392,21 @@ class UtilFunc {
385
392
  return test(tg.status);
386
393
  return test(tg);
387
394
  }
395
+ /**类似空值 undefined null None
396
+ * @param t - 检测目标
397
+ * @param strictLog - 应该严格等于None 否则将输出警告 但任然返回true
398
+ */
399
+ static likeNone(t, strictLog = true) {
400
+ if (t === UtilSymbol_1.None)
401
+ return true;
402
+ if (t === "null" || t === "undefined" || t === String(UtilSymbol_1.None)) {
403
+ UtilLogger_1.SLogger.warn(`输入值为字符串类型的空值, 已作为 None 处理`, `具体值: ${t}`);
404
+ return true;
405
+ }
406
+ if (strictLog && t == null)
407
+ UtilLogger_1.SLogger.warn(`输入值不严格等于 None , 已作为 None 处理`, `具体类型: ${t}`);
408
+ return t == null;
409
+ }
388
410
  /**验证一个变量的类型是否为 T
389
411
  * @template T - 验证类型
390
412
  * @param t - 验证目标
@@ -19,6 +19,12 @@ export interface IJData {
19
19
  export type AnyFunc = (...args: any) => any;
20
20
  /**任意可作为键值的类型 */
21
21
  export type Keyable = string | number | symbol;
22
+ /**排除可选项目
23
+ * 将基础类型中与默认选项重合的部分变为可选
24
+ * @template B - 基础类型
25
+ * @template D - 默认选项
26
+ */
27
+ export type PartialOption<B, D> = keyof D extends keyof B ? Omit<B, keyof D> & Partial<Pick<B, keyof D>> : never;
22
28
  /**真子集 */
23
29
  export type ProperSubset<B, T = B> = T extends B ? B extends T ? never : T : never;
24
30
  /**字面量检测 */
@@ -8,6 +8,9 @@ export type Failed = typeof Failed;
8
8
  /**不存在 无 */
9
9
  export declare const None: unique symbol;
10
10
  export type None = typeof None;
11
+ /**未初始化的 用于静态构造函数标记*/
12
+ export declare const Uninited: unique symbol;
13
+ export type Uninited = typeof Uninited;
11
14
  /**完成 未经验证/未超时的结果
12
15
  * Success扩展
13
16
  * 仅在Success同时出现时使用
@@ -31,7 +34,7 @@ export type FailedLike = Failed | Timeout | Terminated;
31
34
  /**成功及其拓展 */
32
35
  export type SuccessLike = Success | Completed;
33
36
  /**任意状态标识符 */
34
- export type StatusSymbol = FailedLike | SuccessLike | None;
37
+ export type StatusSymbol = FailedLike | SuccessLike | None | Uninited;
35
38
  /**结果为 None 的 Outcome */
36
39
  export type NoneOut = Outcome<None, None>;
37
40
  export declare const NoneOut: NoneOut;
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NoneOut = exports.Timeout = exports.Terminated = exports.Completed = exports.None = exports.Failed = exports.Success = void 0;
3
+ exports.NoneOut = exports.Timeout = exports.Terminated = exports.Completed = exports.Uninited = exports.None = exports.Failed = exports.Success = void 0;
4
4
  /**成功 经过验证的结果 */
5
5
  exports.Success = Symbol("Success");
6
6
  /**失败 可重试的 */
7
7
  exports.Failed = Symbol("Failed");
8
8
  /**不存在 无 */
9
9
  exports.None = Symbol("None");
10
+ /**未初始化的 用于静态构造函数标记*/
11
+ exports.Uninited = Symbol("Uninited");
10
12
  /**完成 未经验证/未超时的结果
11
13
  * Success扩展
12
14
  * 仅在Success同时出现时使用
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.84",
3
+ "version": "1.0.86",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -384,6 +384,13 @@ static async queueProc<T>(flag:Keyable,task:(()=>Promise<T>)|Promise<T>):Promise
384
384
  tryRes();
385
385
  }
386
386
  }
387
+ /**队列获取目标的代办事件数
388
+ * @param flag - 队列标签
389
+ */
390
+ static queueLength(flag:Keyable){
391
+ const pd = this.pendingMap[flag]
392
+ return pd!=null ? pd.length : 0;
393
+ }
387
394
 
388
395
 
389
396
 
@@ -468,6 +475,21 @@ static isSuccess<T>
468
475
  return test(tg) as any
469
476
  }
470
477
 
478
+ /**类似空值 undefined null None
479
+ * @param t - 检测目标
480
+ * @param strictLog - 应该严格等于None 否则将输出警告 但任然返回true
481
+ */
482
+ static likeNone(t:unknown,strictLog=true):t is None{
483
+ if(t===None) return true;
484
+ if(t==="null" || t === "undefined" || t === String(None)){
485
+ SLogger.warn(`输入值为字符串类型的空值, 已作为 None 处理`,`具体值: ${t}`);
486
+ return true;
487
+ }
488
+ if(strictLog && t == null)
489
+ SLogger.warn(`输入值不严格等于 None , 已作为 None 处理`,`具体类型: ${t}`);
490
+ return t == null;
491
+ }
492
+
471
493
  /**验证一个变量的类型是否为 T
472
494
  * @template T - 验证类型
473
495
  * @param t - 验证目标
@@ -23,6 +23,15 @@ export type AnyFunc = (...args:any)=>any;
23
23
  /**任意可作为键值的类型 */
24
24
  export type Keyable = string | number | symbol;
25
25
 
26
+ /**排除可选项目
27
+ * 将基础类型中与默认选项重合的部分变为可选
28
+ * @template B - 基础类型
29
+ * @template D - 默认选项
30
+ */
31
+ export type PartialOption<B,D> = keyof D extends keyof B
32
+ ? Omit<B,keyof D> & Partial<Pick<B,keyof D>>
33
+ : never;
34
+
26
35
  /**真子集 */
27
36
  export type ProperSubset<B, T = B> = T extends B ? B extends T ? never : T : never;
28
37
 
package/src/UtilSymbol.ts CHANGED
@@ -10,6 +10,9 @@ export type Failed = typeof Failed;
10
10
  /**不存在 无 */
11
11
  export const None = Symbol("None");
12
12
  export type None = typeof None;
13
+ /**未初始化的 用于静态构造函数标记*/
14
+ export const Uninited = Symbol("Uninited");
15
+ export type Uninited = typeof Uninited;
13
16
  /**完成 未经验证/未超时的结果
14
17
  * Success扩展
15
18
  * 仅在Success同时出现时使用
@@ -33,7 +36,7 @@ export type FailedLike = Failed|Timeout|Terminated;
33
36
  /**成功及其拓展 */
34
37
  export type SuccessLike = Success|Completed;
35
38
  /**任意状态标识符 */
36
- export type StatusSymbol = FailedLike|SuccessLike|None;
39
+ export type StatusSymbol = FailedLike|SuccessLike|None|Uninited;
37
40
  /**结果为 None 的 Outcome */
38
41
  export type NoneOut = Outcome<None,None>;
39
42
  export const NoneOut = {