@germondai/ts-utils 0.0.3 → 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 {
@@ -248,11 +276,12 @@ var buildUrl = (baseUrl, path, queryParams) => {
248
276
  const normalizedPath = path.startsWith("/") ? path : `/${path}`;
249
277
  url.pathname = `${url.pathname.replace(/\/$/, "")}${normalizedPath}`;
250
278
  }
251
- if (queryParams) {
279
+ if (queryParams)
252
280
  Object.entries(queryParams).forEach(([key, value]) => {
253
- url.searchParams.set(key, String(value));
281
+ if (value === undefined)
282
+ return;
283
+ url.searchParams.set(key, value === null ? "" : String(value));
254
284
  });
255
- }
256
285
  return url.toString();
257
286
  };
258
287
  export {
@@ -291,6 +320,7 @@ export {
291
320
  isIPv4,
292
321
  isHexColor,
293
322
  isHex,
323
+ isEqual,
294
324
  isEmpty,
295
325
  isEmail,
296
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;
@@ -46,4 +46,4 @@ export declare const removeQueryParam: (urlString: string, key: string) => strin
46
46
  * // returns 'https://example.com/api/v1/resource?search=test&page=2'
47
47
  * buildUrl('https://example.com', '/api/v1/resource', { search: 'test', page: 2 });
48
48
  */
49
- export declare const buildUrl: (baseUrl: string, path?: string, queryParams?: Record<string, string | number | boolean>) => string;
49
+ export declare const buildUrl: (baseUrl: string, path?: string, queryParams?: Record<string, string | number | boolean | null | undefined>) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@germondai/ts-utils",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Germond's TypeScript Utilities",
5
5
  "repository": {
6
6
  "type": "git",