@hyper-fetch/react 5.0.1 → 5.0.2
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/index.cjs.js +41 -28
- package/dist/index.cjs.js.map +2 -2
- package/dist/index.d.ts +7 -7
- package/dist/index.esm.js +41 -28
- package/dist/index.esm.js.map +2 -2
- package/package.json +2 -3
- package/src/helpers/use-tracked-state/use-tracked-state.types.ts +3 -2
- package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +8 -4
- package/src/hooks/use-fetch/use-fetch.types.ts +2 -2
- package/src/hooks/use-submit/use-submit.types.ts +3 -9
- package/src/utils/deep-equal.utils.ts +39 -32
|
@@ -17,48 +17,55 @@ export const isEmpty = (value: unknown): boolean => {
|
|
|
17
17
|
* @returns true when elements are equal
|
|
18
18
|
*/
|
|
19
19
|
export const isEqual = (firstValue: unknown, secondValue: unknown): boolean => {
|
|
20
|
-
|
|
21
|
-
const secondValueType = Object.prototype.toString.call(secondValue);
|
|
20
|
+
if (firstValue === secondValue) return true;
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
try {
|
|
23
|
+
const firstValueType = Object.prototype.toString.call(firstValue);
|
|
24
|
+
const secondValueType = Object.prototype.toString.call(secondValue);
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const firstType = typeof firstValue;
|
|
27
|
+
const secondType = typeof secondValue;
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const isType = (type: unknown) => firstType === type && secondType === type;
|
|
30
|
+
const isTypeValue = (type: unknown) => firstValueType === type && secondValueType === type;
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
// Compared types are different
|
|
33
|
+
if (firstValueType !== secondValueType) return false;
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
// Null
|
|
36
|
+
if (firstValue === null && secondValue === null) return true;
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
// NaN
|
|
39
|
+
if (isType("number") && Number.isNaN(firstValue) && Number.isNaN(secondValue)) return true;
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (firstValue.length !== secondValue.length) return false;
|
|
41
|
+
// Empty Array or Object
|
|
42
|
+
if (isEmpty(firstValue) && isEmpty(secondValue)) return true;
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
// Array
|
|
45
|
+
if (Array.isArray(firstValue) && Array.isArray(secondValue)) {
|
|
46
|
+
if (firstValue.length !== secondValue.length) return false;
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (Object.keys(firstValue as object).length !== Object.keys(secondValue as object).length) return false;
|
|
48
|
+
return !firstValue.some((element, i) => !isEqual(element, secondValue[i]));
|
|
49
|
+
}
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
51
|
+
// Object
|
|
52
|
+
if (isType("object") && isTypeValue("[object Object]")) {
|
|
53
|
+
if (Object.keys(firstValue as object).length !== Object.keys(secondValue as object).length) return false;
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
return !Object.entries(firstValue as object).some(
|
|
56
|
+
([key, value]) => !isEqual(value, (secondValue as Record<string, unknown>)[key]),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
// Date
|
|
61
|
+
if (firstValue instanceof Date && secondValue instanceof Date) {
|
|
62
|
+
return +firstValue === +secondValue;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// undefined, string, number, bool
|
|
66
|
+
return firstValue === secondValue;
|
|
67
|
+
} catch (err) {
|
|
68
|
+
console.error(err);
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
64
71
|
};
|