@omnia/velcron 8.0.460-dev → 8.0.462-dev

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.
@@ -1,10 +1,15 @@
1
1
  export declare class Utils {
2
+ private static _timeboxTimer;
2
3
  /**
3
4
  * Determine whether the argument is an array.
4
5
  *
5
6
  * @param obj Object to test whether or not it is an array.
6
7
  */
7
8
  static isArray(obj: any): obj is Array<any>;
9
+ /**
10
+ * Check if array is null or undefined or empty
11
+ */
12
+ static isArrayNullOrEmpty(obj: any): boolean;
8
13
  /**
9
14
  * Check if is type of a function
10
15
  * @param obj Object to test whether or not it is an function.
@@ -26,4 +31,8 @@ export declare class Utils {
26
31
  static isString(target: any): target is string;
27
32
  static isNumber(target: any): target is number;
28
33
  static clone<T extends I, I>(obj: I): T;
34
+ /**
35
+ * Set a timer with an ID. If timebox is called again with the same ID before the timer has triggered, don't do anything. Otherwise, set a new timer with that ID.
36
+ */
37
+ static timebox(id: string, callback: () => any, ms: number): void;
29
38
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Utils = void 0;
4
4
  class Utils {
5
+ static { this._timeboxTimer = {}; }
5
6
  /**
6
7
  * Determine whether the argument is an array.
7
8
  *
@@ -10,6 +11,14 @@ class Utils {
10
11
  static isArray(obj) {
11
12
  return Array.isArray(obj);
12
13
  }
14
+ /**
15
+ * Check if array is null or undefined or empty
16
+ */
17
+ static isArrayNullOrEmpty(obj) {
18
+ if (!Utils.isArray(obj))
19
+ return true;
20
+ return (obj == null || obj == undefined || obj.length == 0);
21
+ }
13
22
  /**
14
23
  * Check if is type of a function
15
24
  * @param obj Object to test whether or not it is an function.
@@ -57,5 +66,16 @@ class Utils {
57
66
  static clone(obj) {
58
67
  return JSON.parse(JSON.stringify(obj));
59
68
  }
69
+ /**
70
+ * Set a timer with an ID. If timebox is called again with the same ID before the timer has triggered, don't do anything. Otherwise, set a new timer with that ID.
71
+ */
72
+ static timebox(id, callback, ms) {
73
+ if (!Utils._timeboxTimer[id]) {
74
+ Utils._timeboxTimer[id] = setTimeout(() => {
75
+ Utils._timeboxTimer[id] = null;
76
+ callback();
77
+ }, ms);
78
+ }
79
+ }
60
80
  }
61
81
  exports.Utils = Utils;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@omnia/velcron",
3
3
  "license": "MIT",
4
- "version": "8.0.460-dev",
4
+ "version": "8.0.462-dev",
5
5
  "description": "Provide Omnia Velcron Stuffs.",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"