@germondai/ts-utils 0.0.4 → 0.0.5

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/module.js CHANGED
@@ -69,6 +69,34 @@ var unescapeHTML = (str) => {
69
69
  };
70
70
  // src/runtime/data.ts
71
71
  var clone = (data) => JSON.parse(JSON.stringify(data));
72
+ var isEqual = (a, b) => {
73
+ if (a === b)
74
+ return true;
75
+ if (a == null || b == null)
76
+ return false;
77
+ if (typeof a !== typeof b)
78
+ return false;
79
+ if (typeof a === "object") {
80
+ if (Array.isArray(a) && Array.isArray(b)) {
81
+ if (a.length !== b.length)
82
+ return false;
83
+ for (let i = 0;i < a.length; i++)
84
+ if (!isEqual(a[i], b[i]))
85
+ return false;
86
+ return true;
87
+ } else {
88
+ const keysA = Object.keys(a);
89
+ const keysB = Object.keys(b);
90
+ if (keysA.length !== keysB.length)
91
+ return false;
92
+ for (const key of keysA)
93
+ if (!keysB.includes(key) || !isEqual(a[key], b[key]))
94
+ return false;
95
+ return true;
96
+ }
97
+ }
98
+ return false;
99
+ };
72
100
  // src/runtime/errors.ts
73
101
  var catchError = async (promise, errorsToCatch) => {
74
102
  try {
@@ -292,6 +320,7 @@ export {
292
320
  isIPv4,
293
321
  isHexColor,
294
322
  isHex,
323
+ isEqual,
295
324
  isEmpty,
296
325
  isEmail,
297
326
  isDomain,
@@ -7,3 +7,19 @@
7
7
  * @returns A deep copy of the data.
8
8
  */
9
9
  export declare const clone: <T>(data: T) => T;
10
+ /**
11
+ * Compares two values of the same type to determine if they are deeply equal.
12
+ *
13
+ * @typeParam T - The type of the values being compared.
14
+ * @param a - The first value to compare.
15
+ * @param b - The second value to compare.
16
+ * @returns `true` if the values are deeply equal, otherwise `false`.
17
+ *
18
+ * @remarks
19
+ * - For primitive types, the function uses strict equality (`===`).
20
+ * - For `null` or `undefined`, the function returns `false` if one value is nullish and the other is not.
21
+ * - For arrays, the function checks if they have the same length and recursively compares their elements.
22
+ * - For objects, the function checks if they have the same keys and recursively compares their corresponding values.
23
+ * - The function does not handle circular references and may result in a stack overflow for deeply nested structures.
24
+ */
25
+ export declare const isEqual: <T>(a: T, b: T) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@germondai/ts-utils",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Germond's TypeScript Utilities",
5
5
  "repository": {
6
6
  "type": "git",