@lowentry/utils 1.23.1 → 1.23.3
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/index.d.ts +1 -1
- package/index.js +227 -93
- package/index.js.map +1 -1
- package/package.json +3 -5
- package/src/LeUtils.js +165 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowentry/utils",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.3",
|
|
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,166 @@ const findTransactionalValueChange = (transactionalValue, changeId) =>
|
|
|
37
36
|
|
|
38
37
|
export const LeUtils = {
|
|
39
38
|
/**
|
|
40
|
-
* A deep equals implementation
|
|
39
|
+
* A deep equals implementation.
|
|
41
40
|
*
|
|
42
|
-
* @param {*}
|
|
43
|
-
* @param {*}
|
|
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
|
-
(
|
|
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
|
+
const proto = Object.getPrototypeOf(a);
|
|
162
|
+
if((a.constructor !== Object) && (a.constructor !== Array) && (proto !== Object.prototype) && (typeof a.equals === 'function'))
|
|
163
|
+
{
|
|
164
|
+
return a.equals(b);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const keys = Object.keys(a);
|
|
168
|
+
const length = keys.length;
|
|
169
|
+
if(length !== Object.keys(b).length)
|
|
170
|
+
{
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
for(let i = length; i-- !== 0;)
|
|
174
|
+
{
|
|
175
|
+
if(!Object.prototype.hasOwnProperty.call(b, keys[i]))
|
|
176
|
+
{
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
for(let i = length; i-- !== 0;)
|
|
181
|
+
{
|
|
182
|
+
const key = keys[i];
|
|
183
|
+
if((key === '_owner') && a.$$typeof)
|
|
184
|
+
{
|
|
185
|
+
// React-specific: avoid traversing _owner, it contains circular references, and is not needed when comparing the actual element
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if(!LeUtils.equals(a[key], b[key]))
|
|
189
|
+
{
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// true if both are NaN, false otherwise
|
|
197
|
+
return ((a !== a) && (b !== b));
|
|
198
|
+
},
|
|
48
199
|
|
|
49
200
|
/**
|
|
50
201
|
* Performs a deep equality comparison between two collections (objects, maps, arrays, etc), sorting on the keys before comparing them.
|
|
@@ -1353,11 +1504,11 @@ export const LeUtils = {
|
|
|
1353
1504
|
|
|
1354
1505
|
ms = FLOAT_LAX(ms);
|
|
1355
1506
|
|
|
1356
|
-
let lastTime = performance?.now?.() ?? 0;
|
|
1507
|
+
let lastTime = globalThis?.performance?.now?.() ?? 0;
|
|
1357
1508
|
/** @type {number|null} */
|
|
1358
1509
|
let handler = globalThis.setTimeout(() =>
|
|
1359
1510
|
{
|
|
1360
|
-
const currentTime = performance?.now?.() ?? 0;
|
|
1511
|
+
const currentTime = globalThis?.performance?.now?.() ?? 0;
|
|
1361
1512
|
try
|
|
1362
1513
|
{
|
|
1363
1514
|
callback((currentTime - lastTime) / 1000);
|
|
@@ -1419,11 +1570,11 @@ export const LeUtils = {
|
|
|
1419
1570
|
};
|
|
1420
1571
|
}
|
|
1421
1572
|
|
|
1422
|
-
let lastTime = performance?.now?.() ?? 0;
|
|
1573
|
+
let lastTime = globalThis?.performance?.now?.() ?? 0;
|
|
1423
1574
|
/** @type {number|null} */
|
|
1424
1575
|
let handler = globalThis.setInterval(() =>
|
|
1425
1576
|
{
|
|
1426
|
-
const currentTime = performance?.now?.() ?? 0;
|
|
1577
|
+
const currentTime = globalThis?.performance?.now?.() ?? 0;
|
|
1427
1578
|
try
|
|
1428
1579
|
{
|
|
1429
1580
|
callback((currentTime - lastTime) / 1000);
|
|
@@ -1474,7 +1625,7 @@ export const LeUtils = {
|
|
|
1474
1625
|
|
|
1475
1626
|
let run = true;
|
|
1476
1627
|
let requestAnimationFrameId = null;
|
|
1477
|
-
let lastTime = performance?.now?.() ?? 0;
|
|
1628
|
+
let lastTime = globalThis?.performance?.now?.() ?? 0;
|
|
1478
1629
|
const tick = () =>
|
|
1479
1630
|
{
|
|
1480
1631
|
if(run)
|
|
@@ -1483,7 +1634,7 @@ export const LeUtils = {
|
|
|
1483
1634
|
{
|
|
1484
1635
|
run = false;
|
|
1485
1636
|
requestAnimationFrameId = null;
|
|
1486
|
-
const currentTime = performance?.now?.() ?? 0;
|
|
1637
|
+
const currentTime = globalThis?.performance?.now?.() ?? 0;
|
|
1487
1638
|
try
|
|
1488
1639
|
{
|
|
1489
1640
|
callback((currentTime - lastTime) / 1000);
|
|
@@ -1554,7 +1705,7 @@ export const LeUtils = {
|
|
|
1554
1705
|
|
|
1555
1706
|
let run = true;
|
|
1556
1707
|
let requestAnimationFrameId = null;
|
|
1557
|
-
let lastTime = performance?.now?.() ?? 0;
|
|
1708
|
+
let lastTime = globalThis?.performance?.now?.() ?? 0;
|
|
1558
1709
|
let frames = intervalFrames;
|
|
1559
1710
|
const tick = () =>
|
|
1560
1711
|
{
|
|
@@ -1562,7 +1713,7 @@ export const LeUtils = {
|
|
|
1562
1713
|
{
|
|
1563
1714
|
if(frames <= 0)
|
|
1564
1715
|
{
|
|
1565
|
-
let currentTime = performance?.now?.() ?? 0;
|
|
1716
|
+
let currentTime = globalThis?.performance?.now?.() ?? 0;
|
|
1566
1717
|
try
|
|
1567
1718
|
{
|
|
1568
1719
|
callback((currentTime - lastTime) / 1000);
|
|
@@ -2144,7 +2295,7 @@ export const LeUtils = {
|
|
|
2144
2295
|
try
|
|
2145
2296
|
{
|
|
2146
2297
|
// noinspection JSDeprecatedSymbols
|
|
2147
|
-
now = (performance?.timeOrigin || performance?.timing?.navigationStart || 0) + (performance?.now?.() ?? 0);
|
|
2298
|
+
now = (globalThis?.performance?.timeOrigin || globalThis?.performance?.timing?.navigationStart || 0) + (globalThis?.performance?.now?.() ?? 0);
|
|
2148
2299
|
}
|
|
2149
2300
|
catch(e)
|
|
2150
2301
|
{
|