@lowentry/utils 1.25.2 → 2.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/LICENSE +23 -0
- package/README.md +0 -2
- package/package.json +52 -53
- package/api-extractor.json +0 -43
- package/index.d.ts +0 -454
- package/index.js +0 -4150
- package/index.js.map +0 -1
- package/src/LeTypes.js +0 -254
- package/src/LeUtils.js +0 -3597
- package/src/classes/EventEmitter.js +0 -124
- package/src/classes/LinkedList.js +0 -145
- package/src/classes/SerializableMap.js +0 -17
- package/src/classes/TreeSet.js +0 -235
- package/src/index.js +0 -6
- package/tsconfig.d.ts +0 -1
- package/tsconfig.json +0 -39
package/index.js
DELETED
|
@@ -1,4150 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
2
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
-
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
4
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
|
-
import _typeof from '@babel/runtime/helpers/typeof';
|
|
6
|
-
import '@babel/runtime/helpers/awaitAsyncGenerator';
|
|
7
|
-
import _wrapAsyncGenerator from '@babel/runtime/helpers/wrapAsyncGenerator';
|
|
8
|
-
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
9
|
-
import CloneDeep from 'clone-deep';
|
|
10
|
-
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
11
|
-
import _createClass from '@babel/runtime/helpers/createClass';
|
|
12
|
-
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
|
|
13
|
-
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
|
|
14
|
-
import _inherits from '@babel/runtime/helpers/inherits';
|
|
15
|
-
import _wrapNativeSuper from '@babel/runtime/helpers/wrapNativeSuper';
|
|
16
|
-
|
|
17
|
-
var REGEX_ALL_NON_FLOAT_CHARACTERS = /[^0-9.\-]/g;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Returns true if the value is set (not undefined and not null).
|
|
21
|
-
*
|
|
22
|
-
* @param {*} value
|
|
23
|
-
* @returns {boolean}
|
|
24
|
-
*/
|
|
25
|
-
var ISSET = function ISSET(value) {
|
|
26
|
-
return typeof value !== 'undefined' && value !== null;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Returns true if the value is an array.
|
|
31
|
-
*
|
|
32
|
-
* @param {*} value
|
|
33
|
-
* @returns {boolean}
|
|
34
|
-
*/
|
|
35
|
-
var IS_ARRAY = function IS_ARRAY(value) {
|
|
36
|
-
return Array.isArray(value);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Ensures the given value is an array (returns the value wrapped in an array if it's not).
|
|
41
|
-
*
|
|
42
|
-
* @param {*} value
|
|
43
|
-
* @returns {*[]}
|
|
44
|
-
*/
|
|
45
|
-
var ARRAY = function ARRAY(value) {
|
|
46
|
-
return IS_ARRAY(value) ? value : typeof value !== 'undefined' ? [value] : [];
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Returns true if the value is an object.
|
|
51
|
-
*
|
|
52
|
-
* @param {*} value
|
|
53
|
-
* @returns {boolean}
|
|
54
|
-
*/
|
|
55
|
-
var IS_OBJECT = function IS_OBJECT(value) {
|
|
56
|
-
return _typeof(value) === 'object' && value !== null && !Array.isArray(value);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Ensures the given value is an object (returns an empty object if it's not).
|
|
61
|
-
*
|
|
62
|
-
* @param value
|
|
63
|
-
* @returns {Object}
|
|
64
|
-
*/
|
|
65
|
-
var OBJECT = function OBJECT(value) {
|
|
66
|
-
return IS_OBJECT(value) ? value : {};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Ensures the given value is a string (casts it to a string if it's not, null and undefined will return an empty string).
|
|
71
|
-
*
|
|
72
|
-
* @param {*} value
|
|
73
|
-
* @returns {string}
|
|
74
|
-
*/
|
|
75
|
-
var STRING = function STRING(value) {
|
|
76
|
-
return ISSET(value) ? '' + value : '';
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Returns the first non-null non-undefined value as a string.
|
|
81
|
-
*
|
|
82
|
-
* @param {*} values
|
|
83
|
-
* @returns {string}
|
|
84
|
-
*/
|
|
85
|
-
var STRING_ANY = function STRING_ANY() {
|
|
86
|
-
for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
87
|
-
values[_key] = arguments[_key];
|
|
88
|
-
}
|
|
89
|
-
for (var _i = 0, _values = values; _i < _values.length; _i++) {
|
|
90
|
-
var value = _values[_i];
|
|
91
|
-
if (ISSET(value)) {
|
|
92
|
-
return '' + value;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return '';
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Ensures the given value is a boolean.
|
|
100
|
-
*
|
|
101
|
-
* This will work differently than !!value, as it will try to figure out the most logical boolean value from the given value.
|
|
102
|
-
*
|
|
103
|
-
* @param {*} value
|
|
104
|
-
* @returns {boolean}
|
|
105
|
-
*/
|
|
106
|
-
var BOOL = function BOOL(value) {
|
|
107
|
-
return BOOL_ANY(value);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Returns the first non-null non-undefined boolean-castable value as a boolean.
|
|
112
|
-
*
|
|
113
|
-
* @param {*} values
|
|
114
|
-
* @returns {boolean}
|
|
115
|
-
*/
|
|
116
|
-
var BOOL_ANY = function BOOL_ANY() {
|
|
117
|
-
for (var _len2 = arguments.length, values = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
118
|
-
values[_key2] = arguments[_key2];
|
|
119
|
-
}
|
|
120
|
-
for (var _i2 = 0, _values2 = values; _i2 < _values2.length; _i2++) {
|
|
121
|
-
var value = _values2[_i2];
|
|
122
|
-
if (!ISSET(value)) {
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
if (typeof value === 'boolean') {
|
|
126
|
-
return value;
|
|
127
|
-
}
|
|
128
|
-
if (typeof value === 'number') {
|
|
129
|
-
if (!isNaN(value)) {
|
|
130
|
-
return value !== 0;
|
|
131
|
-
}
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
if (typeof value === 'string') {
|
|
135
|
-
value = value.toLowerCase().trim();
|
|
136
|
-
if (value === '' || value === 'false' || value === 'no' || value === 'off' || value === '0') {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
if (value === 'true' || value === 'yes' || value === 'on' || value === '1') {
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
|
-
var _float = +value;
|
|
143
|
-
if (!isNaN(_float)) {
|
|
144
|
-
return _float !== 0;
|
|
145
|
-
}
|
|
146
|
-
// unrecognized string, let's try the next value, else we return false (after the loop)
|
|
147
|
-
}
|
|
148
|
-
if (IS_ARRAY(value) || IS_OBJECT(value)) {
|
|
149
|
-
return !!value;
|
|
150
|
-
}
|
|
151
|
-
// unrecognized type, let's try the next value, else we return false (after the loop)
|
|
152
|
-
}
|
|
153
|
-
return false;
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Ensures the given value is an integer (attempts to cast it to an integer if it's not, null and undefined will return 0).
|
|
158
|
-
*
|
|
159
|
-
* @param {*} value
|
|
160
|
-
* @returns {number}
|
|
161
|
-
*/
|
|
162
|
-
var INT = function INT(value) {
|
|
163
|
-
return Math.round(FLOAT(value));
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Returns the first non-null non-undefined int-castable value as an integer.
|
|
168
|
-
*
|
|
169
|
-
* @param {*} values
|
|
170
|
-
* @returns {number}
|
|
171
|
-
*/
|
|
172
|
-
var INT_ANY = function INT_ANY() {
|
|
173
|
-
return Math.round(FLOAT_ANY.apply(void 0, arguments));
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Ensures the given value is a float (attempts to cast it to a float if it's not, null and undefined will return 0).
|
|
178
|
-
*
|
|
179
|
-
* @param {*} value
|
|
180
|
-
* @returns {number}
|
|
181
|
-
*/
|
|
182
|
-
var FLOAT = function FLOAT(value) {
|
|
183
|
-
var v = +value;
|
|
184
|
-
if (!isNaN(v)) {
|
|
185
|
-
return v;
|
|
186
|
-
}
|
|
187
|
-
return 0;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Returns the first non-null non-undefined float-castable value as a float.
|
|
192
|
-
*
|
|
193
|
-
* @param {*} values
|
|
194
|
-
* @returns {number}
|
|
195
|
-
*/
|
|
196
|
-
var FLOAT_ANY = function FLOAT_ANY() {
|
|
197
|
-
for (var _len3 = arguments.length, values = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
198
|
-
values[_key3] = arguments[_key3];
|
|
199
|
-
}
|
|
200
|
-
for (var _i3 = 0, _values3 = values; _i3 < _values3.length; _i3++) {
|
|
201
|
-
var value = _values3[_i3];
|
|
202
|
-
if (value !== null) {
|
|
203
|
-
var v = +value;
|
|
204
|
-
if (!isNaN(v)) {
|
|
205
|
-
return v;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return 0;
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Ensures the given value is an integer (attempts to cast it to an integer if it's not, null and undefined will return 0).
|
|
214
|
-
* This version is less strict than INT, as it relies on parseFloat instead of on +value, meaning that it will accept strings that contain a number followed by other characters, which +value doesn't.
|
|
215
|
-
*
|
|
216
|
-
* @param {*} value
|
|
217
|
-
* @returns {number}
|
|
218
|
-
*/
|
|
219
|
-
var INT_LAX = function INT_LAX(value) {
|
|
220
|
-
return Math.round(FLOAT_LAX(value));
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Returns the first non-null non-undefined int-castable value as an integer.
|
|
225
|
-
* This version is less strict than INT_ANY, as it relies on parseFloat instead of on +value, meaning that it will accept strings that contain a number followed by other characters, which +value doesn't.
|
|
226
|
-
*
|
|
227
|
-
* @param {*} values
|
|
228
|
-
* @returns {number}
|
|
229
|
-
*/
|
|
230
|
-
var INT_LAX_ANY = function INT_LAX_ANY() {
|
|
231
|
-
return Math.round(FLOAT_LAX_ANY.apply(void 0, arguments));
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Ensures the given value is a float (attempts to cast it to a float if it's not, null and undefined will return 0).
|
|
236
|
-
* This version is less strict than FLOAT, as it relies on parseFloat instead of on +value, meaning that it will accept strings that contain a number followed by other characters, which +value doesn't.
|
|
237
|
-
*
|
|
238
|
-
* @param {*} value
|
|
239
|
-
* @returns {number}
|
|
240
|
-
*/
|
|
241
|
-
var FLOAT_LAX = function FLOAT_LAX(value) {
|
|
242
|
-
var v = typeof value === 'number' ? value : parseFloat((value + '').replace(REGEX_ALL_NON_FLOAT_CHARACTERS, ''));
|
|
243
|
-
if (!isNaN(v)) {
|
|
244
|
-
return v;
|
|
245
|
-
}
|
|
246
|
-
return 0;
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Returns the first non-null non-undefined float-castable value as a float.
|
|
251
|
-
* This version is less strict than FLOAT_ANY, as it relies on parseFloat instead of on +value, meaning that it will accept strings that contain a number followed by other characters, which +value doesn't.
|
|
252
|
-
*
|
|
253
|
-
* @param {*} values
|
|
254
|
-
* @returns {number}
|
|
255
|
-
*/
|
|
256
|
-
var FLOAT_LAX_ANY = function FLOAT_LAX_ANY() {
|
|
257
|
-
for (var _len4 = arguments.length, values = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
258
|
-
values[_key4] = arguments[_key4];
|
|
259
|
-
}
|
|
260
|
-
for (var _i4 = 0, _values4 = values; _i4 < _values4.length; _i4++) {
|
|
261
|
-
var value = _values4[_i4];
|
|
262
|
-
if (value !== null) {
|
|
263
|
-
var v = typeof value === 'number' ? value : parseFloat((value + '').replace(REGEX_ALL_NON_FLOAT_CHARACTERS, ''));
|
|
264
|
-
if (!isNaN(v)) {
|
|
265
|
-
return v;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return 0;
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
273
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
274
|
-
function _createForOfIteratorHelper$1(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$1(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
275
|
-
function _unsupportedIterableToArray$1(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$1(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$1(r, a) : void 0; } }
|
|
276
|
-
function _arrayLikeToArray$1(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* @param {LeUtils_TransactionalValue} transactionalValue
|
|
280
|
-
*/
|
|
281
|
-
var checkTransactionalValue = function checkTransactionalValue(transactionalValue) {
|
|
282
|
-
if (!LeUtils.isTransactionalValueValid(transactionalValue)) {
|
|
283
|
-
console.error('The given value is not a valid TransactionalValue:');
|
|
284
|
-
console.error(transactionalValue);
|
|
285
|
-
throw new Error('The given value is not a valid TransactionalValue');
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* @param {LeUtils_TransactionalValue} transactionalValue
|
|
291
|
-
* @param {string} changeId
|
|
292
|
-
* @returns {{index:number, value:*}|null}
|
|
293
|
-
*/
|
|
294
|
-
var findTransactionalValueChange = function findTransactionalValueChange(transactionalValue, changeId) {
|
|
295
|
-
for (var i = 0; i < transactionalValue.changes.length; i++) {
|
|
296
|
-
var change = transactionalValue.changes[i];
|
|
297
|
-
if (change.id === changeId) {
|
|
298
|
-
return {
|
|
299
|
-
index: i,
|
|
300
|
-
value: change.value
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
return null;
|
|
305
|
-
};
|
|
306
|
-
var LeUtils = {
|
|
307
|
-
/**
|
|
308
|
-
* A deep equals implementation.
|
|
309
|
-
*
|
|
310
|
-
* @param {*} a The value to compare.
|
|
311
|
-
* @param {*} b The other value to compare.
|
|
312
|
-
* @returns {boolean} Returns true if the values are equivalent.
|
|
313
|
-
*/
|
|
314
|
-
equals: function equals(a, b) {
|
|
315
|
-
if (a === b) {
|
|
316
|
-
return true;
|
|
317
|
-
}
|
|
318
|
-
if (a && b && _typeof(a) == 'object' && _typeof(b) == 'object') {
|
|
319
|
-
if (a.constructor !== b.constructor) {
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
322
|
-
if (Array.isArray(a)) {
|
|
323
|
-
var _length = a.length;
|
|
324
|
-
if (_length != b.length) {
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
for (var i = _length; i-- !== 0;) {
|
|
328
|
-
if (!LeUtils.equals(a[i], b[i])) {
|
|
329
|
-
return false;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
return true;
|
|
333
|
-
}
|
|
334
|
-
if (a instanceof Map && b instanceof Map) {
|
|
335
|
-
if (a.size !== b.size) {
|
|
336
|
-
return false;
|
|
337
|
-
}
|
|
338
|
-
var _iterator = _createForOfIteratorHelper$1(a.entries()),
|
|
339
|
-
_step;
|
|
340
|
-
try {
|
|
341
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
342
|
-
var _i = _step.value;
|
|
343
|
-
if (!b.has(_i[0])) {
|
|
344
|
-
return false;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
} catch (err) {
|
|
348
|
-
_iterator.e(err);
|
|
349
|
-
} finally {
|
|
350
|
-
_iterator.f();
|
|
351
|
-
}
|
|
352
|
-
var _iterator2 = _createForOfIteratorHelper$1(a.entries()),
|
|
353
|
-
_step2;
|
|
354
|
-
try {
|
|
355
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
356
|
-
var _i2 = _step2.value;
|
|
357
|
-
if (!LeUtils.equals(_i2[1], b.get(_i2[0]))) {
|
|
358
|
-
return false;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
} catch (err) {
|
|
362
|
-
_iterator2.e(err);
|
|
363
|
-
} finally {
|
|
364
|
-
_iterator2.f();
|
|
365
|
-
}
|
|
366
|
-
return true;
|
|
367
|
-
}
|
|
368
|
-
if (a instanceof Set && b instanceof Set) {
|
|
369
|
-
if (a.size !== b.size) {
|
|
370
|
-
return false;
|
|
371
|
-
}
|
|
372
|
-
var _iterator3 = _createForOfIteratorHelper$1(a.entries()),
|
|
373
|
-
_step3;
|
|
374
|
-
try {
|
|
375
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
376
|
-
var _i3 = _step3.value;
|
|
377
|
-
if (!b.has(_i3[0])) {
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
} catch (err) {
|
|
382
|
-
_iterator3.e(err);
|
|
383
|
-
} finally {
|
|
384
|
-
_iterator3.f();
|
|
385
|
-
}
|
|
386
|
-
return true;
|
|
387
|
-
}
|
|
388
|
-
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
|
|
389
|
-
if ('length' in a && 'length' in b && typeof a.length === 'number' && typeof b.length === 'number') {
|
|
390
|
-
if (a.length != b.length) {
|
|
391
|
-
return false;
|
|
392
|
-
}
|
|
393
|
-
for (var _i4 = a.length; _i4-- !== 0;) {
|
|
394
|
-
if (a[_i4] !== b[_i4]) {
|
|
395
|
-
return false;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
return true;
|
|
399
|
-
}
|
|
400
|
-
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') {
|
|
401
|
-
if (a.byteLength !== b.byteLength) {
|
|
402
|
-
return false;
|
|
403
|
-
}
|
|
404
|
-
for (var _i5 = a.byteLength; _i5-- !== 0;) {
|
|
405
|
-
if (a.getUint8(_i5) !== b.getUint8(_i5)) {
|
|
406
|
-
return false;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
return true;
|
|
410
|
-
}
|
|
411
|
-
return false;
|
|
412
|
-
}
|
|
413
|
-
if (a.constructor === RegExp) {
|
|
414
|
-
return a.source === b.source && a.flags === b.flags;
|
|
415
|
-
}
|
|
416
|
-
if (a.valueOf !== Object.prototype.valueOf) {
|
|
417
|
-
return a.valueOf() === b.valueOf();
|
|
418
|
-
}
|
|
419
|
-
if (a.toString !== Object.prototype.toString) {
|
|
420
|
-
return a.toString() === b.toString();
|
|
421
|
-
}
|
|
422
|
-
if (a.constructor && a.constructor !== Object && a.constructor !== Array && Object.getPrototypeOf(a) !== Object.prototype) {
|
|
423
|
-
if (typeof a.equals === 'function') {
|
|
424
|
-
return a.equals(b);
|
|
425
|
-
}
|
|
426
|
-
return false;
|
|
427
|
-
}
|
|
428
|
-
var keys = Object.keys(a);
|
|
429
|
-
var length = keys.length;
|
|
430
|
-
if (length !== Object.keys(b).length) {
|
|
431
|
-
return false;
|
|
432
|
-
}
|
|
433
|
-
for (var _i6 = length; _i6-- !== 0;) {
|
|
434
|
-
if (!Object.prototype.hasOwnProperty.call(b, keys[_i6])) {
|
|
435
|
-
return false;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
for (var _i7 = length; _i7-- !== 0;) {
|
|
439
|
-
var key = keys[_i7];
|
|
440
|
-
if (key === '_owner' && a.$$typeof) {
|
|
441
|
-
// React-specific: avoid traversing _owner, it contains circular references, and is not needed when comparing the actual element
|
|
442
|
-
continue;
|
|
443
|
-
}
|
|
444
|
-
if (!LeUtils.equals(a[key], b[key])) {
|
|
445
|
-
return false;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
return true;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
// true if both are NaN, false otherwise
|
|
452
|
-
return a !== a && b !== b;
|
|
453
|
-
},
|
|
454
|
-
/**
|
|
455
|
-
* Performs a deep equality comparison between two collections (objects, maps, arrays, etc), sorting on the keys before comparing them.
|
|
456
|
-
*
|
|
457
|
-
* This is useful for comparing objects that have the same properties, but in a different order, and/or in a different collection type (like Maps vs Objects).
|
|
458
|
-
*
|
|
459
|
-
* @param {*} elementsA The elements to compare.
|
|
460
|
-
* @param {*} elementsB The other elements to compare.
|
|
461
|
-
* @param {string[]} [ignoreKeys=[]] An array of keys to ignore when comparing the elements. This is useful for ignoring properties that are not relevant for the comparison.
|
|
462
|
-
* @return {boolean} Returns true if the given values are equivalent, ignoring the order of properties.
|
|
463
|
-
*/
|
|
464
|
-
equalsMapLike: function () {
|
|
465
|
-
var sortKeyValueArrays = function sortKeyValueArrays(pairA, pairB) {
|
|
466
|
-
return LeUtils.compare(pairA[0], pairB[0]);
|
|
467
|
-
};
|
|
468
|
-
return function (elementsA, elementsB) {
|
|
469
|
-
var ignoreKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
470
|
-
elementsA = LeUtils.mapToArray(elementsA, function (value, key) {
|
|
471
|
-
return [key, value];
|
|
472
|
-
}).sort(sortKeyValueArrays);
|
|
473
|
-
elementsB = LeUtils.mapToArray(elementsB, function (value, key) {
|
|
474
|
-
return [key, value];
|
|
475
|
-
}).sort(sortKeyValueArrays);
|
|
476
|
-
ignoreKeys = typeof ignoreKeys === 'string' ? ARRAY(ignoreKeys) : LeUtils.mapToArray(ignoreKeys);
|
|
477
|
-
var indexA = 0;
|
|
478
|
-
var indexB = 0;
|
|
479
|
-
while (indexA < elementsA.length && indexB < elementsB.length) {
|
|
480
|
-
var _elementsA$indexA = _slicedToArray(elementsA[indexA], 2),
|
|
481
|
-
mapKey = _elementsA$indexA[0],
|
|
482
|
-
mapValue = _elementsA$indexA[1];
|
|
483
|
-
var _elementsB$indexB = _slicedToArray(elementsB[indexB], 2),
|
|
484
|
-
ownMapKey = _elementsB$indexB[0],
|
|
485
|
-
ownMapValue = _elementsB$indexB[1];
|
|
486
|
-
var ignoreKeysIncludesMapKey = ignoreKeys.includes(mapKey);
|
|
487
|
-
var ignoreKeysIncludesOwnMapKey = ignoreKeys.includes(ownMapKey);
|
|
488
|
-
if (ignoreKeysIncludesMapKey) {
|
|
489
|
-
indexA++;
|
|
490
|
-
if (ignoreKeysIncludesOwnMapKey) {
|
|
491
|
-
indexB++;
|
|
492
|
-
}
|
|
493
|
-
continue;
|
|
494
|
-
} else if (ignoreKeysIncludesOwnMapKey) {
|
|
495
|
-
indexB++;
|
|
496
|
-
continue;
|
|
497
|
-
}
|
|
498
|
-
if (!LeUtils.equals(mapKey, ownMapKey) || !LeUtils.equals(mapValue, ownMapValue)) {
|
|
499
|
-
return false;
|
|
500
|
-
}
|
|
501
|
-
indexA++;
|
|
502
|
-
indexB++;
|
|
503
|
-
}
|
|
504
|
-
while (indexA < elementsA.length && ignoreKeys.includes(elementsA[indexA][0])) {
|
|
505
|
-
indexA++;
|
|
506
|
-
}
|
|
507
|
-
if (indexA < elementsA.length) {
|
|
508
|
-
return false;
|
|
509
|
-
}
|
|
510
|
-
while (indexB < elementsB.length && ignoreKeys.includes(elementsB[indexB][0])) {
|
|
511
|
-
indexB++;
|
|
512
|
-
}
|
|
513
|
-
return indexB >= elementsB.length;
|
|
514
|
-
};
|
|
515
|
-
}(),
|
|
516
|
-
/**
|
|
517
|
-
* Returns a deep copy of the given value.
|
|
518
|
-
*
|
|
519
|
-
* @param {*} value
|
|
520
|
-
* @returns {*}
|
|
521
|
-
*/
|
|
522
|
-
clone: function clone(value) {
|
|
523
|
-
return CloneDeep(value, true);
|
|
524
|
-
},
|
|
525
|
-
/**
|
|
526
|
-
* Executes the given callback when the document is ready.
|
|
527
|
-
*
|
|
528
|
-
* @param {Function} callback
|
|
529
|
-
* @returns {{remove:Function}}
|
|
530
|
-
*/
|
|
531
|
-
onDomReady: function onDomReady(callback) {
|
|
532
|
-
var _globalThis$document, _globalThis$document2;
|
|
533
|
-
if (!(globalThis !== null && globalThis !== void 0 && globalThis.document) || !(globalThis !== null && globalThis !== void 0 && (_globalThis$document = globalThis.document) !== null && _globalThis$document !== void 0 && _globalThis$document.addEventListener) || !(globalThis !== null && globalThis !== void 0 && (_globalThis$document2 = globalThis.document) !== null && _globalThis$document2 !== void 0 && _globalThis$document2.removeEventListener)) {
|
|
534
|
-
// no document, so we can't wait for it to be ready
|
|
535
|
-
console.warn('LeUtils.onDomReady() was called, but there is no document available. This might happen if the code is executed in a non-browser environment.');
|
|
536
|
-
return {
|
|
537
|
-
remove: function remove() {}
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
if (globalThis.document.readyState === 'interactive' || globalThis.document.readyState === 'complete') {
|
|
541
|
-
return LeUtils.setTimeout(function () {
|
|
542
|
-
return callback();
|
|
543
|
-
}, 0);
|
|
544
|
-
} else {
|
|
545
|
-
var listening = true;
|
|
546
|
-
var _callbackWrapper = function callbackWrapper() {
|
|
547
|
-
if (listening) {
|
|
548
|
-
listening = false;
|
|
549
|
-
globalThis.document.removeEventListener('DOMContentLoaded', _callbackWrapper);
|
|
550
|
-
callback();
|
|
551
|
-
}
|
|
552
|
-
};
|
|
553
|
-
globalThis.document.addEventListener('DOMContentLoaded', _callbackWrapper);
|
|
554
|
-
return {
|
|
555
|
-
remove: function remove() {
|
|
556
|
-
if (listening) {
|
|
557
|
-
listening = false;
|
|
558
|
-
globalThis.document.removeEventListener('DOMContentLoaded', _callbackWrapper);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
},
|
|
564
|
-
/**
|
|
565
|
-
* Parses the given version string, and returns an object with the major, minor, and patch numbers, as well as some comparison functions.
|
|
566
|
-
*
|
|
567
|
-
* Expects a version string such as:
|
|
568
|
-
* - "1"
|
|
569
|
-
* - "1.2"
|
|
570
|
-
* - "1.2.3"
|
|
571
|
-
* - "1.2.3 anything"
|
|
572
|
-
* - "1.2.3-anything"
|
|
573
|
-
*
|
|
574
|
-
* @param {string|*} versionString
|
|
575
|
-
* @returns {{major: (number), minor: (number), patch: (number), toString: (function(): string), equals: (function(string|*): boolean), smallerThan: (function(string|*): boolean), smallerThanOrEquals: (function(string|*): boolean), largerThan: (function(string|*): boolean), largerThanOrEquals: (function(string|*): boolean)}}
|
|
576
|
-
*/
|
|
577
|
-
parseVersionString: function parseVersionString(versionString) {
|
|
578
|
-
var _versionString, _versionString2, _versionString3;
|
|
579
|
-
if (IS_OBJECT(versionString) && ISSET((_versionString = versionString) === null || _versionString === void 0 ? void 0 : _versionString.major) && ISSET((_versionString2 = versionString) === null || _versionString2 === void 0 ? void 0 : _versionString2.minor) && ISSET((_versionString3 = versionString) === null || _versionString3 === void 0 ? void 0 : _versionString3.patch)) {
|
|
580
|
-
return versionString;
|
|
581
|
-
}
|
|
582
|
-
versionString = STRING(versionString).trim();
|
|
583
|
-
var partsVersion = versionString.split(' ')[0].split('-')[0].split('.');
|
|
584
|
-
var major = INT_LAX(partsVersion[0]);
|
|
585
|
-
var minor = INT_LAX(partsVersion[1]);
|
|
586
|
-
var patch = INT_LAX(partsVersion[2]);
|
|
587
|
-
var THIS = {
|
|
588
|
-
major: major,
|
|
589
|
-
minor: minor,
|
|
590
|
-
patch: patch,
|
|
591
|
-
toString: function toString() {
|
|
592
|
-
return major + '.' + minor + '.' + patch;
|
|
593
|
-
},
|
|
594
|
-
equals: function equals(otherVersion) {
|
|
595
|
-
otherVersion = LeUtils.parseVersionString(otherVersion);
|
|
596
|
-
return major === otherVersion.major && minor === otherVersion.minor && patch === otherVersion.patch;
|
|
597
|
-
},
|
|
598
|
-
largerThan: function largerThan(otherVersion) {
|
|
599
|
-
otherVersion = LeUtils.parseVersionString(otherVersion);
|
|
600
|
-
if (major > otherVersion.major) {
|
|
601
|
-
return true;
|
|
602
|
-
}
|
|
603
|
-
if (major < otherVersion.major) {
|
|
604
|
-
return false;
|
|
605
|
-
}
|
|
606
|
-
if (minor > otherVersion.minor) {
|
|
607
|
-
return true;
|
|
608
|
-
}
|
|
609
|
-
if (minor < otherVersion.minor) {
|
|
610
|
-
return false;
|
|
611
|
-
}
|
|
612
|
-
return patch > otherVersion.patch;
|
|
613
|
-
},
|
|
614
|
-
largerThanOrEquals: function largerThanOrEquals(otherVersion) {
|
|
615
|
-
otherVersion = LeUtils.parseVersionString(otherVersion);
|
|
616
|
-
if (major > otherVersion.major) {
|
|
617
|
-
return true;
|
|
618
|
-
}
|
|
619
|
-
if (major < otherVersion.major) {
|
|
620
|
-
return false;
|
|
621
|
-
}
|
|
622
|
-
if (minor > otherVersion.minor) {
|
|
623
|
-
return true;
|
|
624
|
-
}
|
|
625
|
-
if (minor < otherVersion.minor) {
|
|
626
|
-
return false;
|
|
627
|
-
}
|
|
628
|
-
return patch >= otherVersion.patch;
|
|
629
|
-
},
|
|
630
|
-
smallerThan: function smallerThan(otherVersion) {
|
|
631
|
-
return !THIS.largerThanOrEquals(otherVersion);
|
|
632
|
-
},
|
|
633
|
-
smallerThanOrEquals: function smallerThanOrEquals(otherVersion) {
|
|
634
|
-
return !THIS.largerThan(otherVersion);
|
|
635
|
-
}
|
|
636
|
-
};
|
|
637
|
-
return THIS;
|
|
638
|
-
},
|
|
639
|
-
/**
|
|
640
|
-
* Returns true if the array or object contains the given value.
|
|
641
|
-
*
|
|
642
|
-
* Values are compared by casting both of them to a string.
|
|
643
|
-
*
|
|
644
|
-
* @param {*[]|Object|Function} array
|
|
645
|
-
* @param {*} value
|
|
646
|
-
* @returns {boolean}
|
|
647
|
-
*/
|
|
648
|
-
contains: function contains(array, value) {
|
|
649
|
-
if (!array) {
|
|
650
|
-
return false;
|
|
651
|
-
}
|
|
652
|
-
var result = false;
|
|
653
|
-
value = STRING(value);
|
|
654
|
-
LeUtils.each(array, function (val) {
|
|
655
|
-
if (STRING(val) === value) {
|
|
656
|
-
result = true;
|
|
657
|
-
return false;
|
|
658
|
-
}
|
|
659
|
-
});
|
|
660
|
-
return result;
|
|
661
|
-
},
|
|
662
|
-
/**
|
|
663
|
-
* Returns true if the array or object contains the given value.
|
|
664
|
-
*
|
|
665
|
-
* Values are compared by casting both of them to a string, and then lowercasing them.
|
|
666
|
-
*
|
|
667
|
-
* @param {*[]|Object|Function} array
|
|
668
|
-
* @param {*} value
|
|
669
|
-
* @returns {boolean}
|
|
670
|
-
*/
|
|
671
|
-
containsCaseInsensitive: function containsCaseInsensitive(array, value) {
|
|
672
|
-
if (!array) {
|
|
673
|
-
return false;
|
|
674
|
-
}
|
|
675
|
-
var result = false;
|
|
676
|
-
value = STRING(value).toLowerCase();
|
|
677
|
-
LeUtils.each(array, function (val) {
|
|
678
|
-
if (STRING(val).toLowerCase() === value) {
|
|
679
|
-
result = true;
|
|
680
|
-
return false;
|
|
681
|
-
}
|
|
682
|
-
});
|
|
683
|
-
return result;
|
|
684
|
-
},
|
|
685
|
-
/**
|
|
686
|
-
* Returns true if the array or object contains all the given values.
|
|
687
|
-
*
|
|
688
|
-
* Values are compared by casting both of them to a string.
|
|
689
|
-
*
|
|
690
|
-
* @param {*[]|Object|Function} array
|
|
691
|
-
* @param {*[]|Object|Function} values
|
|
692
|
-
* @returns {boolean}
|
|
693
|
-
*/
|
|
694
|
-
containsAll: function containsAll(array, values) {
|
|
695
|
-
if (!array) {
|
|
696
|
-
return false;
|
|
697
|
-
}
|
|
698
|
-
var result = true;
|
|
699
|
-
LeUtils.each(values, function (value) {
|
|
700
|
-
if (!LeUtils.contains(array, value)) {
|
|
701
|
-
result = false;
|
|
702
|
-
return false;
|
|
703
|
-
}
|
|
704
|
-
});
|
|
705
|
-
return result;
|
|
706
|
-
},
|
|
707
|
-
/**
|
|
708
|
-
* Returns true if the array or object contains all the given values.
|
|
709
|
-
*
|
|
710
|
-
* Values are compared by casting both of them to a string, and then lowercasing them.
|
|
711
|
-
*
|
|
712
|
-
* @param {*[]|Object|Function} array
|
|
713
|
-
* @param {*[]|Object|Function} values
|
|
714
|
-
* @returns {boolean}
|
|
715
|
-
*/
|
|
716
|
-
containsAllCaseInsensitive: function containsAllCaseInsensitive(array, values) {
|
|
717
|
-
if (!array) {
|
|
718
|
-
return false;
|
|
719
|
-
}
|
|
720
|
-
var result = true;
|
|
721
|
-
LeUtils.each(values, function (value) {
|
|
722
|
-
if (!LeUtils.containsCaseInsensitive(array, value)) {
|
|
723
|
-
result = false;
|
|
724
|
-
return false;
|
|
725
|
-
}
|
|
726
|
-
});
|
|
727
|
-
return result;
|
|
728
|
-
},
|
|
729
|
-
/**
|
|
730
|
-
* Returns true if the array or object contains any of the given values.
|
|
731
|
-
*
|
|
732
|
-
* Values are compared by casting both of them to a string.
|
|
733
|
-
*
|
|
734
|
-
* @param {*[]|Object|Function} array
|
|
735
|
-
* @param {*[]|Object|Function} values
|
|
736
|
-
* @returns {boolean}
|
|
737
|
-
*/
|
|
738
|
-
containsAny: function containsAny(array, values) {
|
|
739
|
-
if (!array) {
|
|
740
|
-
return false;
|
|
741
|
-
}
|
|
742
|
-
var result = false;
|
|
743
|
-
LeUtils.each(values, function (value) {
|
|
744
|
-
if (LeUtils.contains(array, value)) {
|
|
745
|
-
result = true;
|
|
746
|
-
return false;
|
|
747
|
-
}
|
|
748
|
-
});
|
|
749
|
-
return result;
|
|
750
|
-
},
|
|
751
|
-
/**
|
|
752
|
-
* Returns true if the array or object contains any of the given values.
|
|
753
|
-
*
|
|
754
|
-
* Values are compared by casting both of them to a string, and then lowercasing them.
|
|
755
|
-
*
|
|
756
|
-
* @param {*[]|Object|Function} array
|
|
757
|
-
* @param {*[]|Object|Function} values
|
|
758
|
-
* @returns {boolean}
|
|
759
|
-
*/
|
|
760
|
-
containsAnyCaseInsensitive: function containsAnyCaseInsensitive(array, values) {
|
|
761
|
-
if (!array) {
|
|
762
|
-
return false;
|
|
763
|
-
}
|
|
764
|
-
var result = false;
|
|
765
|
-
LeUtils.each(values, function (value) {
|
|
766
|
-
if (LeUtils.containsCaseInsensitive(array, value)) {
|
|
767
|
-
result = true;
|
|
768
|
-
return false;
|
|
769
|
-
}
|
|
770
|
-
});
|
|
771
|
-
return result;
|
|
772
|
-
},
|
|
773
|
-
/**
|
|
774
|
-
* Returns true if the array or object contains none of the given values.
|
|
775
|
-
*
|
|
776
|
-
* Values are compared by casting both of them to a string.
|
|
777
|
-
*
|
|
778
|
-
* @param {*[]|Object|Function} array
|
|
779
|
-
* @param {*[]|Object|Function} values
|
|
780
|
-
* @returns {boolean}
|
|
781
|
-
*/
|
|
782
|
-
containsNone: function containsNone(array, values) {
|
|
783
|
-
if (!array) {
|
|
784
|
-
return true;
|
|
785
|
-
}
|
|
786
|
-
var result = true;
|
|
787
|
-
LeUtils.each(values, function (value) {
|
|
788
|
-
if (LeUtils.contains(array, value)) {
|
|
789
|
-
result = false;
|
|
790
|
-
return false;
|
|
791
|
-
}
|
|
792
|
-
});
|
|
793
|
-
return result;
|
|
794
|
-
},
|
|
795
|
-
/**
|
|
796
|
-
* Returns true if the array or object contains none of the given values.
|
|
797
|
-
*
|
|
798
|
-
* Values are compared by casting both of them to a string, and then lowercasing them.
|
|
799
|
-
*
|
|
800
|
-
* @param {*[]|Object|Function} array
|
|
801
|
-
* @param {*[]|Object|Function} values
|
|
802
|
-
* @returns {boolean}
|
|
803
|
-
*/
|
|
804
|
-
containsNoneCaseInsensitive: function containsNoneCaseInsensitive(array, values) {
|
|
805
|
-
if (!array) {
|
|
806
|
-
return true;
|
|
807
|
-
}
|
|
808
|
-
var result = true;
|
|
809
|
-
LeUtils.each(values, function (value) {
|
|
810
|
-
if (LeUtils.containsCaseInsensitive(array, value)) {
|
|
811
|
-
result = false;
|
|
812
|
-
return false;
|
|
813
|
-
}
|
|
814
|
-
});
|
|
815
|
-
return result;
|
|
816
|
-
},
|
|
817
|
-
/**
|
|
818
|
-
* Finds the first element in the given array or object that returns true from the callback, and returns an object with the index and value.
|
|
819
|
-
*
|
|
820
|
-
* @param {*[]|Object|Function} elements
|
|
821
|
-
* @param {(value:*, index:*) => boolean|void} callback
|
|
822
|
-
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
823
|
-
* @returns {{index:*, value:*}|null}
|
|
824
|
-
*/
|
|
825
|
-
findIndexValue: function findIndexValue(elements, callback) {
|
|
826
|
-
var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
827
|
-
var result = null;
|
|
828
|
-
LeUtils.each(elements, function (value, index) {
|
|
829
|
-
if (callback.call(elements[index], elements[index], index)) {
|
|
830
|
-
result = {
|
|
831
|
-
index: index,
|
|
832
|
-
value: value
|
|
833
|
-
};
|
|
834
|
-
return false;
|
|
835
|
-
}
|
|
836
|
-
}, optionalSkipHasOwnPropertyCheck);
|
|
837
|
-
return result;
|
|
838
|
-
},
|
|
839
|
-
/**
|
|
840
|
-
* Finds the first element in the given array or object that returns true from the callback, and returns the index.
|
|
841
|
-
*
|
|
842
|
-
* @param {*[]|Object|Function} elements
|
|
843
|
-
* @param {(value:*, index:*) => boolean|void} callback
|
|
844
|
-
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
845
|
-
* @returns {*|null}
|
|
846
|
-
*/
|
|
847
|
-
findIndex: function findIndex(elements, callback) {
|
|
848
|
-
var _LeUtils$findIndexVal, _LeUtils$findIndexVal2;
|
|
849
|
-
var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
850
|
-
return (_LeUtils$findIndexVal = (_LeUtils$findIndexVal2 = LeUtils.findIndexValue(elements, callback, optionalSkipHasOwnPropertyCheck)) === null || _LeUtils$findIndexVal2 === void 0 ? void 0 : _LeUtils$findIndexVal2.index) !== null && _LeUtils$findIndexVal !== void 0 ? _LeUtils$findIndexVal : null;
|
|
851
|
-
},
|
|
852
|
-
/**
|
|
853
|
-
* Finds the first element in the given array or object that returns true from the callback, and returns the value.
|
|
854
|
-
*
|
|
855
|
-
* @param {*[]|Object|Function} elements
|
|
856
|
-
* @param {(value:*, index:*) => boolean|void} callback
|
|
857
|
-
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
858
|
-
* @returns {*|null}
|
|
859
|
-
*/
|
|
860
|
-
find: function find(elements, callback) {
|
|
861
|
-
var _LeUtils$findIndexVal3, _LeUtils$findIndexVal4;
|
|
862
|
-
var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
863
|
-
return (_LeUtils$findIndexVal3 = (_LeUtils$findIndexVal4 = LeUtils.findIndexValue(elements, callback, optionalSkipHasOwnPropertyCheck)) === null || _LeUtils$findIndexVal4 === void 0 ? void 0 : _LeUtils$findIndexVal4.value) !== null && _LeUtils$findIndexVal3 !== void 0 ? _LeUtils$findIndexVal3 : null;
|
|
864
|
-
},
|
|
865
|
-
/**
|
|
866
|
-
* Returns the value at the given index in the given elements.
|
|
867
|
-
*
|
|
868
|
-
* @param {*} elements
|
|
869
|
-
* @param {*} index
|
|
870
|
-
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
871
|
-
* @returns {*}
|
|
872
|
-
*/
|
|
873
|
-
getValueAtIndex: function getValueAtIndex(elements, index) {
|
|
874
|
-
var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
875
|
-
if (elements === null || typeof elements === 'undefined') {
|
|
876
|
-
return undefined;
|
|
877
|
-
}
|
|
878
|
-
if (Array.isArray(elements)) {
|
|
879
|
-
return elements[index];
|
|
880
|
-
}
|
|
881
|
-
if (_typeof(elements) === 'object' && (elements === null || elements === void 0 ? void 0 : elements.constructor) === Object) {
|
|
882
|
-
if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, index)) {
|
|
883
|
-
return elements[index];
|
|
884
|
-
}
|
|
885
|
-
return undefined;
|
|
886
|
-
}
|
|
887
|
-
if (elements instanceof Map) {
|
|
888
|
-
return elements.get(index);
|
|
889
|
-
}
|
|
890
|
-
if (elements instanceof Set) {
|
|
891
|
-
return index;
|
|
892
|
-
}
|
|
893
|
-
if (typeof elements !== 'string') {
|
|
894
|
-
if (ArrayBuffer.isView(elements) && !(elements instanceof DataView)) {
|
|
895
|
-
return elements[index];
|
|
896
|
-
}
|
|
897
|
-
if (typeof (elements === null || elements === void 0 ? void 0 : elements[Symbol.iterator]) === 'function') {
|
|
898
|
-
var i = 0;
|
|
899
|
-
var _iterator4 = _createForOfIteratorHelper$1(elements),
|
|
900
|
-
_step4;
|
|
901
|
-
try {
|
|
902
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
903
|
-
var value = _step4.value;
|
|
904
|
-
if (i === index) {
|
|
905
|
-
return value;
|
|
906
|
-
}
|
|
907
|
-
i++;
|
|
908
|
-
}
|
|
909
|
-
} catch (err) {
|
|
910
|
-
_iterator4.e(err);
|
|
911
|
-
} finally {
|
|
912
|
-
_iterator4.f();
|
|
913
|
-
}
|
|
914
|
-
return undefined;
|
|
915
|
-
}
|
|
916
|
-
if (typeof (elements === null || elements === void 0 ? void 0 : elements.forEach) === 'function') {
|
|
917
|
-
var result = undefined;
|
|
918
|
-
var shouldContinue = true;
|
|
919
|
-
elements.forEach(function (value, i) {
|
|
920
|
-
if (shouldContinue) {
|
|
921
|
-
if (i === index) {
|
|
922
|
-
result = value;
|
|
923
|
-
shouldContinue = false;
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
});
|
|
927
|
-
return result;
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
if (_typeof(elements) === 'object' || typeof elements === 'function') {
|
|
931
|
-
if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, index)) {
|
|
932
|
-
return elements[index];
|
|
933
|
-
}
|
|
934
|
-
return undefined;
|
|
935
|
-
}
|
|
936
|
-
return undefined;
|
|
937
|
-
},
|
|
938
|
-
/**
|
|
939
|
-
* Checks if the given elements can be iterated over using LeUtils.each().
|
|
940
|
-
*
|
|
941
|
-
* @param {*} elements
|
|
942
|
-
* @returns {boolean}
|
|
943
|
-
*/
|
|
944
|
-
supportsEach: function supportsEach(elements) {
|
|
945
|
-
if (elements === null || typeof elements === 'undefined' || typeof elements === 'string') {
|
|
946
|
-
return false;
|
|
947
|
-
}
|
|
948
|
-
return !!(Array.isArray(elements) || _typeof(elements) === 'object' && (elements === null || elements === void 0 ? void 0 : elements.constructor) === Object || typeof (elements === null || elements === void 0 ? void 0 : elements[Symbol.iterator]) === 'function' || typeof (elements === null || elements === void 0 ? void 0 : elements.forEach) === 'function' || _typeof(elements) === 'object' || typeof elements === 'function');
|
|
949
|
-
},
|
|
950
|
-
/**
|
|
951
|
-
* Returns an iterator that iterates over each element in the given array or object, yielding an array with the value and the index/key.
|
|
952
|
-
*
|
|
953
|
-
* @param {*} elements
|
|
954
|
-
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
955
|
-
* @yields {[key:*, value:*]}
|
|
956
|
-
*/
|
|
957
|
-
eachIterator: function eachIterator(elements) {
|
|
958
|
-
var optionalSkipHasOwnPropertyCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
959
|
-
return /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
960
|
-
var i, _i8, _iterator5, _step5, _step5$value, _i9, value, _iterator6, _step6, _value, _i0, _iterator7, _step7, _value2, buffer, _i1, _buffer, entry, _i10, _t, _t2, _t3, _t4, _t5, _t6, _t7;
|
|
961
|
-
return _regeneratorRuntime.wrap(function (_context) {
|
|
962
|
-
while (1) switch (_context.prev = _context.next) {
|
|
963
|
-
case 0:
|
|
964
|
-
if (!(elements === null || typeof elements === 'undefined')) {
|
|
965
|
-
_context.next = 1;
|
|
966
|
-
break;
|
|
967
|
-
}
|
|
968
|
-
return _context.abrupt("return");
|
|
969
|
-
case 1:
|
|
970
|
-
if (!Array.isArray(elements)) {
|
|
971
|
-
_context.next = 5;
|
|
972
|
-
break;
|
|
973
|
-
}
|
|
974
|
-
i = 0;
|
|
975
|
-
case 2:
|
|
976
|
-
if (!(i < elements.length)) {
|
|
977
|
-
_context.next = 4;
|
|
978
|
-
break;
|
|
979
|
-
}
|
|
980
|
-
_context.next = 3;
|
|
981
|
-
return [elements[i], i];
|
|
982
|
-
case 3:
|
|
983
|
-
i++;
|
|
984
|
-
_context.next = 2;
|
|
985
|
-
break;
|
|
986
|
-
case 4:
|
|
987
|
-
return _context.abrupt("return");
|
|
988
|
-
case 5:
|
|
989
|
-
if (!(_typeof(elements) === 'object' && (elements === null || elements === void 0 ? void 0 : elements.constructor) === Object)) {
|
|
990
|
-
_context.next = 9;
|
|
991
|
-
break;
|
|
992
|
-
}
|
|
993
|
-
_t = _regeneratorRuntime.keys(elements);
|
|
994
|
-
case 6:
|
|
995
|
-
if ((_t2 = _t()).done) {
|
|
996
|
-
_context.next = 8;
|
|
997
|
-
break;
|
|
998
|
-
}
|
|
999
|
-
_i8 = _t2.value;
|
|
1000
|
-
if (!(optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _i8))) {
|
|
1001
|
-
_context.next = 7;
|
|
1002
|
-
break;
|
|
1003
|
-
}
|
|
1004
|
-
_context.next = 7;
|
|
1005
|
-
return [elements[_i8], _i8];
|
|
1006
|
-
case 7:
|
|
1007
|
-
_context.next = 6;
|
|
1008
|
-
break;
|
|
1009
|
-
case 8:
|
|
1010
|
-
return _context.abrupt("return");
|
|
1011
|
-
case 9:
|
|
1012
|
-
if (!(elements instanceof Map)) {
|
|
1013
|
-
_context.next = 17;
|
|
1014
|
-
break;
|
|
1015
|
-
}
|
|
1016
|
-
_iterator5 = _createForOfIteratorHelper$1(elements);
|
|
1017
|
-
_context.prev = 10;
|
|
1018
|
-
_iterator5.s();
|
|
1019
|
-
case 11:
|
|
1020
|
-
if ((_step5 = _iterator5.n()).done) {
|
|
1021
|
-
_context.next = 13;
|
|
1022
|
-
break;
|
|
1023
|
-
}
|
|
1024
|
-
_step5$value = _slicedToArray(_step5.value, 2), _i9 = _step5$value[0], value = _step5$value[1];
|
|
1025
|
-
_context.next = 12;
|
|
1026
|
-
return [value, _i9];
|
|
1027
|
-
case 12:
|
|
1028
|
-
_context.next = 11;
|
|
1029
|
-
break;
|
|
1030
|
-
case 13:
|
|
1031
|
-
_context.next = 15;
|
|
1032
|
-
break;
|
|
1033
|
-
case 14:
|
|
1034
|
-
_context.prev = 14;
|
|
1035
|
-
_t3 = _context["catch"](10);
|
|
1036
|
-
_iterator5.e(_t3);
|
|
1037
|
-
case 15:
|
|
1038
|
-
_context.prev = 15;
|
|
1039
|
-
_iterator5.f();
|
|
1040
|
-
return _context.finish(15);
|
|
1041
|
-
case 16:
|
|
1042
|
-
return _context.abrupt("return");
|
|
1043
|
-
case 17:
|
|
1044
|
-
if (!(elements instanceof Set)) {
|
|
1045
|
-
_context.next = 25;
|
|
1046
|
-
break;
|
|
1047
|
-
}
|
|
1048
|
-
_iterator6 = _createForOfIteratorHelper$1(elements);
|
|
1049
|
-
_context.prev = 18;
|
|
1050
|
-
_iterator6.s();
|
|
1051
|
-
case 19:
|
|
1052
|
-
if ((_step6 = _iterator6.n()).done) {
|
|
1053
|
-
_context.next = 21;
|
|
1054
|
-
break;
|
|
1055
|
-
}
|
|
1056
|
-
_value = _step6.value;
|
|
1057
|
-
_context.next = 20;
|
|
1058
|
-
return [_value, _value];
|
|
1059
|
-
case 20:
|
|
1060
|
-
_context.next = 19;
|
|
1061
|
-
break;
|
|
1062
|
-
case 21:
|
|
1063
|
-
_context.next = 23;
|
|
1064
|
-
break;
|
|
1065
|
-
case 22:
|
|
1066
|
-
_context.prev = 22;
|
|
1067
|
-
_t4 = _context["catch"](18);
|
|
1068
|
-
_iterator6.e(_t4);
|
|
1069
|
-
case 23:
|
|
1070
|
-
_context.prev = 23;
|
|
1071
|
-
_iterator6.f();
|
|
1072
|
-
return _context.finish(23);
|
|
1073
|
-
case 24:
|
|
1074
|
-
return _context.abrupt("return");
|
|
1075
|
-
case 25:
|
|
1076
|
-
if (!(typeof elements !== 'string')) {
|
|
1077
|
-
_context.next = 38;
|
|
1078
|
-
break;
|
|
1079
|
-
}
|
|
1080
|
-
if (!(typeof (elements === null || elements === void 0 ? void 0 : elements[Symbol.iterator]) === 'function')) {
|
|
1081
|
-
_context.next = 34;
|
|
1082
|
-
break;
|
|
1083
|
-
}
|
|
1084
|
-
_i0 = 0;
|
|
1085
|
-
_iterator7 = _createForOfIteratorHelper$1(elements);
|
|
1086
|
-
_context.prev = 26;
|
|
1087
|
-
_iterator7.s();
|
|
1088
|
-
case 27:
|
|
1089
|
-
if ((_step7 = _iterator7.n()).done) {
|
|
1090
|
-
_context.next = 30;
|
|
1091
|
-
break;
|
|
1092
|
-
}
|
|
1093
|
-
_value2 = _step7.value;
|
|
1094
|
-
_context.next = 28;
|
|
1095
|
-
return [_value2, _i0];
|
|
1096
|
-
case 28:
|
|
1097
|
-
_i0++;
|
|
1098
|
-
case 29:
|
|
1099
|
-
_context.next = 27;
|
|
1100
|
-
break;
|
|
1101
|
-
case 30:
|
|
1102
|
-
_context.next = 32;
|
|
1103
|
-
break;
|
|
1104
|
-
case 31:
|
|
1105
|
-
_context.prev = 31;
|
|
1106
|
-
_t5 = _context["catch"](26);
|
|
1107
|
-
_iterator7.e(_t5);
|
|
1108
|
-
case 32:
|
|
1109
|
-
_context.prev = 32;
|
|
1110
|
-
_iterator7.f();
|
|
1111
|
-
return _context.finish(32);
|
|
1112
|
-
case 33:
|
|
1113
|
-
return _context.abrupt("return");
|
|
1114
|
-
case 34:
|
|
1115
|
-
if (!(typeof (elements === null || elements === void 0 ? void 0 : elements.forEach) === 'function')) {
|
|
1116
|
-
_context.next = 38;
|
|
1117
|
-
break;
|
|
1118
|
-
}
|
|
1119
|
-
buffer = [];
|
|
1120
|
-
elements.forEach(function (value, i) {
|
|
1121
|
-
buffer.push([value, i]);
|
|
1122
|
-
});
|
|
1123
|
-
_i1 = 0, _buffer = buffer;
|
|
1124
|
-
case 35:
|
|
1125
|
-
if (!(_i1 < _buffer.length)) {
|
|
1126
|
-
_context.next = 37;
|
|
1127
|
-
break;
|
|
1128
|
-
}
|
|
1129
|
-
entry = _buffer[_i1];
|
|
1130
|
-
_context.next = 36;
|
|
1131
|
-
return entry;
|
|
1132
|
-
case 36:
|
|
1133
|
-
_i1++;
|
|
1134
|
-
_context.next = 35;
|
|
1135
|
-
break;
|
|
1136
|
-
case 37:
|
|
1137
|
-
return _context.abrupt("return");
|
|
1138
|
-
case 38:
|
|
1139
|
-
if (!(_typeof(elements) === 'object' || typeof elements === 'function')) {
|
|
1140
|
-
_context.next = 42;
|
|
1141
|
-
break;
|
|
1142
|
-
}
|
|
1143
|
-
_t6 = _regeneratorRuntime.keys(elements);
|
|
1144
|
-
case 39:
|
|
1145
|
-
if ((_t7 = _t6()).done) {
|
|
1146
|
-
_context.next = 41;
|
|
1147
|
-
break;
|
|
1148
|
-
}
|
|
1149
|
-
_i10 = _t7.value;
|
|
1150
|
-
if (!(optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(elements, _i10))) {
|
|
1151
|
-
_context.next = 40;
|
|
1152
|
-
break;
|
|
1153
|
-
}
|
|
1154
|
-
_context.next = 40;
|
|
1155
|
-
return [elements[_i10], _i10];
|
|
1156
|
-
case 40:
|
|
1157
|
-
_context.next = 39;
|
|
1158
|
-
break;
|
|
1159
|
-
case 41:
|
|
1160
|
-
return _context.abrupt("return");
|
|
1161
|
-
case 42:
|
|
1162
|
-
console.warn('Executed LeUtils.eachIterator() on an invalid type: [' + _typeof(elements) + ']', elements);
|
|
1163
|
-
case 43:
|
|
1164
|
-
case "end":
|
|
1165
|
-
return _context.stop();
|
|
1166
|
-
}
|
|
1167
|
-
}, _callee, null, [[10, 14, 15, 16], [18, 22, 23, 24], [26, 31, 32, 33]]);
|
|
1168
|
-
})();
|
|
1169
|
-
},
|
|
1170
|
-
/**
|
|
1171
|
-
* Loops through each element in the given array or object, and calls the callback for each element.
|
|
1172
|
-
*
|
|
1173
|
-
* @param {*} elements
|
|
1174
|
-
* @param {(value:*, index?:*) => boolean|void} callback
|
|
1175
|
-
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
1176
|
-
* @returns {*}
|
|
1177
|
-
*/
|
|
1178
|
-
each: function each(elements, callback) {
|
|
1179
|
-
var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1180
|
-
var _iterator8 = _createForOfIteratorHelper$1(LeUtils.eachIterator(elements, optionalSkipHasOwnPropertyCheck)),
|
|
1181
|
-
_step8;
|
|
1182
|
-
try {
|
|
1183
|
-
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1184
|
-
var _step8$value = _slicedToArray(_step8.value, 2),
|
|
1185
|
-
value = _step8$value[0],
|
|
1186
|
-
key = _step8$value[1];
|
|
1187
|
-
if (callback.call(value, value, key) === false) {
|
|
1188
|
-
break;
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
} catch (err) {
|
|
1192
|
-
_iterator8.e(err);
|
|
1193
|
-
} finally {
|
|
1194
|
-
_iterator8.f();
|
|
1195
|
-
}
|
|
1196
|
-
return elements;
|
|
1197
|
-
},
|
|
1198
|
-
/**
|
|
1199
|
-
* Like LeUtils.each(), except that it expects an async callback.
|
|
1200
|
-
*
|
|
1201
|
-
* @param {*} elements
|
|
1202
|
-
* @param {(value:*, index?:*) => Promise<boolean|undefined>} asyncCallback
|
|
1203
|
-
* @param {number} [optionalParallelCount]
|
|
1204
|
-
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
1205
|
-
* @returns {Promise<*>}
|
|
1206
|
-
*/
|
|
1207
|
-
eachAsync: function () {
|
|
1208
|
-
/**
|
|
1209
|
-
* Instead of waiting for every promise individually, this function will queue up multiple promises at once, then wait for any of them to finish, before adding more, until it has looped through all elements.
|
|
1210
|
-
* Then, at the end, it will wait for the remaining promises to finish.
|
|
1211
|
-
*/
|
|
1212
|
-
var eachAsyncParallel = /*#__PURE__*/function () {
|
|
1213
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(elements, asyncCallback, optionalParallelCount, optionalSkipHasOwnPropertyCheck) {
|
|
1214
|
-
var runningPromises, doBreak;
|
|
1215
|
-
return _regeneratorRuntime.wrap(function (_context4) {
|
|
1216
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
1217
|
-
case 0:
|
|
1218
|
-
runningPromises = new Set();
|
|
1219
|
-
doBreak = false;
|
|
1220
|
-
_context4.next = 1;
|
|
1221
|
-
return LeUtils.eachAsync(elements, /*#__PURE__*/function () {
|
|
1222
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(value, index) {
|
|
1223
|
-
var promise;
|
|
1224
|
-
return _regeneratorRuntime.wrap(function (_context3) {
|
|
1225
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
1226
|
-
case 0:
|
|
1227
|
-
if (!doBreak) {
|
|
1228
|
-
_context3.next = 1;
|
|
1229
|
-
break;
|
|
1230
|
-
}
|
|
1231
|
-
return _context3.abrupt("return", false);
|
|
1232
|
-
case 1:
|
|
1233
|
-
if (!(runningPromises.size >= optionalParallelCount)) {
|
|
1234
|
-
_context3.next = 4;
|
|
1235
|
-
break;
|
|
1236
|
-
}
|
|
1237
|
-
_context3.next = 2;
|
|
1238
|
-
return Promise.race(runningPromises);
|
|
1239
|
-
case 2:
|
|
1240
|
-
if (!doBreak) {
|
|
1241
|
-
_context3.next = 3;
|
|
1242
|
-
break;
|
|
1243
|
-
}
|
|
1244
|
-
return _context3.abrupt("return", false);
|
|
1245
|
-
case 3:
|
|
1246
|
-
_context3.next = 1;
|
|
1247
|
-
break;
|
|
1248
|
-
case 4:
|
|
1249
|
-
// process this element, by creating a promise, and adding it to the queue
|
|
1250
|
-
promise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
1251
|
-
var _t8;
|
|
1252
|
-
return _regeneratorRuntime.wrap(function (_context2) {
|
|
1253
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
1254
|
-
case 0:
|
|
1255
|
-
_context2.next = 1;
|
|
1256
|
-
return asyncCallback.call(value, value, index);
|
|
1257
|
-
case 1:
|
|
1258
|
-
_t8 = _context2.sent;
|
|
1259
|
-
if (!(_t8 === false)) {
|
|
1260
|
-
_context2.next = 2;
|
|
1261
|
-
break;
|
|
1262
|
-
}
|
|
1263
|
-
doBreak = true;
|
|
1264
|
-
case 2:
|
|
1265
|
-
case "end":
|
|
1266
|
-
return _context2.stop();
|
|
1267
|
-
}
|
|
1268
|
-
}, _callee2);
|
|
1269
|
-
}))();
|
|
1270
|
-
runningPromises.add(promise);
|
|
1271
|
-
promise["finally"](function () {
|
|
1272
|
-
runningPromises["delete"](promise);
|
|
1273
|
-
});
|
|
1274
|
-
case 5:
|
|
1275
|
-
case "end":
|
|
1276
|
-
return _context3.stop();
|
|
1277
|
-
}
|
|
1278
|
-
}, _callee3);
|
|
1279
|
-
}));
|
|
1280
|
-
return function (_x5, _x6) {
|
|
1281
|
-
return _ref3.apply(this, arguments);
|
|
1282
|
-
};
|
|
1283
|
-
}(), 1, optionalSkipHasOwnPropertyCheck);
|
|
1284
|
-
case 1:
|
|
1285
|
-
_context4.next = 2;
|
|
1286
|
-
return Promise.all(runningPromises);
|
|
1287
|
-
case 2:
|
|
1288
|
-
return _context4.abrupt("return", elements);
|
|
1289
|
-
case 3:
|
|
1290
|
-
case "end":
|
|
1291
|
-
return _context4.stop();
|
|
1292
|
-
}
|
|
1293
|
-
}, _callee4);
|
|
1294
|
-
}));
|
|
1295
|
-
return function eachAsyncParallel(_x, _x2, _x3, _x4) {
|
|
1296
|
-
return _ref2.apply(this, arguments);
|
|
1297
|
-
};
|
|
1298
|
-
}();
|
|
1299
|
-
return /*#__PURE__*/function () {
|
|
1300
|
-
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(elements, asyncCallback) {
|
|
1301
|
-
var parallelCount,
|
|
1302
|
-
optionalSkipHasOwnPropertyCheck,
|
|
1303
|
-
_iterator9,
|
|
1304
|
-
_step9,
|
|
1305
|
-
_step9$value,
|
|
1306
|
-
value,
|
|
1307
|
-
key,
|
|
1308
|
-
_args5 = arguments,
|
|
1309
|
-
_t9,
|
|
1310
|
-
_t0;
|
|
1311
|
-
return _regeneratorRuntime.wrap(function (_context5) {
|
|
1312
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
1313
|
-
case 0:
|
|
1314
|
-
parallelCount = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : 1;
|
|
1315
|
-
optionalSkipHasOwnPropertyCheck = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : false;
|
|
1316
|
-
if (!(elements !== null && typeof elements !== 'undefined')) {
|
|
1317
|
-
_context5.next = 10;
|
|
1318
|
-
break;
|
|
1319
|
-
}
|
|
1320
|
-
parallelCount = INT_LAX(parallelCount);
|
|
1321
|
-
if (!(parallelCount > 1)) {
|
|
1322
|
-
_context5.next = 2;
|
|
1323
|
-
break;
|
|
1324
|
-
}
|
|
1325
|
-
_context5.next = 1;
|
|
1326
|
-
return eachAsyncParallel(elements, asyncCallback, parallelCount, optionalSkipHasOwnPropertyCheck);
|
|
1327
|
-
case 1:
|
|
1328
|
-
return _context5.abrupt("return", _context5.sent);
|
|
1329
|
-
case 2:
|
|
1330
|
-
_iterator9 = _createForOfIteratorHelper$1(LeUtils.eachIterator(elements, optionalSkipHasOwnPropertyCheck));
|
|
1331
|
-
_context5.prev = 3;
|
|
1332
|
-
_iterator9.s();
|
|
1333
|
-
case 4:
|
|
1334
|
-
if ((_step9 = _iterator9.n()).done) {
|
|
1335
|
-
_context5.next = 7;
|
|
1336
|
-
break;
|
|
1337
|
-
}
|
|
1338
|
-
_step9$value = _slicedToArray(_step9.value, 2), value = _step9$value[0], key = _step9$value[1];
|
|
1339
|
-
_context5.next = 5;
|
|
1340
|
-
return asyncCallback.call(value, value, key);
|
|
1341
|
-
case 5:
|
|
1342
|
-
_t9 = _context5.sent;
|
|
1343
|
-
if (!(_t9 === false)) {
|
|
1344
|
-
_context5.next = 6;
|
|
1345
|
-
break;
|
|
1346
|
-
}
|
|
1347
|
-
return _context5.abrupt("continue", 7);
|
|
1348
|
-
case 6:
|
|
1349
|
-
_context5.next = 4;
|
|
1350
|
-
break;
|
|
1351
|
-
case 7:
|
|
1352
|
-
_context5.next = 9;
|
|
1353
|
-
break;
|
|
1354
|
-
case 8:
|
|
1355
|
-
_context5.prev = 8;
|
|
1356
|
-
_t0 = _context5["catch"](3);
|
|
1357
|
-
_iterator9.e(_t0);
|
|
1358
|
-
case 9:
|
|
1359
|
-
_context5.prev = 9;
|
|
1360
|
-
_iterator9.f();
|
|
1361
|
-
return _context5.finish(9);
|
|
1362
|
-
case 10:
|
|
1363
|
-
return _context5.abrupt("return", elements);
|
|
1364
|
-
case 11:
|
|
1365
|
-
case "end":
|
|
1366
|
-
return _context5.stop();
|
|
1367
|
-
}
|
|
1368
|
-
}, _callee5, null, [[3, 8, 9, 10]]);
|
|
1369
|
-
}));
|
|
1370
|
-
return function (_x7, _x8) {
|
|
1371
|
-
return _ref5.apply(this, arguments);
|
|
1372
|
-
};
|
|
1373
|
-
}();
|
|
1374
|
-
}(),
|
|
1375
|
-
/**
|
|
1376
|
-
* Returns an empty simplified collection (array, object, or Map), based on the given elements.
|
|
1377
|
-
*
|
|
1378
|
-
* Usage:
|
|
1379
|
-
*
|
|
1380
|
-
* ```js
|
|
1381
|
-
* const [success, collection, add] = LeUtils.getEmptySimplifiedCollection(elements);
|
|
1382
|
-
* ```
|
|
1383
|
-
*
|
|
1384
|
-
* @param {*} elements
|
|
1385
|
-
* @returns {[boolean, *[]|Object|Map, (value:*,index:*)=>void]}
|
|
1386
|
-
*/
|
|
1387
|
-
getEmptySimplifiedCollection: function getEmptySimplifiedCollection(elements) {
|
|
1388
|
-
if (elements === null || typeof elements === 'undefined') {
|
|
1389
|
-
return [false, [], function (value, index) {}];
|
|
1390
|
-
}
|
|
1391
|
-
var collection = null;
|
|
1392
|
-
var add = null;
|
|
1393
|
-
if (Array.isArray(elements)) {
|
|
1394
|
-
collection = [];
|
|
1395
|
-
add = function add(value, index) {
|
|
1396
|
-
collection.push(value);
|
|
1397
|
-
};
|
|
1398
|
-
} else if (_typeof(elements) === 'object' && (elements === null || elements === void 0 ? void 0 : elements.constructor) === Object) {
|
|
1399
|
-
collection = {};
|
|
1400
|
-
add = function add(value, index) {
|
|
1401
|
-
collection[index] = value;
|
|
1402
|
-
};
|
|
1403
|
-
} else if (elements instanceof Map) {
|
|
1404
|
-
collection = new Map();
|
|
1405
|
-
add = function add(value, index) {
|
|
1406
|
-
collection.set(index, value);
|
|
1407
|
-
};
|
|
1408
|
-
} else if (typeof elements !== 'string' && (typeof (elements === null || elements === void 0 ? void 0 : elements[Symbol.iterator]) === 'function' || typeof (elements === null || elements === void 0 ? void 0 : elements.forEach) === 'function')) {
|
|
1409
|
-
collection = [];
|
|
1410
|
-
add = function add(value, index) {
|
|
1411
|
-
collection.push(value);
|
|
1412
|
-
};
|
|
1413
|
-
} else if (_typeof(elements) === 'object' || typeof elements === 'function') {
|
|
1414
|
-
collection = {};
|
|
1415
|
-
add = function add(value, index) {
|
|
1416
|
-
collection[index] = value;
|
|
1417
|
-
};
|
|
1418
|
-
} else {
|
|
1419
|
-
console.warn('Executed LeUtils.getEmptySimplifiedCollection() on an invalid type: [' + _typeof(elements) + ']', elements);
|
|
1420
|
-
return [false, [], function (value, index) {}];
|
|
1421
|
-
}
|
|
1422
|
-
return [true, collection, add];
|
|
1423
|
-
},
|
|
1424
|
-
/**
|
|
1425
|
-
* Loops through the given elements, and returns a new collection, with only the elements that returned true (or a value equals to true) from the callback.
|
|
1426
|
-
* If no callback is given, it will return all elements that are of a true value (for example, values that are: not null, not undefined, not false, not 0, not an empty string, not an empty array, not an empty object).
|
|
1427
|
-
*
|
|
1428
|
-
* @param {*} elements
|
|
1429
|
-
* @param {(value:*, index:*) => boolean|undefined} [callback]
|
|
1430
|
-
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
1431
|
-
* @returns {*}
|
|
1432
|
-
*/
|
|
1433
|
-
filter: function filter(elements, callback) {
|
|
1434
|
-
var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1435
|
-
var _LeUtils$getEmptySimp = LeUtils.getEmptySimplifiedCollection(elements),
|
|
1436
|
-
_LeUtils$getEmptySimp2 = _slicedToArray(_LeUtils$getEmptySimp, 3),
|
|
1437
|
-
success = _LeUtils$getEmptySimp2[0],
|
|
1438
|
-
collection = _LeUtils$getEmptySimp2[1],
|
|
1439
|
-
add = _LeUtils$getEmptySimp2[2];
|
|
1440
|
-
if (!success) {
|
|
1441
|
-
return elements;
|
|
1442
|
-
}
|
|
1443
|
-
LeUtils.each(elements, function (value, index) {
|
|
1444
|
-
if (!callback) {
|
|
1445
|
-
if (value) {
|
|
1446
|
-
add(value, index);
|
|
1447
|
-
}
|
|
1448
|
-
} else if (callback.call(value, value, index)) {
|
|
1449
|
-
add(value, index);
|
|
1450
|
-
}
|
|
1451
|
-
}, optionalSkipHasOwnPropertyCheck);
|
|
1452
|
-
return collection;
|
|
1453
|
-
},
|
|
1454
|
-
/**
|
|
1455
|
-
* Loops through the given elements, and returns a new collection, with the elements that were returned from the callback.
|
|
1456
|
-
*
|
|
1457
|
-
* @param {*} elements
|
|
1458
|
-
* @param {(value:*, index:*) => *} [callback]
|
|
1459
|
-
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
1460
|
-
* @returns {*}
|
|
1461
|
-
*/
|
|
1462
|
-
map: function map(elements, callback) {
|
|
1463
|
-
var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1464
|
-
var _LeUtils$getEmptySimp3 = LeUtils.getEmptySimplifiedCollection(elements),
|
|
1465
|
-
_LeUtils$getEmptySimp4 = _slicedToArray(_LeUtils$getEmptySimp3, 3),
|
|
1466
|
-
success = _LeUtils$getEmptySimp4[0],
|
|
1467
|
-
collection = _LeUtils$getEmptySimp4[1],
|
|
1468
|
-
add = _LeUtils$getEmptySimp4[2];
|
|
1469
|
-
if (!success) {
|
|
1470
|
-
return elements;
|
|
1471
|
-
}
|
|
1472
|
-
LeUtils.each(elements, function (value, index) {
|
|
1473
|
-
if (!callback) {
|
|
1474
|
-
add(value, index);
|
|
1475
|
-
} else {
|
|
1476
|
-
add(callback.call(value, value, index), index);
|
|
1477
|
-
}
|
|
1478
|
-
}, optionalSkipHasOwnPropertyCheck);
|
|
1479
|
-
return collection;
|
|
1480
|
-
},
|
|
1481
|
-
/**
|
|
1482
|
-
* Loops through the given elements, and returns a new array, with the elements that were returned from the callback. Always returns an array.
|
|
1483
|
-
*
|
|
1484
|
-
* @param {*} elements
|
|
1485
|
-
* @param {(value:*, index:*) => *} [callback]
|
|
1486
|
-
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
1487
|
-
* @returns {*[]}
|
|
1488
|
-
*/
|
|
1489
|
-
mapToArray: function mapToArray(elements, callback) {
|
|
1490
|
-
var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1491
|
-
var result = [];
|
|
1492
|
-
LeUtils.each(elements, function (value, index) {
|
|
1493
|
-
if (!callback) {
|
|
1494
|
-
result.push(value);
|
|
1495
|
-
} else {
|
|
1496
|
-
result.push(callback.call(value, value, index));
|
|
1497
|
-
}
|
|
1498
|
-
}, optionalSkipHasOwnPropertyCheck);
|
|
1499
|
-
return result;
|
|
1500
|
-
},
|
|
1501
|
-
/**
|
|
1502
|
-
* Loops through the given elements, and returns a new array, with the elements that were returned from the callback. The elements will be sorted by the result from the given comparator. Always returns an array.
|
|
1503
|
-
*
|
|
1504
|
-
* @param {*} elements
|
|
1505
|
-
* @param {(valueA:*, valueB:*) => number} comparator
|
|
1506
|
-
* @param {(value:*, index:*) => *} [callback]
|
|
1507
|
-
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
1508
|
-
* @returns {*[]}
|
|
1509
|
-
*/
|
|
1510
|
-
mapToArraySorted: function mapToArraySorted(elements, comparator, callback) {
|
|
1511
|
-
var optionalSkipHasOwnPropertyCheck = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
1512
|
-
var keys = LeUtils.sortKeys(elements, comparator, optionalSkipHasOwnPropertyCheck);
|
|
1513
|
-
var result = [];
|
|
1514
|
-
var _iterator0 = _createForOfIteratorHelper$1(keys),
|
|
1515
|
-
_step0;
|
|
1516
|
-
try {
|
|
1517
|
-
for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
|
|
1518
|
-
var key = _step0.value;
|
|
1519
|
-
var value = LeUtils.getValueAtIndex(elements, key, optionalSkipHasOwnPropertyCheck);
|
|
1520
|
-
if (!callback) {
|
|
1521
|
-
result.push(value);
|
|
1522
|
-
} else {
|
|
1523
|
-
result.push(callback.call(value, value, key));
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
} catch (err) {
|
|
1527
|
-
_iterator0.e(err);
|
|
1528
|
-
} finally {
|
|
1529
|
-
_iterator0.f();
|
|
1530
|
-
}
|
|
1531
|
-
return result;
|
|
1532
|
-
},
|
|
1533
|
-
/**
|
|
1534
|
-
* Loops through the given elements, and returns a new array, with the keys from the given elements, sorted by the result from the given comparator. Always returns an array.
|
|
1535
|
-
*
|
|
1536
|
-
* @param {*} elements
|
|
1537
|
-
* @param {(valueA:*, valueB:*) => number} comparator
|
|
1538
|
-
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
1539
|
-
* @returns {*[]}
|
|
1540
|
-
*/
|
|
1541
|
-
sortKeys: function sortKeys(elements, comparator) {
|
|
1542
|
-
var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1543
|
-
var keys = [];
|
|
1544
|
-
LeUtils.each(elements, function (value, index) {
|
|
1545
|
-
keys.push(index);
|
|
1546
|
-
}, optionalSkipHasOwnPropertyCheck);
|
|
1547
|
-
keys.sort(function (a, b) {
|
|
1548
|
-
return comparator(LeUtils.getValueAtIndex(elements, a, optionalSkipHasOwnPropertyCheck), LeUtils.getValueAtIndex(elements, b, optionalSkipHasOwnPropertyCheck));
|
|
1549
|
-
});
|
|
1550
|
-
return keys;
|
|
1551
|
-
},
|
|
1552
|
-
/**
|
|
1553
|
-
* Turns the given value(s) into a 1 dimensional array.
|
|
1554
|
-
*
|
|
1555
|
-
* Does the same thing as Array.flat(Infinity).
|
|
1556
|
-
*
|
|
1557
|
-
* @param {*} array
|
|
1558
|
-
* @returns {*[]}
|
|
1559
|
-
*/
|
|
1560
|
-
flattenArray: function () {
|
|
1561
|
-
var _flattenArrayRecursive = function flattenArrayRecursive(result, array) {
|
|
1562
|
-
if (!Array.isArray(array)) {
|
|
1563
|
-
result.push(array);
|
|
1564
|
-
return;
|
|
1565
|
-
}
|
|
1566
|
-
array.forEach(function (entry) {
|
|
1567
|
-
_flattenArrayRecursive(result, entry);
|
|
1568
|
-
});
|
|
1569
|
-
};
|
|
1570
|
-
return function (array) {
|
|
1571
|
-
if (!Array.isArray(array)) {
|
|
1572
|
-
return [array];
|
|
1573
|
-
}
|
|
1574
|
-
var result = [];
|
|
1575
|
-
array.forEach(function (entry) {
|
|
1576
|
-
_flattenArrayRecursive(result, entry);
|
|
1577
|
-
});
|
|
1578
|
-
return result;
|
|
1579
|
-
};
|
|
1580
|
-
}(),
|
|
1581
|
-
/**
|
|
1582
|
-
* Turns the given value(s) into a 1 dimensional array.
|
|
1583
|
-
*
|
|
1584
|
-
* Compared to LeUtils.flattenArray(), this function also supports objects, Maps, Sets, and other iterable objects.
|
|
1585
|
-
*
|
|
1586
|
-
* @param {*} elements
|
|
1587
|
-
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
1588
|
-
* @returns {*[]}
|
|
1589
|
-
*/
|
|
1590
|
-
flattenToArray: function () {
|
|
1591
|
-
var _flattenToArrayRecursive = function flattenToArrayRecursive(result, elements, optionalSkipHasOwnPropertyCheck) {
|
|
1592
|
-
if (!LeUtils.supportsEach(elements)) {
|
|
1593
|
-
result.push(elements);
|
|
1594
|
-
return;
|
|
1595
|
-
}
|
|
1596
|
-
LeUtils.each(elements, function (entry) {
|
|
1597
|
-
_flattenToArrayRecursive(result, entry, optionalSkipHasOwnPropertyCheck);
|
|
1598
|
-
}, optionalSkipHasOwnPropertyCheck);
|
|
1599
|
-
};
|
|
1600
|
-
return function (elements) {
|
|
1601
|
-
var optionalSkipHasOwnPropertyCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1602
|
-
if (!LeUtils.supportsEach(elements)) {
|
|
1603
|
-
return [elements];
|
|
1604
|
-
}
|
|
1605
|
-
var result = [];
|
|
1606
|
-
LeUtils.each(elements, function (entry) {
|
|
1607
|
-
_flattenToArrayRecursive(result, entry, optionalSkipHasOwnPropertyCheck);
|
|
1608
|
-
}, optionalSkipHasOwnPropertyCheck);
|
|
1609
|
-
return result;
|
|
1610
|
-
};
|
|
1611
|
-
}(),
|
|
1612
|
-
/**
|
|
1613
|
-
* Compares two values. Primarily used for sorting.
|
|
1614
|
-
*
|
|
1615
|
-
* @param {*} a
|
|
1616
|
-
* @param {*} b
|
|
1617
|
-
* @returns {number}
|
|
1618
|
-
*/
|
|
1619
|
-
compare: function compare(a, b) {
|
|
1620
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
1621
|
-
},
|
|
1622
|
-
/**
|
|
1623
|
-
* Compares two numbers. Primarily used for sorting.
|
|
1624
|
-
*
|
|
1625
|
-
* @param {number} a
|
|
1626
|
-
* @param {number} b
|
|
1627
|
-
* @returns {number}
|
|
1628
|
-
*/
|
|
1629
|
-
compareNumbers: function compareNumbers(a, b) {
|
|
1630
|
-
return a - b;
|
|
1631
|
-
},
|
|
1632
|
-
/**
|
|
1633
|
-
* Compares two numeric strings. Primarily used for sorting.
|
|
1634
|
-
*
|
|
1635
|
-
* @param {string|number} a
|
|
1636
|
-
* @param {string|number} b
|
|
1637
|
-
* @returns {number}
|
|
1638
|
-
*/
|
|
1639
|
-
compareNumericStrings: function compareNumericStrings(a, b) {
|
|
1640
|
-
var aParts = STRING(a).split('.');
|
|
1641
|
-
var bParts = STRING(b).split('.');
|
|
1642
|
-
for (var i = 0; i < Math.min(aParts.length, bParts.length); i++) {
|
|
1643
|
-
a = aParts[i].trim();
|
|
1644
|
-
b = bParts[i].trim();
|
|
1645
|
-
if (a.length !== b.length) {
|
|
1646
|
-
return a.length < b.length ? -1 : 1;
|
|
1647
|
-
}
|
|
1648
|
-
if (a !== b) {
|
|
1649
|
-
return a < b ? -1 : 1;
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
if (aParts.length !== bParts.length) {
|
|
1653
|
-
return aParts.length < bParts.length ? -1 : 1;
|
|
1654
|
-
}
|
|
1655
|
-
return 0;
|
|
1656
|
-
},
|
|
1657
|
-
/**
|
|
1658
|
-
* Compares two strings in a natural way, meaning that it will compare numbers in the strings as actual numbers.
|
|
1659
|
-
*
|
|
1660
|
-
* This will correctly sort numeric parts so that "file5.txt" comes before "file10.txt", as well as that "file/5/test.txt" comes before "file/10/test.txt".
|
|
1661
|
-
*
|
|
1662
|
-
* @param {string} a
|
|
1663
|
-
* @param {string} b
|
|
1664
|
-
* @returns {number}
|
|
1665
|
-
*/
|
|
1666
|
-
compareNaturalStrings: function compareNaturalStrings(a, b) {
|
|
1667
|
-
var _a$match, _b$match;
|
|
1668
|
-
var re = /(\d+|\D+)/g; // split into runs of digits or non-digits
|
|
1669
|
-
var aTokens = (_a$match = a.match(re)) !== null && _a$match !== void 0 ? _a$match : [];
|
|
1670
|
-
var bTokens = (_b$match = b.match(re)) !== null && _b$match !== void 0 ? _b$match : [];
|
|
1671
|
-
var len = Math.min(aTokens.length, bTokens.length);
|
|
1672
|
-
for (var i = 0; i < len; i++) {
|
|
1673
|
-
var x = aTokens[i];
|
|
1674
|
-
var y = bTokens[i];
|
|
1675
|
-
if (x === y) {
|
|
1676
|
-
continue;
|
|
1677
|
-
}
|
|
1678
|
-
|
|
1679
|
-
// if both are numbers, compare as numbers
|
|
1680
|
-
var nx = parseInt(x, 10);
|
|
1681
|
-
var ny = parseInt(y, 10);
|
|
1682
|
-
if (!isNaN(nx) && !isNaN(ny)) {
|
|
1683
|
-
return nx - ny;
|
|
1684
|
-
}
|
|
1685
|
-
|
|
1686
|
-
// otherwise compare lexically
|
|
1687
|
-
return x < y ? -1 : 1;
|
|
1688
|
-
}
|
|
1689
|
-
return aTokens.length - bTokens.length;
|
|
1690
|
-
},
|
|
1691
|
-
/**
|
|
1692
|
-
* Compares two strings generated by LeUtils.timestamp(). Primarily used for sorting.
|
|
1693
|
-
*
|
|
1694
|
-
* @param {string} a
|
|
1695
|
-
* @param {string} b
|
|
1696
|
-
* @returns {number}
|
|
1697
|
-
*/
|
|
1698
|
-
compareTimestampStrings: function compareTimestampStrings(a, b) {
|
|
1699
|
-
a = LeUtils.base64ToHex(STRING(a).replaceAll('-', '+').replaceAll('_', '/'));
|
|
1700
|
-
b = LeUtils.base64ToHex(STRING(b).replaceAll('-', '+').replaceAll('_', '/'));
|
|
1701
|
-
return LeUtils.compare(a, b);
|
|
1702
|
-
},
|
|
1703
|
-
/**
|
|
1704
|
-
* Returns true if the given object is empty, false otherwise.
|
|
1705
|
-
*
|
|
1706
|
-
* @param {Object} obj
|
|
1707
|
-
* @param [optionalSkipHasOwnPropertyCheck]
|
|
1708
|
-
* @returns {boolean}
|
|
1709
|
-
*/
|
|
1710
|
-
isEmptyObject: function isEmptyObject(obj) {
|
|
1711
|
-
var optionalSkipHasOwnPropertyCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1712
|
-
for (var field in obj) {
|
|
1713
|
-
if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(obj, field)) {
|
|
1714
|
-
return false;
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
return true;
|
|
1718
|
-
},
|
|
1719
|
-
/**
|
|
1720
|
-
* Returns the number of fields in the given object.
|
|
1721
|
-
*
|
|
1722
|
-
* @param {Object} obj
|
|
1723
|
-
* @param [optionalSkipHasOwnPropertyCheck]
|
|
1724
|
-
* @returns {number}
|
|
1725
|
-
*/
|
|
1726
|
-
getObjectFieldsCount: function getObjectFieldsCount(obj) {
|
|
1727
|
-
var optionalSkipHasOwnPropertyCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1728
|
-
var count = 0;
|
|
1729
|
-
for (var field in obj) {
|
|
1730
|
-
if (optionalSkipHasOwnPropertyCheck === true || Object.prototype.hasOwnProperty.call(obj, field)) {
|
|
1731
|
-
count++;
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
|
-
return count;
|
|
1735
|
-
},
|
|
1736
|
-
/**
|
|
1737
|
-
* Returns true if the given function is a generator function (like: "function* (){}"), returns false otherwise.
|
|
1738
|
-
*
|
|
1739
|
-
* @param {Function} func
|
|
1740
|
-
* @returns {boolean}
|
|
1741
|
-
*/
|
|
1742
|
-
isGeneratorFunction: function () {
|
|
1743
|
-
var GeneratorFunction = _regeneratorRuntime.mark(function _callee6() {
|
|
1744
|
-
return _regeneratorRuntime.wrap(function (_context6) {
|
|
1745
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
1746
|
-
case 0:
|
|
1747
|
-
case "end":
|
|
1748
|
-
return _context6.stop();
|
|
1749
|
-
}
|
|
1750
|
-
}, _callee6);
|
|
1751
|
-
}).constructor;
|
|
1752
|
-
var AsyncGeneratorFunction = _wrapAsyncGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
|
|
1753
|
-
return _regeneratorRuntime.wrap(function (_context7) {
|
|
1754
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
1755
|
-
case 0:
|
|
1756
|
-
case "end":
|
|
1757
|
-
return _context7.stop();
|
|
1758
|
-
}
|
|
1759
|
-
}, _callee7);
|
|
1760
|
-
})).constructor;
|
|
1761
|
-
var RegularFunction = function () {}.constructor;
|
|
1762
|
-
var PossibleGeneratorFunctionNames = Array.from(new Set(['GeneratorFunction', 'AsyncFunction', 'AsyncGeneratorFunction', GeneratorFunction.name, AsyncGeneratorFunction.name])).filter(function (element) {
|
|
1763
|
-
return element && element !== RegularFunction.name;
|
|
1764
|
-
});
|
|
1765
|
-
return function (func) {
|
|
1766
|
-
if (!func) {
|
|
1767
|
-
return false;
|
|
1768
|
-
}
|
|
1769
|
-
var constructor = func.constructor;
|
|
1770
|
-
if (!constructor) {
|
|
1771
|
-
return false;
|
|
1772
|
-
}
|
|
1773
|
-
// noinspection JSUnresolvedVariable
|
|
1774
|
-
return constructor.name && PossibleGeneratorFunctionNames.includes(constructor.name) || constructor.displayName && PossibleGeneratorFunctionNames.includes(constructor.displayName);
|
|
1775
|
-
};
|
|
1776
|
-
}(),
|
|
1777
|
-
/**
|
|
1778
|
-
* Executes the callback after the given number of milliseconds. Passes the elapsed time in seconds to the callback.
|
|
1779
|
-
*
|
|
1780
|
-
* To cancel the timeout, call remove() on the result of this function (example: "const timeoutHandler = LeUtils.setTimeout((deltaTime)=>{}, 1000); timeoutHandler.remove();")
|
|
1781
|
-
*
|
|
1782
|
-
* @param {(deltaTime:number) => *} callback
|
|
1783
|
-
* @param {number} ms
|
|
1784
|
-
* @returns {{remove:Function}}
|
|
1785
|
-
*/
|
|
1786
|
-
setTimeout: function setTimeout(callback, ms) {
|
|
1787
|
-
var _globalThis$performan, _globalThis$performan2, _globalThis$performan3;
|
|
1788
|
-
if (!(globalThis !== null && globalThis !== void 0 && globalThis.setTimeout) || !(globalThis !== null && globalThis !== void 0 && globalThis.clearTimeout)) {
|
|
1789
|
-
console.warn('LeUtils.setTimeout() called in an environment without globalThis.setTimeout, returning a no-op handler.');
|
|
1790
|
-
return {
|
|
1791
|
-
remove: function remove() {}
|
|
1792
|
-
};
|
|
1793
|
-
}
|
|
1794
|
-
ms = FLOAT_LAX(ms);
|
|
1795
|
-
var lastTime = (_globalThis$performan = globalThis === null || globalThis === void 0 || (_globalThis$performan2 = globalThis.performance) === null || _globalThis$performan2 === void 0 || (_globalThis$performan3 = _globalThis$performan2.now) === null || _globalThis$performan3 === void 0 ? void 0 : _globalThis$performan3.call(_globalThis$performan2)) !== null && _globalThis$performan !== void 0 ? _globalThis$performan : 0;
|
|
1796
|
-
/** @type {number|null} */
|
|
1797
|
-
var handler = globalThis.setTimeout(function () {
|
|
1798
|
-
var _globalThis$performan4, _globalThis$performan5, _globalThis$performan6;
|
|
1799
|
-
var currentTime = (_globalThis$performan4 = globalThis === null || globalThis === void 0 || (_globalThis$performan5 = globalThis.performance) === null || _globalThis$performan5 === void 0 || (_globalThis$performan6 = _globalThis$performan5.now) === null || _globalThis$performan6 === void 0 ? void 0 : _globalThis$performan6.call(_globalThis$performan5)) !== null && _globalThis$performan4 !== void 0 ? _globalThis$performan4 : 0;
|
|
1800
|
-
try {
|
|
1801
|
-
callback((currentTime - lastTime) / 1000);
|
|
1802
|
-
} catch (e) {
|
|
1803
|
-
console.error(e);
|
|
1804
|
-
}
|
|
1805
|
-
lastTime = currentTime;
|
|
1806
|
-
}, ms);
|
|
1807
|
-
return {
|
|
1808
|
-
remove: function remove() {
|
|
1809
|
-
if (handler !== null) {
|
|
1810
|
-
globalThis.clearTimeout(handler);
|
|
1811
|
-
handler = null;
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
};
|
|
1815
|
-
},
|
|
1816
|
-
/**
|
|
1817
|
-
* Executes the callback every given number of milliseconds. Passes the time difference in seconds between the last frame and now to it.
|
|
1818
|
-
*
|
|
1819
|
-
* To remove the interval, call remove() on the result of this function (example: "const intervalHandler = LeUtils.setInterval((deltaTime)=>{}, 1000); intervalHandler.remove();")
|
|
1820
|
-
*
|
|
1821
|
-
* @param {(deltaTime:number) => *} callback
|
|
1822
|
-
* @param {number} [intervalMs]
|
|
1823
|
-
* @param {boolean} [fireImmediately]
|
|
1824
|
-
* @returns {{remove:Function}}
|
|
1825
|
-
*/
|
|
1826
|
-
setInterval: function setInterval(callback) {
|
|
1827
|
-
var _globalThis$performan7, _globalThis$performan8, _globalThis$performan9;
|
|
1828
|
-
var intervalMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
|
|
1829
|
-
var fireImmediately = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1830
|
-
intervalMs = FLOAT_LAX_ANY(intervalMs, 1000);
|
|
1831
|
-
if (fireImmediately) {
|
|
1832
|
-
try {
|
|
1833
|
-
callback(0);
|
|
1834
|
-
} catch (e) {
|
|
1835
|
-
console.error(e);
|
|
1836
|
-
}
|
|
1837
|
-
}
|
|
1838
|
-
if (!(globalThis !== null && globalThis !== void 0 && globalThis.setInterval) || !(globalThis !== null && globalThis !== void 0 && globalThis.clearInterval)) {
|
|
1839
|
-
console.warn('LeUtils.setInterval() called in an environment without globalThis.setInterval, returning a no-op handler.');
|
|
1840
|
-
return {
|
|
1841
|
-
remove: function remove() {}
|
|
1842
|
-
};
|
|
1843
|
-
}
|
|
1844
|
-
var lastTime = (_globalThis$performan7 = globalThis === null || globalThis === void 0 || (_globalThis$performan8 = globalThis.performance) === null || _globalThis$performan8 === void 0 || (_globalThis$performan9 = _globalThis$performan8.now) === null || _globalThis$performan9 === void 0 ? void 0 : _globalThis$performan9.call(_globalThis$performan8)) !== null && _globalThis$performan7 !== void 0 ? _globalThis$performan7 : 0;
|
|
1845
|
-
/** @type {number|null} */
|
|
1846
|
-
var handler = globalThis.setInterval(function () {
|
|
1847
|
-
var _globalThis$performan0, _globalThis$performan1, _globalThis$performan10;
|
|
1848
|
-
var currentTime = (_globalThis$performan0 = globalThis === null || globalThis === void 0 || (_globalThis$performan1 = globalThis.performance) === null || _globalThis$performan1 === void 0 || (_globalThis$performan10 = _globalThis$performan1.now) === null || _globalThis$performan10 === void 0 ? void 0 : _globalThis$performan10.call(_globalThis$performan1)) !== null && _globalThis$performan0 !== void 0 ? _globalThis$performan0 : 0;
|
|
1849
|
-
try {
|
|
1850
|
-
callback((currentTime - lastTime) / 1000);
|
|
1851
|
-
} catch (e) {
|
|
1852
|
-
console.error(e);
|
|
1853
|
-
}
|
|
1854
|
-
lastTime = currentTime;
|
|
1855
|
-
}, intervalMs);
|
|
1856
|
-
return {
|
|
1857
|
-
remove: function remove() {
|
|
1858
|
-
if (handler !== null) {
|
|
1859
|
-
globalThis.clearInterval(handler);
|
|
1860
|
-
handler = null;
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
};
|
|
1864
|
-
},
|
|
1865
|
-
/**
|
|
1866
|
-
* Executes the callback after the given number of frames. Passes the elapsed time in seconds to the callback.
|
|
1867
|
-
*
|
|
1868
|
-
* To cancel the timeout, call remove() on the result of this function (example: "const timeoutHandler = LeUtils.setAnimationFrameTimeout((deltaTime){}, 5); timeoutHandler.remove();")
|
|
1869
|
-
*
|
|
1870
|
-
* @param {(deltaTime:number) => *} callback
|
|
1871
|
-
* @param {number} [frames]
|
|
1872
|
-
* @returns {{remove:Function}}
|
|
1873
|
-
*/
|
|
1874
|
-
setAnimationFrameTimeout: function setAnimationFrameTimeout(callback) {
|
|
1875
|
-
var _globalThis$performan11, _globalThis$performan12, _globalThis$performan13;
|
|
1876
|
-
var frames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1877
|
-
if (!(globalThis !== null && globalThis !== void 0 && globalThis.requestAnimationFrame) || !(globalThis !== null && globalThis !== void 0 && globalThis.cancelAnimationFrame)) {
|
|
1878
|
-
console.warn('LeUtils.setAnimationFrameTimeout() called in an environment without globalThis.requestAnimationFrame, returning a no-op handler.');
|
|
1879
|
-
return {
|
|
1880
|
-
remove: function remove() {}
|
|
1881
|
-
};
|
|
1882
|
-
}
|
|
1883
|
-
frames = INT_LAX_ANY(frames, 1);
|
|
1884
|
-
var run = true;
|
|
1885
|
-
var requestAnimationFrameId = null;
|
|
1886
|
-
var lastTime = (_globalThis$performan11 = globalThis === null || globalThis === void 0 || (_globalThis$performan12 = globalThis.performance) === null || _globalThis$performan12 === void 0 || (_globalThis$performan13 = _globalThis$performan12.now) === null || _globalThis$performan13 === void 0 ? void 0 : _globalThis$performan13.call(_globalThis$performan12)) !== null && _globalThis$performan11 !== void 0 ? _globalThis$performan11 : 0;
|
|
1887
|
-
var _tick = function tick() {
|
|
1888
|
-
if (run) {
|
|
1889
|
-
if (frames <= 0) {
|
|
1890
|
-
var _globalThis$performan14, _globalThis$performan15, _globalThis$performan16;
|
|
1891
|
-
run = false;
|
|
1892
|
-
requestAnimationFrameId = null;
|
|
1893
|
-
var currentTime = (_globalThis$performan14 = globalThis === null || globalThis === void 0 || (_globalThis$performan15 = globalThis.performance) === null || _globalThis$performan15 === void 0 || (_globalThis$performan16 = _globalThis$performan15.now) === null || _globalThis$performan16 === void 0 ? void 0 : _globalThis$performan16.call(_globalThis$performan15)) !== null && _globalThis$performan14 !== void 0 ? _globalThis$performan14 : 0;
|
|
1894
|
-
try {
|
|
1895
|
-
callback((currentTime - lastTime) / 1000);
|
|
1896
|
-
} catch (e) {
|
|
1897
|
-
console.error(e);
|
|
1898
|
-
}
|
|
1899
|
-
lastTime = currentTime;
|
|
1900
|
-
return;
|
|
1901
|
-
}
|
|
1902
|
-
frames--;
|
|
1903
|
-
requestAnimationFrameId = globalThis.requestAnimationFrame(_tick);
|
|
1904
|
-
}
|
|
1905
|
-
};
|
|
1906
|
-
_tick();
|
|
1907
|
-
return {
|
|
1908
|
-
remove: function remove() {
|
|
1909
|
-
run = false;
|
|
1910
|
-
if (requestAnimationFrameId !== null) {
|
|
1911
|
-
globalThis.cancelAnimationFrame(requestAnimationFrameId);
|
|
1912
|
-
requestAnimationFrameId = null;
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1915
|
-
};
|
|
1916
|
-
},
|
|
1917
|
-
/**
|
|
1918
|
-
* Executes the callback every given number of frames. Passes the time difference in seconds between the last frame and now to it.
|
|
1919
|
-
*
|
|
1920
|
-
* To remove the interval, call remove() on the result of this function (example: "const intervalHandler = LeUtils.setAnimationFrameInterval((deltaTime)=>{}, 5); intervalHandler.remove();")
|
|
1921
|
-
*
|
|
1922
|
-
* @param {(deltaTime:number) => *} callback
|
|
1923
|
-
* @param {number} [intervalFrames]
|
|
1924
|
-
* @param {boolean} [fireImmediately]
|
|
1925
|
-
* @returns {{remove:Function}}
|
|
1926
|
-
*/
|
|
1927
|
-
setAnimationFrameInterval: function setAnimationFrameInterval(callback) {
|
|
1928
|
-
var intervalFrames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1929
|
-
var fireImmediately = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1930
|
-
intervalFrames = INT_LAX_ANY(intervalFrames, 1);
|
|
1931
|
-
if (fireImmediately) {
|
|
1932
|
-
try {
|
|
1933
|
-
callback(0);
|
|
1934
|
-
} catch (e) {
|
|
1935
|
-
console.error(e);
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
if (!(globalThis !== null && globalThis !== void 0 && globalThis.requestAnimationFrame) || !(globalThis !== null && globalThis !== void 0 && globalThis.cancelAnimationFrame)) {
|
|
1939
|
-
console.warn('LeUtils.setAnimationFrameInterval() called in an environment without globalThis.requestAnimationFrame, returning a no-op handler.');
|
|
1940
|
-
return {
|
|
1941
|
-
remove: function remove() {}
|
|
1942
|
-
};
|
|
1943
|
-
}
|
|
1944
|
-
var run = true;
|
|
1945
|
-
var requestAnimationFrameId = null;
|
|
1946
|
-
var lastTimestamp = 0;
|
|
1947
|
-
var totalTime = 0;
|
|
1948
|
-
var frames = intervalFrames;
|
|
1949
|
-
var _tick2 = function tick(timestamp) {
|
|
1950
|
-
if (run) {
|
|
1951
|
-
if (lastTimestamp === 0) {
|
|
1952
|
-
lastTimestamp = timestamp;
|
|
1953
|
-
}
|
|
1954
|
-
totalTime += timestamp - lastTimestamp;
|
|
1955
|
-
lastTimestamp = timestamp;
|
|
1956
|
-
frames--;
|
|
1957
|
-
if (frames <= 0) {
|
|
1958
|
-
try {
|
|
1959
|
-
callback(totalTime / 1000);
|
|
1960
|
-
} catch (e) {
|
|
1961
|
-
console.error(e);
|
|
1962
|
-
}
|
|
1963
|
-
totalTime = 0;
|
|
1964
|
-
frames = intervalFrames;
|
|
1965
|
-
}
|
|
1966
|
-
if (run) {
|
|
1967
|
-
requestAnimationFrameId = globalThis.requestAnimationFrame(_tick2);
|
|
1968
|
-
}
|
|
1969
|
-
}
|
|
1970
|
-
};
|
|
1971
|
-
globalThis.requestAnimationFrame(_tick2);
|
|
1972
|
-
return {
|
|
1973
|
-
remove: function remove() {
|
|
1974
|
-
run = false;
|
|
1975
|
-
if (requestAnimationFrameId !== null) {
|
|
1976
|
-
globalThis.cancelAnimationFrame(requestAnimationFrameId);
|
|
1977
|
-
requestAnimationFrameId = null;
|
|
1978
|
-
}
|
|
1979
|
-
}
|
|
1980
|
-
};
|
|
1981
|
-
},
|
|
1982
|
-
/**
|
|
1983
|
-
* Returns a promise, which will be resolved after the given number of milliseconds.
|
|
1984
|
-
*
|
|
1985
|
-
* @param {number} ms
|
|
1986
|
-
* @returns {Promise<number>}
|
|
1987
|
-
*/
|
|
1988
|
-
promiseTimeout: function promiseTimeout(ms) {
|
|
1989
|
-
ms = FLOAT_LAX(ms);
|
|
1990
|
-
if (ms <= 0) {
|
|
1991
|
-
return new Promise(function (resolve) {
|
|
1992
|
-
return resolve(0);
|
|
1993
|
-
});
|
|
1994
|
-
}
|
|
1995
|
-
return new Promise(function (resolve) {
|
|
1996
|
-
return LeUtils.setTimeout(resolve, ms);
|
|
1997
|
-
});
|
|
1998
|
-
},
|
|
1999
|
-
/**
|
|
2000
|
-
* Returns a promise, which will be resolved after the given number of frames.
|
|
2001
|
-
*
|
|
2002
|
-
* @param {number} frames
|
|
2003
|
-
* @returns {Promise<number>}
|
|
2004
|
-
*/
|
|
2005
|
-
promiseAnimationFrameTimeout: function promiseAnimationFrameTimeout(frames) {
|
|
2006
|
-
frames = INT_LAX(frames);
|
|
2007
|
-
if (frames <= 0) {
|
|
2008
|
-
return new Promise(function (resolve) {
|
|
2009
|
-
return resolve(0);
|
|
2010
|
-
});
|
|
2011
|
-
}
|
|
2012
|
-
return new Promise(function (resolve) {
|
|
2013
|
-
return LeUtils.setAnimationFrameTimeout(resolve, frames);
|
|
2014
|
-
});
|
|
2015
|
-
},
|
|
2016
|
-
/**
|
|
2017
|
-
* Allows you to do a fetch, with built-in retry and abort functionality.
|
|
2018
|
-
*
|
|
2019
|
-
* @param {string} url
|
|
2020
|
-
* @param {{retries?:number|null, delay?:number|((attempt:number)=>number)|null}|Object|null} [options]
|
|
2021
|
-
* @returns {{then:Function, catch:Function, finally:Function, remove:Function, isRemoved:Function}}
|
|
2022
|
-
*/
|
|
2023
|
-
fetch: function (_fetch) {
|
|
2024
|
-
function fetch(_x9, _x0) {
|
|
2025
|
-
return _fetch.apply(this, arguments);
|
|
2026
|
-
}
|
|
2027
|
-
fetch.toString = function () {
|
|
2028
|
-
return _fetch.toString();
|
|
2029
|
-
};
|
|
2030
|
-
return fetch;
|
|
2031
|
-
}(function (url, options) {
|
|
2032
|
-
var currentRetries = 0;
|
|
2033
|
-
var retries = INT_LAX(options === null || options === void 0 ? void 0 : options.retries);
|
|
2034
|
-
var controllerAborted = false;
|
|
2035
|
-
var controller = null;
|
|
2036
|
-
if (globalThis !== null && globalThis !== void 0 && globalThis.AbortController) {
|
|
2037
|
-
controller = new AbortController();
|
|
2038
|
-
}
|
|
2039
|
-
var promise = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
2040
|
-
var _attemptFetch;
|
|
2041
|
-
return _regeneratorRuntime.wrap(function (_context9) {
|
|
2042
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
2043
|
-
case 0:
|
|
2044
|
-
_attemptFetch = /*#__PURE__*/function () {
|
|
2045
|
-
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
|
|
2046
|
-
var _controller;
|
|
2047
|
-
var _controller2, response, _controller3, _t1;
|
|
2048
|
-
return _regeneratorRuntime.wrap(function (_context8) {
|
|
2049
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
2050
|
-
case 0:
|
|
2051
|
-
if (!(controllerAborted || (_controller = controller) !== null && _controller !== void 0 && (_controller = _controller.signal) !== null && _controller !== void 0 && _controller.aborted)) {
|
|
2052
|
-
_context8.next = 1;
|
|
2053
|
-
break;
|
|
2054
|
-
}
|
|
2055
|
-
throw new Error('Aborted');
|
|
2056
|
-
case 1:
|
|
2057
|
-
_context8.prev = 1;
|
|
2058
|
-
_context8.next = 2;
|
|
2059
|
-
return fetch(url, _objectSpread(_objectSpread({
|
|
2060
|
-
signal: (_controller2 = controller) === null || _controller2 === void 0 ? void 0 : _controller2.signal
|
|
2061
|
-
}, options !== null && options !== void 0 ? options : {}), {}, {
|
|
2062
|
-
retries: undefined,
|
|
2063
|
-
delay: undefined
|
|
2064
|
-
}));
|
|
2065
|
-
case 2:
|
|
2066
|
-
response = _context8.sent;
|
|
2067
|
-
if (response.ok) {
|
|
2068
|
-
_context8.next = 3;
|
|
2069
|
-
break;
|
|
2070
|
-
}
|
|
2071
|
-
throw new Error('Network request failed: ' + response.status + ' ' + response.statusText);
|
|
2072
|
-
case 3:
|
|
2073
|
-
return _context8.abrupt("return", response);
|
|
2074
|
-
case 4:
|
|
2075
|
-
_context8.prev = 4;
|
|
2076
|
-
_t1 = _context8["catch"](1);
|
|
2077
|
-
if (!(controllerAborted || (_controller3 = controller) !== null && _controller3 !== void 0 && (_controller3 = _controller3.signal) !== null && _controller3 !== void 0 && _controller3.aborted)) {
|
|
2078
|
-
_context8.next = 5;
|
|
2079
|
-
break;
|
|
2080
|
-
}
|
|
2081
|
-
throw new Error('Aborted');
|
|
2082
|
-
case 5:
|
|
2083
|
-
if (!(currentRetries >= retries)) {
|
|
2084
|
-
_context8.next = 6;
|
|
2085
|
-
break;
|
|
2086
|
-
}
|
|
2087
|
-
throw _t1;
|
|
2088
|
-
case 6:
|
|
2089
|
-
currentRetries++;
|
|
2090
|
-
_context8.next = 7;
|
|
2091
|
-
return LeUtils.promiseTimeout(typeof (options === null || options === void 0 ? void 0 : options.delay) === 'function' ? INT_LAX_ANY(options === null || options === void 0 ? void 0 : options.delay(currentRetries), 500) : INT_LAX_ANY(options === null || options === void 0 ? void 0 : options.delay, 500));
|
|
2092
|
-
case 7:
|
|
2093
|
-
_context8.next = 8;
|
|
2094
|
-
return _attemptFetch();
|
|
2095
|
-
case 8:
|
|
2096
|
-
return _context8.abrupt("return", _context8.sent);
|
|
2097
|
-
case 9:
|
|
2098
|
-
case "end":
|
|
2099
|
-
return _context8.stop();
|
|
2100
|
-
}
|
|
2101
|
-
}, _callee8, null, [[1, 4]]);
|
|
2102
|
-
}));
|
|
2103
|
-
return function attemptFetch() {
|
|
2104
|
-
return _ref7.apply(this, arguments);
|
|
2105
|
-
};
|
|
2106
|
-
}();
|
|
2107
|
-
_context9.next = 1;
|
|
2108
|
-
return _attemptFetch();
|
|
2109
|
-
case 1:
|
|
2110
|
-
return _context9.abrupt("return", _context9.sent);
|
|
2111
|
-
case 2:
|
|
2112
|
-
case "end":
|
|
2113
|
-
return _context9.stop();
|
|
2114
|
-
}
|
|
2115
|
-
}, _callee9);
|
|
2116
|
-
}))();
|
|
2117
|
-
var result = {};
|
|
2118
|
-
result.then = function () {
|
|
2119
|
-
var _promise;
|
|
2120
|
-
promise = (_promise = promise).then.apply(_promise, arguments);
|
|
2121
|
-
return result;
|
|
2122
|
-
};
|
|
2123
|
-
result["catch"] = function () {
|
|
2124
|
-
var _promise2;
|
|
2125
|
-
promise = (_promise2 = promise)["catch"].apply(_promise2, arguments);
|
|
2126
|
-
return result;
|
|
2127
|
-
};
|
|
2128
|
-
result["finally"] = function () {
|
|
2129
|
-
var _promise3;
|
|
2130
|
-
promise = (_promise3 = promise)["finally"].apply(_promise3, arguments);
|
|
2131
|
-
return result;
|
|
2132
|
-
};
|
|
2133
|
-
result.remove = function () {
|
|
2134
|
-
controllerAborted = true;
|
|
2135
|
-
if (controller) {
|
|
2136
|
-
var _controller4;
|
|
2137
|
-
(_controller4 = controller).abort.apply(_controller4, arguments);
|
|
2138
|
-
}
|
|
2139
|
-
return result;
|
|
2140
|
-
};
|
|
2141
|
-
result.isRemoved = function () {
|
|
2142
|
-
var _controller5;
|
|
2143
|
-
return controllerAborted || !!((_controller5 = controller) !== null && _controller5 !== void 0 && (_controller5 = _controller5.signal) !== null && _controller5 !== void 0 && _controller5.aborted);
|
|
2144
|
-
};
|
|
2145
|
-
return result;
|
|
2146
|
-
}),
|
|
2147
|
-
/**
|
|
2148
|
-
* Allows you to do a fetch, with built-in retry functionality. Caches on the requested URL, so that the same URL will not be fetched multiple times.
|
|
2149
|
-
*
|
|
2150
|
-
* @param {string} url
|
|
2151
|
-
* @param {{retries?:number|null, delay?:number|((attempt:number)=>number)|null, [verify]:((data:*,response:*)=>void)|null}|null} [options]
|
|
2152
|
-
* @param {((response:*)=>*)|null} [responseFunction] A function that will be called with the response object, and should return the data to be cached.
|
|
2153
|
-
* @returns {Promise<*>}
|
|
2154
|
-
*/
|
|
2155
|
-
cachedFetch: function () {
|
|
2156
|
-
var cache = new Map();
|
|
2157
|
-
return /*#__PURE__*/function () {
|
|
2158
|
-
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee1(url, options, responseFunction) {
|
|
2159
|
-
var result, promise;
|
|
2160
|
-
return _regeneratorRuntime.wrap(function (_context1) {
|
|
2161
|
-
while (1) switch (_context1.prev = _context1.next) {
|
|
2162
|
-
case 0:
|
|
2163
|
-
if (!cache.has(url)) {
|
|
2164
|
-
_context1.next = 5;
|
|
2165
|
-
break;
|
|
2166
|
-
}
|
|
2167
|
-
result = cache.get(url);
|
|
2168
|
-
if (!result.data) {
|
|
2169
|
-
_context1.next = 1;
|
|
2170
|
-
break;
|
|
2171
|
-
}
|
|
2172
|
-
return _context1.abrupt("return", result.data);
|
|
2173
|
-
case 1:
|
|
2174
|
-
if (!result.promise) {
|
|
2175
|
-
_context1.next = 3;
|
|
2176
|
-
break;
|
|
2177
|
-
}
|
|
2178
|
-
_context1.next = 2;
|
|
2179
|
-
return result.promise;
|
|
2180
|
-
case 2:
|
|
2181
|
-
return _context1.abrupt("return", _context1.sent);
|
|
2182
|
-
case 3:
|
|
2183
|
-
if (!result.error) {
|
|
2184
|
-
_context1.next = 4;
|
|
2185
|
-
break;
|
|
2186
|
-
}
|
|
2187
|
-
throw result.error;
|
|
2188
|
-
case 4:
|
|
2189
|
-
console.warn('Failed to use the cachedFetch cache, for URL: ', url, ', it is in an unexpected state: ', result);
|
|
2190
|
-
return _context1.abrupt("return", null);
|
|
2191
|
-
case 5:
|
|
2192
|
-
promise = LeUtils.fetch(url, options).then(/*#__PURE__*/function () {
|
|
2193
|
-
var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0(response) {
|
|
2194
|
-
var data, _t10;
|
|
2195
|
-
return _regeneratorRuntime.wrap(function (_context0) {
|
|
2196
|
-
while (1) switch (_context0.prev = _context0.next) {
|
|
2197
|
-
case 0:
|
|
2198
|
-
if (!responseFunction) {
|
|
2199
|
-
_context0.next = 2;
|
|
2200
|
-
break;
|
|
2201
|
-
}
|
|
2202
|
-
_context0.next = 1;
|
|
2203
|
-
return responseFunction(response);
|
|
2204
|
-
case 1:
|
|
2205
|
-
_t10 = _context0.sent;
|
|
2206
|
-
_context0.next = 3;
|
|
2207
|
-
break;
|
|
2208
|
-
case 2:
|
|
2209
|
-
_t10 = response;
|
|
2210
|
-
case 3:
|
|
2211
|
-
data = _t10;
|
|
2212
|
-
if (!(typeof (options === null || options === void 0 ? void 0 : options.verify) === 'function')) {
|
|
2213
|
-
_context0.next = 4;
|
|
2214
|
-
break;
|
|
2215
|
-
}
|
|
2216
|
-
_context0.next = 4;
|
|
2217
|
-
return options.verify(data, response);
|
|
2218
|
-
case 4:
|
|
2219
|
-
return _context0.abrupt("return", data);
|
|
2220
|
-
case 5:
|
|
2221
|
-
case "end":
|
|
2222
|
-
return _context0.stop();
|
|
2223
|
-
}
|
|
2224
|
-
}, _callee0);
|
|
2225
|
-
}));
|
|
2226
|
-
return function (_x12) {
|
|
2227
|
-
return _ref9.apply(this, arguments);
|
|
2228
|
-
};
|
|
2229
|
-
}()).then(function (data) {
|
|
2230
|
-
cache.set(url, {
|
|
2231
|
-
data: data
|
|
2232
|
-
});
|
|
2233
|
-
return data;
|
|
2234
|
-
})["catch"](function (error) {
|
|
2235
|
-
cache.set(url, {
|
|
2236
|
-
error: error
|
|
2237
|
-
});
|
|
2238
|
-
console.error('Failed to fetch: ', error);
|
|
2239
|
-
throw error;
|
|
2240
|
-
});
|
|
2241
|
-
if (!cache.has(url)) {
|
|
2242
|
-
cache.set(url, {
|
|
2243
|
-
promise: promise
|
|
2244
|
-
});
|
|
2245
|
-
}
|
|
2246
|
-
_context1.next = 6;
|
|
2247
|
-
return promise;
|
|
2248
|
-
case 6:
|
|
2249
|
-
return _context1.abrupt("return", _context1.sent);
|
|
2250
|
-
case 7:
|
|
2251
|
-
case "end":
|
|
2252
|
-
return _context1.stop();
|
|
2253
|
-
}
|
|
2254
|
-
}, _callee1);
|
|
2255
|
-
}));
|
|
2256
|
-
return function (_x1, _x10, _x11) {
|
|
2257
|
-
return _ref8.apply(this, arguments);
|
|
2258
|
-
};
|
|
2259
|
-
}();
|
|
2260
|
-
}(),
|
|
2261
|
-
/**
|
|
2262
|
-
* Returns true if the user is on a smartphone device (mobile).
|
|
2263
|
-
* Will return false if the user is on a tablet or on a desktop.
|
|
2264
|
-
*
|
|
2265
|
-
* In short:
|
|
2266
|
-
* - Mobile: True
|
|
2267
|
-
* - Tablet: False
|
|
2268
|
-
* - Desktop: False
|
|
2269
|
-
*
|
|
2270
|
-
* @returns {boolean}
|
|
2271
|
-
*/
|
|
2272
|
-
platformIsMobile: function platformIsMobile() {
|
|
2273
|
-
var _globalThis$navigator, _globalThis$navigator2;
|
|
2274
|
-
// noinspection JSDeprecatedSymbols, JSUnresolvedReference
|
|
2275
|
-
/** navigator.userAgentData.mobile doesn't return the correct value on some platforms, so this is a work-around, code from: http://detectmobilebrowsers.com **/
|
|
2276
|
-
var a = STRING((globalThis === null || globalThis === void 0 || (_globalThis$navigator = globalThis.navigator) === null || _globalThis$navigator === void 0 ? void 0 : _globalThis$navigator.userAgent) || (globalThis === null || globalThis === void 0 || (_globalThis$navigator2 = globalThis.navigator) === null || _globalThis$navigator2 === void 0 ? void 0 : _globalThis$navigator2.vendor) || (globalThis === null || globalThis === void 0 ? void 0 : globalThis.opera) || '');
|
|
2277
|
-
var b = a.substring(0, 4);
|
|
2278
|
-
return !!(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series([46])0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br([ev])w|bumb|bw-([nu])|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do([cp])o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly([-_])|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-([mpt])|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c([- _agpst])|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac([ \-/])|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja([tv])a|jbro|jemu|jigs|kddi|keji|kgt([ /])|klon|kpt |kwc-|kyo([ck])|le(no|xi)|lg( g|\/([klu])|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t([- ov])|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30([02])|n50([025])|n7(0([01])|10)|ne(([cm])-|on|tf|wf|wg|wt)|nok([6i])|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan([adt])|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c([-01])|47|mc|nd|ri)|sgh-|shar|sie([-m])|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel([im])|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c([- ])|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(b));
|
|
2279
|
-
},
|
|
2280
|
-
/**
|
|
2281
|
-
* Returns true if the user has a cursor (mouse, touchpad, etc).
|
|
2282
|
-
* In this context, a cursor is defined as an input device that can hover over elements without necessarily interacting with them.
|
|
2283
|
-
*
|
|
2284
|
-
* @returns {boolean}
|
|
2285
|
-
*/
|
|
2286
|
-
platformHasCursor: function platformHasCursor() {
|
|
2287
|
-
var _globalThis$matchMedi;
|
|
2288
|
-
return !LeUtils.platformIsMobile() && !(globalThis !== null && globalThis !== void 0 && (_globalThis$matchMedi = globalThis.matchMedia) !== null && _globalThis$matchMedi !== void 0 && (_globalThis$matchMedi = _globalThis$matchMedi.call(globalThis, '(any-hover: none)')) !== null && _globalThis$matchMedi !== void 0 && _globalThis$matchMedi.matches);
|
|
2289
|
-
},
|
|
2290
|
-
/**
|
|
2291
|
-
* Returns the given string, with the first character capitalized.
|
|
2292
|
-
*
|
|
2293
|
-
* @param {String} string
|
|
2294
|
-
* @returns {string}
|
|
2295
|
-
*/
|
|
2296
|
-
capitalize: function capitalize(string) {
|
|
2297
|
-
string = STRING(string).trim();
|
|
2298
|
-
if (string.length <= 0) {
|
|
2299
|
-
return string;
|
|
2300
|
-
}
|
|
2301
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
2302
|
-
},
|
|
2303
|
-
/**
|
|
2304
|
-
* Returns true if the given string ends with any of the given characters or words.
|
|
2305
|
-
*
|
|
2306
|
-
* @param {string} string
|
|
2307
|
-
* @param {string|string[]} endingCharsStringOrArray
|
|
2308
|
-
* @returns {boolean}
|
|
2309
|
-
*/
|
|
2310
|
-
endsWithAny: function endsWithAny(string, endingCharsStringOrArray) {
|
|
2311
|
-
string = STRING(string);
|
|
2312
|
-
var endingCharsArray;
|
|
2313
|
-
if (Array.isArray(endingCharsStringOrArray)) {
|
|
2314
|
-
endingCharsArray = endingCharsStringOrArray;
|
|
2315
|
-
} else {
|
|
2316
|
-
endingCharsArray = STRING(endingCharsStringOrArray).split('');
|
|
2317
|
-
}
|
|
2318
|
-
var result = false;
|
|
2319
|
-
LeUtils.each(endingCharsArray, function (chars) {
|
|
2320
|
-
if (string.endsWith(STRING(chars))) {
|
|
2321
|
-
result = true;
|
|
2322
|
-
return false;
|
|
2323
|
-
}
|
|
2324
|
-
});
|
|
2325
|
-
return result;
|
|
2326
|
-
},
|
|
2327
|
-
/**
|
|
2328
|
-
* Returns true if the given string starts with any of the given characters or words.
|
|
2329
|
-
*
|
|
2330
|
-
* @param {string} string
|
|
2331
|
-
* @param {string|string[]} startingCharsStringOrArray
|
|
2332
|
-
* @returns {boolean}
|
|
2333
|
-
*/
|
|
2334
|
-
startsWithAny: function startsWithAny(string, startingCharsStringOrArray) {
|
|
2335
|
-
string = STRING(string);
|
|
2336
|
-
var startingCharsArray;
|
|
2337
|
-
if (Array.isArray(startingCharsStringOrArray)) {
|
|
2338
|
-
startingCharsArray = startingCharsStringOrArray;
|
|
2339
|
-
} else {
|
|
2340
|
-
startingCharsArray = STRING(startingCharsStringOrArray).split('');
|
|
2341
|
-
}
|
|
2342
|
-
var result = false;
|
|
2343
|
-
LeUtils.each(startingCharsArray, function (chars) {
|
|
2344
|
-
if (string.startsWith(STRING(chars))) {
|
|
2345
|
-
result = true;
|
|
2346
|
-
return false;
|
|
2347
|
-
}
|
|
2348
|
-
});
|
|
2349
|
-
return result;
|
|
2350
|
-
},
|
|
2351
|
-
/**
|
|
2352
|
-
* Trims the end of the given string, by removing the given characters from it.
|
|
2353
|
-
*
|
|
2354
|
-
* @param {string} string
|
|
2355
|
-
* @param {string|string[]} trimCharsStringOrArray
|
|
2356
|
-
*/
|
|
2357
|
-
trimEnd: function trimEnd(string, trimCharsStringOrArray) {
|
|
2358
|
-
string = STRING(string);
|
|
2359
|
-
var endingCharsArray;
|
|
2360
|
-
if (Array.isArray(trimCharsStringOrArray)) {
|
|
2361
|
-
endingCharsArray = trimCharsStringOrArray;
|
|
2362
|
-
} else {
|
|
2363
|
-
endingCharsArray = STRING(trimCharsStringOrArray).split('');
|
|
2364
|
-
}
|
|
2365
|
-
var trimChars = function trimChars(chars) {
|
|
2366
|
-
chars = STRING(chars);
|
|
2367
|
-
if (string.endsWith(chars)) {
|
|
2368
|
-
string = string.substring(0, string.length - chars.length);
|
|
2369
|
-
run = true;
|
|
2370
|
-
}
|
|
2371
|
-
};
|
|
2372
|
-
var run = true;
|
|
2373
|
-
while (run) {
|
|
2374
|
-
run = false;
|
|
2375
|
-
LeUtils.each(endingCharsArray, trimChars);
|
|
2376
|
-
}
|
|
2377
|
-
return string;
|
|
2378
|
-
},
|
|
2379
|
-
/**
|
|
2380
|
-
* Trims the start of the given string, by removing the given characters from it.
|
|
2381
|
-
*
|
|
2382
|
-
* @param {string} string
|
|
2383
|
-
* @param {string|string[]} trimCharsStringOrArray
|
|
2384
|
-
*/
|
|
2385
|
-
trimStart: function trimStart(string, trimCharsStringOrArray) {
|
|
2386
|
-
string = STRING(string);
|
|
2387
|
-
var startingCharsArray;
|
|
2388
|
-
if (Array.isArray(trimCharsStringOrArray)) {
|
|
2389
|
-
startingCharsArray = trimCharsStringOrArray;
|
|
2390
|
-
} else {
|
|
2391
|
-
startingCharsArray = STRING(trimCharsStringOrArray).split('');
|
|
2392
|
-
}
|
|
2393
|
-
var trimChars = function trimChars(chars) {
|
|
2394
|
-
chars = STRING(chars);
|
|
2395
|
-
if (string.startsWith(chars)) {
|
|
2396
|
-
string = string.substring(chars.length);
|
|
2397
|
-
run = true;
|
|
2398
|
-
}
|
|
2399
|
-
};
|
|
2400
|
-
var run = true;
|
|
2401
|
-
while (run) {
|
|
2402
|
-
run = false;
|
|
2403
|
-
LeUtils.each(startingCharsArray, trimChars);
|
|
2404
|
-
}
|
|
2405
|
-
return string;
|
|
2406
|
-
},
|
|
2407
|
-
/**
|
|
2408
|
-
* Trims the start and end of the given string, by removing the given characters from it.
|
|
2409
|
-
*
|
|
2410
|
-
* @param {string} string
|
|
2411
|
-
* @param {string|string[]} trimCharsStringOrArray
|
|
2412
|
-
*/
|
|
2413
|
-
trim: function trim(string, trimCharsStringOrArray) {
|
|
2414
|
-
return LeUtils.trimEnd(LeUtils.trimStart(string, trimCharsStringOrArray), trimCharsStringOrArray);
|
|
2415
|
-
},
|
|
2416
|
-
/**
|
|
2417
|
-
* Returns the given string, trims the start and end, and makes sure it ends with a valid sentence ending character (such as !?;.).
|
|
2418
|
-
*
|
|
2419
|
-
* @param {string} sentence
|
|
2420
|
-
* @returns {string}
|
|
2421
|
-
*/
|
|
2422
|
-
purgeSentence: function purgeSentence(sentence) {
|
|
2423
|
-
sentence = LeUtils.trimEnd(STRING(sentence).trim(), '.: \r\n\t');
|
|
2424
|
-
sentence += LeUtils.endsWithAny(sentence, '!?;') ? '' : '.';
|
|
2425
|
-
return sentence;
|
|
2426
|
-
},
|
|
2427
|
-
/**
|
|
2428
|
-
* Attempts to obtain and return an error message from the given error, regardless of what is passed to this function.
|
|
2429
|
-
*
|
|
2430
|
-
* @param {*} error
|
|
2431
|
-
* @returns {string}
|
|
2432
|
-
*/
|
|
2433
|
-
purgeErrorMessage: function purgeErrorMessage(error) {
|
|
2434
|
-
var _error;
|
|
2435
|
-
if ((_error = error) !== null && _error !== void 0 && _error.message) {
|
|
2436
|
-
error = error.message;
|
|
2437
|
-
}
|
|
2438
|
-
if (typeof error === 'string') {
|
|
2439
|
-
var errorParts = error.split('threw an error:');
|
|
2440
|
-
error = errorParts[errorParts.length - 1];
|
|
2441
|
-
} else {
|
|
2442
|
-
try {
|
|
2443
|
-
error = JSON.stringify(error);
|
|
2444
|
-
} catch (e) {
|
|
2445
|
-
error = 'An unknown error occurred';
|
|
2446
|
-
}
|
|
2447
|
-
}
|
|
2448
|
-
return error.trim();
|
|
2449
|
-
},
|
|
2450
|
-
/**
|
|
2451
|
-
* Generates all permutations of the given names.
|
|
2452
|
-
*
|
|
2453
|
-
* For example, if you pass "foo" and "bar", it will return:
|
|
2454
|
-
* - foobar
|
|
2455
|
-
* - fooBar
|
|
2456
|
-
* - FooBar
|
|
2457
|
-
* - foo-bar
|
|
2458
|
-
* - foo_bar
|
|
2459
|
-
*
|
|
2460
|
-
* @param {string[]} names
|
|
2461
|
-
* @returns {string[]}
|
|
2462
|
-
*/
|
|
2463
|
-
generateNamePermutations: function generateNamePermutations() {
|
|
2464
|
-
for (var _len = arguments.length, names = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2465
|
-
names[_key] = arguments[_key];
|
|
2466
|
-
}
|
|
2467
|
-
names = LeUtils.flattenToArray(names).map(function (name) {
|
|
2468
|
-
return STRING(name).trim().toLowerCase();
|
|
2469
|
-
}).filter(function (name) {
|
|
2470
|
-
return name.length > 0;
|
|
2471
|
-
});
|
|
2472
|
-
var results = [];
|
|
2473
|
-
if (names.length > 0) {
|
|
2474
|
-
results.push(names.join('')); //foobar
|
|
2475
|
-
results.push(names.map(LeUtils.capitalize).join('')); //FooBar
|
|
2476
|
-
}
|
|
2477
|
-
if (names.length > 1) {
|
|
2478
|
-
results.push([names[0]].concat(names.slice(1).map(LeUtils.capitalize)).join('')); //fooBar
|
|
2479
|
-
results.push(names.join('-')); //foo-bar
|
|
2480
|
-
results.push(names.join('_')); //foo_bar
|
|
2481
|
-
}
|
|
2482
|
-
return results;
|
|
2483
|
-
},
|
|
2484
|
-
/**
|
|
2485
|
-
* Increases the given numeric string by 1, this allows you to increase a numeric string without a limit.
|
|
2486
|
-
*
|
|
2487
|
-
* @param {string} string
|
|
2488
|
-
* @returns {string}
|
|
2489
|
-
*/
|
|
2490
|
-
increaseNumericStringByOne: function increaseNumericStringByOne(string) {
|
|
2491
|
-
if (typeof string !== 'string') {
|
|
2492
|
-
string = '' + string;
|
|
2493
|
-
for (var i = string.length - 1; i >= 0; i--) {
|
|
2494
|
-
var c = string.charAt(i);
|
|
2495
|
-
if (c < '0' || c > '9') {
|
|
2496
|
-
return '1';
|
|
2497
|
-
}
|
|
2498
|
-
}
|
|
2499
|
-
}
|
|
2500
|
-
if (string === '') {
|
|
2501
|
-
return '1';
|
|
2502
|
-
}
|
|
2503
|
-
for (var _i11 = string.length - 1; _i11 >= 0; _i11--) {
|
|
2504
|
-
var _c = string.charAt(_i11);
|
|
2505
|
-
if (_c < '0' || _c > '9') {
|
|
2506
|
-
return '1';
|
|
2507
|
-
}
|
|
2508
|
-
if (_c < '9') {
|
|
2509
|
-
_c = String.fromCharCode(_c.charCodeAt(0) + 1);
|
|
2510
|
-
string = string.substring(0, _i11) + _c + string.substring(_i11 + 1); // string[i] = (char + 1);
|
|
2511
|
-
break;
|
|
2512
|
-
}
|
|
2513
|
-
string = string.substring(0, _i11) + '0' + string.substring(_i11 + 1); // string[i] = '0';
|
|
2514
|
-
}
|
|
2515
|
-
if (string.charAt(0) === '0') {
|
|
2516
|
-
string = '1' + string;
|
|
2517
|
-
}
|
|
2518
|
-
return string;
|
|
2519
|
-
},
|
|
2520
|
-
/**
|
|
2521
|
-
* Generates a base64 string (with +/ replaced by -_) that is guaranteed to be unique.
|
|
2522
|
-
*
|
|
2523
|
-
* @returns {string}
|
|
2524
|
-
*/
|
|
2525
|
-
uniqueId: function () {
|
|
2526
|
-
var previousUniqueIdsTime = null;
|
|
2527
|
-
var previousUniqueIds = new Map();
|
|
2528
|
-
var numberToBytes = function numberToBytes(number) {
|
|
2529
|
-
var size = number === 0 ? 0 : Math.ceil((Math.floor(Math.log2(number)) + 1) / 8);
|
|
2530
|
-
var bytes = new Uint8ClampedArray(size);
|
|
2531
|
-
var x = number;
|
|
2532
|
-
for (var i = size - 1; i >= 0; i--) {
|
|
2533
|
-
var rightByte = x & 0xff;
|
|
2534
|
-
bytes[i] = rightByte;
|
|
2535
|
-
x = Math.floor(x / 0x100);
|
|
2536
|
-
}
|
|
2537
|
-
return bytes;
|
|
2538
|
-
};
|
|
2539
|
-
var generateUniqueId = function generateUniqueId() {
|
|
2540
|
-
var now;
|
|
2541
|
-
try {
|
|
2542
|
-
var _globalThis$performan17, _globalThis$performan18, _globalThis$performan19, _globalThis$performan20, _globalThis$performan21;
|
|
2543
|
-
// noinspection JSDeprecatedSymbols
|
|
2544
|
-
now = ((globalThis === null || globalThis === void 0 || (_globalThis$performan17 = globalThis.performance) === null || _globalThis$performan17 === void 0 ? void 0 : _globalThis$performan17.timeOrigin) || (globalThis === null || globalThis === void 0 || (_globalThis$performan18 = globalThis.performance) === null || _globalThis$performan18 === void 0 || (_globalThis$performan18 = _globalThis$performan18.timing) === null || _globalThis$performan18 === void 0 ? void 0 : _globalThis$performan18.navigationStart) || 0) + ((_globalThis$performan19 = globalThis === null || globalThis === void 0 || (_globalThis$performan20 = globalThis.performance) === null || _globalThis$performan20 === void 0 || (_globalThis$performan21 = _globalThis$performan20.now) === null || _globalThis$performan21 === void 0 ? void 0 : _globalThis$performan21.call(_globalThis$performan20)) !== null && _globalThis$performan19 !== void 0 ? _globalThis$performan19 : 0);
|
|
2545
|
-
} catch (e) {}
|
|
2546
|
-
now = now || (Date.now ? Date.now() : new Date().getTime());
|
|
2547
|
-
now = Math.round(now);
|
|
2548
|
-
var nowBytes = numberToBytes(now);
|
|
2549
|
-
var uuid = null;
|
|
2550
|
-
try {
|
|
2551
|
-
var _crypto;
|
|
2552
|
-
uuid = (_crypto = crypto) === null || _crypto === void 0 ? void 0 : _crypto.randomUUID();
|
|
2553
|
-
} catch (e) {}
|
|
2554
|
-
if (uuid) {
|
|
2555
|
-
uuid = LeUtils.base64ToBytes(LeUtils.hexToBase64(uuid));
|
|
2556
|
-
} else {
|
|
2557
|
-
var bytesChunkA = numberToBytes((Math.random() + ' ').substring(2, 12).padEnd(10, '0'));
|
|
2558
|
-
var bytesChunkB = numberToBytes((Math.random() + ' ').substring(2, 12).padEnd(10, '0'));
|
|
2559
|
-
var bytesChunkC = numberToBytes((Math.random() + ' ').substring(2, 12).padEnd(10, '0'));
|
|
2560
|
-
var bytesChunkD = numberToBytes((Math.random() + ' ').substring(2, 12).padEnd(10, '0'));
|
|
2561
|
-
uuid = new Uint8Array(bytesChunkA.length + bytesChunkB.length + bytesChunkC.length + bytesChunkD.length);
|
|
2562
|
-
uuid.set(bytesChunkA, 0);
|
|
2563
|
-
uuid.set(bytesChunkB, bytesChunkA.length);
|
|
2564
|
-
uuid.set(bytesChunkC, bytesChunkA.length + bytesChunkB.length);
|
|
2565
|
-
uuid.set(bytesChunkD, bytesChunkA.length + bytesChunkB.length + bytesChunkC.length);
|
|
2566
|
-
}
|
|
2567
|
-
var bytes = new Uint8Array(nowBytes.length + uuid.length);
|
|
2568
|
-
bytes.set(nowBytes, 0);
|
|
2569
|
-
bytes.set(uuid, nowBytes.length);
|
|
2570
|
-
uuid = LeUtils.bytesToBase64(bytes).replaceAll('=', '').replaceAll('+', '-').replaceAll('/', '_');
|
|
2571
|
-
return {
|
|
2572
|
-
time: now,
|
|
2573
|
-
id: uuid
|
|
2574
|
-
};
|
|
2575
|
-
};
|
|
2576
|
-
return function () {
|
|
2577
|
-
while (true) {
|
|
2578
|
-
var result = generateUniqueId();
|
|
2579
|
-
if (previousUniqueIdsTime !== result.time) {
|
|
2580
|
-
previousUniqueIdsTime = result.time;
|
|
2581
|
-
previousUniqueIds.clear();
|
|
2582
|
-
previousUniqueIds.set(result.id, true);
|
|
2583
|
-
return result.id;
|
|
2584
|
-
} else if (previousUniqueIds.get(result.id) !== true) {
|
|
2585
|
-
previousUniqueIds.set(result.id, true);
|
|
2586
|
-
return result.id;
|
|
2587
|
-
}
|
|
2588
|
-
}
|
|
2589
|
-
};
|
|
2590
|
-
}(),
|
|
2591
|
-
/**
|
|
2592
|
-
* Generates a base64 string (with +/ replaced by -_) of the current time (in milliseconds since 1970).
|
|
2593
|
-
*
|
|
2594
|
-
* @param {number} [now] Optional time to use instead of the current time. If not set, the current time will be used.
|
|
2595
|
-
* @returns {string}
|
|
2596
|
-
*/
|
|
2597
|
-
timestamp: function () {
|
|
2598
|
-
var numberToBytes = function numberToBytes(number) {
|
|
2599
|
-
var size = number === 0 ? 0 : Math.ceil((Math.floor(Math.log2(number)) + 1) / 8);
|
|
2600
|
-
var bytes = new Uint8ClampedArray(size);
|
|
2601
|
-
var x = number;
|
|
2602
|
-
for (var i = size - 1; i >= 0; i--) {
|
|
2603
|
-
var rightByte = x & 0xff;
|
|
2604
|
-
bytes[i] = rightByte;
|
|
2605
|
-
x = Math.floor(x / 0x100);
|
|
2606
|
-
}
|
|
2607
|
-
return bytes;
|
|
2608
|
-
};
|
|
2609
|
-
return function () {
|
|
2610
|
-
var now = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
2611
|
-
if (ISSET(now)) {
|
|
2612
|
-
now = FLOAT_LAX(now);
|
|
2613
|
-
} else {
|
|
2614
|
-
try {
|
|
2615
|
-
var _performance, _performance2, _performance$now, _performance3, _performance3$now;
|
|
2616
|
-
// noinspection JSDeprecatedSymbols
|
|
2617
|
-
now = (((_performance = performance) === null || _performance === void 0 ? void 0 : _performance.timeOrigin) || ((_performance2 = performance) === null || _performance2 === void 0 || (_performance2 = _performance2.timing) === null || _performance2 === void 0 ? void 0 : _performance2.navigationStart) || 0) + ((_performance$now = (_performance3 = performance) === null || _performance3 === void 0 || (_performance3$now = _performance3.now) === null || _performance3$now === void 0 ? void 0 : _performance3$now.call(_performance3)) !== null && _performance$now !== void 0 ? _performance$now : 0);
|
|
2618
|
-
} catch (e) {}
|
|
2619
|
-
now = now || (Date.now ? Date.now() : new Date().getTime());
|
|
2620
|
-
}
|
|
2621
|
-
now = Math.round(now);
|
|
2622
|
-
var nowBytes = numberToBytes(now);
|
|
2623
|
-
return LeUtils.bytesToBase64(nowBytes).replaceAll('=', '').replaceAll('+', '-').replaceAll('/', '_');
|
|
2624
|
-
};
|
|
2625
|
-
}(),
|
|
2626
|
-
/**
|
|
2627
|
-
* Returns a data URL of a 1x1 transparent pixel.
|
|
2628
|
-
*
|
|
2629
|
-
* @returns {string}
|
|
2630
|
-
*/
|
|
2631
|
-
getEmptyImageSrc: function getEmptyImageSrc() {
|
|
2632
|
-
// noinspection SpellCheckingInspection
|
|
2633
|
-
return 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
|
|
2634
|
-
},
|
|
2635
|
-
/**
|
|
2636
|
-
* Calculates and returns the percentage of the part and total ((part / total) * 100).
|
|
2637
|
-
*
|
|
2638
|
-
* @param {number|string} part
|
|
2639
|
-
* @param {number|string} total
|
|
2640
|
-
* @returns {number}
|
|
2641
|
-
*/
|
|
2642
|
-
getPercentage: function getPercentage(part, total) {
|
|
2643
|
-
part = FLOAT_LAX(part);
|
|
2644
|
-
total = FLOAT_LAX(total);
|
|
2645
|
-
if (total === 0) {
|
|
2646
|
-
return 100;
|
|
2647
|
-
}
|
|
2648
|
-
return Math.max(0, Math.min(100, part / total * 100));
|
|
2649
|
-
},
|
|
2650
|
-
/**
|
|
2651
|
-
* Returns the pixels of the given Image object.
|
|
2652
|
-
*
|
|
2653
|
-
* @param {HTMLImageElement} image
|
|
2654
|
-
* @returns {Uint8ClampedArray}
|
|
2655
|
-
*/
|
|
2656
|
-
getImagePixels: function getImagePixels(image) {
|
|
2657
|
-
var _globalThis$document3, _globalThis$document4;
|
|
2658
|
-
if (!(globalThis !== null && globalThis !== void 0 && (_globalThis$document3 = globalThis.document) !== null && _globalThis$document3 !== void 0 && _globalThis$document3.createElement) || !(globalThis !== null && globalThis !== void 0 && (_globalThis$document4 = globalThis.document) !== null && _globalThis$document4 !== void 0 && (_globalThis$document4 = _globalThis$document4.body) !== null && _globalThis$document4 !== void 0 && _globalThis$document4.appendChild)) {
|
|
2659
|
-
console.warn('LeUtils.getImagePixels: Document is not available, returning empty pixels.');
|
|
2660
|
-
return new Uint8ClampedArray();
|
|
2661
|
-
}
|
|
2662
|
-
var canvas = globalThis.document.createElement('canvas');
|
|
2663
|
-
globalThis.document.body.appendChild(canvas);
|
|
2664
|
-
try {
|
|
2665
|
-
var ctx = canvas.getContext('2d');
|
|
2666
|
-
var width = Math.floor(image.width);
|
|
2667
|
-
var height = Math.floor(image.height);
|
|
2668
|
-
if (!ctx || width <= 0 || height <= 0) {
|
|
2669
|
-
return new Uint8ClampedArray();
|
|
2670
|
-
}
|
|
2671
|
-
canvas.width = width;
|
|
2672
|
-
canvas.height = height;
|
|
2673
|
-
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
2674
|
-
return ctx.getImageData(0, 0, canvas.width, canvas.height).data;
|
|
2675
|
-
} finally {
|
|
2676
|
-
var _canvas$parentNode;
|
|
2677
|
-
canvas === null || canvas === void 0 || (_canvas$parentNode = canvas.parentNode) === null || _canvas$parentNode === void 0 || _canvas$parentNode.removeChild(canvas);
|
|
2678
|
-
}
|
|
2679
|
-
},
|
|
2680
|
-
/**
|
|
2681
|
-
* Returns the data URL (mimetype "image/png") of a colored version of the given Image object.
|
|
2682
|
-
*
|
|
2683
|
-
* @param {HTMLImageElement} image
|
|
2684
|
-
* @param {string} color
|
|
2685
|
-
* @returns {string}
|
|
2686
|
-
*/
|
|
2687
|
-
getColoredImage: function getColoredImage(image, color) {
|
|
2688
|
-
var _globalThis$document5, _globalThis$document6;
|
|
2689
|
-
if (!(globalThis !== null && globalThis !== void 0 && (_globalThis$document5 = globalThis.document) !== null && _globalThis$document5 !== void 0 && _globalThis$document5.createElement) || !(globalThis !== null && globalThis !== void 0 && (_globalThis$document6 = globalThis.document) !== null && _globalThis$document6 !== void 0 && (_globalThis$document6 = _globalThis$document6.body) !== null && _globalThis$document6 !== void 0 && _globalThis$document6.appendChild)) {
|
|
2690
|
-
console.warn('LeUtils.getColoredImage: Document is not available, returning empty image src.');
|
|
2691
|
-
return LeUtils.getEmptyImageSrc();
|
|
2692
|
-
}
|
|
2693
|
-
var canvas = globalThis.document.createElement('canvas');
|
|
2694
|
-
globalThis.document.body.appendChild(canvas);
|
|
2695
|
-
try {
|
|
2696
|
-
var ctx = canvas.getContext('2d');
|
|
2697
|
-
var width = Math.floor(image.width);
|
|
2698
|
-
var height = Math.floor(image.height);
|
|
2699
|
-
if (!ctx || width <= 0 || height <= 0) {
|
|
2700
|
-
return LeUtils.getEmptyImageSrc();
|
|
2701
|
-
}
|
|
2702
|
-
canvas.width = width;
|
|
2703
|
-
canvas.height = height;
|
|
2704
|
-
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
2705
|
-
ctx.globalCompositeOperation = 'source-in';
|
|
2706
|
-
ctx.fillStyle = color;
|
|
2707
|
-
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
2708
|
-
return canvas.toDataURL('image/png');
|
|
2709
|
-
} finally {
|
|
2710
|
-
var _canvas$parentNode2;
|
|
2711
|
-
canvas === null || canvas === void 0 || (_canvas$parentNode2 = canvas.parentNode) === null || _canvas$parentNode2 === void 0 || _canvas$parentNode2.removeChild(canvas);
|
|
2712
|
-
}
|
|
2713
|
-
},
|
|
2714
|
-
/**
|
|
2715
|
-
* Returns the hex color of the given RGB(A).
|
|
2716
|
-
*
|
|
2717
|
-
* @param {number[]} rgb
|
|
2718
|
-
* @returns {string}
|
|
2719
|
-
*/
|
|
2720
|
-
rgbToHex: function rgbToHex(rgb) {
|
|
2721
|
-
return '#' + rgb.map(function (x) {
|
|
2722
|
-
var hex = x.toString(16);
|
|
2723
|
-
return hex.length === 1 ? '0' + hex : hex;
|
|
2724
|
-
}).join('');
|
|
2725
|
-
},
|
|
2726
|
-
/**
|
|
2727
|
-
* Returns the RGB(A) of the given hex color.
|
|
2728
|
-
*
|
|
2729
|
-
* @param {string} hexstring
|
|
2730
|
-
* @returns {number[]}
|
|
2731
|
-
*/
|
|
2732
|
-
hexToRgb: function hexToRgb(hexstring) {
|
|
2733
|
-
var _hexstring$match;
|
|
2734
|
-
var initialHexstring = hexstring;
|
|
2735
|
-
hexstring = hexstring.replace(/[^0-9A-F]/gi, '');
|
|
2736
|
-
var hasAlpha = hexstring.length === 4 || hexstring.length === 8;
|
|
2737
|
-
while (hexstring.length < 6) {
|
|
2738
|
-
hexstring = hexstring.replace(/(.)/g, '$1$1');
|
|
2739
|
-
}
|
|
2740
|
-
var result = (_hexstring$match = hexstring.match(/\w{2}/g)) === null || _hexstring$match === void 0 ? void 0 : _hexstring$match.map(function (a) {
|
|
2741
|
-
return parseInt(a, 16);
|
|
2742
|
-
});
|
|
2743
|
-
if (!result || result.length < 3) {
|
|
2744
|
-
throw new Error('Invalid hex color: "' + hexstring + '" (was given "' + initialHexstring + '")');
|
|
2745
|
-
}
|
|
2746
|
-
return [result[0], result[1], result[2]].concat(_toConsumableArray(hasAlpha ? [result[3]] : []));
|
|
2747
|
-
},
|
|
2748
|
-
/**
|
|
2749
|
-
* Returns the HSL(A) of the given RGB(A).
|
|
2750
|
-
*
|
|
2751
|
-
* @param {number[]} rgb
|
|
2752
|
-
* @returns {number[]}
|
|
2753
|
-
*/
|
|
2754
|
-
rgbToHsl: function rgbToHsl(rgb) {
|
|
2755
|
-
var r = rgb[0] / 255;
|
|
2756
|
-
var g = rgb[1] / 255;
|
|
2757
|
-
var b = rgb[2] / 255;
|
|
2758
|
-
var max = Math.max(r, g, b);
|
|
2759
|
-
var min = Math.min(r, g, b);
|
|
2760
|
-
var h = 0;
|
|
2761
|
-
var s = 0;
|
|
2762
|
-
var l = (max + min) / 2;
|
|
2763
|
-
if (max !== min) {
|
|
2764
|
-
var d = max - min;
|
|
2765
|
-
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
2766
|
-
switch (max) {
|
|
2767
|
-
case r:
|
|
2768
|
-
h = (g - b) / d + (g < b ? 6 : 0);
|
|
2769
|
-
break;
|
|
2770
|
-
case g:
|
|
2771
|
-
h = (b - r) / d + 2;
|
|
2772
|
-
break;
|
|
2773
|
-
case b:
|
|
2774
|
-
h = (r - g) / d + 4;
|
|
2775
|
-
break;
|
|
2776
|
-
}
|
|
2777
|
-
h /= 6;
|
|
2778
|
-
}
|
|
2779
|
-
return [h, s, l].concat(_toConsumableArray(rgb.length >= 4 ? [rgb[3] / 255] : []));
|
|
2780
|
-
},
|
|
2781
|
-
/**
|
|
2782
|
-
* Returns the RGB(A) of the given HSL(A).
|
|
2783
|
-
*
|
|
2784
|
-
* @param {number[]} hsl
|
|
2785
|
-
* @returns {number[]}
|
|
2786
|
-
*/
|
|
2787
|
-
hslToRgb: function () {
|
|
2788
|
-
var hue2rgb = function hue2rgb(p, q, t) {
|
|
2789
|
-
if (t < 0) {
|
|
2790
|
-
t += 1;
|
|
2791
|
-
}
|
|
2792
|
-
if (t > 1) {
|
|
2793
|
-
t -= 1;
|
|
2794
|
-
}
|
|
2795
|
-
if (t < 1 / 6) {
|
|
2796
|
-
return p + (q - p) * 6 * t;
|
|
2797
|
-
}
|
|
2798
|
-
if (t < 1 / 2) {
|
|
2799
|
-
return q;
|
|
2800
|
-
}
|
|
2801
|
-
if (t < 2 / 3) {
|
|
2802
|
-
return p + (q - p) * (2 / 3 - t) * 6;
|
|
2803
|
-
}
|
|
2804
|
-
return p;
|
|
2805
|
-
};
|
|
2806
|
-
return function (hsl) {
|
|
2807
|
-
var h = hsl[0];
|
|
2808
|
-
var s = hsl[1];
|
|
2809
|
-
var l = hsl[2];
|
|
2810
|
-
var r = 1;
|
|
2811
|
-
var g = 1;
|
|
2812
|
-
var b = 1;
|
|
2813
|
-
if (s !== 0) {
|
|
2814
|
-
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
2815
|
-
var p = 2 * l - q;
|
|
2816
|
-
r = hue2rgb(p, q, h + 1 / 3);
|
|
2817
|
-
g = hue2rgb(p, q, h);
|
|
2818
|
-
b = hue2rgb(p, q, h - 1 / 3);
|
|
2819
|
-
}
|
|
2820
|
-
return [r * 255, g * 255, b * 255].concat(_toConsumableArray(hsl.length >= 4 ? [hsl[3] * 255] : [])).map(function (c) {
|
|
2821
|
-
return Math.max(0, Math.min(255, Math.round(c)));
|
|
2822
|
-
});
|
|
2823
|
-
};
|
|
2824
|
-
}(),
|
|
2825
|
-
/**
|
|
2826
|
-
* Returns the LAB(A) of the given RGB(A).
|
|
2827
|
-
*
|
|
2828
|
-
* @param {number[]} rgb
|
|
2829
|
-
* @returns {number[]}
|
|
2830
|
-
*/
|
|
2831
|
-
rgbToLab: function rgbToLab(rgb) {
|
|
2832
|
-
var r = rgb[0] / 255;
|
|
2833
|
-
var g = rgb[1] / 255;
|
|
2834
|
-
var b = rgb[2] / 255;
|
|
2835
|
-
r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
|
|
2836
|
-
g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
|
|
2837
|
-
b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
|
|
2838
|
-
var x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;
|
|
2839
|
-
var y = r * 0.2126 + g * 0.7152 + b * 0.0722;
|
|
2840
|
-
var z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;
|
|
2841
|
-
x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
|
|
2842
|
-
y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
|
|
2843
|
-
z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
|
|
2844
|
-
return [116 * y - 16, 500 * (x - y), 200 * (y - z)].concat(_toConsumableArray(rgb.length >= 4 ? [rgb[3] / 255] : []));
|
|
2845
|
-
},
|
|
2846
|
-
/**
|
|
2847
|
-
* Returns the difference (calculated with DeltaE) of the LAB values of the given RGB values.
|
|
2848
|
-
*
|
|
2849
|
-
* Returns a number:
|
|
2850
|
-
*
|
|
2851
|
-
* ```js
|
|
2852
|
-
* < 1 is not perceptible by human eyes
|
|
2853
|
-
* 1-2 is perceptible through close observation
|
|
2854
|
-
* 2-10 is perceptible at a glance
|
|
2855
|
-
* 11-49 is more similar than opposite
|
|
2856
|
-
* 100 is exactly the opposite color
|
|
2857
|
-
* ```
|
|
2858
|
-
*
|
|
2859
|
-
* @param {number[]} rgbA
|
|
2860
|
-
* @param {number[]} rgbB
|
|
2861
|
-
* @returns {number}
|
|
2862
|
-
*/
|
|
2863
|
-
getDifferenceBetweenRgb: function getDifferenceBetweenRgb(rgbA, rgbB) {
|
|
2864
|
-
var labA = LeUtils.rgbToLab(rgbA);
|
|
2865
|
-
var labB = LeUtils.rgbToLab(rgbB);
|
|
2866
|
-
return LeUtils.getDifferenceBetweenLab(labA, labB);
|
|
2867
|
-
},
|
|
2868
|
-
/**
|
|
2869
|
-
* Returns the difference (calculated with DeltaE) of the given LAB values. Ignores the Alpha channel.
|
|
2870
|
-
*
|
|
2871
|
-
* Returns a number:
|
|
2872
|
-
*
|
|
2873
|
-
* ```js
|
|
2874
|
-
* < 1 is not perceptible by human eyes
|
|
2875
|
-
* 1-2 is perceptible through close observation
|
|
2876
|
-
* 2-10 is perceptible at a glance
|
|
2877
|
-
* 11-49 is more similar than opposite
|
|
2878
|
-
* 100 is exactly the opposite color
|
|
2879
|
-
* ```
|
|
2880
|
-
*
|
|
2881
|
-
* @param {number[]} labA
|
|
2882
|
-
* @param {number[]} labB
|
|
2883
|
-
* @returns {number}
|
|
2884
|
-
*/
|
|
2885
|
-
getDifferenceBetweenLab: function getDifferenceBetweenLab(labA, labB) {
|
|
2886
|
-
var deltaL = labA[0] - labB[0];
|
|
2887
|
-
var deltaA = labA[1] - labB[1];
|
|
2888
|
-
var deltaB = labA[2] - labB[2];
|
|
2889
|
-
var c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);
|
|
2890
|
-
var c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);
|
|
2891
|
-
var deltaC = c1 - c2;
|
|
2892
|
-
var deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;
|
|
2893
|
-
deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);
|
|
2894
|
-
var sc = 1.0 + 0.045 * c1;
|
|
2895
|
-
var sh = 1.0 + 0.015 * c1;
|
|
2896
|
-
var deltaLKlsl = deltaL / 1.0;
|
|
2897
|
-
var deltaCkcsc = deltaC / sc;
|
|
2898
|
-
var deltaHkhsh = deltaH / sh;
|
|
2899
|
-
var i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;
|
|
2900
|
-
return i < 0 ? 0 : Math.sqrt(i);
|
|
2901
|
-
},
|
|
2902
|
-
/**
|
|
2903
|
-
* Returns the RGB(A) of the given RGB(A) values, based on the given percentage (0-100).
|
|
2904
|
-
* This allows you to define a gradient of colors to fade in between, rather than just having a start and an end color.
|
|
2905
|
-
*
|
|
2906
|
-
* Usage:
|
|
2907
|
-
*
|
|
2908
|
-
* ```js
|
|
2909
|
-
* LeUtils.getRgbOfGradient({
|
|
2910
|
-
* 0: [255, 0, 0],
|
|
2911
|
-
* 33: [255, 255, 0],
|
|
2912
|
-
* 66: [0, 255, 0],
|
|
2913
|
-
* 100:[0, 255, 255],
|
|
2914
|
-
* }, 45.1234);
|
|
2915
|
-
* ```
|
|
2916
|
-
*
|
|
2917
|
-
* @param {{percentage?:number[]}} gradient
|
|
2918
|
-
* @param {number} percentage
|
|
2919
|
-
* @returns {number[]}
|
|
2920
|
-
*/
|
|
2921
|
-
getRgbOfGradient: function getRgbOfGradient(gradient, percentage) {
|
|
2922
|
-
percentage = Math.max(0, Math.min(100, FLOAT_LAX(percentage)));
|
|
2923
|
-
var closest = null;
|
|
2924
|
-
LeUtils.each(gradient, function (color, percent) {
|
|
2925
|
-
percent = INT_LAX(percent);
|
|
2926
|
-
if (closest === null) {
|
|
2927
|
-
closest = [percent, Math.abs(percentage - percent)];
|
|
2928
|
-
} else {
|
|
2929
|
-
var difference = Math.abs(percentage - percent);
|
|
2930
|
-
if (difference < closest[1]) {
|
|
2931
|
-
closest = [percent, difference];
|
|
2932
|
-
}
|
|
2933
|
-
}
|
|
2934
|
-
});
|
|
2935
|
-
if (closest === null) {
|
|
2936
|
-
return [0, 0, 0];
|
|
2937
|
-
}
|
|
2938
|
-
closest = closest[0];
|
|
2939
|
-
var HIGHER = 99999;
|
|
2940
|
-
var LOWER = -99999;
|
|
2941
|
-
var higher = HIGHER;
|
|
2942
|
-
var lower = LOWER;
|
|
2943
|
-
LeUtils.each(gradient, function (color, percent) {
|
|
2944
|
-
percent = INT_LAX(percent);
|
|
2945
|
-
if (percent < closest) {
|
|
2946
|
-
if (percent > lower) {
|
|
2947
|
-
lower = percent;
|
|
2948
|
-
}
|
|
2949
|
-
}
|
|
2950
|
-
if (percent > closest) {
|
|
2951
|
-
if (percent < higher) {
|
|
2952
|
-
higher = percent;
|
|
2953
|
-
}
|
|
2954
|
-
}
|
|
2955
|
-
});
|
|
2956
|
-
if (higher === HIGHER && lower === LOWER || higher === lower) {
|
|
2957
|
-
return gradient[closest];
|
|
2958
|
-
} else if (higher !== HIGHER && lower !== LOWER) {
|
|
2959
|
-
var higherDifference = Math.abs(higher - percentage);
|
|
2960
|
-
var lowerDifference = Math.abs(percentage - lower);
|
|
2961
|
-
if (higherDifference > lowerDifference) {
|
|
2962
|
-
higher = closest;
|
|
2963
|
-
} else {
|
|
2964
|
-
lower = closest;
|
|
2965
|
-
}
|
|
2966
|
-
} else if (lower === LOWER) {
|
|
2967
|
-
lower = closest;
|
|
2968
|
-
} else {
|
|
2969
|
-
higher = closest;
|
|
2970
|
-
}
|
|
2971
|
-
if (lower > higher) {
|
|
2972
|
-
var tmp = higher;
|
|
2973
|
-
higher = lower;
|
|
2974
|
-
lower = tmp;
|
|
2975
|
-
}
|
|
2976
|
-
var total = higher - lower;
|
|
2977
|
-
var part = percentage - lower;
|
|
2978
|
-
return LeUtils.getRgbBetween(gradient[lower], gradient[higher], part / total * 100);
|
|
2979
|
-
},
|
|
2980
|
-
/**
|
|
2981
|
-
* Returns the RGB(A) between the two given RGB(A) values, based on the given percentage (0-100).
|
|
2982
|
-
*
|
|
2983
|
-
* @param {number[]} startRgb
|
|
2984
|
-
* @param {number[]} endRgb
|
|
2985
|
-
* @param {number} percentage
|
|
2986
|
-
* @returns {number[]}
|
|
2987
|
-
*/
|
|
2988
|
-
getRgbBetween: function getRgbBetween(startRgb, endRgb, percentage) {
|
|
2989
|
-
percentage = FLOAT_LAX(percentage);
|
|
2990
|
-
var partEnd = Math.max(0, Math.min(1, percentage / 100.0));
|
|
2991
|
-
var partStart = 1 - partEnd;
|
|
2992
|
-
var length = Math.min(startRgb.length, endRgb.length);
|
|
2993
|
-
var result = [];
|
|
2994
|
-
for (var i = 0; i < length; i++) {
|
|
2995
|
-
result.push(Math.max(0, Math.min(255, Math.round(startRgb[i] * partStart + endRgb[i] * partEnd))));
|
|
2996
|
-
}
|
|
2997
|
-
return result;
|
|
2998
|
-
},
|
|
2999
|
-
/**
|
|
3000
|
-
* An implementation of the btoa function, which should work in all environments.
|
|
3001
|
-
*
|
|
3002
|
-
* @param {string} string
|
|
3003
|
-
* @returns {string}
|
|
3004
|
-
*/
|
|
3005
|
-
btoa: function btoa(string) {
|
|
3006
|
-
var _globalThis$Buffer;
|
|
3007
|
-
if (typeof (globalThis === null || globalThis === void 0 ? void 0 : globalThis.btoa) === 'function') {
|
|
3008
|
-
return globalThis.btoa(string);
|
|
3009
|
-
}
|
|
3010
|
-
if (typeof (globalThis === null || globalThis === void 0 || (_globalThis$Buffer = globalThis.Buffer) === null || _globalThis$Buffer === void 0 ? void 0 : _globalThis$Buffer.from) === 'function') {
|
|
3011
|
-
return globalThis.Buffer.from(string).toString('base64');
|
|
3012
|
-
}
|
|
3013
|
-
throw new Error('LeUtils.btoa: No btoa implementation found in this environment.');
|
|
3014
|
-
},
|
|
3015
|
-
/**
|
|
3016
|
-
* An implementation of the atob function, which should work in all environments.
|
|
3017
|
-
*
|
|
3018
|
-
* @param {string} base64string
|
|
3019
|
-
* @returns {string}
|
|
3020
|
-
*/
|
|
3021
|
-
atob: function atob(base64string) {
|
|
3022
|
-
var _globalThis$Buffer2;
|
|
3023
|
-
if (typeof (globalThis === null || globalThis === void 0 ? void 0 : globalThis.atob) === 'function') {
|
|
3024
|
-
return globalThis.atob(base64string);
|
|
3025
|
-
}
|
|
3026
|
-
if (typeof (globalThis === null || globalThis === void 0 || (_globalThis$Buffer2 = globalThis.Buffer) === null || _globalThis$Buffer2 === void 0 ? void 0 : _globalThis$Buffer2.from) === 'function') {
|
|
3027
|
-
return globalThis.Buffer.from(base64string, 'base64').toString();
|
|
3028
|
-
}
|
|
3029
|
-
throw new Error('LeUtils.atob: No atob implementation found in this environment.');
|
|
3030
|
-
},
|
|
3031
|
-
/**
|
|
3032
|
-
* Encodes a UTF-8 string into a base64 string.
|
|
3033
|
-
*
|
|
3034
|
-
* @param {string} string
|
|
3035
|
-
* @returns {string}
|
|
3036
|
-
*/
|
|
3037
|
-
utf8ToBase64: function utf8ToBase64(string) {
|
|
3038
|
-
return LeUtils.btoa(encodeURIComponent(string).replace(/%([0-9A-F]{2})/g, function (match, p1) {
|
|
3039
|
-
return String.fromCharCode(parseInt(p1, 16));
|
|
3040
|
-
}));
|
|
3041
|
-
},
|
|
3042
|
-
/**
|
|
3043
|
-
* Decodes a base64 string back into a UTF-8 string.
|
|
3044
|
-
*
|
|
3045
|
-
* @param {string} base64string
|
|
3046
|
-
* @returns {string}
|
|
3047
|
-
*/
|
|
3048
|
-
base64ToUtf8: function base64ToUtf8(base64string) {
|
|
3049
|
-
return decodeURIComponent(LeUtils.atob(base64string.trim()).split('').map(function (c) {
|
|
3050
|
-
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
3051
|
-
}).join(''));
|
|
3052
|
-
},
|
|
3053
|
-
/**
|
|
3054
|
-
* Converts a base64 string into a hex string.
|
|
3055
|
-
*
|
|
3056
|
-
* @param {string} base64string
|
|
3057
|
-
* @returns {string}
|
|
3058
|
-
*/
|
|
3059
|
-
base64ToHex: function base64ToHex(base64string) {
|
|
3060
|
-
return LeUtils.atob(base64string.trim()).split('').map(function (c) {
|
|
3061
|
-
return ('0' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
3062
|
-
}).join('');
|
|
3063
|
-
},
|
|
3064
|
-
/**
|
|
3065
|
-
* Converts a hex string into a base64 string.
|
|
3066
|
-
*
|
|
3067
|
-
* @param {string} hexstring
|
|
3068
|
-
* @returns {string}
|
|
3069
|
-
*/
|
|
3070
|
-
hexToBase64: function hexToBase64(hexstring) {
|
|
3071
|
-
var _hexstring$replace$ma;
|
|
3072
|
-
var hexResult = (_hexstring$replace$ma = hexstring.replace(/[^0-9A-F]/gi, '').match(/\w{2}/g)) === null || _hexstring$replace$ma === void 0 || (_hexstring$replace$ma = _hexstring$replace$ma.map(function (a) {
|
|
3073
|
-
return String.fromCharCode(parseInt(a, 16));
|
|
3074
|
-
})) === null || _hexstring$replace$ma === void 0 ? void 0 : _hexstring$replace$ma.join('');
|
|
3075
|
-
if (!hexResult) {
|
|
3076
|
-
throw new Error('Invalid hex string: "' + hexstring + '"');
|
|
3077
|
-
}
|
|
3078
|
-
return LeUtils.btoa(hexResult);
|
|
3079
|
-
},
|
|
3080
|
-
/**
|
|
3081
|
-
* Converts a base64 string into bytes (Uint8Array).
|
|
3082
|
-
*
|
|
3083
|
-
* @param {string} base64string
|
|
3084
|
-
* @returns {Uint8Array}
|
|
3085
|
-
*/
|
|
3086
|
-
base64ToBytes: function base64ToBytes(base64string) {
|
|
3087
|
-
return Uint8Array.from(LeUtils.atob(base64string.trim()), function (c) {
|
|
3088
|
-
return c.charCodeAt(0);
|
|
3089
|
-
});
|
|
3090
|
-
},
|
|
3091
|
-
/**
|
|
3092
|
-
* Converts bytes into a base64 string.
|
|
3093
|
-
*
|
|
3094
|
-
* @param {ArrayLike<number>|ArrayBuffer} arraybuffer
|
|
3095
|
-
* @returns {string}
|
|
3096
|
-
*/
|
|
3097
|
-
bytesToBase64: function bytesToBase64(arraybuffer) {
|
|
3098
|
-
return LeUtils.btoa(String.fromCharCode.apply(String, _toConsumableArray(new Uint8Array(arraybuffer))));
|
|
3099
|
-
},
|
|
3100
|
-
/**
|
|
3101
|
-
* Downloads the given base64 string as a file.
|
|
3102
|
-
*
|
|
3103
|
-
* @param {string} base64string
|
|
3104
|
-
* @param {string} [fileName]
|
|
3105
|
-
* @param {string} [mimeType]
|
|
3106
|
-
*/
|
|
3107
|
-
downloadFile: function downloadFile(base64string, fileName, mimeType) {
|
|
3108
|
-
var _globalThis$document7;
|
|
3109
|
-
if (!(globalThis !== null && globalThis !== void 0 && (_globalThis$document7 = globalThis.document) !== null && _globalThis$document7 !== void 0 && _globalThis$document7.createElement)) {
|
|
3110
|
-
console.warn('LeUtils.downloadFile: Document is not available, cannot download file.');
|
|
3111
|
-
return;
|
|
3112
|
-
}
|
|
3113
|
-
var link = globalThis.document.createElement('a');
|
|
3114
|
-
link.setAttribute('download', typeof fileName === 'string' ? fileName : 'file');
|
|
3115
|
-
link.href = 'data:' + mimeType + ';base64,' + base64string;
|
|
3116
|
-
link.setAttribute('target', '_blank');
|
|
3117
|
-
link.click();
|
|
3118
|
-
},
|
|
3119
|
-
/**
|
|
3120
|
-
* Loads the value from the browser, returns undefined if the value doesn't exist.
|
|
3121
|
-
*
|
|
3122
|
-
* @param {string} id
|
|
3123
|
-
* @returns {*}
|
|
3124
|
-
*/
|
|
3125
|
-
localStorageGet: function localStorageGet(id) {
|
|
3126
|
-
var _globalThis$localStor;
|
|
3127
|
-
if (!(globalThis !== null && globalThis !== void 0 && (_globalThis$localStor = globalThis.localStorage) !== null && _globalThis$localStor !== void 0 && _globalThis$localStor.getItem)) {
|
|
3128
|
-
console.warn('LeUtils.localStorageGet: LocalStorage is not available, returning undefined.');
|
|
3129
|
-
return;
|
|
3130
|
-
}
|
|
3131
|
-
var result = globalThis.localStorage.getItem('LeUtils_' + id);
|
|
3132
|
-
if (typeof result !== 'string') {
|
|
3133
|
-
return;
|
|
3134
|
-
}
|
|
3135
|
-
try {
|
|
3136
|
-
var _JSON$parse;
|
|
3137
|
-
return (_JSON$parse = JSON.parse(result)) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse['-'];
|
|
3138
|
-
} catch (e) {}
|
|
3139
|
-
},
|
|
3140
|
-
/**
|
|
3141
|
-
* Saves the given data in the browser.
|
|
3142
|
-
*
|
|
3143
|
-
* @param {string} id
|
|
3144
|
-
* @param {*} data
|
|
3145
|
-
*/
|
|
3146
|
-
localStorageSet: function localStorageSet(id, data) {
|
|
3147
|
-
var _globalThis$localStor2;
|
|
3148
|
-
if (!(globalThis !== null && globalThis !== void 0 && (_globalThis$localStor2 = globalThis.localStorage) !== null && _globalThis$localStor2 !== void 0 && _globalThis$localStor2.setItem)) {
|
|
3149
|
-
console.warn('LeUtils.localStorageSet: LocalStorage is not available, cannot save data.');
|
|
3150
|
-
return;
|
|
3151
|
-
}
|
|
3152
|
-
if (typeof data === 'undefined') {
|
|
3153
|
-
globalThis.localStorage.removeItem('LeUtils_' + id);
|
|
3154
|
-
return;
|
|
3155
|
-
}
|
|
3156
|
-
globalThis.localStorage.setItem('LeUtils_' + id, JSON.stringify({
|
|
3157
|
-
'-': data
|
|
3158
|
-
}));
|
|
3159
|
-
},
|
|
3160
|
-
/**
|
|
3161
|
-
* Removes the data from the browser.
|
|
3162
|
-
*
|
|
3163
|
-
* @param {string} id
|
|
3164
|
-
*/
|
|
3165
|
-
localStorageRemove: function localStorageRemove(id) {
|
|
3166
|
-
var _globalThis$localStor3;
|
|
3167
|
-
if (!(globalThis !== null && globalThis !== void 0 && (_globalThis$localStor3 = globalThis.localStorage) !== null && _globalThis$localStor3 !== void 0 && _globalThis$localStor3.removeItem)) {
|
|
3168
|
-
console.warn('LeUtils.localStorageRemove: LocalStorage is not available, cannot remove data.');
|
|
3169
|
-
return;
|
|
3170
|
-
}
|
|
3171
|
-
globalThis.localStorage.removeItem('LeUtils_' + id);
|
|
3172
|
-
},
|
|
3173
|
-
/**
|
|
3174
|
-
* Returns whether the current hostname (globalThis.location.hostname) is private (such as localhost, 192.168.1.1, etc).
|
|
3175
|
-
* This can be used to determine if the app is running in a development environment or not.
|
|
3176
|
-
*
|
|
3177
|
-
* Only "localhost" and IPv4 addresses are supported. IPv6 addresses will always return false.
|
|
3178
|
-
*
|
|
3179
|
-
* @returns {boolean}
|
|
3180
|
-
*/
|
|
3181
|
-
isCurrentHostPrivate: function () {
|
|
3182
|
-
var lastHostname = null;
|
|
3183
|
-
var lastResult = false;
|
|
3184
|
-
return function () {
|
|
3185
|
-
var _globalThis$location;
|
|
3186
|
-
if (!(globalThis !== null && globalThis !== void 0 && (_globalThis$location = globalThis.location) !== null && _globalThis$location !== void 0 && _globalThis$location.hostname)) {
|
|
3187
|
-
console.warn('LeUtils.isCurrentHostPrivate: No location.hostname found, returning false.');
|
|
3188
|
-
return false;
|
|
3189
|
-
}
|
|
3190
|
-
var hostname = globalThis.location.hostname;
|
|
3191
|
-
if (lastHostname === hostname) {
|
|
3192
|
-
return lastResult;
|
|
3193
|
-
}
|
|
3194
|
-
lastHostname = hostname;
|
|
3195
|
-
lastResult = LeUtils.isGivenHostPrivate(lastHostname);
|
|
3196
|
-
return lastResult;
|
|
3197
|
-
};
|
|
3198
|
-
}(),
|
|
3199
|
-
/**
|
|
3200
|
-
* Returns true if the given hostname is private (such as localhost, 192.168.1.1, etc).
|
|
3201
|
-
*
|
|
3202
|
-
* Only "localhost" and IPv4 addresses are supported. IPv6 addresses will always return false.
|
|
3203
|
-
*
|
|
3204
|
-
* @param {string} host
|
|
3205
|
-
* @returns {boolean}
|
|
3206
|
-
*/
|
|
3207
|
-
isGivenHostPrivate: function isGivenHostPrivate(host) {
|
|
3208
|
-
host = STRING(host).trim();
|
|
3209
|
-
if (!host) {
|
|
3210
|
-
return false;
|
|
3211
|
-
}
|
|
3212
|
-
try {
|
|
3213
|
-
host = new URL(host).hostname;
|
|
3214
|
-
} catch (e) {
|
|
3215
|
-
host = host.split(':')[0];
|
|
3216
|
-
}
|
|
3217
|
-
host = STRING(host).trim().toLowerCase();
|
|
3218
|
-
if (host === 'localhost' || host === '127.0.0.1') {
|
|
3219
|
-
return true;
|
|
3220
|
-
}
|
|
3221
|
-
if (!/^(\d{1,3}\.){3}\d{1,3}$/.test(host)) {
|
|
3222
|
-
return false;
|
|
3223
|
-
}
|
|
3224
|
-
var parts = host.split('.');
|
|
3225
|
-
return parts[0] === '10' ||
|
|
3226
|
-
// 10.0.0.0 - 10.255.255.255
|
|
3227
|
-
parts[0] === '172' && parseInt(parts[1], 10) >= 16 && parseInt(parts[1], 10) <= 31 ||
|
|
3228
|
-
// 172.16.0.0 - 172.31.255.255
|
|
3229
|
-
parts[0] === '192' && parts[1] === '168'; // 192.168.0.0 - 192.168.255.255
|
|
3230
|
-
},
|
|
3231
|
-
/**
|
|
3232
|
-
* @typedef {Object} LeUtils_TransactionalValue
|
|
3233
|
-
* @property {*} value
|
|
3234
|
-
* @property {{id:string, value:*}[]} changes
|
|
3235
|
-
*/
|
|
3236
|
-
/**
|
|
3237
|
-
* Creates and returns a new TransactionalValue object.
|
|
3238
|
-
* With a TransactionalValue, you can keep track of changes to a value, and commit or cancel them.
|
|
3239
|
-
*
|
|
3240
|
-
* Multiple uncommitted changes can be made at the same time, the last change will be the one that overwrites older changes.
|
|
3241
|
-
* If that change is cancelled, the previous change will be the one that overwrites older changes.
|
|
3242
|
-
* This allows you to make multiple unconfirmed changes, and confirm or cancel each of them individually at any time.
|
|
3243
|
-
*
|
|
3244
|
-
* @param {*} [value]
|
|
3245
|
-
* @returns {LeUtils_TransactionalValue}
|
|
3246
|
-
*/
|
|
3247
|
-
createTransactionalValue: function createTransactionalValue(value) {
|
|
3248
|
-
if (typeof value === 'undefined') {
|
|
3249
|
-
value = null;
|
|
3250
|
-
}
|
|
3251
|
-
return {
|
|
3252
|
-
value: value,
|
|
3253
|
-
changes: []
|
|
3254
|
-
};
|
|
3255
|
-
},
|
|
3256
|
-
/**
|
|
3257
|
-
* Returns true if the given value is a valid TransactionalValue, returns false if it isn't.
|
|
3258
|
-
*
|
|
3259
|
-
* @param {LeUtils_TransactionalValue} transactionalValue
|
|
3260
|
-
* @returns {boolean}
|
|
3261
|
-
*/
|
|
3262
|
-
isTransactionalValueValid: function isTransactionalValueValid(transactionalValue) {
|
|
3263
|
-
return _typeof(transactionalValue) === 'object' && 'value' in transactionalValue && 'changes' in transactionalValue && Array.isArray(transactionalValue.changes);
|
|
3264
|
-
},
|
|
3265
|
-
/**
|
|
3266
|
-
* Returns true if the given value is a TransactionalValue, false otherwise.
|
|
3267
|
-
*
|
|
3268
|
-
* @param {LeUtils_TransactionalValue} transactionalValue
|
|
3269
|
-
* @returns {string}
|
|
3270
|
-
*/
|
|
3271
|
-
transactionalValueToString: function transactionalValueToString(transactionalValue) {
|
|
3272
|
-
if (!LeUtils.isTransactionalValueValid(transactionalValue)) {
|
|
3273
|
-
return transactionalValue + '';
|
|
3274
|
-
}
|
|
3275
|
-
if (transactionalValue.changes.length <= 0) {
|
|
3276
|
-
return '' + transactionalValue.value;
|
|
3277
|
-
}
|
|
3278
|
-
var valuesString = '' + transactionalValue.value;
|
|
3279
|
-
for (var i = 0; i < transactionalValue.changes.length; i++) {
|
|
3280
|
-
valuesString += ' -> ' + transactionalValue.changes[i].value;
|
|
3281
|
-
}
|
|
3282
|
-
return transactionalValue.changes[transactionalValue.changes.length - 1].value + ' (' + valuesString + ')';
|
|
3283
|
-
},
|
|
3284
|
-
/**
|
|
3285
|
-
* Sets the committed value of the given TransactionalValue to the given value. Clears out the previously uncommitted changes.
|
|
3286
|
-
*
|
|
3287
|
-
* @param {LeUtils_TransactionalValue} transactionalValue
|
|
3288
|
-
* @param {*} value
|
|
3289
|
-
*/
|
|
3290
|
-
transactionSetAndCommit: function transactionSetAndCommit(transactionalValue, value) {
|
|
3291
|
-
checkTransactionalValue(transactionalValue);
|
|
3292
|
-
if (typeof value === 'undefined') {
|
|
3293
|
-
value = null;
|
|
3294
|
-
}
|
|
3295
|
-
transactionalValue.value = value;
|
|
3296
|
-
transactionalValue.changes = [];
|
|
3297
|
-
},
|
|
3298
|
-
/**
|
|
3299
|
-
* Sets the value of the given TransactionalValue to the given value, without yet committing it, meaning it can be committed or cancelled later.
|
|
3300
|
-
* It returns the ID of the change, which can be used to commit or cancel the change later.
|
|
3301
|
-
*
|
|
3302
|
-
* @param {LeUtils_TransactionalValue} transactionalValue
|
|
3303
|
-
* @param {*} value
|
|
3304
|
-
* @returns {string}
|
|
3305
|
-
*/
|
|
3306
|
-
transactionSetWithoutCommitting: function transactionSetWithoutCommitting(transactionalValue, value) {
|
|
3307
|
-
checkTransactionalValue(transactionalValue);
|
|
3308
|
-
if (typeof value === 'undefined') {
|
|
3309
|
-
value = null;
|
|
3310
|
-
}
|
|
3311
|
-
var id = LeUtils.uniqueId();
|
|
3312
|
-
transactionalValue.changes.push({
|
|
3313
|
-
id: id,
|
|
3314
|
-
value: value
|
|
3315
|
-
});
|
|
3316
|
-
return id;
|
|
3317
|
-
},
|
|
3318
|
-
/**
|
|
3319
|
-
* Commits the change with the given ID, making it the new committed value.
|
|
3320
|
-
* Returns true if the change was found and committed, returns false if it was already overwritten by a newer committed change.
|
|
3321
|
-
*
|
|
3322
|
-
* @param {LeUtils_TransactionalValue} transactionalValue
|
|
3323
|
-
* @param {string} changeId
|
|
3324
|
-
* @returns {boolean}
|
|
3325
|
-
*/
|
|
3326
|
-
transactionCommitChange: function transactionCommitChange(transactionalValue, changeId) {
|
|
3327
|
-
checkTransactionalValue(transactionalValue);
|
|
3328
|
-
var change = findTransactionalValueChange(transactionalValue, changeId);
|
|
3329
|
-
if (change === null) {
|
|
3330
|
-
return false;
|
|
3331
|
-
}
|
|
3332
|
-
transactionalValue.value = change.value;
|
|
3333
|
-
transactionalValue.changes.splice(0, change.index + 1);
|
|
3334
|
-
return true;
|
|
3335
|
-
},
|
|
3336
|
-
/**
|
|
3337
|
-
* Cancels the change with the given ID, removing it from the uncommitted changes.
|
|
3338
|
-
* Returns true if the change was found and removed, returns false if it was already overwritten by a newer committed change.
|
|
3339
|
-
*
|
|
3340
|
-
* @param {LeUtils_TransactionalValue} transactionalValue
|
|
3341
|
-
* @param {string} changeId
|
|
3342
|
-
* @returns {boolean}
|
|
3343
|
-
*/
|
|
3344
|
-
transactionCancelChange: function transactionCancelChange(transactionalValue, changeId) {
|
|
3345
|
-
checkTransactionalValue(transactionalValue);
|
|
3346
|
-
var change = findTransactionalValueChange(transactionalValue, changeId);
|
|
3347
|
-
if (change === null) {
|
|
3348
|
-
return false;
|
|
3349
|
-
}
|
|
3350
|
-
transactionalValue.changes.splice(change.index, 1);
|
|
3351
|
-
return true;
|
|
3352
|
-
},
|
|
3353
|
-
/**
|
|
3354
|
-
* Returns true if the change was found, meaning it can still make a difference to the final committed value of this TransactionalValue.
|
|
3355
|
-
* Returns false if it was already overwritten by a newer committed change, meaning that this change can no longer make a difference to the final committed value of this TransactionalValue.
|
|
3356
|
-
*
|
|
3357
|
-
* @param {LeUtils_TransactionalValue} transactionalValue
|
|
3358
|
-
* @param {string} changeId
|
|
3359
|
-
* @returns {boolean}
|
|
3360
|
-
*/
|
|
3361
|
-
transactionIsChangeRelevant: function transactionIsChangeRelevant(transactionalValue, changeId) {
|
|
3362
|
-
checkTransactionalValue(transactionalValue);
|
|
3363
|
-
return findTransactionalValueChange(transactionalValue, changeId) !== null;
|
|
3364
|
-
},
|
|
3365
|
-
/**
|
|
3366
|
-
* Returns the committed value of the given TransactionalValue.
|
|
3367
|
-
*
|
|
3368
|
-
* @param {LeUtils_TransactionalValue} transactionalValue
|
|
3369
|
-
* @returns {*}
|
|
3370
|
-
*/
|
|
3371
|
-
transactionGetCommittedValue: function transactionGetCommittedValue(transactionalValue) {
|
|
3372
|
-
checkTransactionalValue(transactionalValue);
|
|
3373
|
-
return transactionalValue.value;
|
|
3374
|
-
},
|
|
3375
|
-
/**
|
|
3376
|
-
* Returns the value (including any uncommitted changes made to it) of the given TransactionalValue.
|
|
3377
|
-
*
|
|
3378
|
-
* @param {LeUtils_TransactionalValue} transactionalValue
|
|
3379
|
-
* @returns {*}
|
|
3380
|
-
*/
|
|
3381
|
-
transactionGetValue: function transactionGetValue(transactionalValue) {
|
|
3382
|
-
checkTransactionalValue(transactionalValue);
|
|
3383
|
-
if (transactionalValue.changes.length <= 0) {
|
|
3384
|
-
return transactionalValue.value;
|
|
3385
|
-
}
|
|
3386
|
-
return transactionalValue.changes[transactionalValue.changes.length - 1].value;
|
|
3387
|
-
},
|
|
3388
|
-
/**
|
|
3389
|
-
* Creates a worker thread. Workers have to be stored at /workers/{workerName}.worker.js for this to work.
|
|
3390
|
-
*
|
|
3391
|
-
* Example of a worker file:
|
|
3392
|
-
*
|
|
3393
|
-
* ```js
|
|
3394
|
-
* onmessage = (message) =>
|
|
3395
|
-
* {
|
|
3396
|
-
* postMessage({
|
|
3397
|
-
* ...message.data,
|
|
3398
|
-
* results: ['...some expensive calculation involving message.data...'],
|
|
3399
|
-
* });
|
|
3400
|
-
* };
|
|
3401
|
-
* ```
|
|
3402
|
-
*
|
|
3403
|
-
* Usage:
|
|
3404
|
-
*
|
|
3405
|
-
* ```js
|
|
3406
|
-
* const {results} = await (async () =>
|
|
3407
|
-
* {
|
|
3408
|
-
* try
|
|
3409
|
-
* {
|
|
3410
|
-
* return await LeUtils.sendWorkerMessage('my-worker', {someData:[1, 2, 3, 4, 5]});
|
|
3411
|
-
* }
|
|
3412
|
-
* catch(error)
|
|
3413
|
-
* {
|
|
3414
|
-
* console.error('MyWorker: ', error);
|
|
3415
|
-
* return {results:[]};
|
|
3416
|
-
* }
|
|
3417
|
-
* })();
|
|
3418
|
-
* ```
|
|
3419
|
-
*
|
|
3420
|
-
* or, if you want more control over the number of threads you have (the above example will only create 1 thread per worker):
|
|
3421
|
-
*
|
|
3422
|
-
* ```js
|
|
3423
|
-
* const myWorker1 = LeUtils.createWorkerThread('my-worker'); // creates a thread, you can create multiple worker threads of the same worker, to run multiple instances in parallel
|
|
3424
|
-
* const myWorker2 = LeUtils.createWorkerThread('my-worker'); // same worker, another thread
|
|
3425
|
-
* const {results} = await (async () =>
|
|
3426
|
-
* {
|
|
3427
|
-
* try
|
|
3428
|
-
* {
|
|
3429
|
-
* return await myWorker1.sendMessage({someData:[1, 2, 3, 4, 5]});
|
|
3430
|
-
* }
|
|
3431
|
-
* catch(error)
|
|
3432
|
-
* {
|
|
3433
|
-
* console.error('MyWorker: ', error);
|
|
3434
|
-
* return {results:[]};
|
|
3435
|
-
* }
|
|
3436
|
-
* })();
|
|
3437
|
-
* ```
|
|
3438
|
-
*
|
|
3439
|
-
* @param {string} name
|
|
3440
|
-
* @returns {{worker:Worker|null, sendMessage:(data:Object,options:{timeout:number|undefined}|undefined)=>Promise<Object>}}
|
|
3441
|
-
*/
|
|
3442
|
-
createWorkerThread: function createWorkerThread(name) {
|
|
3443
|
-
if (!(globalThis !== null && globalThis !== void 0 && globalThis.Worker)) {
|
|
3444
|
-
console.warn('LeUtils.createWorkerThread: Workers are not supported in this environment, returning a dummy worker.');
|
|
3445
|
-
return {
|
|
3446
|
-
worker: null,
|
|
3447
|
-
sendMessage: function sendMessage(data, options) {
|
|
3448
|
-
return new Promise(function (resolve, reject) {
|
|
3449
|
-
reject('Workers are not supported in this environment');
|
|
3450
|
-
});
|
|
3451
|
-
}
|
|
3452
|
-
};
|
|
3453
|
-
}
|
|
3454
|
-
var worker = new globalThis.Worker('/workers/' + name + '.worker.js');
|
|
3455
|
-
var listeners = new Map();
|
|
3456
|
-
var addListener = function addListener(id, callback) {
|
|
3457
|
-
listeners.set(id, callback);
|
|
3458
|
-
};
|
|
3459
|
-
var removeListener = function removeListener(id) {
|
|
3460
|
-
listeners["delete"](id);
|
|
3461
|
-
};
|
|
3462
|
-
var sendMessage = function sendMessage(data, options) {
|
|
3463
|
-
return new Promise(function (resolve, reject) {
|
|
3464
|
-
var _options$timeout;
|
|
3465
|
-
var id = LeUtils.uniqueId();
|
|
3466
|
-
addListener(id, resolve);
|
|
3467
|
-
setTimeout(function () {
|
|
3468
|
-
removeListener(id);
|
|
3469
|
-
reject('timeout');
|
|
3470
|
-
}, (_options$timeout = options === null || options === void 0 ? void 0 : options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : 10000);
|
|
3471
|
-
worker.postMessage(_objectSpread({
|
|
3472
|
-
id: id
|
|
3473
|
-
}, data));
|
|
3474
|
-
});
|
|
3475
|
-
};
|
|
3476
|
-
worker.onerror = function (error) {
|
|
3477
|
-
console.error('Worker ' + name + ':', error);
|
|
3478
|
-
};
|
|
3479
|
-
worker.onmessage = function (message) {
|
|
3480
|
-
var data = message.data;
|
|
3481
|
-
if (data !== null && data !== void 0 && data.id) {
|
|
3482
|
-
var callback = listeners.get(data.id);
|
|
3483
|
-
if (callback) {
|
|
3484
|
-
removeListener(data.id);
|
|
3485
|
-
callback(data);
|
|
3486
|
-
}
|
|
3487
|
-
}
|
|
3488
|
-
};
|
|
3489
|
-
return {
|
|
3490
|
-
worker: worker,
|
|
3491
|
-
sendMessage: sendMessage
|
|
3492
|
-
};
|
|
3493
|
-
},
|
|
3494
|
-
/**
|
|
3495
|
-
* Sends a message to the given worker. Creates a worker thread for this worker if it doesn't exist yet.
|
|
3496
|
-
*
|
|
3497
|
-
* See {@link LeUtils#createWorkerThread} for more info on how to use workers.
|
|
3498
|
-
*
|
|
3499
|
-
* @param {string} workerName
|
|
3500
|
-
* @param {Object} data
|
|
3501
|
-
* @param {{timeout:number|undefined}} [options]
|
|
3502
|
-
* @returns {Promise<Object>}
|
|
3503
|
-
*/
|
|
3504
|
-
sendWorkerMessage: function () {
|
|
3505
|
-
var workers = new Map();
|
|
3506
|
-
return function (workerName, data, options) {
|
|
3507
|
-
if (!workers.has(workerName)) {
|
|
3508
|
-
workers.set(workerName, LeUtils.createWorkerThread(workerName));
|
|
3509
|
-
}
|
|
3510
|
-
return workers.get(workerName).sendMessage(data, options);
|
|
3511
|
-
};
|
|
3512
|
-
}(),
|
|
3513
|
-
/**
|
|
3514
|
-
* Purges the given email address, returning an empty string if it's invalid.
|
|
3515
|
-
*
|
|
3516
|
-
* @param {string} email
|
|
3517
|
-
* @returns {string}
|
|
3518
|
-
*/
|
|
3519
|
-
purgeEmail: function purgeEmail(email) {
|
|
3520
|
-
email = STRING(email).trim().toLowerCase().replace(/\s/g, '');
|
|
3521
|
-
if (!email.includes('@') || !email.includes('.')) {
|
|
3522
|
-
return '';
|
|
3523
|
-
}
|
|
3524
|
-
return email;
|
|
3525
|
-
},
|
|
3526
|
-
/**
|
|
3527
|
-
* Returns true if the focus is effectively clear, meaning that the user is not typing in an input field.
|
|
3528
|
-
*
|
|
3529
|
-
* @returns {boolean}
|
|
3530
|
-
*/
|
|
3531
|
-
isFocusClear: function () {
|
|
3532
|
-
var inputTypes = ['text', 'search', 'email', 'number', 'password', 'tel', 'time', 'url', 'week', 'month', 'date', 'datetime-local'];
|
|
3533
|
-
return function () {
|
|
3534
|
-
var _globalThis$document8, _globalThis$document$, _globalThis$document9;
|
|
3535
|
-
return !((globalThis === null || globalThis === void 0 || (_globalThis$document8 = globalThis.document) === null || _globalThis$document8 === void 0 || (_globalThis$document8 = _globalThis$document8.activeElement) === null || _globalThis$document8 === void 0 || (_globalThis$document8 = _globalThis$document8.tagName) === null || _globalThis$document8 === void 0 ? void 0 : _globalThis$document8.toLowerCase()) === 'input' && inputTypes.includes((_globalThis$document$ = globalThis === null || globalThis === void 0 || (_globalThis$document9 = globalThis.document) === null || _globalThis$document9 === void 0 || (_globalThis$document9 = _globalThis$document9.activeElement) === null || _globalThis$document9 === void 0 || (_globalThis$document9 = _globalThis$document9.getAttribute('type')) === null || _globalThis$document9 === void 0 ? void 0 : _globalThis$document9.toLowerCase()) !== null && _globalThis$document$ !== void 0 ? _globalThis$document$ : ''));
|
|
3536
|
-
};
|
|
3537
|
-
}(),
|
|
3538
|
-
/**
|
|
3539
|
-
* Returns the user's locale. Returns 'en-US' if it can't be determined.
|
|
3540
|
-
*
|
|
3541
|
-
* @returns {string}
|
|
3542
|
-
*/
|
|
3543
|
-
getUserLocale: function () {
|
|
3544
|
-
var userLocale = null;
|
|
3545
|
-
return function () {
|
|
3546
|
-
if (userLocale === null) {
|
|
3547
|
-
userLocale = function (_globalThis$navigator3, _globalThis$navigator4) {
|
|
3548
|
-
var locales = (_globalThis$navigator3 = globalThis === null || globalThis === void 0 || (_globalThis$navigator4 = globalThis.navigator) === null || _globalThis$navigator4 === void 0 ? void 0 : _globalThis$navigator4.languages) !== null && _globalThis$navigator3 !== void 0 ? _globalThis$navigator3 : [];
|
|
3549
|
-
if (!IS_ARRAY(locales) || locales.length <= 0) {
|
|
3550
|
-
return 'en-US';
|
|
3551
|
-
}
|
|
3552
|
-
locales = locales.filter(function (locale) {
|
|
3553
|
-
return typeof locale === 'string' && locale.includes('-') && locale.toLowerCase() !== 'en-us';
|
|
3554
|
-
});
|
|
3555
|
-
if (locales.length <= 0) {
|
|
3556
|
-
return 'en-US';
|
|
3557
|
-
}
|
|
3558
|
-
var localesNoEnglish = locales.filter(function (locale) {
|
|
3559
|
-
return !locale.toLowerCase().startsWith('en-');
|
|
3560
|
-
});
|
|
3561
|
-
if (localesNoEnglish.length <= 0) {
|
|
3562
|
-
return locales[0];
|
|
3563
|
-
}
|
|
3564
|
-
return localesNoEnglish[0];
|
|
3565
|
-
}();
|
|
3566
|
-
}
|
|
3567
|
-
return userLocale;
|
|
3568
|
-
};
|
|
3569
|
-
}(),
|
|
3570
|
-
/**
|
|
3571
|
-
* Returns the user's locale date format. Always returns YYYY MM DD, with the character in between depending on the user's locale. Returns 'YYYY/MM/DD' if the user's locale can't be determined.
|
|
3572
|
-
*
|
|
3573
|
-
* @returns {string}
|
|
3574
|
-
*/
|
|
3575
|
-
getUserLocaleDateFormat: function () {
|
|
3576
|
-
var userLocaleDateFormat = null;
|
|
3577
|
-
return function () {
|
|
3578
|
-
if (userLocaleDateFormat === null) {
|
|
3579
|
-
userLocaleDateFormat = function (_globalThis$Intl) {
|
|
3580
|
-
var _char = '/';
|
|
3581
|
-
if (globalThis !== null && globalThis !== void 0 && (_globalThis$Intl = globalThis.Intl) !== null && _globalThis$Intl !== void 0 && _globalThis$Intl.DateTimeFormat) {
|
|
3582
|
-
var formattedDate = new globalThis.Intl.DateTimeFormat(LeUtils.getUserLocale()).format();
|
|
3583
|
-
if (formattedDate.includes('-')) {
|
|
3584
|
-
_char = '-';
|
|
3585
|
-
} else if (formattedDate.includes('. ')) {
|
|
3586
|
-
_char = '.';
|
|
3587
|
-
} else if (formattedDate.includes('.')) {
|
|
3588
|
-
_char = '.';
|
|
3589
|
-
}
|
|
3590
|
-
}
|
|
3591
|
-
return 'YYYY' + _char + 'MM' + _char + 'DD';
|
|
3592
|
-
}();
|
|
3593
|
-
}
|
|
3594
|
-
return userLocaleDateFormat;
|
|
3595
|
-
};
|
|
3596
|
-
}()
|
|
3597
|
-
};
|
|
3598
|
-
|
|
3599
|
-
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
3600
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3601
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
3602
|
-
function _classPrivateFieldInitSpec$2(e, t, a) { _checkPrivateRedeclaration$2(e, t), t.set(e, a); }
|
|
3603
|
-
function _checkPrivateRedeclaration$2(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
3604
|
-
function _classPrivateFieldGet$2(s, a) { return s.get(_assertClassBrand$2(s, a)); }
|
|
3605
|
-
function _classPrivateFieldSet$2(s, a, r) { return s.set(_assertClassBrand$2(s, a), r), r; }
|
|
3606
|
-
function _assertClassBrand$2(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
3607
|
-
var _events = /*#__PURE__*/new WeakMap();
|
|
3608
|
-
/**
|
|
3609
|
-
* A simple event emitter class that allows you to register listeners for events, emit events, and remove listeners.
|
|
3610
|
-
*/
|
|
3611
|
-
var EventEmitter = /*#__PURE__*/function () {
|
|
3612
|
-
/**
|
|
3613
|
-
* Creates a new EventEmitter instance.
|
|
3614
|
-
*/
|
|
3615
|
-
function EventEmitter() {
|
|
3616
|
-
_classCallCheck(this, EventEmitter);
|
|
3617
|
-
/** @type {Map<string, Set<Function>>} */
|
|
3618
|
-
_classPrivateFieldInitSpec$2(this, _events, void 0);
|
|
3619
|
-
_classPrivateFieldSet$2(_events, this, new Map());
|
|
3620
|
-
}
|
|
3621
|
-
|
|
3622
|
-
/**
|
|
3623
|
-
* Registers a listener for a specific event.
|
|
3624
|
-
*
|
|
3625
|
-
* @param {string} event - The name of the event to listen for.
|
|
3626
|
-
* @param {Function} listener - The function to call when the event is emitted.
|
|
3627
|
-
* @returns {{remove:(()=>void)}}
|
|
3628
|
-
*/
|
|
3629
|
-
return _createClass(EventEmitter, [{
|
|
3630
|
-
key: "on",
|
|
3631
|
-
value: function on(event, listener) {
|
|
3632
|
-
var _classPrivateFieldGet2,
|
|
3633
|
-
_this = this;
|
|
3634
|
-
if (!_classPrivateFieldGet$2(_events, this).has(event)) {
|
|
3635
|
-
_classPrivateFieldGet$2(_events, this).set(event, new Set());
|
|
3636
|
-
}
|
|
3637
|
-
(_classPrivateFieldGet2 = _classPrivateFieldGet$2(_events, this).get(event)) === null || _classPrivateFieldGet2 === void 0 || _classPrivateFieldGet2.add(listener);
|
|
3638
|
-
return {
|
|
3639
|
-
remove: function remove() {
|
|
3640
|
-
return _this.off(event, listener);
|
|
3641
|
-
}
|
|
3642
|
-
};
|
|
3643
|
-
}
|
|
3644
|
-
|
|
3645
|
-
/**
|
|
3646
|
-
* Registers a listener for a specific event, this listener will be called only once.
|
|
3647
|
-
*
|
|
3648
|
-
* @param {string} event - The name of the event to listen for.
|
|
3649
|
-
* @param {Function} listener - The function to call when the event is emitted.
|
|
3650
|
-
* @returns {{remove:()=>void}}
|
|
3651
|
-
*/
|
|
3652
|
-
}, {
|
|
3653
|
-
key: "once",
|
|
3654
|
-
value: function once(event, listener) {
|
|
3655
|
-
var _this2 = this;
|
|
3656
|
-
var _wrapper = function wrapper() {
|
|
3657
|
-
_this2.off(event, _wrapper);
|
|
3658
|
-
listener.apply(void 0, arguments);
|
|
3659
|
-
};
|
|
3660
|
-
this.on(event, _wrapper);
|
|
3661
|
-
return {
|
|
3662
|
-
remove: function remove() {
|
|
3663
|
-
return _this2.off(event, _wrapper);
|
|
3664
|
-
}
|
|
3665
|
-
};
|
|
3666
|
-
}
|
|
3667
|
-
|
|
3668
|
-
/**
|
|
3669
|
-
* Removes a listener for a specific event.
|
|
3670
|
-
*
|
|
3671
|
-
* @param {string} event - The name of the event to stop listening for.
|
|
3672
|
-
* @param {Function} listener - The function to remove from the event listeners.
|
|
3673
|
-
*/
|
|
3674
|
-
}, {
|
|
3675
|
-
key: "off",
|
|
3676
|
-
value: function off(event, listener) {
|
|
3677
|
-
var listeners = _classPrivateFieldGet$2(_events, this).get(event);
|
|
3678
|
-
if (listeners) {
|
|
3679
|
-
listeners["delete"](listener);
|
|
3680
|
-
if (listeners.size === 0) {
|
|
3681
|
-
_classPrivateFieldGet$2(_events, this)["delete"](event);
|
|
3682
|
-
}
|
|
3683
|
-
}
|
|
3684
|
-
}
|
|
3685
|
-
|
|
3686
|
-
/**
|
|
3687
|
-
* Emits an event, calling all registered listeners with the provided arguments.
|
|
3688
|
-
*
|
|
3689
|
-
* @param {string} event - The name of the event to emit.
|
|
3690
|
-
* @param {...*} args - The arguments to pass to the listeners.
|
|
3691
|
-
*/
|
|
3692
|
-
}, {
|
|
3693
|
-
key: "emit",
|
|
3694
|
-
value: function emit(event) {
|
|
3695
|
-
var listeners = _classPrivateFieldGet$2(_events, this).get(event);
|
|
3696
|
-
if (listeners) {
|
|
3697
|
-
var snapshot = _toConsumableArray(listeners);
|
|
3698
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
3699
|
-
args[_key - 1] = arguments[_key];
|
|
3700
|
-
}
|
|
3701
|
-
var _iterator = _createForOfIteratorHelper(snapshot),
|
|
3702
|
-
_step;
|
|
3703
|
-
try {
|
|
3704
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
3705
|
-
var listener = _step.value;
|
|
3706
|
-
try {
|
|
3707
|
-
listener.apply(void 0, args);
|
|
3708
|
-
} catch (err) {
|
|
3709
|
-
console.error("Error in listener for \"".concat(event, "\":"), err);
|
|
3710
|
-
}
|
|
3711
|
-
}
|
|
3712
|
-
} catch (err) {
|
|
3713
|
-
_iterator.e(err);
|
|
3714
|
-
} finally {
|
|
3715
|
-
_iterator.f();
|
|
3716
|
-
}
|
|
3717
|
-
}
|
|
3718
|
-
}
|
|
3719
|
-
|
|
3720
|
-
/**
|
|
3721
|
-
* Clears all listeners for a specific event or all events if no event is specified.
|
|
3722
|
-
*
|
|
3723
|
-
* @param {string} [event] - The name of the event to clear listeners for. If not provided, all events will be cleared.
|
|
3724
|
-
*/
|
|
3725
|
-
}, {
|
|
3726
|
-
key: "clear",
|
|
3727
|
-
value: function clear(event) {
|
|
3728
|
-
if (event !== undefined) {
|
|
3729
|
-
_classPrivateFieldGet$2(_events, this)["delete"](event);
|
|
3730
|
-
} else {
|
|
3731
|
-
_classPrivateFieldGet$2(_events, this).clear();
|
|
3732
|
-
}
|
|
3733
|
-
}
|
|
3734
|
-
}]);
|
|
3735
|
-
}();
|
|
3736
|
-
|
|
3737
|
-
function _classPrivateFieldInitSpec$1(e, t, a) { _checkPrivateRedeclaration$1(e, t), t.set(e, a); }
|
|
3738
|
-
function _checkPrivateRedeclaration$1(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
3739
|
-
function _classPrivateFieldSet$1(s, a, r) { return s.set(_assertClassBrand$1(s, a), r), r; }
|
|
3740
|
-
function _classPrivateFieldGet$1(s, a) { return s.get(_assertClassBrand$1(s, a)); }
|
|
3741
|
-
function _assertClassBrand$1(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
3742
|
-
var LinkedListNode = /*#__PURE__*/_createClass(
|
|
3743
|
-
/**
|
|
3744
|
-
* @param {*} value
|
|
3745
|
-
*/
|
|
3746
|
-
function LinkedListNode(value) {
|
|
3747
|
-
_classCallCheck(this, LinkedListNode);
|
|
3748
|
-
/** @type {*} */
|
|
3749
|
-
_defineProperty(this, "value", void 0);
|
|
3750
|
-
/** @type {LinkedListNode|null} */
|
|
3751
|
-
_defineProperty(this, "next", null);
|
|
3752
|
-
/** @type {LinkedListNode|null} */
|
|
3753
|
-
_defineProperty(this, "previous", null);
|
|
3754
|
-
this.value = value;
|
|
3755
|
-
});
|
|
3756
|
-
var _head = /*#__PURE__*/new WeakMap();
|
|
3757
|
-
var _tail = /*#__PURE__*/new WeakMap();
|
|
3758
|
-
var _size = /*#__PURE__*/new WeakMap();
|
|
3759
|
-
var LinkedList = /*#__PURE__*/function () {
|
|
3760
|
-
function LinkedList() {
|
|
3761
|
-
_classCallCheck(this, LinkedList);
|
|
3762
|
-
/** @type {LinkedListNode|null} */
|
|
3763
|
-
_classPrivateFieldInitSpec$1(this, _head, null);
|
|
3764
|
-
/** @type {LinkedListNode|null} */
|
|
3765
|
-
_classPrivateFieldInitSpec$1(this, _tail, null);
|
|
3766
|
-
/** @type {number} */
|
|
3767
|
-
_classPrivateFieldInitSpec$1(this, _size, 0);
|
|
3768
|
-
}
|
|
3769
|
-
|
|
3770
|
-
/**
|
|
3771
|
-
* Returns the number of elements in the list.
|
|
3772
|
-
*
|
|
3773
|
-
* @returns {number}
|
|
3774
|
-
*/
|
|
3775
|
-
return _createClass(LinkedList, [{
|
|
3776
|
-
key: "size",
|
|
3777
|
-
get: function get() {
|
|
3778
|
-
return _classPrivateFieldGet$1(_size, this);
|
|
3779
|
-
}
|
|
3780
|
-
|
|
3781
|
-
/**
|
|
3782
|
-
* Adds a new value to the beginning of the list.
|
|
3783
|
-
*
|
|
3784
|
-
* @param {*} value
|
|
3785
|
-
*/
|
|
3786
|
-
}, {
|
|
3787
|
-
key: "unshift",
|
|
3788
|
-
value: function unshift(value) {
|
|
3789
|
-
var _this$size;
|
|
3790
|
-
var newNode = new LinkedListNode(value);
|
|
3791
|
-
if (_classPrivateFieldGet$1(_head, this) === null) {
|
|
3792
|
-
_classPrivateFieldSet$1(_head, this, newNode);
|
|
3793
|
-
_classPrivateFieldSet$1(_tail, this, newNode);
|
|
3794
|
-
} else {
|
|
3795
|
-
newNode.next = _classPrivateFieldGet$1(_head, this);
|
|
3796
|
-
_classPrivateFieldGet$1(_head, this).previous = newNode;
|
|
3797
|
-
_classPrivateFieldSet$1(_head, this, newNode);
|
|
3798
|
-
}
|
|
3799
|
-
_classPrivateFieldSet$1(_size, this, (_this$size = _classPrivateFieldGet$1(_size, this), _this$size++, _this$size));
|
|
3800
|
-
}
|
|
3801
|
-
|
|
3802
|
-
/**
|
|
3803
|
-
* Adds a new value to the end of the list.
|
|
3804
|
-
*
|
|
3805
|
-
* @param {*} value
|
|
3806
|
-
*/
|
|
3807
|
-
}, {
|
|
3808
|
-
key: "push",
|
|
3809
|
-
value: function push(value) {
|
|
3810
|
-
var _this$size3;
|
|
3811
|
-
var newNode = new LinkedListNode(value);
|
|
3812
|
-
if (_classPrivateFieldGet$1(_tail, this) === null) {
|
|
3813
|
-
_classPrivateFieldSet$1(_head, this, newNode);
|
|
3814
|
-
_classPrivateFieldSet$1(_tail, this, newNode);
|
|
3815
|
-
} else {
|
|
3816
|
-
newNode.previous = _classPrivateFieldGet$1(_tail, this);
|
|
3817
|
-
_classPrivateFieldGet$1(_tail, this).next = newNode;
|
|
3818
|
-
_classPrivateFieldSet$1(_tail, this, newNode);
|
|
3819
|
-
}
|
|
3820
|
-
_classPrivateFieldSet$1(_size, this, (_this$size3 = _classPrivateFieldGet$1(_size, this), _this$size3++, _this$size3));
|
|
3821
|
-
}
|
|
3822
|
-
|
|
3823
|
-
/**
|
|
3824
|
-
* Removes the first value from the list and returns it.
|
|
3825
|
-
*
|
|
3826
|
-
* @returns {*|undefined}
|
|
3827
|
-
*/
|
|
3828
|
-
}, {
|
|
3829
|
-
key: "shift",
|
|
3830
|
-
value: function shift() {
|
|
3831
|
-
var _this$size5;
|
|
3832
|
-
if (_classPrivateFieldGet$1(_head, this) === null) {
|
|
3833
|
-
return undefined;
|
|
3834
|
-
}
|
|
3835
|
-
var value = _classPrivateFieldGet$1(_head, this).value;
|
|
3836
|
-
_classPrivateFieldSet$1(_head, this, _classPrivateFieldGet$1(_head, this).next);
|
|
3837
|
-
if (_classPrivateFieldGet$1(_head, this) !== null) {
|
|
3838
|
-
_classPrivateFieldGet$1(_head, this).previous = null;
|
|
3839
|
-
} else {
|
|
3840
|
-
_classPrivateFieldSet$1(_tail, this, null);
|
|
3841
|
-
}
|
|
3842
|
-
_classPrivateFieldSet$1(_size, this, (_this$size5 = _classPrivateFieldGet$1(_size, this), _this$size5--, _this$size5));
|
|
3843
|
-
return value;
|
|
3844
|
-
}
|
|
3845
|
-
|
|
3846
|
-
/**
|
|
3847
|
-
* Removes the last value from the list and returns it.
|
|
3848
|
-
*
|
|
3849
|
-
* @returns {*|undefined}
|
|
3850
|
-
*/
|
|
3851
|
-
}, {
|
|
3852
|
-
key: "pop",
|
|
3853
|
-
value: function pop() {
|
|
3854
|
-
var _this$size7;
|
|
3855
|
-
if (_classPrivateFieldGet$1(_tail, this) === null) {
|
|
3856
|
-
return undefined;
|
|
3857
|
-
}
|
|
3858
|
-
var value = _classPrivateFieldGet$1(_tail, this).value;
|
|
3859
|
-
_classPrivateFieldSet$1(_tail, this, _classPrivateFieldGet$1(_tail, this).previous);
|
|
3860
|
-
if (_classPrivateFieldGet$1(_tail, this) !== null) {
|
|
3861
|
-
_classPrivateFieldGet$1(_tail, this).next = null;
|
|
3862
|
-
} else {
|
|
3863
|
-
_classPrivateFieldSet$1(_head, this, null);
|
|
3864
|
-
}
|
|
3865
|
-
_classPrivateFieldSet$1(_size, this, (_this$size7 = _classPrivateFieldGet$1(_size, this), _this$size7--, _this$size7));
|
|
3866
|
-
return value;
|
|
3867
|
-
}
|
|
3868
|
-
}]);
|
|
3869
|
-
}();
|
|
3870
|
-
|
|
3871
|
-
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
3872
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
3873
|
-
/**
|
|
3874
|
-
* SerializableMap class extends the native Map to provide a JSON representation.
|
|
3875
|
-
*
|
|
3876
|
-
* This class can only have string keys, as JSON does not support non-string keys.
|
|
3877
|
-
*/
|
|
3878
|
-
var SerializableMap = /*#__PURE__*/function (_Map) {
|
|
3879
|
-
function SerializableMap() {
|
|
3880
|
-
_classCallCheck(this, SerializableMap);
|
|
3881
|
-
return _callSuper(this, SerializableMap, arguments);
|
|
3882
|
-
}
|
|
3883
|
-
_inherits(SerializableMap, _Map);
|
|
3884
|
-
return _createClass(SerializableMap, [{
|
|
3885
|
-
key: "toJSON",
|
|
3886
|
-
value:
|
|
3887
|
-
/**
|
|
3888
|
-
* Returns a JSON representation of the map.
|
|
3889
|
-
*
|
|
3890
|
-
* @returns {Object}
|
|
3891
|
-
*/
|
|
3892
|
-
function toJSON() {
|
|
3893
|
-
return Object.fromEntries(this);
|
|
3894
|
-
}
|
|
3895
|
-
}]);
|
|
3896
|
-
}(/*#__PURE__*/_wrapNativeSuper(Map));
|
|
3897
|
-
|
|
3898
|
-
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
3899
|
-
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
3900
|
-
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
3901
|
-
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
3902
|
-
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
3903
|
-
|
|
3904
|
-
/**
|
|
3905
|
-
* A TreeSet is a set of elements, sorted by a comparator.
|
|
3906
|
-
* Binary search is used to find elements, which makes it very fast to find elements.
|
|
3907
|
-
*
|
|
3908
|
-
* The comparator is also used to determine if two values are equal to each other.
|
|
3909
|
-
* This way, you can have values that aren't the same be treated as if they are. This can be used to deal with issues such as floating point errors for example.
|
|
3910
|
-
*/
|
|
3911
|
-
var _elements = /*#__PURE__*/new WeakMap();
|
|
3912
|
-
var _comparator = /*#__PURE__*/new WeakMap();
|
|
3913
|
-
var TreeSet = /*#__PURE__*/function () {
|
|
3914
|
-
/**
|
|
3915
|
-
* Creates a new TreeSet with the given elements and comparator.
|
|
3916
|
-
*
|
|
3917
|
-
* @param {*[]} [elements=[]] - The initial elements of the set.
|
|
3918
|
-
* @param {(valueA:*, valueB:*) => number} [comparator=LeUtils.compare] - The comparator function to use for sorting.
|
|
3919
|
-
*/
|
|
3920
|
-
function TreeSet(elements, comparator) {
|
|
3921
|
-
_classCallCheck(this, TreeSet);
|
|
3922
|
-
/** @type {*[]} */
|
|
3923
|
-
_classPrivateFieldInitSpec(this, _elements, void 0);
|
|
3924
|
-
/** @type {(valueA:*, valueB:*) => number} */
|
|
3925
|
-
_classPrivateFieldInitSpec(this, _comparator, void 0);
|
|
3926
|
-
_classPrivateFieldSet(_comparator, this, comparator || LeUtils.compare);
|
|
3927
|
-
_classPrivateFieldSet(_elements, this, elements || []);
|
|
3928
|
-
_classPrivateFieldGet(_elements, this).sort(_classPrivateFieldGet(_comparator, this));
|
|
3929
|
-
}
|
|
3930
|
-
|
|
3931
|
-
/**
|
|
3932
|
-
*
|
|
3933
|
-
*
|
|
3934
|
-
* @param {*} value - The value to search for in the set.
|
|
3935
|
-
* @returns {{found:boolean, index:number, value:*|undefined}} - An object containing whether the value was found, the index where it would be inserted, and the value at that index (if found).
|
|
3936
|
-
* @private
|
|
3937
|
-
*/
|
|
3938
|
-
return _createClass(TreeSet, [{
|
|
3939
|
-
key: "binarySearch",
|
|
3940
|
-
value: function binarySearch(value) {
|
|
3941
|
-
var low = 0;
|
|
3942
|
-
var high = _classPrivateFieldGet(_elements, this).length - 1;
|
|
3943
|
-
while (low <= high) {
|
|
3944
|
-
var mid = Math.floor((low + high) / 2);
|
|
3945
|
-
var midValue = _classPrivateFieldGet(_elements, this)[mid];
|
|
3946
|
-
var cmp = _classPrivateFieldGet(_comparator, this).call(this, midValue, value);
|
|
3947
|
-
if (cmp < 0) {
|
|
3948
|
-
low = mid + 1;
|
|
3949
|
-
} else if (cmp > 0) {
|
|
3950
|
-
high = mid - 1;
|
|
3951
|
-
} else {
|
|
3952
|
-
return {
|
|
3953
|
-
found: true,
|
|
3954
|
-
index: mid,
|
|
3955
|
-
value: midValue
|
|
3956
|
-
};
|
|
3957
|
-
}
|
|
3958
|
-
}
|
|
3959
|
-
return {
|
|
3960
|
-
found: false,
|
|
3961
|
-
index: low,
|
|
3962
|
-
value: undefined
|
|
3963
|
-
};
|
|
3964
|
-
}
|
|
3965
|
-
}, {
|
|
3966
|
-
key: "getElements",
|
|
3967
|
-
value:
|
|
3968
|
-
/**
|
|
3969
|
-
* Returns the elements of the set.
|
|
3970
|
-
*/
|
|
3971
|
-
function getElements() {
|
|
3972
|
-
return _classPrivateFieldGet(_elements, this);
|
|
3973
|
-
}
|
|
3974
|
-
|
|
3975
|
-
/**
|
|
3976
|
-
* Returns the comparator of the set.
|
|
3977
|
-
*
|
|
3978
|
-
* @returns {(valueA:*, valueB:*) => number}
|
|
3979
|
-
*/
|
|
3980
|
-
}, {
|
|
3981
|
-
key: "getComparator",
|
|
3982
|
-
value: function getComparator() {
|
|
3983
|
-
return _classPrivateFieldGet(_comparator, this);
|
|
3984
|
-
}
|
|
3985
|
-
|
|
3986
|
-
/**
|
|
3987
|
-
* Returns the size of the set.
|
|
3988
|
-
*
|
|
3989
|
-
* @returns {number}
|
|
3990
|
-
*/
|
|
3991
|
-
}, {
|
|
3992
|
-
key: "size",
|
|
3993
|
-
value: function size() {
|
|
3994
|
-
return _classPrivateFieldGet(_elements, this).length;
|
|
3995
|
-
}
|
|
3996
|
-
|
|
3997
|
-
/**
|
|
3998
|
-
* Returns true if the set is empty, false otherwise.
|
|
3999
|
-
*
|
|
4000
|
-
* @returns {boolean}
|
|
4001
|
-
*/
|
|
4002
|
-
}, {
|
|
4003
|
-
key: "isEmpty",
|
|
4004
|
-
value: function isEmpty() {
|
|
4005
|
-
return _classPrivateFieldGet(_elements, this).length <= 0;
|
|
4006
|
-
}
|
|
4007
|
-
|
|
4008
|
-
/**
|
|
4009
|
-
* Returns true if the set contains a value that is equal to the given value, returns false otherwise.
|
|
4010
|
-
*
|
|
4011
|
-
* @param {*} value - The value to check for in the set.
|
|
4012
|
-
* @return {boolean} - True if the set contains the value, false otherwise.
|
|
4013
|
-
*/
|
|
4014
|
-
}, {
|
|
4015
|
-
key: "contains",
|
|
4016
|
-
value: function contains(value) {
|
|
4017
|
-
return this.binarySearch(value).found;
|
|
4018
|
-
}
|
|
4019
|
-
|
|
4020
|
-
/**
|
|
4021
|
-
* Returns the first element of the set, or undefined if it is empty.
|
|
4022
|
-
*
|
|
4023
|
-
* @return {*|undefined} - The first element of the set, or undefined if it is empty.
|
|
4024
|
-
*/
|
|
4025
|
-
}, {
|
|
4026
|
-
key: "first",
|
|
4027
|
-
value: function first() {
|
|
4028
|
-
return _classPrivateFieldGet(_elements, this).length > 0 ? _classPrivateFieldGet(_elements, this)[0] : undefined;
|
|
4029
|
-
}
|
|
4030
|
-
|
|
4031
|
-
/**
|
|
4032
|
-
* Returns the last element of the set, or undefined if it is empty.
|
|
4033
|
-
*
|
|
4034
|
-
* @return {*|undefined} - The last element of the set, or undefined if it is empty.
|
|
4035
|
-
*/
|
|
4036
|
-
}, {
|
|
4037
|
-
key: "last",
|
|
4038
|
-
value: function last() {
|
|
4039
|
-
return _classPrivateFieldGet(_elements, this).length > 0 ? _classPrivateFieldGet(_elements, this)[_classPrivateFieldGet(_elements, this).length - 1] : undefined;
|
|
4040
|
-
}
|
|
4041
|
-
|
|
4042
|
-
/**
|
|
4043
|
-
* Removes and returns the first element of the set, or undefined if it is empty.
|
|
4044
|
-
*
|
|
4045
|
-
* @returns {*|undefined} - The first element of the set, or undefined if it is empty.
|
|
4046
|
-
*/
|
|
4047
|
-
}, {
|
|
4048
|
-
key: "pollFirst",
|
|
4049
|
-
value: function pollFirst() {
|
|
4050
|
-
return _classPrivateFieldGet(_elements, this).length > 0 ? _classPrivateFieldGet(_elements, this).splice(0, 1)[0] : undefined;
|
|
4051
|
-
}
|
|
4052
|
-
|
|
4053
|
-
/**
|
|
4054
|
-
* Removes and returns the last element of the set, or undefined if it is empty.
|
|
4055
|
-
*
|
|
4056
|
-
* @returns {*|undefined} - The last element of the set, or undefined if it is empty.
|
|
4057
|
-
*/
|
|
4058
|
-
}, {
|
|
4059
|
-
key: "pollLast",
|
|
4060
|
-
value: function pollLast() {
|
|
4061
|
-
return _classPrivateFieldGet(_elements, this).length > 0 ? _classPrivateFieldGet(_elements, this).splice(_classPrivateFieldGet(_elements, this).length - 1, 1)[0] : undefined;
|
|
4062
|
-
}
|
|
4063
|
-
|
|
4064
|
-
/**
|
|
4065
|
-
* Adds the given value to the set. Will only do so if no equal value already exists.
|
|
4066
|
-
* @param {*} value - The value to add to the set.
|
|
4067
|
-
*/
|
|
4068
|
-
}, {
|
|
4069
|
-
key: "add",
|
|
4070
|
-
value: function add(value) {
|
|
4071
|
-
var result = this.binarySearch(value);
|
|
4072
|
-
if (result.found) {
|
|
4073
|
-
return;
|
|
4074
|
-
}
|
|
4075
|
-
_classPrivateFieldGet(_elements, this).splice(result.index, 0, value);
|
|
4076
|
-
}
|
|
4077
|
-
|
|
4078
|
-
/**
|
|
4079
|
-
* Adds all the given values to the set. Will only do so if no equal value already exists.
|
|
4080
|
-
*
|
|
4081
|
-
* @param {*} values - The values to add to the set.
|
|
4082
|
-
*/
|
|
4083
|
-
}, {
|
|
4084
|
-
key: "addAll",
|
|
4085
|
-
value: function addAll(values) {
|
|
4086
|
-
LeUtils.each(values, this.add.bind(this));
|
|
4087
|
-
}
|
|
4088
|
-
|
|
4089
|
-
/**
|
|
4090
|
-
* Returns an equal value that's already in the tree set, or undefined if no equal values in it exist.
|
|
4091
|
-
*
|
|
4092
|
-
* @param {*} value - The value to search for in the set.
|
|
4093
|
-
* @return {*|undefined} - The equal value if found, or undefined if not found.
|
|
4094
|
-
*/
|
|
4095
|
-
}, {
|
|
4096
|
-
key: "getEqualValue",
|
|
4097
|
-
value: function getEqualValue(value) {
|
|
4098
|
-
var result = this.binarySearch(value);
|
|
4099
|
-
if (result.found) {
|
|
4100
|
-
return result.value;
|
|
4101
|
-
}
|
|
4102
|
-
return undefined;
|
|
4103
|
-
}
|
|
4104
|
-
|
|
4105
|
-
/**
|
|
4106
|
-
* Returns an equal value that's already in the tree set. If no equal values in it exist, the given value will be added and returned.
|
|
4107
|
-
*
|
|
4108
|
-
* @param {*} value - The value to search for in the set.
|
|
4109
|
-
* @return {*} - The equal value if found, or the added value if not found.
|
|
4110
|
-
*/
|
|
4111
|
-
}, {
|
|
4112
|
-
key: "getEqualValueOrAdd",
|
|
4113
|
-
value: function getEqualValueOrAdd(value) {
|
|
4114
|
-
var result = this.binarySearch(value);
|
|
4115
|
-
if (result.found) {
|
|
4116
|
-
return result.value;
|
|
4117
|
-
}
|
|
4118
|
-
_classPrivateFieldGet(_elements, this).splice(result.index, 0, value);
|
|
4119
|
-
return value;
|
|
4120
|
-
}
|
|
4121
|
-
|
|
4122
|
-
/**
|
|
4123
|
-
* Returns a string representation of the TreeSet.
|
|
4124
|
-
*
|
|
4125
|
-
* @returns {string} - A string representation of the TreeSet, including its elements and comparator.
|
|
4126
|
-
*/
|
|
4127
|
-
}, {
|
|
4128
|
-
key: "toString",
|
|
4129
|
-
value: function toString() {
|
|
4130
|
-
return "TreeSet{elements:".concat(_classPrivateFieldGet(_elements, this), ", comparator:").concat(_classPrivateFieldGet(_comparator, this), "}");
|
|
4131
|
-
}
|
|
4132
|
-
|
|
4133
|
-
/**
|
|
4134
|
-
* Returns a JSON representation of the TreeSet.
|
|
4135
|
-
*
|
|
4136
|
-
* @returns {Object} - An object containing the elements and comparator of the TreeSet.
|
|
4137
|
-
*/
|
|
4138
|
-
}, {
|
|
4139
|
-
key: "toJSON",
|
|
4140
|
-
value: function toJSON() {
|
|
4141
|
-
return {
|
|
4142
|
-
elements: _classPrivateFieldGet(_elements, this),
|
|
4143
|
-
comparator: _classPrivateFieldGet(_comparator, this).toString()
|
|
4144
|
-
};
|
|
4145
|
-
}
|
|
4146
|
-
}]);
|
|
4147
|
-
}();
|
|
4148
|
-
|
|
4149
|
-
export { ARRAY, BOOL, BOOL_ANY, EventEmitter, FLOAT, FLOAT_ANY, FLOAT_LAX, FLOAT_LAX_ANY, INT, INT_ANY, INT_LAX, INT_LAX_ANY, ISSET, IS_ARRAY, IS_OBJECT, LeUtils, LinkedList, OBJECT, STRING, STRING_ANY, SerializableMap, TreeSet };
|
|
4150
|
-
//# sourceMappingURL=index.js.map
|