@develia/commons 0.4.8 → 0.4.12

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 (103) hide show
  1. package/dist/cjs/array.js +5 -4
  2. package/dist/cjs/array.js.map +1 -1
  3. package/dist/cjs/browser/form-utilities.js +29 -23
  4. package/dist/cjs/browser/form-utilities.js.map +1 -1
  5. package/dist/cjs/browser/geo-location.js +61 -37
  6. package/dist/cjs/browser/geo-location.js.map +1 -1
  7. package/dist/cjs/browser/index.js +46 -1
  8. package/dist/cjs/browser/index.js.map +1 -1
  9. package/dist/cjs/cancellable-promise.js +60 -0
  10. package/dist/cjs/cancellable-promise.js.map +1 -0
  11. package/dist/cjs/event-bus.js +70 -0
  12. package/dist/cjs/event-bus.js.map +1 -0
  13. package/dist/cjs/from.js +1 -1
  14. package/dist/cjs/from.js.map +1 -1
  15. package/dist/cjs/index.js +6 -1
  16. package/dist/cjs/index.js.map +1 -1
  17. package/dist/cjs/math.js +3 -2
  18. package/dist/cjs/math.js.map +1 -1
  19. package/dist/cjs/parse.js +70 -0
  20. package/dist/cjs/parse.js.map +1 -0
  21. package/dist/cjs/patch.js +3 -2
  22. package/dist/cjs/patch.js.map +1 -1
  23. package/dist/cjs/string.js +43 -3
  24. package/dist/cjs/string.js.map +1 -1
  25. package/dist/cjs/utilities.js +25 -24
  26. package/dist/cjs/utilities.js.map +1 -1
  27. package/dist/esm/browser/form-utilities.js +23 -18
  28. package/dist/esm/browser/form-utilities.js.map +1 -1
  29. package/dist/esm/browser/geo-location.js +60 -36
  30. package/dist/esm/browser/geo-location.js.map +1 -1
  31. package/dist/esm/browser/index.js +44 -0
  32. package/dist/esm/browser/index.js.map +1 -1
  33. package/dist/esm/cancellable-promise.js +57 -0
  34. package/dist/esm/cancellable-promise.js.map +1 -0
  35. package/dist/esm/event-bus.js +65 -0
  36. package/dist/esm/event-bus.js.map +1 -0
  37. package/dist/esm/index.js +2 -0
  38. package/dist/esm/index.js.map +1 -1
  39. package/dist/esm/parse.js +64 -0
  40. package/dist/esm/parse.js.map +1 -0
  41. package/dist/esm/string.js +34 -0
  42. package/dist/esm/string.js.map +1 -1
  43. package/dist/types/browser/form-utilities.d.ts +2 -2
  44. package/dist/types/browser/form-utilities.d.ts.map +1 -1
  45. package/dist/types/browser/geo-location.d.ts.map +1 -1
  46. package/dist/types/browser/index.d.ts +7 -0
  47. package/dist/types/browser/index.d.ts.map +1 -1
  48. package/dist/types/cancellable-promise.d.ts +13 -0
  49. package/dist/types/cancellable-promise.d.ts.map +1 -0
  50. package/dist/types/event-bus.d.ts +21 -0
  51. package/dist/types/event-bus.d.ts.map +1 -0
  52. package/dist/types/index.d.ts +2 -0
  53. package/dist/types/index.d.ts.map +1 -1
  54. package/dist/types/parse.d.ts +16 -0
  55. package/dist/types/parse.d.ts.map +1 -0
  56. package/dist/types/string.d.ts +5 -0
  57. package/dist/types/string.d.ts.map +1 -1
  58. package/dist/web/browser/form-utilities.js +23 -18
  59. package/dist/web/browser/form-utilities.js.map +1 -1
  60. package/dist/web/browser/geo-location.js +60 -36
  61. package/dist/web/browser/geo-location.js.map +1 -1
  62. package/dist/web/browser/index.js +44 -0
  63. package/dist/web/browser/index.js.map +1 -1
  64. package/dist/web/cancellable-promise.js +57 -0
  65. package/dist/web/cancellable-promise.js.map +1 -0
  66. package/dist/web/event-bus.js +65 -0
  67. package/dist/web/event-bus.js.map +1 -0
  68. package/dist/web/index.js +2 -0
  69. package/dist/web/index.js.map +1 -1
  70. package/dist/web/parse.js +64 -0
  71. package/dist/web/parse.js.map +1 -0
  72. package/dist/web/string.js +34 -0
  73. package/dist/web/string.js.map +1 -1
  74. package/package.json +56 -56
  75. package/src/array.ts +0 -0
  76. package/src/async-pool-executor.ts +0 -0
  77. package/src/browser/form-utilities.ts +179 -173
  78. package/src/browser/geo-location.ts +113 -79
  79. package/src/browser/index.ts +78 -4
  80. package/src/browser/native-bridge.ts +116 -116
  81. package/src/cancellable-promise.ts +77 -0
  82. package/src/clean-url-search-params.ts +0 -0
  83. package/src/collections/cache-dictionary.ts +0 -0
  84. package/src/collections/default-map.ts +0 -0
  85. package/src/collections/default-weak-map.ts +0 -0
  86. package/src/collections/index.ts +2 -2
  87. package/src/event-bus.ts +84 -0
  88. package/src/from.ts +0 -0
  89. package/src/index.ts +37 -35
  90. package/src/key-value-pair.ts +0 -0
  91. package/src/lazy.ts +0 -0
  92. package/src/math.ts +0 -0
  93. package/src/order.ts +0 -0
  94. package/src/parse.ts +241 -0
  95. package/src/patch.ts +0 -0
  96. package/src/stopwatch.ts +0 -0
  97. package/src/string.ts +82 -2
  98. package/src/timer.ts +0 -0
  99. package/src/timespan.ts +0 -0
  100. package/src/type-code.ts +15 -15
  101. package/src/type.ts +371 -371
  102. package/src/types.ts +30 -30
  103. package/src/utilities.ts +404 -404
package/src/utilities.ts CHANGED
@@ -1,404 +1,404 @@
1
- // noinspection JSUnusedGlobalSymbols
2
-
3
-
4
- import KeyValuePair from "./key-value-pair.js";
5
- import type {Resolvable} from "./types.js";
6
- import Type from "./type.js";
7
-
8
- export function lazy<T extends object>(factory: () => T): T {
9
- let instance: T | null = null;
10
-
11
- const getInstance = (): T => {
12
- if (!instance) {
13
- instance = factory();
14
- }
15
- return instance;
16
- };
17
-
18
- return new Proxy({} as T, {
19
- get(_, prop, receiver) {
20
- return Reflect.get(getInstance(), prop, receiver);
21
- },
22
- set(_, prop, value, receiver) {
23
- return Reflect.set(getInstance(), prop, value, receiver);
24
- },
25
- has(_, prop) {
26
- return Reflect.has(getInstance(), prop);
27
- },
28
- deleteProperty(_, prop) {
29
- return Reflect.deleteProperty(getInstance(), prop);
30
- },
31
- ownKeys() {
32
- return Reflect.ownKeys(getInstance());
33
- },
34
- getOwnPropertyDescriptor(_, prop) {
35
- return Reflect.getOwnPropertyDescriptor(getInstance(), prop);
36
- },
37
- getPrototypeOf() {
38
- return Reflect.getPrototypeOf(getInstance());
39
- },
40
- });
41
- }
42
-
43
- /**
44
- * Checks if an object is iterable.
45
- *
46
- * @param {any} obj - The object to check.
47
- * @return {boolean} - Returns true if the object is iterable, otherwise false.
48
- */
49
- export function isIterable(obj: any): boolean {
50
- return obj[Symbol.iterator] === 'function';
51
- }
52
-
53
- /**
54
- * Checks if a given value is a string.
55
- *
56
- * @param {*} value - The value to check.
57
- * @return {boolean} - Returns true if the value is a string, otherwise returns false.
58
- */
59
- export function isString(value: any): value is string {
60
- return typeof value === 'string';
61
- }
62
-
63
- /**
64
- * Checks if a value is a number.
65
- *
66
- * @param {any} value - The value to check.
67
- * @return {boolean} - Returns true if the value is a number, otherwise false.
68
- */
69
- export function isNumber(value: any): value is number {
70
- return typeof value === 'number';
71
- }
72
-
73
- /**
74
- * Checks if a given value is a boolean.
75
- *
76
- * @param {any} value - The value to be checked.
77
- *
78
- * @return {boolean} - Returns true if the value is a boolean, otherwise false.
79
- */
80
- export function isBoolean(value: any): value is boolean {
81
- return typeof value === 'boolean';
82
- }
83
-
84
- /**
85
- * Checks if a value is an object.
86
- * @param {any} value - The value to be checked.
87
- * @returns {boolean} - Returns true if the value is an object, otherwise returns false.
88
- */
89
- export function isObject(value: any): value is object {
90
- return value != null && typeof value === 'object' && !Array.isArray(value);
91
- }
92
-
93
- /**
94
- * Determines if a value is an array.
95
- *
96
- * @param value - The value to be checked.
97
- *
98
- * @return Whether the value is an array.
99
- */
100
- export function isArray(value: any): value is any[] {
101
- return Array.isArray(value);
102
- }
103
-
104
- /**
105
- * Checks if a value is a function.
106
- *
107
- * @param {any} value - The value to be checked.
108
- * @return {boolean} - Returns true if the value is a function, otherwise returns false.
109
- */
110
- export function isFunction(value: any): value is Function {
111
- return typeof value === 'function';
112
- }
113
-
114
-
115
- /**
116
- * Compares two objects or arrays to check if they have the same fields and values,
117
- * or the same elements if they are arrays (deep equality check).
118
- *
119
- * @param {any} a - The first object or array.
120
- * @param {any} b - The second object or array.
121
- * @return {boolean} - Returns true if the objects/arrays are deeply equal, otherwise false.
122
- */
123
- export function deepEqual(a: any, b: any): boolean {
124
- if (a === b) {
125
- return true;
126
- }
127
-
128
- if (a === null || b === null || typeof a !== typeof b) {
129
- return false;
130
- }
131
-
132
- if (Array.isArray(a) && Array.isArray(b)) {
133
- if (a.length !== b.length) {
134
- return false;
135
- }
136
- for (let i = 0; i < a.length; i++) {
137
- if (!deepEqual(a[i], b[i])) {
138
- return false;
139
- }
140
- }
141
- return true;
142
- }
143
-
144
- if (typeof a === "object" && typeof b === "object") {
145
- const keysA = Object.keys(a);
146
- const keysB = Object.keys(b);
147
-
148
- if (keysA.length !== keysB.length) {
149
- return false;
150
- }
151
- for (const key of keysA) {
152
- if (!keysB.includes(key) || !deepEqual(a[key], b[key])) {
153
- return false;
154
- }
155
- }
156
- return true;
157
- }
158
-
159
- return false;
160
- }
161
-
162
-
163
- /**
164
- * Submits an HTML form programmatically using the specified HTTP method (default is POST),
165
- * without using AJAX. Supports nested objects and arrays using bracket notation (e.g., `user[name]`, `tags[]`).
166
- *
167
- * @param url - The destination URL where the form will be submitted.
168
- * @param data - An object containing key-value pairs. Supports nested structures and arrays.
169
- * @param method - HTTP method to use: 'POST' or 'GET' (default: 'POST').
170
- * @param target - Optional parameter specifying the target for the form submission (e.g., '_blank', '_self', '_parent', '_top').
171
- */
172
-
173
-
174
- /**
175
- * Compares two objects or arrays to check if they have the same immediate fields and values,
176
- * or the same immediate elements if they are arrays (shallow equality check).
177
- *
178
- * @param {any} a - The first object or array.
179
- * @param {any} b - The second object or array.
180
- * @return {boolean} - Returns true if the objects/arrays are shallowly equal, otherwise false.
181
- */
182
- export function shallowEqual(a: any, b: any): boolean {
183
- if (a === b) {
184
- return true;
185
- }
186
-
187
- if (a === null || b === null || typeof a !== typeof b) {
188
- return false;
189
- }
190
-
191
- if (Array.isArray(a) && Array.isArray(b)) {
192
- if (a.length !== b.length) {
193
- return false;
194
- }
195
- return a.every((value, index) => value === b[index]);
196
- }
197
-
198
- if (typeof a === "object" && typeof b === "object") {
199
- const keysA = Object.keys(a);
200
- const keysB = Object.keys(b);
201
-
202
- if (keysA.length !== keysB.length) {
203
- return false;
204
- }
205
- return keysA.every(key => b.hasOwnProperty(key) && a[key] === b[key]);
206
- }
207
-
208
- return false;
209
- }
210
-
211
-
212
- /**
213
- * Pauses the execution of an asynchronous function for a specified duration.
214
- *
215
- * @param {number} ms - The delay duration in milliseconds.
216
- * @return {Promise<void>} A promise that resolves after the specified delay.
217
- */
218
- export async function delay(ms: number): Promise<void> {
219
- await new Promise(resolve => setTimeout(resolve, ms));
220
- }
221
-
222
- /**
223
- * Checks if a value is undefined.
224
- *
225
- * @param {any} value - The value to check.
226
- * @returns {boolean} - True if the value is undefined, false otherwise.
227
- */
228
- export function isUndefined(value: any): value is undefined {
229
- return typeof value === 'undefined';
230
- }
231
-
232
- /**
233
- * Checks if a value is defined or not.
234
- *
235
- * @param {any} value - The value to be checked.
236
- *
237
- * @return {boolean} - True if the value is defined, false otherwise.
238
- */
239
- export function isDefined(value: any): value is undefined {
240
- return typeof value !== 'undefined';
241
- }
242
-
243
- /**
244
- * Checks if a given value is null.
245
- *
246
- * @param {any} value - The value to check for null.
247
- * @return {boolean} - Returns true if the value is null, otherwise returns false.
248
- */
249
- export function isNull(value: any): value is null {
250
- return value === null;
251
- }
252
-
253
-
254
- /**
255
- * Determines whether the given value is of type bigint.
256
- * @param {any} value - The value to be checked.
257
- * @return {boolean} - Returns true if the value is of type bigint, false otherwise.
258
- */
259
- export function isBigInt(value: any): value is bigint {
260
- return typeof value === 'bigint';
261
- }
262
-
263
- /**
264
- * Checks if a given value is a symbol.
265
- *
266
- * @param {any} value - The value to be checked.
267
- * @return {boolean} - Returns true if the value is a symbol, false otherwise.
268
- */
269
- export function isSymbol(value: any): value is symbol {
270
- return typeof value === 'symbol';
271
- }
272
-
273
- /**
274
- * Checks if a value is null or undefined.
275
- *
276
- * @param {any} value - The value to check.
277
- * @return {boolean} - Returns true if the value is null or undefined, false otherwise.
278
- * @deprecated
279
- */
280
- export function isNullOrUndefined(value: any): boolean {
281
- return value === null || typeof value === 'undefined';
282
- }
283
-
284
- /**
285
- * Checks if a value is null or undefined.
286
- *
287
- * @param {any} value - The value to check.
288
- * @return {boolean} - Returns true if the value is null or undefined, false otherwise.
289
-
290
- */
291
- export function isNullish(value: any): boolean {
292
- return value === null || typeof value === 'undefined';
293
- }
294
-
295
- /**
296
- * Checks if a given value is empty.
297
- *
298
- * @param {any} value - The value to check.
299
- * @return {boolean} - Returns true if the value is empty, otherwise returns false.
300
- */
301
- export function isEmpty(value: any): boolean {
302
- return (Array.isArray(value) && value.length === 0) ||
303
- (typeof value === 'string' && value === '') ||
304
- value === null || typeof value === 'undefined';
305
- }
306
-
307
- /**
308
- * Check if a value is empty or contains only whitespace characters.
309
- *
310
- * @param {any} value - The value to check.
311
- * @return {boolean} Returns true if the value is empty or contains only whitespace characters, otherwise returns false.
312
- */
313
- export function isEmptyOrWhitespace(value: any): boolean {
314
- return (Array.isArray(value) && value.length === 0) ||
315
- (typeof value === 'string' && value.trim() === '') ||
316
- value === null || typeof value === 'undefined';
317
- }
318
-
319
-
320
- /**
321
- * Converts an object into an array of key-value pairs.
322
- *
323
- * @param {Record<string, any>} obj - The object to convert.
324
- * @return {KeyValuePair<string, any>[]} - The array of key-value pairs.
325
- */
326
- export function toPairs(obj: Record<string, any>): KeyValuePair<string, any>[] {
327
-
328
- let output = [];
329
- for (const key in obj) {
330
- output.push(new KeyValuePair(key, obj[key]));
331
- }
332
- return output;
333
-
334
- }
335
-
336
- /**
337
- * Converts a given thing into a Promise.
338
- * @template T
339
- * @param {any} thing - The thing to be converted into a Promise.
340
- * @returns {Promise<T>} - A Promise representing the given thing.
341
- */
342
- export function promisify<T>(thing: Resolvable<T>): Promise<T> {
343
-
344
- if (thing instanceof Promise)
345
- return thing;
346
-
347
-
348
- if (isFunction(thing)) {
349
- return new Promise<T>((resolve, reject) => {
350
- try {
351
- const result = thing();
352
- resolve(result);
353
- } catch (error) {
354
- reject(error);
355
- }
356
- });
357
- }
358
-
359
- return Promise.resolve(thing);
360
- }
361
-
362
-
363
- /**
364
- * Creates a deep clone of the given object.
365
- * @template T
366
- * @param {T} obj - The object to clone.
367
- * @return {T} - The deep clone of the given object.
368
- */
369
- export function deepClone<T>(obj: T): T {
370
- if (obj === null || typeof obj !== 'object') {
371
- return obj;
372
- }
373
-
374
- if (Array.isArray(obj)) {
375
- const copy: any[] = [];
376
- for (const element of obj) {
377
- copy.push(deepClone(element));
378
- }
379
- return copy as T;
380
- }
381
-
382
- const copy: { [key: string]: any } = {};
383
- for (const key in obj) {
384
- if (obj.hasOwnProperty(key)) {
385
- copy[key] = deepClone((obj as { [key: string]: any })[key]);
386
- }
387
- }
388
- return copy as T;
389
- }
390
-
391
- /**
392
- * Returns the type of the given value.
393
- *
394
- * @param {any} value - The value to determine the type of.
395
- * @return {Type} - The type of the given value.
396
- * @deprecated use Type.of(...)
397
- */
398
- export function getType(value: any): Type {
399
-
400
- return Type.of(value);
401
- }
402
-
403
-
404
-
1
+ // noinspection JSUnusedGlobalSymbols
2
+
3
+
4
+ import KeyValuePair from "./key-value-pair.js";
5
+ import type {Resolvable} from "./types.js";
6
+ import Type from "./type.js";
7
+
8
+ export function lazy<T extends object>(factory: () => T): T {
9
+ let instance: T | null = null;
10
+
11
+ const getInstance = (): T => {
12
+ if (!instance) {
13
+ instance = factory();
14
+ }
15
+ return instance;
16
+ };
17
+
18
+ return new Proxy({} as T, {
19
+ get(_, prop, receiver) {
20
+ return Reflect.get(getInstance(), prop, receiver);
21
+ },
22
+ set(_, prop, value, receiver) {
23
+ return Reflect.set(getInstance(), prop, value, receiver);
24
+ },
25
+ has(_, prop) {
26
+ return Reflect.has(getInstance(), prop);
27
+ },
28
+ deleteProperty(_, prop) {
29
+ return Reflect.deleteProperty(getInstance(), prop);
30
+ },
31
+ ownKeys() {
32
+ return Reflect.ownKeys(getInstance());
33
+ },
34
+ getOwnPropertyDescriptor(_, prop) {
35
+ return Reflect.getOwnPropertyDescriptor(getInstance(), prop);
36
+ },
37
+ getPrototypeOf() {
38
+ return Reflect.getPrototypeOf(getInstance());
39
+ },
40
+ });
41
+ }
42
+
43
+ /**
44
+ * Checks if an object is iterable.
45
+ *
46
+ * @param {any} obj - The object to check.
47
+ * @return {boolean} - Returns true if the object is iterable, otherwise false.
48
+ */
49
+ export function isIterable(obj: any): boolean {
50
+ return obj[Symbol.iterator] === 'function';
51
+ }
52
+
53
+ /**
54
+ * Checks if a given value is a string.
55
+ *
56
+ * @param {*} value - The value to check.
57
+ * @return {boolean} - Returns true if the value is a string, otherwise returns false.
58
+ */
59
+ export function isString(value: any): value is string {
60
+ return typeof value === 'string';
61
+ }
62
+
63
+ /**
64
+ * Checks if a value is a number.
65
+ *
66
+ * @param {any} value - The value to check.
67
+ * @return {boolean} - Returns true if the value is a number, otherwise false.
68
+ */
69
+ export function isNumber(value: any): value is number {
70
+ return typeof value === 'number';
71
+ }
72
+
73
+ /**
74
+ * Checks if a given value is a boolean.
75
+ *
76
+ * @param {any} value - The value to be checked.
77
+ *
78
+ * @return {boolean} - Returns true if the value is a boolean, otherwise false.
79
+ */
80
+ export function isBoolean(value: any): value is boolean {
81
+ return typeof value === 'boolean';
82
+ }
83
+
84
+ /**
85
+ * Checks if a value is an object.
86
+ * @param {any} value - The value to be checked.
87
+ * @returns {boolean} - Returns true if the value is an object, otherwise returns false.
88
+ */
89
+ export function isObject(value: any): value is object {
90
+ return value != null && typeof value === 'object' && !Array.isArray(value);
91
+ }
92
+
93
+ /**
94
+ * Determines if a value is an array.
95
+ *
96
+ * @param value - The value to be checked.
97
+ *
98
+ * @return Whether the value is an array.
99
+ */
100
+ export function isArray(value: any): value is any[] {
101
+ return Array.isArray(value);
102
+ }
103
+
104
+ /**
105
+ * Checks if a value is a function.
106
+ *
107
+ * @param {any} value - The value to be checked.
108
+ * @return {boolean} - Returns true if the value is a function, otherwise returns false.
109
+ */
110
+ export function isFunction(value: any): value is Function {
111
+ return typeof value === 'function';
112
+ }
113
+
114
+
115
+ /**
116
+ * Compares two objects or arrays to check if they have the same fields and values,
117
+ * or the same elements if they are arrays (deep equality check).
118
+ *
119
+ * @param {any} a - The first object or array.
120
+ * @param {any} b - The second object or array.
121
+ * @return {boolean} - Returns true if the objects/arrays are deeply equal, otherwise false.
122
+ */
123
+ export function deepEqual(a: any, b: any): boolean {
124
+ if (a === b) {
125
+ return true;
126
+ }
127
+
128
+ if (a === null || b === null || typeof a !== typeof b) {
129
+ return false;
130
+ }
131
+
132
+ if (Array.isArray(a) && Array.isArray(b)) {
133
+ if (a.length !== b.length) {
134
+ return false;
135
+ }
136
+ for (let i = 0; i < a.length; i++) {
137
+ if (!deepEqual(a[i], b[i])) {
138
+ return false;
139
+ }
140
+ }
141
+ return true;
142
+ }
143
+
144
+ if (typeof a === "object" && typeof b === "object") {
145
+ const keysA = Object.keys(a);
146
+ const keysB = Object.keys(b);
147
+
148
+ if (keysA.length !== keysB.length) {
149
+ return false;
150
+ }
151
+ for (const key of keysA) {
152
+ if (!keysB.includes(key) || !deepEqual(a[key], b[key])) {
153
+ return false;
154
+ }
155
+ }
156
+ return true;
157
+ }
158
+
159
+ return false;
160
+ }
161
+
162
+
163
+ /**
164
+ * Submits an HTML form programmatically using the specified HTTP method (default is POST),
165
+ * without using AJAX. Supports nested objects and arrays using bracket notation (e.g., `user[name]`, `tags[]`).
166
+ *
167
+ * @param url - The destination URL where the form will be submitted.
168
+ * @param data - An object containing key-value pairs. Supports nested structures and arrays.
169
+ * @param method - HTTP method to use: 'POST' or 'GET' (default: 'POST').
170
+ * @param target - Optional parameter specifying the target for the form submission (e.g., '_blank', '_self', '_parent', '_top').
171
+ */
172
+
173
+
174
+ /**
175
+ * Compares two objects or arrays to check if they have the same immediate fields and values,
176
+ * or the same immediate elements if they are arrays (shallow equality check).
177
+ *
178
+ * @param {any} a - The first object or array.
179
+ * @param {any} b - The second object or array.
180
+ * @return {boolean} - Returns true if the objects/arrays are shallowly equal, otherwise false.
181
+ */
182
+ export function shallowEqual(a: any, b: any): boolean {
183
+ if (a === b) {
184
+ return true;
185
+ }
186
+
187
+ if (a === null || b === null || typeof a !== typeof b) {
188
+ return false;
189
+ }
190
+
191
+ if (Array.isArray(a) && Array.isArray(b)) {
192
+ if (a.length !== b.length) {
193
+ return false;
194
+ }
195
+ return a.every((value, index) => value === b[index]);
196
+ }
197
+
198
+ if (typeof a === "object" && typeof b === "object") {
199
+ const keysA = Object.keys(a);
200
+ const keysB = Object.keys(b);
201
+
202
+ if (keysA.length !== keysB.length) {
203
+ return false;
204
+ }
205
+ return keysA.every(key => b.hasOwnProperty(key) && a[key] === b[key]);
206
+ }
207
+
208
+ return false;
209
+ }
210
+
211
+
212
+ /**
213
+ * Pauses the execution of an asynchronous function for a specified duration.
214
+ *
215
+ * @param {number} ms - The delay duration in milliseconds.
216
+ * @return {Promise<void>} A promise that resolves after the specified delay.
217
+ */
218
+ export async function delay(ms: number): Promise<void> {
219
+ await new Promise(resolve => setTimeout(resolve, ms));
220
+ }
221
+
222
+ /**
223
+ * Checks if a value is undefined.
224
+ *
225
+ * @param {any} value - The value to check.
226
+ * @returns {boolean} - True if the value is undefined, false otherwise.
227
+ */
228
+ export function isUndefined(value: any): value is undefined {
229
+ return typeof value === 'undefined';
230
+ }
231
+
232
+ /**
233
+ * Checks if a value is defined or not.
234
+ *
235
+ * @param {any} value - The value to be checked.
236
+ *
237
+ * @return {boolean} - True if the value is defined, false otherwise.
238
+ */
239
+ export function isDefined(value: any): value is undefined {
240
+ return typeof value !== 'undefined';
241
+ }
242
+
243
+ /**
244
+ * Checks if a given value is null.
245
+ *
246
+ * @param {any} value - The value to check for null.
247
+ * @return {boolean} - Returns true if the value is null, otherwise returns false.
248
+ */
249
+ export function isNull(value: any): value is null {
250
+ return value === null;
251
+ }
252
+
253
+
254
+ /**
255
+ * Determines whether the given value is of type bigint.
256
+ * @param {any} value - The value to be checked.
257
+ * @return {boolean} - Returns true if the value is of type bigint, false otherwise.
258
+ */
259
+ export function isBigInt(value: any): value is bigint {
260
+ return typeof value === 'bigint';
261
+ }
262
+
263
+ /**
264
+ * Checks if a given value is a symbol.
265
+ *
266
+ * @param {any} value - The value to be checked.
267
+ * @return {boolean} - Returns true if the value is a symbol, false otherwise.
268
+ */
269
+ export function isSymbol(value: any): value is symbol {
270
+ return typeof value === 'symbol';
271
+ }
272
+
273
+ /**
274
+ * Checks if a value is null or undefined.
275
+ *
276
+ * @param {any} value - The value to check.
277
+ * @return {boolean} - Returns true if the value is null or undefined, false otherwise.
278
+ * @deprecated
279
+ */
280
+ export function isNullOrUndefined(value: any): boolean {
281
+ return value === null || typeof value === 'undefined';
282
+ }
283
+
284
+ /**
285
+ * Checks if a value is null or undefined.
286
+ *
287
+ * @param {any} value - The value to check.
288
+ * @return {boolean} - Returns true if the value is null or undefined, false otherwise.
289
+
290
+ */
291
+ export function isNullish(value: any): boolean {
292
+ return value === null || typeof value === 'undefined';
293
+ }
294
+
295
+ /**
296
+ * Checks if a given value is empty.
297
+ *
298
+ * @param {any} value - The value to check.
299
+ * @return {boolean} - Returns true if the value is empty, otherwise returns false.
300
+ */
301
+ export function isEmpty(value: any): boolean {
302
+ return (Array.isArray(value) && value.length === 0) ||
303
+ (typeof value === 'string' && value === '') ||
304
+ value === null || typeof value === 'undefined';
305
+ }
306
+
307
+ /**
308
+ * Check if a value is empty or contains only whitespace characters.
309
+ *
310
+ * @param {any} value - The value to check.
311
+ * @return {boolean} Returns true if the value is empty or contains only whitespace characters, otherwise returns false.
312
+ */
313
+ export function isEmptyOrWhitespace(value: any): boolean {
314
+ return (Array.isArray(value) && value.length === 0) ||
315
+ (typeof value === 'string' && value.trim() === '') ||
316
+ value === null || typeof value === 'undefined';
317
+ }
318
+
319
+
320
+ /**
321
+ * Converts an object into an array of key-value pairs.
322
+ *
323
+ * @param {Record<string, any>} obj - The object to convert.
324
+ * @return {KeyValuePair<string, any>[]} - The array of key-value pairs.
325
+ */
326
+ export function toPairs(obj: Record<string, any>): KeyValuePair<string, any>[] {
327
+
328
+ let output = [];
329
+ for (const key in obj) {
330
+ output.push(new KeyValuePair(key, obj[key]));
331
+ }
332
+ return output;
333
+
334
+ }
335
+
336
+ /**
337
+ * Converts a given thing into a Promise.
338
+ * @template T
339
+ * @param {any} thing - The thing to be converted into a Promise.
340
+ * @returns {Promise<T>} - A Promise representing the given thing.
341
+ */
342
+ export function promisify<T>(thing: Resolvable<T>): Promise<T> {
343
+
344
+ if (thing instanceof Promise)
345
+ return thing;
346
+
347
+
348
+ if (isFunction(thing)) {
349
+ return new Promise<T>((resolve, reject) => {
350
+ try {
351
+ const result = thing();
352
+ resolve(result);
353
+ } catch (error) {
354
+ reject(error);
355
+ }
356
+ });
357
+ }
358
+
359
+ return Promise.resolve(thing);
360
+ }
361
+
362
+
363
+ /**
364
+ * Creates a deep clone of the given object.
365
+ * @template T
366
+ * @param {T} obj - The object to clone.
367
+ * @return {T} - The deep clone of the given object.
368
+ */
369
+ export function deepClone<T>(obj: T): T {
370
+ if (obj === null || typeof obj !== 'object') {
371
+ return obj;
372
+ }
373
+
374
+ if (Array.isArray(obj)) {
375
+ const copy: any[] = [];
376
+ for (const element of obj) {
377
+ copy.push(deepClone(element));
378
+ }
379
+ return copy as T;
380
+ }
381
+
382
+ const copy: { [key: string]: any } = {};
383
+ for (const key in obj) {
384
+ if (obj.hasOwnProperty(key)) {
385
+ copy[key] = deepClone((obj as { [key: string]: any })[key]);
386
+ }
387
+ }
388
+ return copy as T;
389
+ }
390
+
391
+ /**
392
+ * Returns the type of the given value.
393
+ *
394
+ * @param {any} value - The value to determine the type of.
395
+ * @return {Type} - The type of the given value.
396
+ * @deprecated use Type.of(...)
397
+ */
398
+ export function getType(value: any): Type {
399
+
400
+ return Type.of(value);
401
+ }
402
+
403
+
404
+