@adobe/spacecat-shared-utils 1.17.1 → 1.18.0
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/functions.js +39 -1
- package/src/index.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-utils-v1.18.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.17.1...@adobe/spacecat-shared-utils-v1.18.0) (2024-07-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* utils deepEqual ([#282](https://github.com/adobe/spacecat-shared/issues/282)) ([d17ef5f](https://github.com/adobe/spacecat-shared/commit/d17ef5ff6dcacb7ddb3e60512d40d66202e14ffc))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-utils-v1.17.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.17.0...@adobe/spacecat-shared-utils-v1.17.1) (2024-07-02)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/functions.js
CHANGED
|
@@ -63,7 +63,7 @@ function isNumber(value) {
|
|
|
63
63
|
* @returns {boolean} True if the parameter is an object, false otherwise.
|
|
64
64
|
*/
|
|
65
65
|
function isObject(value) {
|
|
66
|
-
return
|
|
66
|
+
return value !== null && typeof value === 'object' && !isArray(value);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
@@ -75,6 +75,43 @@ function isNonEmptyObject(value) {
|
|
|
75
75
|
return isObject(value) && Object.keys(value).length > 0;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Deeply compares two objects or arrays for equality. Supports nested objects and arrays.
|
|
80
|
+
* Does not support circular references. Does not compare functions.
|
|
81
|
+
* @param {unknown} x - The first object or array to compare.
|
|
82
|
+
* @param {unknown} y - The second object or array to compare.
|
|
83
|
+
* @return {boolean} True if the objects or arrays are equal, false otherwise.
|
|
84
|
+
*/
|
|
85
|
+
function deepEqual(x, y) {
|
|
86
|
+
if (x === y) return true;
|
|
87
|
+
|
|
88
|
+
if (isArray(x) && isArray(y)) {
|
|
89
|
+
if (x.length !== y.length) return false;
|
|
90
|
+
for (let i = 0; i < x.length; i += 1) {
|
|
91
|
+
if (!deepEqual(x[i], y[i])) return false;
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!isObject(x) || !isObject(y)) return false;
|
|
97
|
+
|
|
98
|
+
if (x.constructor !== y.constructor) return false;
|
|
99
|
+
|
|
100
|
+
if (x instanceof Date) return x.getTime() === y.getTime();
|
|
101
|
+
if (x instanceof RegExp) return x.toString() === y.toString();
|
|
102
|
+
|
|
103
|
+
const xKeys = Object.keys(x).filter((key) => typeof x[key] !== 'function');
|
|
104
|
+
const yKeys = Object.keys(y).filter((key) => typeof y[key] !== 'function');
|
|
105
|
+
|
|
106
|
+
if (xKeys.length !== yKeys.length) return false;
|
|
107
|
+
|
|
108
|
+
for (const key of xKeys) {
|
|
109
|
+
if (!Object.prototype.hasOwnProperty.call(y, key) || !deepEqual(x[key], y[key])) return false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
78
115
|
/**
|
|
79
116
|
* Determines if the given parameter is a string.
|
|
80
117
|
*
|
|
@@ -210,4 +247,5 @@ export {
|
|
|
210
247
|
toBoolean,
|
|
211
248
|
isValidUrl,
|
|
212
249
|
dateAfterDays,
|
|
250
|
+
deepEqual,
|
|
213
251
|
};
|
package/src/index.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ export function isValidUrl(urlString: string): boolean;
|
|
|
39
39
|
|
|
40
40
|
export function dateAfterDays(days: number, dateString: string): Date;
|
|
41
41
|
|
|
42
|
+
export function deepEqual(a: unknown, b: unknown): boolean;
|
|
43
|
+
|
|
42
44
|
export function sqsWrapper(fn: (message: object, context: object) => Promise<Response>):
|
|
43
45
|
(request: object, context: object) => Promise<Response>;
|
|
44
46
|
|