@lowentry/utils 1.23.2 → 1.24.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowentry/utils",
3
- "version": "1.23.2",
3
+ "version": "1.24.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -24,13 +24,11 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@babel/runtime": "*",
27
- "clone-deep": "^4",
28
- "fast-deep-equal": "^3"
27
+ "clone-deep": "^4"
29
28
  },
30
29
  "peerDependencies": {
31
30
  "@babel/runtime": "*",
32
- "clone-deep": "^4",
33
- "fast-deep-equal": "^3"
31
+ "clone-deep": "^4"
34
32
  },
35
33
  "devDependencies": {
36
34
  "@babel/core": "^7.24.7",
package/src/LeUtils.js CHANGED
@@ -1,4 +1,3 @@
1
- import FastDeepEqual from 'fast-deep-equal';
2
1
  import CloneDeep from 'clone-deep';
3
2
  import {ISSET, IS_OBJECT, IS_ARRAY, STRING, INT_LAX, FLOAT_LAX, INT_LAX_ANY, FLOAT_LAX_ANY, ARRAY} from './LeTypes.js';
4
3
 
@@ -37,14 +36,169 @@ const findTransactionalValueChange = (transactionalValue, changeId) =>
37
36
 
38
37
  export const LeUtils = {
39
38
  /**
40
- * A deep equals implementation (npm package "fast-deep-equal").
39
+ * A deep equals implementation.
41
40
  *
42
- * @param {*} value The value to compare.
43
- * @param {*} other The other value to compare.
41
+ * @param {*} a The value to compare.
42
+ * @param {*} b The other value to compare.
44
43
  * @returns {boolean} Returns true if the values are equivalent.
45
44
  */
46
45
  equals:
47
- (value, other) => FastDeepEqual(value, other),
46
+ (a, b) =>
47
+ {
48
+ if(a === b)
49
+ {
50
+ return true;
51
+ }
52
+
53
+ if(a && b && typeof a == 'object' && typeof b == 'object')
54
+ {
55
+ if(a.constructor !== b.constructor)
56
+ {
57
+ return false;
58
+ }
59
+
60
+ if(Array.isArray(a))
61
+ {
62
+ const length = a.length;
63
+ if(length != b.length)
64
+ {
65
+ return false;
66
+ }
67
+ for(let i = length; i-- !== 0;)
68
+ {
69
+ if(!LeUtils.equals(a[i], b[i]))
70
+ {
71
+ return false;
72
+ }
73
+ }
74
+ return true;
75
+ }
76
+ if((a instanceof Map) && (b instanceof Map))
77
+ {
78
+ if(a.size !== b.size)
79
+ {
80
+ return false;
81
+ }
82
+ for(let i of a.entries())
83
+ {
84
+ if(!b.has(i[0]))
85
+ {
86
+ return false;
87
+ }
88
+ }
89
+ for(let i of a.entries())
90
+ {
91
+ if(!LeUtils.equals(i[1], b.get(i[0])))
92
+ {
93
+ return false;
94
+ }
95
+ }
96
+ return true;
97
+ }
98
+ if((a instanceof Set) && (b instanceof Set))
99
+ {
100
+ if(a.size !== b.size)
101
+ {
102
+ return false;
103
+ }
104
+ for(let i of a.entries())
105
+ {
106
+ if(!b.has(i[0]))
107
+ {
108
+ return false;
109
+ }
110
+ }
111
+ return true;
112
+ }
113
+ if(ArrayBuffer.isView(a) && ArrayBuffer.isView(b))
114
+ {
115
+ if(('length' in a) && ('length' in b) && (typeof a.length === 'number') && (typeof b.length === 'number'))
116
+ {
117
+ if(a.length != b.length)
118
+ {
119
+ return false;
120
+ }
121
+ for(let i = a.length; i-- !== 0;)
122
+ {
123
+ if(a[i] !== b[i])
124
+ {
125
+ return false;
126
+ }
127
+ }
128
+ return true;
129
+ }
130
+ if(('byteLength' in a) && ('byteLength' in b) && (typeof a.byteLength === 'number') && (typeof b.byteLength === 'number') && ('getUint8' in a) && ('getUint8' in b) && (typeof a.getUint8 === 'function') && (typeof b.getUint8 === 'function'))
131
+ {
132
+ if(a.byteLength !== b.byteLength)
133
+ {
134
+ return false;
135
+ }
136
+ for(let i = a.byteLength; i-- !== 0;)
137
+ {
138
+ if(a.getUint8(i) !== b.getUint8(i))
139
+ {
140
+ return false;
141
+ }
142
+ }
143
+ return true;
144
+ }
145
+ return false;
146
+ }
147
+
148
+ if(a.constructor === RegExp)
149
+ {
150
+ return a.source === b.source && a.flags === b.flags;
151
+ }
152
+ if(a.valueOf !== Object.prototype.valueOf)
153
+ {
154
+ return a.valueOf() === b.valueOf();
155
+ }
156
+ if(a.toString !== Object.prototype.toString)
157
+ {
158
+ return a.toString() === b.toString();
159
+ }
160
+
161
+ if(a.constructor && (a.constructor !== Object) && (a.constructor !== Array) && (Object.getPrototypeOf(a) !== Object.prototype))
162
+ {
163
+ if(typeof a.equals === 'function')
164
+ {
165
+ return a.equals(b);
166
+ }
167
+ return false;
168
+ }
169
+
170
+ const keys = Object.keys(a);
171
+ const length = keys.length;
172
+ if(length !== Object.keys(b).length)
173
+ {
174
+ return false;
175
+ }
176
+ for(let i = length; i-- !== 0;)
177
+ {
178
+ if(!Object.prototype.hasOwnProperty.call(b, keys[i]))
179
+ {
180
+ return false;
181
+ }
182
+ }
183
+ for(let i = length; i-- !== 0;)
184
+ {
185
+ const key = keys[i];
186
+ if((key === '_owner') && a.$$typeof)
187
+ {
188
+ // React-specific: avoid traversing _owner, it contains circular references, and is not needed when comparing the actual element
189
+ continue;
190
+ }
191
+ if(!LeUtils.equals(a[key], b[key]))
192
+ {
193
+ return false;
194
+ }
195
+ }
196
+ return true;
197
+ }
198
+
199
+ // true if both are NaN, false otherwise
200
+ return ((a !== a) && (b !== b));
201
+ },
48
202
 
49
203
  /**
50
204
  * Performs a deep equality comparison between two collections (objects, maps, arrays, etc), sorting on the keys before comparing them.