@hyper-fetch/react 5.0.1 → 5.1.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.
@@ -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
- const firstValueType = Object.prototype.toString.call(firstValue);
21
- const secondValueType = Object.prototype.toString.call(secondValue);
20
+ if (firstValue === secondValue) return true;
22
21
 
23
- const firstType = typeof firstValue;
24
- const secondType = typeof secondValue;
22
+ try {
23
+ const firstValueType = Object.prototype.toString.call(firstValue);
24
+ const secondValueType = Object.prototype.toString.call(secondValue);
25
25
 
26
- const isType = (type: unknown) => firstType === type && secondType === type;
27
- const isTypeValue = (type: unknown) => firstValueType === type && secondValueType === type;
26
+ const firstType = typeof firstValue;
27
+ const secondType = typeof secondValue;
28
28
 
29
- // Compared types are different
30
- if (firstValueType !== secondValueType) return false;
29
+ const isType = (type: unknown) => firstType === type && secondType === type;
30
+ const isTypeValue = (type: unknown) => firstValueType === type && secondValueType === type;
31
31
 
32
- // Null
33
- if (firstValue === null && secondValue === null) return true;
32
+ // Compared types are different
33
+ if (firstValueType !== secondValueType) return false;
34
34
 
35
- // NaN
36
- if (isType("number") && Number.isNaN(firstValue) && Number.isNaN(secondValue)) return true;
35
+ // Null
36
+ if (firstValue === null && secondValue === null) return true;
37
37
 
38
- // Empty Array or Object
39
- if (isEmpty(firstValue) && isEmpty(secondValue)) return true;
38
+ // NaN
39
+ if (isType("number") && Number.isNaN(firstValue) && Number.isNaN(secondValue)) return true;
40
40
 
41
- // Array
42
- if (Array.isArray(firstValue) && Array.isArray(secondValue)) {
43
- if (firstValue.length !== secondValue.length) return false;
41
+ // Empty Array or Object
42
+ if (isEmpty(firstValue) && isEmpty(secondValue)) return true;
44
43
 
45
- return !firstValue.some((element, i) => !isEqual(element, secondValue[i]));
46
- }
44
+ // Array
45
+ if (Array.isArray(firstValue) && Array.isArray(secondValue)) {
46
+ if (firstValue.length !== secondValue.length) return false;
47
47
 
48
- // Object
49
- if (isType("object") && isTypeValue("[object Object]")) {
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
- return !Object.entries(firstValue as object).some(
53
- ([key, value]) => !isEqual(value, (secondValue as Record<string, unknown>)[key]),
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
- // Date
58
- if (firstValue instanceof Date && secondValue instanceof Date) {
59
- return +firstValue === +secondValue;
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
- // undefined, string, number, bool
63
- return firstValue === secondValue;
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
  };