@andrew_l/toolkit 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/index.cjs +3446 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3725 -0
- package/dist/index.d.mts +3725 -0
- package/dist/index.d.ts +3725 -0
- package/dist/index.mjs +3267 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +37 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,3267 @@
|
|
|
1
|
+
import _get from 'lodash/get';
|
|
2
|
+
import _cloneDeep from 'lodash/cloneDeep';
|
|
3
|
+
import _cloneDeepWith from 'lodash/cloneDeepWith';
|
|
4
|
+
import _defaultsDeep from 'lodash/defaultsDeep';
|
|
5
|
+
import _set from 'lodash/set';
|
|
6
|
+
import _unset from 'lodash/unset';
|
|
7
|
+
import { isWeakSet as isWeakSet$1, isWeakMap as isWeakMap$1 } from 'lodash';
|
|
8
|
+
|
|
9
|
+
const isClient = typeof globalThis?.window !== "undefined";
|
|
10
|
+
const isDef = (val) => typeof val !== "undefined";
|
|
11
|
+
const toString = Object.prototype.toString;
|
|
12
|
+
function isNullOrUndefined(value) {
|
|
13
|
+
return value === null || value === void 0;
|
|
14
|
+
}
|
|
15
|
+
const isBigInt = (val) => typeof val === "bigint";
|
|
16
|
+
const isBoolean = (val) => typeof val === "boolean";
|
|
17
|
+
const isFunction = (val) => typeof val === "function";
|
|
18
|
+
const isNumber = (val) => typeof val === "number" && !isNaN(val);
|
|
19
|
+
const isString = (val) => typeof val === "string";
|
|
20
|
+
const isObject = (val) => toString.call(val) === "[object Object]";
|
|
21
|
+
const isDate = (val) => val instanceof Date && !isNaN(val);
|
|
22
|
+
const noop = () => {
|
|
23
|
+
};
|
|
24
|
+
const isError = (val) => val instanceof Error || //@ts-expect-error
|
|
25
|
+
isObject(val) && isString(val.message) && isString(val.stack);
|
|
26
|
+
const isSymbol = (val) => typeof val == "symbol";
|
|
27
|
+
const isSet = (val) => val instanceof Set;
|
|
28
|
+
const isWeakSet = (val) => val instanceof WeakSet;
|
|
29
|
+
const isMap = (val) => val instanceof Map;
|
|
30
|
+
const isWeakMap = (val) => val instanceof WeakMap;
|
|
31
|
+
function isEqual(a, b) {
|
|
32
|
+
if (Object.is(a, b)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if (a instanceof Date && b instanceof Date) {
|
|
36
|
+
return a.getTime() === b.getTime();
|
|
37
|
+
}
|
|
38
|
+
if (a instanceof RegExp && b instanceof RegExp) {
|
|
39
|
+
return a.source === b.source && a.flags === b.flags;
|
|
40
|
+
}
|
|
41
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const aKeys = Object.keys(a);
|
|
45
|
+
const bKeys = Object.keys(b);
|
|
46
|
+
if (aKeys.length !== bKeys.length) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (Array.from(new Set(aKeys.concat(bKeys))).length !== aKeys.length) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
for (let i = 0; i < aKeys.length; i++) {
|
|
53
|
+
const propKey = aKeys[i];
|
|
54
|
+
const aProp = a[propKey];
|
|
55
|
+
const bProp = b[propKey];
|
|
56
|
+
if (!isEqual(aProp, bProp)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
const isEmpty = (obj) => {
|
|
63
|
+
if (obj === null || obj === void 0) return true;
|
|
64
|
+
switch (obj?.constructor) {
|
|
65
|
+
case Object: {
|
|
66
|
+
for (const _ in obj) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
case Array: {
|
|
72
|
+
for (const _ in obj) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
case String: {
|
|
78
|
+
return !obj.length;
|
|
79
|
+
}
|
|
80
|
+
case Map: {
|
|
81
|
+
return !obj.size;
|
|
82
|
+
}
|
|
83
|
+
case Set: {
|
|
84
|
+
return !obj.size;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
};
|
|
89
|
+
function isPromise(value) {
|
|
90
|
+
return value && typeof value === "object" && "then" in value && "catch" in value && typeof value.then === "function" && typeof value.catch === "function";
|
|
91
|
+
}
|
|
92
|
+
const primitiveTypeofSet = Object.freeze(
|
|
93
|
+
/* @__PURE__ */ new Set(["string", "number", "boolean", "bigint", "symbol", "undefined"])
|
|
94
|
+
);
|
|
95
|
+
const isPrimitive = (value) => {
|
|
96
|
+
return value === null || primitiveTypeofSet.has(typeof value);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
function arrayable(value) {
|
|
100
|
+
const result = Array.isArray(value) ? value : value === null ? [] : value === void 0 ? [] : isString(value) ? value.split(",").map((v) => v.trim()).filter(Boolean) : [value];
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const avg = (values) => {
|
|
105
|
+
let sum = 0;
|
|
106
|
+
let amount = 0;
|
|
107
|
+
for (const item of values) {
|
|
108
|
+
if (!isNumber(item)) continue;
|
|
109
|
+
sum += item;
|
|
110
|
+
amount++;
|
|
111
|
+
}
|
|
112
|
+
if (amount === 0) return 0;
|
|
113
|
+
return sum / amount;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
function chunk(list, size = 1) {
|
|
117
|
+
return list.reduce((res, item, index) => {
|
|
118
|
+
if (index % size === 0) {
|
|
119
|
+
res.push([]);
|
|
120
|
+
}
|
|
121
|
+
res[res.length - 1].push(item);
|
|
122
|
+
return res;
|
|
123
|
+
}, []);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function chunkSeries(list, step = 1) {
|
|
127
|
+
const result = [];
|
|
128
|
+
if (!list.length) {
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
const sortedList = [...list].sort();
|
|
132
|
+
let currentRange = [list[0]];
|
|
133
|
+
let currentValue;
|
|
134
|
+
for (let idx = 1; idx < sortedList.length; idx++) {
|
|
135
|
+
currentValue = sortedList[idx];
|
|
136
|
+
if (currentValue - currentRange.at(-1) > step) {
|
|
137
|
+
result.push(currentRange);
|
|
138
|
+
currentRange = [currentValue];
|
|
139
|
+
} else {
|
|
140
|
+
currentRange[1] = currentValue;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
result.push(currentRange);
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function keyBy(array, keyBy2, objectMode) {
|
|
148
|
+
const getItemKey = isFunction(keyBy2) ? keyBy2 : (item) => item?.[keyBy2];
|
|
149
|
+
if (objectMode === true) {
|
|
150
|
+
const result2 = {};
|
|
151
|
+
for (const item of array) {
|
|
152
|
+
result2[getItemKey(item)] = item;
|
|
153
|
+
}
|
|
154
|
+
return result2;
|
|
155
|
+
}
|
|
156
|
+
const result = /* @__PURE__ */ new Map();
|
|
157
|
+
for (const item of array) {
|
|
158
|
+
result.set(getItemKey(item), item);
|
|
159
|
+
}
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function compareAscending(value, other) {
|
|
164
|
+
if (value !== other) {
|
|
165
|
+
const valIsDefined = value !== void 0, valIsNull = value === null, valIsReflexive = value === value, valIsSymbol = isSymbol(value);
|
|
166
|
+
const othIsDefined = other !== void 0, othIsNull = other === null, othIsReflexive = other === other, othIsSymbol = isSymbol(other);
|
|
167
|
+
if (!othIsNull && !othIsSymbol && !valIsSymbol && value > other || valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol || valIsNull && othIsDefined && othIsReflexive || !valIsDefined && othIsReflexive || !valIsReflexive) {
|
|
168
|
+
return 1;
|
|
169
|
+
}
|
|
170
|
+
if (!valIsNull && !valIsSymbol && !othIsSymbol && value < other || othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol || othIsNull && valIsDefined && valIsReflexive || !othIsDefined && valIsReflexive || !othIsReflexive) {
|
|
171
|
+
return -1;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return 0;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function orderBy(array, fields, orders) {
|
|
178
|
+
return [...array].sort((a, b) => {
|
|
179
|
+
let index = -1, length = fields.length, ordersLength = orders.length;
|
|
180
|
+
while (++index < length) {
|
|
181
|
+
const field = fields[index];
|
|
182
|
+
const filedFn = isFunction(field);
|
|
183
|
+
const objCriteria = filedFn ? field(a) : a?.[field];
|
|
184
|
+
const othCriteria = filedFn ? field(b) : b?.[field];
|
|
185
|
+
const result = compareAscending(objCriteria, othCriteria);
|
|
186
|
+
if (result) {
|
|
187
|
+
if (index >= ordersLength) {
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
return result * (orders[index] === "desc" ? -1 : 1);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return 0;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const sum = (values) => {
|
|
198
|
+
return values.reduce((a, b) => a + (isNumber(b) ? b : 0), 0);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
function uniq(value) {
|
|
202
|
+
if (!Array.isArray(value)) {
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
return [...new Set(value)];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function union(arr1, arr2) {
|
|
209
|
+
return uniq(arr1.concat(arr2));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const get = _get;
|
|
213
|
+
|
|
214
|
+
function uniqBy(array, comparator) {
|
|
215
|
+
const seen = /* @__PURE__ */ new Set();
|
|
216
|
+
if (!isFunction(comparator)) {
|
|
217
|
+
const key = comparator;
|
|
218
|
+
comparator = (value) => get(value, key);
|
|
219
|
+
}
|
|
220
|
+
return array.filter((value) => {
|
|
221
|
+
const computed = comparator(value);
|
|
222
|
+
const hasSeen = seen.has(computed);
|
|
223
|
+
if (!hasSeen) {
|
|
224
|
+
seen.add(computed);
|
|
225
|
+
}
|
|
226
|
+
return !hasSeen;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
let AssertionError;
|
|
231
|
+
(async () => {
|
|
232
|
+
AssertionError = globalThis.window ? await Promise.resolve().then(function () { return BrowserAssertionError$1; }).then(
|
|
233
|
+
(r) => r.BrowserAssertionError
|
|
234
|
+
) : await import('node:assert').then((r) => r.AssertionError);
|
|
235
|
+
})();
|
|
236
|
+
function ok(value, message) {
|
|
237
|
+
if (!value) {
|
|
238
|
+
throw toError$1(
|
|
239
|
+
ok,
|
|
240
|
+
value,
|
|
241
|
+
message,
|
|
242
|
+
"The expression evaluated to a falsy value."
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function equal(actual, expected, message) {
|
|
247
|
+
if (actual !== expected) {
|
|
248
|
+
new AssertionError({
|
|
249
|
+
actual,
|
|
250
|
+
expected,
|
|
251
|
+
message: isString(message) ? message : "The actual value not as expected.",
|
|
252
|
+
operator: "equal",
|
|
253
|
+
stackStartFn: equal
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function object(value, message) {
|
|
258
|
+
if (!isObject(value)) {
|
|
259
|
+
throw toError$1(object, value, message, "Expected object value.");
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function string(value, message) {
|
|
263
|
+
if (!isString(value)) {
|
|
264
|
+
throw toError$1(string, value, message, "Expected string value.");
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function boolean(value, message) {
|
|
268
|
+
if (!isBoolean(value)) {
|
|
269
|
+
throw toError$1(boolean, value, message, "Expected boolean value.");
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function notEmptyString(value, message) {
|
|
273
|
+
if (!isString(value) || !value.trim()) {
|
|
274
|
+
throw toError$1(
|
|
275
|
+
notEmptyString,
|
|
276
|
+
value,
|
|
277
|
+
message,
|
|
278
|
+
"Expected not empty string value."
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function number$1(value, message) {
|
|
283
|
+
if (!isNumber(value)) {
|
|
284
|
+
throw toError$1(number$1, value, message, "Expected number value.");
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function array(value, message) {
|
|
288
|
+
if (!Array.isArray(value)) {
|
|
289
|
+
throw toError$1(array, value, message, "Expected array value.");
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function arrayStrings(value, message) {
|
|
293
|
+
if (!Array.isArray(value) || !value.every(isString)) {
|
|
294
|
+
throw toError$1(arrayStrings, value, message, "Expected strings list value.");
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function arrayNumbers(value, message) {
|
|
298
|
+
if (!Array.isArray(value) || !value.every(isNumber)) {
|
|
299
|
+
throw toError$1(arrayNumbers, value, message, "Expected numbers list value.");
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function toError$1(operator, actual, message, unknownMessage = "Unknown error") {
|
|
303
|
+
if (isError(message)) {
|
|
304
|
+
return message;
|
|
305
|
+
}
|
|
306
|
+
return new AssertionError({
|
|
307
|
+
actual,
|
|
308
|
+
message: isString(message) ? message : unknownMessage,
|
|
309
|
+
operator: operator.name,
|
|
310
|
+
stackStartFn: operator
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const assert = {
|
|
315
|
+
__proto__: null,
|
|
316
|
+
array: array,
|
|
317
|
+
arrayNumbers: arrayNumbers,
|
|
318
|
+
arrayStrings: arrayStrings,
|
|
319
|
+
boolean: boolean,
|
|
320
|
+
equal: equal,
|
|
321
|
+
notEmptyString: notEmptyString,
|
|
322
|
+
number: number$1,
|
|
323
|
+
object: object,
|
|
324
|
+
ok: ok,
|
|
325
|
+
string: string
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const def = (obj, key, value, writable = false) => {
|
|
329
|
+
Object.defineProperty(obj, key, {
|
|
330
|
+
configurable: true,
|
|
331
|
+
enumerable: false,
|
|
332
|
+
writable,
|
|
333
|
+
value
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const rndCharacters = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
338
|
+
const charactersLength = rndCharacters.length;
|
|
339
|
+
function randomString(length) {
|
|
340
|
+
let result = "";
|
|
341
|
+
for (let i = 0; i < length; i++) {
|
|
342
|
+
result += rndCharacters.charAt(
|
|
343
|
+
Math.floor(Math.random() * charactersLength)
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
return result;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const objectKeys = /* @__PURE__ */ new WeakMap();
|
|
350
|
+
const BSON_TYPES = Object.freeze(/* @__PURE__ */ new Set(["ObjectID", "ObjectId"]));
|
|
351
|
+
const SYM_WITH_CACHE = Symbol();
|
|
352
|
+
const argToKey = (value, options = { objectStrategy: "ref" }) => {
|
|
353
|
+
let result = "";
|
|
354
|
+
if (isObject(value)) {
|
|
355
|
+
if (BSON_TYPES.has(value?._bsontype)) {
|
|
356
|
+
return String(value);
|
|
357
|
+
}
|
|
358
|
+
let key;
|
|
359
|
+
if (options.objectStrategy === "json") {
|
|
360
|
+
key = JSON.stringify(value);
|
|
361
|
+
} else {
|
|
362
|
+
key = objectKeys.get(value);
|
|
363
|
+
if (!key) {
|
|
364
|
+
key = createRadomKey();
|
|
365
|
+
objectKeys.set(value, key);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return key;
|
|
369
|
+
} else if (Array.isArray(value)) {
|
|
370
|
+
result += value.map((v) => argToKey(v, options)).join("/");
|
|
371
|
+
} else {
|
|
372
|
+
result = String(value);
|
|
373
|
+
}
|
|
374
|
+
return result;
|
|
375
|
+
};
|
|
376
|
+
function createRadomKey() {
|
|
377
|
+
return Date.now() + "_" + randomString(16);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function createWithCache({
|
|
381
|
+
fn,
|
|
382
|
+
getPointer,
|
|
383
|
+
getBucket,
|
|
384
|
+
objectStrategy = "ref"
|
|
385
|
+
}) {
|
|
386
|
+
const isAsync = fn.constructor.name === "AsyncFunction";
|
|
387
|
+
const argToKeyOptions = { objectStrategy };
|
|
388
|
+
const $cache = {
|
|
389
|
+
getBucket: () => getBucket(getPointer()),
|
|
390
|
+
getPointer,
|
|
391
|
+
argToKeyOptions
|
|
392
|
+
};
|
|
393
|
+
const wrapFn = (...args) => {
|
|
394
|
+
const storage = getBucket(getPointer());
|
|
395
|
+
const cacheKey = args.map((v) => argToKey(v, argToKeyOptions)).join("_");
|
|
396
|
+
if (storage.has(cacheKey)) {
|
|
397
|
+
const value = storage.get(cacheKey);
|
|
398
|
+
return isAsync ? Promise.resolve(value) : value;
|
|
399
|
+
}
|
|
400
|
+
const newValue = fn(...args);
|
|
401
|
+
if (isPromise(newValue)) {
|
|
402
|
+
return newValue.then((value) => {
|
|
403
|
+
storage.set(cacheKey, value);
|
|
404
|
+
return value;
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
storage.set(cacheKey, newValue);
|
|
408
|
+
return newValue;
|
|
409
|
+
};
|
|
410
|
+
wrapFn.$cache = $cache;
|
|
411
|
+
def(wrapFn, SYM_WITH_CACHE, true);
|
|
412
|
+
return wrapFn;
|
|
413
|
+
}
|
|
414
|
+
function isWithCache(value) {
|
|
415
|
+
return !!value && value[SYM_WITH_CACHE] === true;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
419
|
+
function withCache(...args) {
|
|
420
|
+
let options = {};
|
|
421
|
+
let fn = noop;
|
|
422
|
+
if (isFunction(args[0])) {
|
|
423
|
+
fn = args[0];
|
|
424
|
+
} else if (isFunction(args[1])) {
|
|
425
|
+
options = args[0] || {};
|
|
426
|
+
fn = args[1];
|
|
427
|
+
}
|
|
428
|
+
const pointer = options.cachePointer || fn;
|
|
429
|
+
const getPointer = () => pointer;
|
|
430
|
+
const getBucket = (pointer2) => {
|
|
431
|
+
let fnCache = cache.get(pointer2);
|
|
432
|
+
if (!fnCache) {
|
|
433
|
+
fnCache = /* @__PURE__ */ new Map();
|
|
434
|
+
cache.set(pointer2, fnCache);
|
|
435
|
+
}
|
|
436
|
+
return fnCache;
|
|
437
|
+
};
|
|
438
|
+
return createWithCache({
|
|
439
|
+
fn,
|
|
440
|
+
getBucket,
|
|
441
|
+
getPointer,
|
|
442
|
+
...options
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function assertCapacity(value) {
|
|
447
|
+
number$1(value, "capacity must be a number");
|
|
448
|
+
ok(value > 0, "capacity must be more then 0.");
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
class FixedMap extends Map {
|
|
452
|
+
constructor(_capacity) {
|
|
453
|
+
assertCapacity(_capacity);
|
|
454
|
+
super();
|
|
455
|
+
this._capacity = _capacity;
|
|
456
|
+
this._tail = [];
|
|
457
|
+
}
|
|
458
|
+
_tail;
|
|
459
|
+
set(key, value) {
|
|
460
|
+
if (!super.has.call(this, key)) {
|
|
461
|
+
this._tail.push(key);
|
|
462
|
+
}
|
|
463
|
+
super.set.call(this, key, value);
|
|
464
|
+
this._drain();
|
|
465
|
+
return this;
|
|
466
|
+
}
|
|
467
|
+
delete(key) {
|
|
468
|
+
const removed = super.delete.call(this, key);
|
|
469
|
+
if (removed) {
|
|
470
|
+
const idx = this._tail.findIndex((v) => v === key);
|
|
471
|
+
if (idx > -1) {
|
|
472
|
+
this._tail.splice(idx, 1);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return removed;
|
|
476
|
+
}
|
|
477
|
+
clear() {
|
|
478
|
+
delete this._tail;
|
|
479
|
+
this._tail = [];
|
|
480
|
+
super.clear.call(this);
|
|
481
|
+
}
|
|
482
|
+
get capacity() {
|
|
483
|
+
return this._capacity;
|
|
484
|
+
}
|
|
485
|
+
set capacity(value) {
|
|
486
|
+
assertCapacity(value);
|
|
487
|
+
this._capacity = value;
|
|
488
|
+
this._drain();
|
|
489
|
+
}
|
|
490
|
+
_drain() {
|
|
491
|
+
while (this._tail.length > this._capacity) {
|
|
492
|
+
const key = this._tail.shift();
|
|
493
|
+
key !== void 0 && this.delete(key);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
class TimeBucket {
|
|
499
|
+
_pointer;
|
|
500
|
+
_sizeMs;
|
|
501
|
+
_bucket;
|
|
502
|
+
constructor({ capacity = Infinity, sizeMs }) {
|
|
503
|
+
assetSizeMs(sizeMs);
|
|
504
|
+
this._sizeMs = sizeMs;
|
|
505
|
+
this._pointer = 0;
|
|
506
|
+
this._bucket = capacity === Infinity ? /* @__PURE__ */ new Map() : new FixedMap(capacity);
|
|
507
|
+
}
|
|
508
|
+
get capacity() {
|
|
509
|
+
if (this._bucket instanceof FixedMap) {
|
|
510
|
+
return this._bucket.capacity;
|
|
511
|
+
}
|
|
512
|
+
return Infinity;
|
|
513
|
+
}
|
|
514
|
+
get sizeMs() {
|
|
515
|
+
return this.sizeMs;
|
|
516
|
+
}
|
|
517
|
+
set sizeMs(value) {
|
|
518
|
+
assetSizeMs(value);
|
|
519
|
+
this._sizeMs = value;
|
|
520
|
+
this._drainBucket();
|
|
521
|
+
}
|
|
522
|
+
get size() {
|
|
523
|
+
this._drainBucket();
|
|
524
|
+
return this._bucket.size;
|
|
525
|
+
}
|
|
526
|
+
set(key, value) {
|
|
527
|
+
this._drainBucket();
|
|
528
|
+
this._bucket.set(key, value);
|
|
529
|
+
return this;
|
|
530
|
+
}
|
|
531
|
+
get(key) {
|
|
532
|
+
this._drainBucket();
|
|
533
|
+
return this._bucket.get(key);
|
|
534
|
+
}
|
|
535
|
+
has(key) {
|
|
536
|
+
this._drainBucket();
|
|
537
|
+
return this._bucket.has(key);
|
|
538
|
+
}
|
|
539
|
+
delete(key) {
|
|
540
|
+
this._drainBucket();
|
|
541
|
+
return this._bucket.delete(key);
|
|
542
|
+
}
|
|
543
|
+
clear() {
|
|
544
|
+
this._pointer = 0;
|
|
545
|
+
this._drainBucket();
|
|
546
|
+
}
|
|
547
|
+
keys() {
|
|
548
|
+
this._drainBucket();
|
|
549
|
+
return this._bucket.keys();
|
|
550
|
+
}
|
|
551
|
+
values() {
|
|
552
|
+
this._drainBucket();
|
|
553
|
+
return this._bucket.values();
|
|
554
|
+
}
|
|
555
|
+
entries() {
|
|
556
|
+
this._drainBucket();
|
|
557
|
+
return this._bucket.entries();
|
|
558
|
+
}
|
|
559
|
+
forEach(callbackfn, thisArg) {
|
|
560
|
+
this._drainBucket();
|
|
561
|
+
return this._bucket.forEach((value, key) => {
|
|
562
|
+
callbackfn(value, key, this);
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
_drainBucket() {
|
|
566
|
+
const newPointer = bucketPointer(this._sizeMs);
|
|
567
|
+
if (newPointer !== this._pointer) {
|
|
568
|
+
const capacity = this._bucket instanceof FixedMap ? this._bucket.capacity : Infinity;
|
|
569
|
+
delete this._bucket;
|
|
570
|
+
this._pointer = newPointer;
|
|
571
|
+
this._bucket = capacity === Infinity ? /* @__PURE__ */ new Map() : new FixedMap(capacity);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
function assetSizeMs(value) {
|
|
576
|
+
if (typeof value !== "number" || isNaN(value)) {
|
|
577
|
+
throw new TypeError("msSize must be a number");
|
|
578
|
+
}
|
|
579
|
+
if (value <= 0) {
|
|
580
|
+
throw new TypeError("msSize must be more then 0.");
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
function bucketPointer(size) {
|
|
584
|
+
return Math.floor(Date.now() / size) * size;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const cacheBucket = /* @__PURE__ */ new WeakMap();
|
|
588
|
+
function withCacheBucket({ capacity, sizeMs, cachePointer, ...options }, fn) {
|
|
589
|
+
const pointer = cachePointer || fn;
|
|
590
|
+
const getPointer = () => {
|
|
591
|
+
return pointer;
|
|
592
|
+
};
|
|
593
|
+
const getBucket = () => {
|
|
594
|
+
let fnCache = cacheBucket.get(pointer);
|
|
595
|
+
if (!fnCache) {
|
|
596
|
+
fnCache = new TimeBucket({ sizeMs, capacity });
|
|
597
|
+
cacheBucket.set(pointer, fnCache);
|
|
598
|
+
}
|
|
599
|
+
return fnCache;
|
|
600
|
+
};
|
|
601
|
+
return createWithCache({
|
|
602
|
+
fn,
|
|
603
|
+
getBucket,
|
|
604
|
+
getPointer,
|
|
605
|
+
...options
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
const cacheFixed = /* @__PURE__ */ new WeakMap();
|
|
610
|
+
function withCacheFixed({ capacity, cachePointer, ...options }, fn) {
|
|
611
|
+
const pointer = cachePointer || fn;
|
|
612
|
+
const getPointer = () => fn;
|
|
613
|
+
const getBucket = () => {
|
|
614
|
+
let fnCache = cacheFixed.get(pointer);
|
|
615
|
+
if (!fnCache) {
|
|
616
|
+
fnCache = new FixedMap(capacity);
|
|
617
|
+
cacheFixed.set(pointer, fnCache);
|
|
618
|
+
}
|
|
619
|
+
return fnCache;
|
|
620
|
+
};
|
|
621
|
+
return createWithCache({
|
|
622
|
+
fn,
|
|
623
|
+
getBucket,
|
|
624
|
+
getPointer,
|
|
625
|
+
...options
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
class LruCache {
|
|
630
|
+
constructor(capacity) {
|
|
631
|
+
this.capacity = capacity;
|
|
632
|
+
this.capacity = Math.max(isNumber(capacity) ? capacity : 0, 0);
|
|
633
|
+
this.forward = pointerArray(this.capacity);
|
|
634
|
+
this.backward = pointerArray(this.capacity);
|
|
635
|
+
this.K = new Array(capacity);
|
|
636
|
+
this.V = new Array(capacity);
|
|
637
|
+
this.items = /* @__PURE__ */ new Map();
|
|
638
|
+
this.size = 0;
|
|
639
|
+
this.head = 0;
|
|
640
|
+
this.tail = 0;
|
|
641
|
+
}
|
|
642
|
+
items;
|
|
643
|
+
forward;
|
|
644
|
+
backward;
|
|
645
|
+
K;
|
|
646
|
+
V;
|
|
647
|
+
size;
|
|
648
|
+
head;
|
|
649
|
+
tail;
|
|
650
|
+
/**
|
|
651
|
+
* Method used to clear the structure.
|
|
652
|
+
*/
|
|
653
|
+
clear() {
|
|
654
|
+
this.size = 0;
|
|
655
|
+
this.head = 0;
|
|
656
|
+
this.tail = 0;
|
|
657
|
+
this.items.clear();
|
|
658
|
+
}
|
|
659
|
+
set(key, value) {
|
|
660
|
+
let pointer = this.items.get(key);
|
|
661
|
+
if (pointer !== void 0) {
|
|
662
|
+
this.splayOnTop(pointer);
|
|
663
|
+
this.V[pointer] = value;
|
|
664
|
+
return this;
|
|
665
|
+
}
|
|
666
|
+
if (this.size < this.capacity) {
|
|
667
|
+
pointer = this.size++;
|
|
668
|
+
} else {
|
|
669
|
+
pointer = this.tail;
|
|
670
|
+
this.tail = this.backward[pointer];
|
|
671
|
+
this.items.delete(this.K[pointer]);
|
|
672
|
+
}
|
|
673
|
+
this.items.set(key, pointer);
|
|
674
|
+
this.K[pointer] = key;
|
|
675
|
+
this.V[pointer] = value;
|
|
676
|
+
this.forward[pointer] = this.head;
|
|
677
|
+
this.backward[this.head] = pointer;
|
|
678
|
+
this.head = pointer;
|
|
679
|
+
return this;
|
|
680
|
+
}
|
|
681
|
+
has(key) {
|
|
682
|
+
return this.peek(key) !== void 0;
|
|
683
|
+
}
|
|
684
|
+
delete(key) {
|
|
685
|
+
const pointer = this.items.get(key);
|
|
686
|
+
if (pointer === void 0) return;
|
|
687
|
+
this.V[pointer] = void 0;
|
|
688
|
+
}
|
|
689
|
+
get(key) {
|
|
690
|
+
const pointer = this.items.get(key);
|
|
691
|
+
if (pointer === void 0) return;
|
|
692
|
+
this.splayOnTop(pointer);
|
|
693
|
+
return this.V[pointer];
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Method used to get the value attached to the given key. Does not modify
|
|
697
|
+
* the ordering of the underlying linked list.
|
|
698
|
+
*/
|
|
699
|
+
peek(key) {
|
|
700
|
+
const pointer = this.items.get(key);
|
|
701
|
+
if (pointer === void 0) return;
|
|
702
|
+
return this.V[pointer];
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Method used to create an iterator over the cache's keys from most
|
|
706
|
+
* recently used to least recently used.
|
|
707
|
+
*/
|
|
708
|
+
keys() {
|
|
709
|
+
let i = 0, l = this.size;
|
|
710
|
+
let pointer = this.head, keys = this.K, forward = this.forward;
|
|
711
|
+
const iterator = {
|
|
712
|
+
next: () => {
|
|
713
|
+
if (i >= l) return { done: true, value: void 0 };
|
|
714
|
+
const key = keys[pointer];
|
|
715
|
+
i++;
|
|
716
|
+
if (i < l) pointer = forward[pointer];
|
|
717
|
+
if (this.peek(key) === void 0) return iterator.next();
|
|
718
|
+
return {
|
|
719
|
+
done: false,
|
|
720
|
+
value: key
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
return {
|
|
725
|
+
...iterator,
|
|
726
|
+
[Symbol.iterator]() {
|
|
727
|
+
return this;
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Method used to create an iterator over the cache's values from most
|
|
733
|
+
* recently used to least recently used.
|
|
734
|
+
*
|
|
735
|
+
*/
|
|
736
|
+
values() {
|
|
737
|
+
let i = 0, l = this.size;
|
|
738
|
+
let pointer = this.head, values = this.V, forward = this.forward;
|
|
739
|
+
const iterator = {
|
|
740
|
+
next: () => {
|
|
741
|
+
if (i >= l) return { done: true, value: void 0 };
|
|
742
|
+
const value = values[pointer];
|
|
743
|
+
i++;
|
|
744
|
+
if (i < l) pointer = forward[pointer];
|
|
745
|
+
if (value === void 0) return iterator.next();
|
|
746
|
+
return {
|
|
747
|
+
done: false,
|
|
748
|
+
value
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
return {
|
|
753
|
+
...iterator,
|
|
754
|
+
[Symbol.iterator]() {
|
|
755
|
+
return this;
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Method used to create an iterator over the cache's entries from most
|
|
761
|
+
* recently used to least recently used.
|
|
762
|
+
*
|
|
763
|
+
* @return {IterableIterator<[TKey, TValue | undefined]>}
|
|
764
|
+
*/
|
|
765
|
+
entries() {
|
|
766
|
+
let i = 0, l = this.size;
|
|
767
|
+
let pointer = this.head, keys = this.K, values = this.V, forward = this.forward;
|
|
768
|
+
const iterator = {
|
|
769
|
+
next() {
|
|
770
|
+
if (i >= l) return { done: true, value: void 0 };
|
|
771
|
+
const key = keys[pointer], value = values[pointer];
|
|
772
|
+
i++;
|
|
773
|
+
if (i < l) pointer = forward[pointer];
|
|
774
|
+
return {
|
|
775
|
+
done: false,
|
|
776
|
+
value: [key, value]
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
return {
|
|
781
|
+
...iterator,
|
|
782
|
+
[Symbol.iterator]() {
|
|
783
|
+
return this;
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Method used to splay a value on top.
|
|
789
|
+
*
|
|
790
|
+
* @param {number} pointer - Pointer of the value to splay on top.
|
|
791
|
+
*/
|
|
792
|
+
splayOnTop(pointer) {
|
|
793
|
+
const oldHead = this.head;
|
|
794
|
+
if (this.head === pointer) return this;
|
|
795
|
+
const previous = this.backward[pointer], next = this.forward[pointer];
|
|
796
|
+
if (this.tail === pointer) {
|
|
797
|
+
this.tail = previous;
|
|
798
|
+
} else {
|
|
799
|
+
this.backward[next] = previous;
|
|
800
|
+
}
|
|
801
|
+
this.forward[previous] = next;
|
|
802
|
+
this.backward[oldHead] = pointer;
|
|
803
|
+
this.head = pointer;
|
|
804
|
+
this.forward[pointer] = oldHead;
|
|
805
|
+
return this;
|
|
806
|
+
}
|
|
807
|
+
[Symbol.iterator]() {
|
|
808
|
+
return this.entries();
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
const MAX_8BIT_INTEGER = Math.pow(2, 8) - 1, MAX_16BIT_INTEGER = Math.pow(2, 16) - 1, MAX_32BIT_INTEGER = Math.pow(2, 32) - 1;
|
|
812
|
+
function pointerArray(size) {
|
|
813
|
+
const maxIndex = size - 1;
|
|
814
|
+
if (maxIndex <= MAX_8BIT_INTEGER) return new Uint8Array(size);
|
|
815
|
+
if (maxIndex <= MAX_16BIT_INTEGER) return new Uint16Array(size);
|
|
816
|
+
if (maxIndex <= MAX_32BIT_INTEGER) return new Uint32Array(size);
|
|
817
|
+
throw new Error("Pointer Array of size > 4294967295 is not supported.");
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
const cacheLRU = /* @__PURE__ */ new WeakMap();
|
|
821
|
+
function withCacheLRU({ capacity, cachePointer, ...options }, fn) {
|
|
822
|
+
const pointer = cachePointer || fn;
|
|
823
|
+
const getPointer = () => {
|
|
824
|
+
return pointer;
|
|
825
|
+
};
|
|
826
|
+
const getBucket = () => {
|
|
827
|
+
let fnCache = cacheLRU.get(pointer);
|
|
828
|
+
if (!fnCache) {
|
|
829
|
+
fnCache = new LruCache(capacity);
|
|
830
|
+
cacheLRU.set(pointer, fnCache);
|
|
831
|
+
}
|
|
832
|
+
return fnCache;
|
|
833
|
+
};
|
|
834
|
+
return createWithCache({
|
|
835
|
+
fn,
|
|
836
|
+
getBucket,
|
|
837
|
+
getPointer,
|
|
838
|
+
...options
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
function dropCache(cachePointer, ...args) {
|
|
843
|
+
let argToKeyOptions = { objectStrategy: "ref" };
|
|
844
|
+
let removed = false;
|
|
845
|
+
if (isWithCache(cachePointer)) {
|
|
846
|
+
argToKeyOptions = cachePointer.$cache.argToKeyOptions;
|
|
847
|
+
}
|
|
848
|
+
const cacheKey = args.map((v) => argToKey(v, argToKeyOptions)).join("_");
|
|
849
|
+
if (isWithCache(cachePointer)) {
|
|
850
|
+
if (cachePointer.$cache.getBucket().has(cacheKey)) {
|
|
851
|
+
removed = true;
|
|
852
|
+
cachePointer.$cache.getBucket().delete(cacheKey);
|
|
853
|
+
}
|
|
854
|
+
cachePointer = cachePointer.$cache.getPointer();
|
|
855
|
+
}
|
|
856
|
+
[cache, cacheFixed, cacheBucket, cacheLRU].forEach((map) => {
|
|
857
|
+
if (map.get(cachePointer)?.has(cacheKey)) {
|
|
858
|
+
removed = true;
|
|
859
|
+
map.get(cachePointer)?.delete(cacheKey);
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
return removed;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
class FixedWeakMap extends WeakMap {
|
|
866
|
+
constructor(_capacity) {
|
|
867
|
+
assertCapacity(_capacity);
|
|
868
|
+
super();
|
|
869
|
+
this._capacity = _capacity;
|
|
870
|
+
this._tail = [];
|
|
871
|
+
}
|
|
872
|
+
_tail;
|
|
873
|
+
set(key, value) {
|
|
874
|
+
if (!super.has(key)) {
|
|
875
|
+
this._tail.push(key);
|
|
876
|
+
}
|
|
877
|
+
super.set(key, value);
|
|
878
|
+
this._drain();
|
|
879
|
+
return this;
|
|
880
|
+
}
|
|
881
|
+
delete(key) {
|
|
882
|
+
const removed = super.delete(key);
|
|
883
|
+
if (removed) {
|
|
884
|
+
const idx = this._tail.findIndex((v) => v === key);
|
|
885
|
+
if (idx > -1) {
|
|
886
|
+
this._tail.splice(idx, 1);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
return removed;
|
|
890
|
+
}
|
|
891
|
+
clear() {
|
|
892
|
+
for (const item of this._tail) {
|
|
893
|
+
super.delete(item);
|
|
894
|
+
}
|
|
895
|
+
delete this._tail;
|
|
896
|
+
this._tail = [];
|
|
897
|
+
}
|
|
898
|
+
get size() {
|
|
899
|
+
return this._tail.length;
|
|
900
|
+
}
|
|
901
|
+
get capacity() {
|
|
902
|
+
return this._capacity;
|
|
903
|
+
}
|
|
904
|
+
set capacity(value) {
|
|
905
|
+
assertCapacity(value);
|
|
906
|
+
this._capacity = value;
|
|
907
|
+
this._drain();
|
|
908
|
+
}
|
|
909
|
+
_drain() {
|
|
910
|
+
while (this._tail.length > this._capacity) {
|
|
911
|
+
const key = this._tail.shift();
|
|
912
|
+
key !== void 0 && this.delete(key);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
function isCached(fn, ...args) {
|
|
918
|
+
let argToKeyOptions = { objectStrategy: "ref" };
|
|
919
|
+
let cachePointer = fn;
|
|
920
|
+
let cached = false;
|
|
921
|
+
if (isWithCache(fn)) {
|
|
922
|
+
argToKeyOptions = fn.$cache.argToKeyOptions;
|
|
923
|
+
}
|
|
924
|
+
const cacheKey = args.map((v) => argToKey(v, argToKeyOptions)).join("_");
|
|
925
|
+
if (isWithCache(fn)) {
|
|
926
|
+
cached = fn.$cache.getBucket().has(cacheKey);
|
|
927
|
+
cachePointer = fn.$cache.getPointer();
|
|
928
|
+
if (cached) return true;
|
|
929
|
+
}
|
|
930
|
+
return !![cache, cacheFixed, cacheBucket, cacheLRU].some(
|
|
931
|
+
(storage) => storage.get(cachePointer)?.has(cacheKey)
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
const EMPTY_SYM = Symbol("empty");
|
|
936
|
+
function withCacheBucketBatch({
|
|
937
|
+
capacity,
|
|
938
|
+
sizeMs,
|
|
939
|
+
key,
|
|
940
|
+
batchSize = 10,
|
|
941
|
+
cachePointer,
|
|
942
|
+
retryEmpty = true
|
|
943
|
+
}, resolver) {
|
|
944
|
+
const pointer = cachePointer || resolver;
|
|
945
|
+
const argToKeyOptions = {
|
|
946
|
+
objectStrategy: "json"
|
|
947
|
+
};
|
|
948
|
+
const getPointer = () => {
|
|
949
|
+
return pointer;
|
|
950
|
+
};
|
|
951
|
+
const getBucket = () => {
|
|
952
|
+
let fnCache = cacheBucket.get(pointer);
|
|
953
|
+
if (!fnCache) {
|
|
954
|
+
fnCache = new TimeBucket({ sizeMs, capacity });
|
|
955
|
+
cacheBucket.set(pointer, fnCache);
|
|
956
|
+
}
|
|
957
|
+
return fnCache;
|
|
958
|
+
};
|
|
959
|
+
const wrapFn = async (values) => {
|
|
960
|
+
const result = /* @__PURE__ */ new Map();
|
|
961
|
+
let fnCache = getBucket();
|
|
962
|
+
const batchSet = /* @__PURE__ */ new Set();
|
|
963
|
+
const drainMaybe = async () => {
|
|
964
|
+
if (!batchSet.size) return;
|
|
965
|
+
const items = await resolver(Array.from(batchSet));
|
|
966
|
+
for (let idx = 0; idx < items.length; idx++) {
|
|
967
|
+
const item = items[idx];
|
|
968
|
+
if (!isObject(item)) continue;
|
|
969
|
+
const id = argToKey(item[key], argToKeyOptions);
|
|
970
|
+
batchSet.delete(id);
|
|
971
|
+
result.set(id, item);
|
|
972
|
+
fnCache?.set(id, item);
|
|
973
|
+
}
|
|
974
|
+
for (const batchItem of batchSet.values()) {
|
|
975
|
+
fnCache?.set(batchItem, EMPTY_SYM);
|
|
976
|
+
}
|
|
977
|
+
batchSet.clear();
|
|
978
|
+
};
|
|
979
|
+
let pos = 0;
|
|
980
|
+
while (pos < values.length) {
|
|
981
|
+
const id = argToKey(values[pos], argToKeyOptions);
|
|
982
|
+
const item = fnCache.get(id);
|
|
983
|
+
if (item) {
|
|
984
|
+
if (item === EMPTY_SYM) {
|
|
985
|
+
if (retryEmpty) batchSet.add(id);
|
|
986
|
+
} else {
|
|
987
|
+
result.set(id, item);
|
|
988
|
+
}
|
|
989
|
+
} else {
|
|
990
|
+
batchSet.add(id);
|
|
991
|
+
}
|
|
992
|
+
if (batchSet.size >= batchSize) {
|
|
993
|
+
await drainMaybe();
|
|
994
|
+
}
|
|
995
|
+
pos++;
|
|
996
|
+
}
|
|
997
|
+
await drainMaybe();
|
|
998
|
+
return result;
|
|
999
|
+
};
|
|
1000
|
+
wrapFn.$cache = { getBucket, getPointer, argToKeyOptions };
|
|
1001
|
+
def(wrapFn, SYM_WITH_CACHE, true);
|
|
1002
|
+
return wrapFn;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
function cleanEmpty(obj) {
|
|
1006
|
+
let value;
|
|
1007
|
+
for (const key of Object.keys(obj)) {
|
|
1008
|
+
value = obj[key];
|
|
1009
|
+
if (isEmpty(value)) {
|
|
1010
|
+
delete obj[key];
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
return obj;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
const cleanObject = (input) => {
|
|
1017
|
+
[...Object.keys(input), ...Object.getOwnPropertySymbols(input)].forEach(
|
|
1018
|
+
(key) => {
|
|
1019
|
+
delete input[key];
|
|
1020
|
+
}
|
|
1021
|
+
);
|
|
1022
|
+
};
|
|
1023
|
+
|
|
1024
|
+
const deepAssign = (dest, source) => {
|
|
1025
|
+
for (const key of Object.keys(source)) {
|
|
1026
|
+
const destValue = dest[key];
|
|
1027
|
+
const sourceValue = source[key];
|
|
1028
|
+
if (isObject(destValue) && isObject(sourceValue)) {
|
|
1029
|
+
deepAssign(destValue, sourceValue);
|
|
1030
|
+
} else {
|
|
1031
|
+
dest[key] = sourceValue;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
|
|
1036
|
+
const deepClone = (value) => {
|
|
1037
|
+
return _cloneDeep(value);
|
|
1038
|
+
};
|
|
1039
|
+
|
|
1040
|
+
const WITH_CUSTOMIZER_FACTORY_SYM = Symbol();
|
|
1041
|
+
function deepCloneWith(value, customizer) {
|
|
1042
|
+
const fns = prepareCustomizes(customizer);
|
|
1043
|
+
return _cloneDeepWith(value, (value2, key) => {
|
|
1044
|
+
let newValue;
|
|
1045
|
+
let replaced = false;
|
|
1046
|
+
for (const fn of fns) {
|
|
1047
|
+
newValue = fn(value2, key);
|
|
1048
|
+
if (newValue !== void 0) {
|
|
1049
|
+
value2 = newValue;
|
|
1050
|
+
replaced = true;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
if (replaced) return value2;
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
function createDeepCloneWith(customizer) {
|
|
1057
|
+
return (value) => {
|
|
1058
|
+
return deepCloneWith(value, customizer);
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
function prepareCustomizes(value) {
|
|
1062
|
+
return arrayable(value).map((v) => isCustomizerFactory(v) ? v() : v);
|
|
1063
|
+
}
|
|
1064
|
+
function isCustomizerFactory(value) {
|
|
1065
|
+
return value?.[WITH_CUSTOMIZER_FACTORY_SYM] === true;
|
|
1066
|
+
}
|
|
1067
|
+
function createCustomizer(fn) {
|
|
1068
|
+
return fn;
|
|
1069
|
+
}
|
|
1070
|
+
function createCustomizerFactory(fn) {
|
|
1071
|
+
def(fn, WITH_CUSTOMIZER_FACTORY_SYM, true);
|
|
1072
|
+
return fn;
|
|
1073
|
+
}
|
|
1074
|
+
function createSecureCustomizer(properties) {
|
|
1075
|
+
const secureLabel = `<** secure **>`;
|
|
1076
|
+
const circularLabel = `<** circular **>`;
|
|
1077
|
+
const propertiesSet = Object.freeze(
|
|
1078
|
+
new Set(properties.map((v) => v.toLocaleLowerCase()))
|
|
1079
|
+
);
|
|
1080
|
+
const withCustomizer = (seenSet, value, key) => {
|
|
1081
|
+
if (isPrimitive(value)) {
|
|
1082
|
+
if (!isString(key)) return;
|
|
1083
|
+
if (!propertiesSet.has(key.toLocaleLowerCase())) return;
|
|
1084
|
+
return secureLabel;
|
|
1085
|
+
}
|
|
1086
|
+
if (seenSet.has(value)) {
|
|
1087
|
+
return circularLabel;
|
|
1088
|
+
}
|
|
1089
|
+
seenSet.add(value);
|
|
1090
|
+
if (isError(value)) {
|
|
1091
|
+
return {
|
|
1092
|
+
message: value.message,
|
|
1093
|
+
stack: value.stack,
|
|
1094
|
+
name: value.name
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
return createCustomizerFactory(() => {
|
|
1099
|
+
const seenSet = /* @__PURE__ */ new WeakSet();
|
|
1100
|
+
return withCustomizer.bind(null, seenSet);
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
const deepDefaults = _defaultsDeep;
|
|
1105
|
+
|
|
1106
|
+
function deepFreeze(value) {
|
|
1107
|
+
let currentValue = value;
|
|
1108
|
+
if (!currentValue || typeof currentValue !== "object") return currentValue;
|
|
1109
|
+
Object.freeze(currentValue);
|
|
1110
|
+
if (Array.isArray(currentValue)) {
|
|
1111
|
+
for (const item of currentValue) {
|
|
1112
|
+
deepFreeze(item);
|
|
1113
|
+
}
|
|
1114
|
+
return currentValue;
|
|
1115
|
+
} else {
|
|
1116
|
+
for (const value2 of Object.values(currentValue)) {
|
|
1117
|
+
deepFreeze(value2);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
return currentValue;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
function flagsToMap(value, bitmaskMap) {
|
|
1124
|
+
const result = {};
|
|
1125
|
+
const compare = typeof value === "bigint" ? 0n : 0;
|
|
1126
|
+
for (const [key, mask] of Object.entries(bitmaskMap)) {
|
|
1127
|
+
result[key] = (value & mask) !== compare;
|
|
1128
|
+
}
|
|
1129
|
+
return result;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
function flatten(obj, {
|
|
1133
|
+
separator = "_",
|
|
1134
|
+
initialPrefix = "",
|
|
1135
|
+
withArrays = true,
|
|
1136
|
+
isObjectCompare = isObject
|
|
1137
|
+
} = {}) {
|
|
1138
|
+
const result = {};
|
|
1139
|
+
const processed = /* @__PURE__ */ new WeakSet();
|
|
1140
|
+
const handle = (node, prefix, initial) => {
|
|
1141
|
+
if (processed.has(node)) return;
|
|
1142
|
+
if (isObjectCompare(node)) {
|
|
1143
|
+
processed.add(node);
|
|
1144
|
+
prefix = prefix && !initial ? `${prefix}${separator}` : prefix;
|
|
1145
|
+
for (const [key, value] of Object.entries(node)) {
|
|
1146
|
+
handle(value, `${prefix}${key}`);
|
|
1147
|
+
}
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
if (Array.isArray(node) && withArrays) {
|
|
1151
|
+
processed.add(node);
|
|
1152
|
+
prefix = prefix && !initial ? `${prefix}${separator}` : prefix;
|
|
1153
|
+
node.forEach((value, idx) => handle(value, `${prefix}${idx}`));
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
result[prefix] = node;
|
|
1157
|
+
};
|
|
1158
|
+
handle(obj, initialPrefix, true);
|
|
1159
|
+
return result;
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
function has(value, keys) {
|
|
1163
|
+
if (!isObject(value)) return false;
|
|
1164
|
+
for (let idx = 0; idx < keys.length; idx++) {
|
|
1165
|
+
const element = keys[idx];
|
|
1166
|
+
if (!(element in value)) return false;
|
|
1167
|
+
}
|
|
1168
|
+
return true;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
|
|
1172
|
+
|
|
1173
|
+
function omit(obj, excludes) {
|
|
1174
|
+
const excludesSet = Array.isArray(excludes) ? new Set(excludes) : excludes instanceof Set ? excludes : void 0;
|
|
1175
|
+
if (!excludesSet) {
|
|
1176
|
+
return obj;
|
|
1177
|
+
}
|
|
1178
|
+
const result = {};
|
|
1179
|
+
if (!isObject(obj)) {
|
|
1180
|
+
return result;
|
|
1181
|
+
}
|
|
1182
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1183
|
+
if (excludesSet.has(key)) continue;
|
|
1184
|
+
result[key] = value;
|
|
1185
|
+
}
|
|
1186
|
+
return result;
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
function omitPrefixed(obj, prefix) {
|
|
1190
|
+
const result = {};
|
|
1191
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1192
|
+
if (key.startsWith(prefix)) continue;
|
|
1193
|
+
result[key] = value;
|
|
1194
|
+
}
|
|
1195
|
+
return result;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
function pick(obj, keys) {
|
|
1199
|
+
const keysSet = Array.isArray(keys) ? new Set(keys) : keys instanceof Set ? keys : void 0;
|
|
1200
|
+
const result = {};
|
|
1201
|
+
if (!keysSet || !isObject(obj)) {
|
|
1202
|
+
return result;
|
|
1203
|
+
}
|
|
1204
|
+
for (const key of keysSet.values()) {
|
|
1205
|
+
if (hasOwn(obj, key)) {
|
|
1206
|
+
result[key] = obj[key];
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
return result;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
function pickPrefixed(obj, options) {
|
|
1213
|
+
let prefix;
|
|
1214
|
+
let prefixTrim = false;
|
|
1215
|
+
if (typeof options === "string") {
|
|
1216
|
+
prefix = options;
|
|
1217
|
+
} else {
|
|
1218
|
+
prefix = options.prefix;
|
|
1219
|
+
prefixTrim = options.prefixTrim === true;
|
|
1220
|
+
}
|
|
1221
|
+
const result = {};
|
|
1222
|
+
for (let [key, value] of Object.entries(obj)) {
|
|
1223
|
+
if (!key.startsWith(prefix)) continue;
|
|
1224
|
+
if (prefixTrim) key = key.substring(prefix.length);
|
|
1225
|
+
result[key] = value;
|
|
1226
|
+
}
|
|
1227
|
+
return result;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
const set = _set;
|
|
1231
|
+
|
|
1232
|
+
const toMap = (obj) => {
|
|
1233
|
+
const map = new Map(Object.entries(obj));
|
|
1234
|
+
for (const symbol of Object.getOwnPropertySymbols(obj)) {
|
|
1235
|
+
map.set(symbol, obj[symbol]);
|
|
1236
|
+
}
|
|
1237
|
+
return map;
|
|
1238
|
+
};
|
|
1239
|
+
|
|
1240
|
+
function unflatten(obj, separator = "_") {
|
|
1241
|
+
const result = {};
|
|
1242
|
+
Object.keys(obj).forEach((path) => {
|
|
1243
|
+
set(result, path.split(separator), obj[path]);
|
|
1244
|
+
});
|
|
1245
|
+
return result;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
const unset = _unset;
|
|
1249
|
+
|
|
1250
|
+
function withDeepClone(fn) {
|
|
1251
|
+
const wrapFn = function(...args) {
|
|
1252
|
+
const result = fn.apply(this, args);
|
|
1253
|
+
if (isPromise(result)) {
|
|
1254
|
+
return result.then(deepClone);
|
|
1255
|
+
}
|
|
1256
|
+
return deepClone(result);
|
|
1257
|
+
};
|
|
1258
|
+
if (isWithCache(fn)) {
|
|
1259
|
+
wrapFn.$cache = fn.$cache;
|
|
1260
|
+
}
|
|
1261
|
+
if ("$cache" in fn) {
|
|
1262
|
+
wrapFn.$cache = fn.$cache;
|
|
1263
|
+
def(wrapFn, SYM_WITH_CACHE, true);
|
|
1264
|
+
}
|
|
1265
|
+
return wrapFn;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
function withPointerCache(pointer, dependencies, fn) {
|
|
1269
|
+
const cacheKey = dependencies.map(String).join("_");
|
|
1270
|
+
let fnCache = cache.get(pointer);
|
|
1271
|
+
if (fnCache) {
|
|
1272
|
+
const cached = fnCache.get(cacheKey);
|
|
1273
|
+
if (cached) {
|
|
1274
|
+
return cached;
|
|
1275
|
+
}
|
|
1276
|
+
} else {
|
|
1277
|
+
fnCache = /* @__PURE__ */ new Map();
|
|
1278
|
+
cache.set(pointer, fnCache);
|
|
1279
|
+
}
|
|
1280
|
+
const newValue = fn();
|
|
1281
|
+
fnCache.set(cacheKey, newValue);
|
|
1282
|
+
return newValue;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
function captureStackTrace(till) {
|
|
1286
|
+
const err = new Error("");
|
|
1287
|
+
if ("captureStackTrace" in Error) {
|
|
1288
|
+
Error.captureStackTrace(err, till);
|
|
1289
|
+
}
|
|
1290
|
+
return (err.stack || "").slice(6);
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
function toError(value, unknownMessage = "Unknown error") {
|
|
1294
|
+
if (isError(value)) {
|
|
1295
|
+
return value;
|
|
1296
|
+
}
|
|
1297
|
+
const error = new Error(unknownMessage, { cause: value });
|
|
1298
|
+
Error.captureStackTrace(error, toError);
|
|
1299
|
+
return error;
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
function catchError(fn) {
|
|
1303
|
+
try {
|
|
1304
|
+
const res = fn();
|
|
1305
|
+
if (isPromise(res)) {
|
|
1306
|
+
return res.then((r) => [void 0, r]).catch(onError$1);
|
|
1307
|
+
}
|
|
1308
|
+
return [void 0, res];
|
|
1309
|
+
} catch (err) {
|
|
1310
|
+
return onError$1(err);
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
function onError$1(error) {
|
|
1314
|
+
const err = toError(error);
|
|
1315
|
+
return [err, void 0];
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
const clamp = (num, min, max) => {
|
|
1319
|
+
if (!isNumber(num)) return min;
|
|
1320
|
+
return Math.min(max, Math.max(min, num));
|
|
1321
|
+
};
|
|
1322
|
+
|
|
1323
|
+
function parseAlpha(value, fallback = 1) {
|
|
1324
|
+
let a = value;
|
|
1325
|
+
if (isString(value)) {
|
|
1326
|
+
a = value.endsWith("%") ? parseFloat(value) / 100 : parseFloat(value);
|
|
1327
|
+
}
|
|
1328
|
+
if (!isNumber(a)) {
|
|
1329
|
+
a = fallback;
|
|
1330
|
+
}
|
|
1331
|
+
return clamp(a, 0, 1);
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
const hexReg = new RegExp(
|
|
1335
|
+
/^#([a-f0-9]{3,4}|[a-f0-9]{4}(?:[a-f0-9]{2}){1,2})\b$/,
|
|
1336
|
+
"i"
|
|
1337
|
+
);
|
|
1338
|
+
function parseHEX(value) {
|
|
1339
|
+
if (!isString(value)) return null;
|
|
1340
|
+
const parsed = hexReg.exec(value);
|
|
1341
|
+
if (!parsed) return null;
|
|
1342
|
+
let a = 1;
|
|
1343
|
+
let hex = parsed[0].replace(/^#/, "");
|
|
1344
|
+
if (hex.length === 8) {
|
|
1345
|
+
a = Number.parseInt(hex.slice(6, 8), 16) / 255;
|
|
1346
|
+
hex = hex.slice(0, 6);
|
|
1347
|
+
}
|
|
1348
|
+
if (hex.length === 4) {
|
|
1349
|
+
a = Number.parseInt(hex.slice(3, 4).repeat(2), 16) / 255;
|
|
1350
|
+
hex = hex.slice(0, 3);
|
|
1351
|
+
}
|
|
1352
|
+
if (hex.length === 3) hex = hex + hex;
|
|
1353
|
+
return [
|
|
1354
|
+
parseInt(hex.slice(0, 2), 16),
|
|
1355
|
+
parseInt(hex.slice(2, 4), 16),
|
|
1356
|
+
parseInt(hex.slice(4, 6), 16),
|
|
1357
|
+
parseAlpha(a)
|
|
1358
|
+
];
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
function parsePercentage(value) {
|
|
1362
|
+
const parsed = parseFloat(value);
|
|
1363
|
+
if (!isNumber(parsed)) return 0;
|
|
1364
|
+
return clamp(parsed, 0, 100);
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
const float = "-?\\d*(?:\\.\\d+)";
|
|
1368
|
+
const number = `(${float}?)`;
|
|
1369
|
+
const percentage = `(${float}?%)`;
|
|
1370
|
+
const numberOrPercentage = `(${float}?%?)`;
|
|
1371
|
+
function isColorChannels(value) {
|
|
1372
|
+
return Array.isArray(value) && value.length === 4;
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
const hsl = new RegExp(
|
|
1376
|
+
`^
|
|
1377
|
+
hsla?\\(
|
|
1378
|
+
\\s*(-?\\d*(?:\\.\\d+)?(?:deg|rad|turn)?)\\s*,
|
|
1379
|
+
\\s*${percentage}\\s*,
|
|
1380
|
+
\\s*${percentage}\\s*
|
|
1381
|
+
(?:,\\s*${numberOrPercentage}\\s*)?
|
|
1382
|
+
\\)
|
|
1383
|
+
$
|
|
1384
|
+
`.replace(/\n|\s/g, "")
|
|
1385
|
+
);
|
|
1386
|
+
const hsla = new RegExp(
|
|
1387
|
+
`^
|
|
1388
|
+
hsla?\\(
|
|
1389
|
+
\\s*(-?\\d*(?:\\.\\d+)?(?:deg|rad|turn)?)\\s*
|
|
1390
|
+
\\s+${percentage}
|
|
1391
|
+
\\s+${percentage}
|
|
1392
|
+
\\s*(?:\\s*\\/\\s*${numberOrPercentage}\\s*)?
|
|
1393
|
+
\\)
|
|
1394
|
+
$
|
|
1395
|
+
`.replace(/\n|\s/g, "")
|
|
1396
|
+
);
|
|
1397
|
+
function parseHSL(value) {
|
|
1398
|
+
const parsed = hsla.exec(value) || hsl.exec(value);
|
|
1399
|
+
if (!parsed) return null;
|
|
1400
|
+
const [, h, s, l, a = 1] = parsed;
|
|
1401
|
+
let hh = h;
|
|
1402
|
+
if (hh.endsWith("turn")) {
|
|
1403
|
+
hh = parseFloat(hh) * 360 / 1;
|
|
1404
|
+
} else if (hh.endsWith("rad")) {
|
|
1405
|
+
hh = Math.round(parseFloat(hh) * 180 / Math.PI);
|
|
1406
|
+
} else {
|
|
1407
|
+
hh = parseFloat(hh);
|
|
1408
|
+
}
|
|
1409
|
+
return {
|
|
1410
|
+
h: hh,
|
|
1411
|
+
s: parsePercentage(s),
|
|
1412
|
+
l: parsePercentage(l),
|
|
1413
|
+
a: parseAlpha(a === null ? 1 : a)
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
function checkBitmask(scope, flag) {
|
|
1418
|
+
return (scope & flag) === flag;
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
function getRandomInt(min, max) {
|
|
1422
|
+
min = Math.ceil(min);
|
|
1423
|
+
max = Math.floor(max);
|
|
1424
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
class Randomizer {
|
|
1428
|
+
_pool = [];
|
|
1429
|
+
_step = 0;
|
|
1430
|
+
_min;
|
|
1431
|
+
_max;
|
|
1432
|
+
_pregenerateAmount;
|
|
1433
|
+
_transform;
|
|
1434
|
+
constructor({ min, max, pregenerateAmount, transform }) {
|
|
1435
|
+
this._min = min;
|
|
1436
|
+
this._max = max;
|
|
1437
|
+
this._pregenerateAmount = pregenerateAmount;
|
|
1438
|
+
this._transform = transform;
|
|
1439
|
+
}
|
|
1440
|
+
/**
|
|
1441
|
+
* Returns the current step of the randomizer.
|
|
1442
|
+
*
|
|
1443
|
+
* @returns {number} The current step.
|
|
1444
|
+
*/
|
|
1445
|
+
getCurrentStep() {
|
|
1446
|
+
return this._step;
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
* Sets the current step of the randomizer.
|
|
1450
|
+
*
|
|
1451
|
+
* @param {number} value - The step to set.
|
|
1452
|
+
* @throws {Error} If the provided value is not a valid number or less than 0.
|
|
1453
|
+
*/
|
|
1454
|
+
setCurrentStep(value) {
|
|
1455
|
+
number$1(value, "Current step must be an number");
|
|
1456
|
+
ok(value >= 0, "Current step must be getter or equal 0");
|
|
1457
|
+
this._step = value;
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* Retrieves a random number either from the current step or a specific step if provided.
|
|
1461
|
+
*
|
|
1462
|
+
* @param {number} [fromStep] - The step from which to retrieve the random number (optional).
|
|
1463
|
+
* @returns {number} The random number at the current or specified step.
|
|
1464
|
+
*/
|
|
1465
|
+
get(fromStep) {
|
|
1466
|
+
if (fromStep === void 0) {
|
|
1467
|
+
return this._lookup(this._step++);
|
|
1468
|
+
}
|
|
1469
|
+
return this._lookup(fromStep);
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Resets the current step to 0.
|
|
1473
|
+
*/
|
|
1474
|
+
resetStep() {
|
|
1475
|
+
this._step = 0;
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* Resets the random number pool, clearing and repopulating it with new random values.
|
|
1479
|
+
*/
|
|
1480
|
+
resetPool() {
|
|
1481
|
+
const size = this._pregenerateAmount;
|
|
1482
|
+
this._pool = Array.from({ length: size });
|
|
1483
|
+
for (let step = 0; step < size; step++) {
|
|
1484
|
+
this._pool[step] = this._rand();
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
_rand() {
|
|
1488
|
+
return this._transform(getRandomInt(this._min, this._max));
|
|
1489
|
+
}
|
|
1490
|
+
_lookup(step) {
|
|
1491
|
+
if (this._pool[step] === void 0) {
|
|
1492
|
+
this._pool[step] = this._rand();
|
|
1493
|
+
}
|
|
1494
|
+
return this._pool[step];
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
const noopTransform = (v) => v;
|
|
1498
|
+
function createRandomizer({
|
|
1499
|
+
min = Number.MIN_SAFE_INTEGER,
|
|
1500
|
+
max = Number.MAX_SAFE_INTEGER,
|
|
1501
|
+
pregenerateAmount = 100,
|
|
1502
|
+
transform = noopTransform
|
|
1503
|
+
}) {
|
|
1504
|
+
return new Randomizer({ min, max, pregenerateAmount, transform });
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
class FindMean {
|
|
1508
|
+
#count = 0;
|
|
1509
|
+
#value = 0;
|
|
1510
|
+
constructor(initialValue) {
|
|
1511
|
+
this.reset(initialValue);
|
|
1512
|
+
}
|
|
1513
|
+
/**
|
|
1514
|
+
* Resets the current progress of the mean calculation.
|
|
1515
|
+
* Optionally, you can pass an initial value to start the calculation.
|
|
1516
|
+
*
|
|
1517
|
+
* @param {number} [initialValue] - The initial value to start the mean calculation with.
|
|
1518
|
+
* @returns {FindMean} The current instance of the FindMean class for chaining.
|
|
1519
|
+
*
|
|
1520
|
+
* @example
|
|
1521
|
+
* const avg = findMean();
|
|
1522
|
+
* avg.push(2, 4);
|
|
1523
|
+
* avg.reset();
|
|
1524
|
+
* console.log(avg.value); // Output: 0
|
|
1525
|
+
*/
|
|
1526
|
+
reset(initialValue) {
|
|
1527
|
+
if (initialValue === void 0) {
|
|
1528
|
+
this.#count = 0;
|
|
1529
|
+
this.#value = 0;
|
|
1530
|
+
} else {
|
|
1531
|
+
this.#count = 1;
|
|
1532
|
+
this.#value = initialValue;
|
|
1533
|
+
}
|
|
1534
|
+
return this;
|
|
1535
|
+
}
|
|
1536
|
+
/**
|
|
1537
|
+
* Retrieves the current mean value (average).
|
|
1538
|
+
*
|
|
1539
|
+
* @returns {number} The current mean value.
|
|
1540
|
+
*
|
|
1541
|
+
* @example
|
|
1542
|
+
* const avg = findMean();
|
|
1543
|
+
* avg.push(5, 10);
|
|
1544
|
+
* console.log(avg.value); // Output: 7.5 (average of 5, 10)
|
|
1545
|
+
*/
|
|
1546
|
+
get value() {
|
|
1547
|
+
return this.#value;
|
|
1548
|
+
}
|
|
1549
|
+
/**
|
|
1550
|
+
* Retrieves the count of numbers added so far.
|
|
1551
|
+
*
|
|
1552
|
+
* @returns {number} The count of numbers in the set.
|
|
1553
|
+
*
|
|
1554
|
+
* @example
|
|
1555
|
+
* const avg = findMean();
|
|
1556
|
+
* avg.push(10, 20);
|
|
1557
|
+
* console.log(avg.count); // Output: 2
|
|
1558
|
+
*/
|
|
1559
|
+
get count() {
|
|
1560
|
+
return this.#count;
|
|
1561
|
+
}
|
|
1562
|
+
/**
|
|
1563
|
+
* Adds values to the set and updates the running mean.
|
|
1564
|
+
*
|
|
1565
|
+
* @param {...number} values - The values to add to the set.
|
|
1566
|
+
* @returns {FindMean} The current instance of the FindMean class for chaining.
|
|
1567
|
+
*
|
|
1568
|
+
* @example
|
|
1569
|
+
* const avg = findMean();
|
|
1570
|
+
* avg.push(1, 2, 3);
|
|
1571
|
+
* console.log(avg.value); // Output: 2 (average of 1, 2, 3)
|
|
1572
|
+
* console.log(avg.count); // Output: 3
|
|
1573
|
+
*/
|
|
1574
|
+
push(...values) {
|
|
1575
|
+
for (const item of values) {
|
|
1576
|
+
this.#count++;
|
|
1577
|
+
this.#value += (item - this.#value) / this.#count;
|
|
1578
|
+
}
|
|
1579
|
+
return this;
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
function findMean(value) {
|
|
1583
|
+
return new FindMean(value);
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
const defaultFormat = {
|
|
1587
|
+
/**
|
|
1588
|
+
* Symbol to separate thousands parts
|
|
1589
|
+
*/
|
|
1590
|
+
thousands: ",",
|
|
1591
|
+
/**
|
|
1592
|
+
* Symbol to separate decimal part
|
|
1593
|
+
*/
|
|
1594
|
+
decimal: "."
|
|
1595
|
+
};
|
|
1596
|
+
const regExp = /\B(?=(\d{3})+(?!\d))/g;
|
|
1597
|
+
function formatNumber(value, format = defaultFormat) {
|
|
1598
|
+
if (isString(value)) {
|
|
1599
|
+
return formatNumber(parseFloat(value), format);
|
|
1600
|
+
}
|
|
1601
|
+
if (!isNumber(value)) return "";
|
|
1602
|
+
const [integerPart, decimalPart] = value.toFixed(2).split(".");
|
|
1603
|
+
let result = String(integerPart).replace(regExp, format.thousands);
|
|
1604
|
+
if (decimalPart !== "00") {
|
|
1605
|
+
result += format.decimal + decimalPart;
|
|
1606
|
+
}
|
|
1607
|
+
return result;
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
function round2digits(value, digits = 2) {
|
|
1611
|
+
if (digits === 0) {
|
|
1612
|
+
return value << 0;
|
|
1613
|
+
}
|
|
1614
|
+
return Number(Math.round(value + "e" + digits) + "e-" + digits);
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
const CURRENCY_FORMAT = /* @__PURE__ */ new Map([
|
|
1618
|
+
["USD", { symbol: "$", thousands: ",", decimal: ".", symbolBefore: true }],
|
|
1619
|
+
["EUR", { symbol: "\u20AC", thousands: ".", decimal: ",", symbolBefore: true }],
|
|
1620
|
+
["GBP", { symbol: "\xA3", thousands: ",", decimal: ".", symbolBefore: true }],
|
|
1621
|
+
["JPY", { symbol: "\xA5", thousands: ",", decimal: "", symbolBefore: true }],
|
|
1622
|
+
["AUD", { symbol: "A$", thousands: ",", decimal: ".", symbolBefore: true }],
|
|
1623
|
+
["CAD", { symbol: "C$", thousands: ",", decimal: ".", symbolBefore: true }],
|
|
1624
|
+
["CHF", { symbol: "CHF", thousands: "'", decimal: ".", symbolBefore: true }],
|
|
1625
|
+
["CNY", { symbol: "\xA5", thousands: ",", decimal: ".", symbolBefore: true }],
|
|
1626
|
+
["INR", { symbol: "\u20B9", thousands: ",", decimal: ".", symbolBefore: true }],
|
|
1627
|
+
["KRW", { symbol: "\u20A9", thousands: ",", decimal: "", symbolBefore: true }],
|
|
1628
|
+
["RUB", { symbol: "\u20BD", thousands: " ", decimal: ",", symbolBefore: false }],
|
|
1629
|
+
["UAH", { symbol: "\u20B4", thousands: " ", decimal: ",", symbolBefore: false }],
|
|
1630
|
+
["BRL", { symbol: "R$", thousands: ".", decimal: ",", symbolBefore: true }],
|
|
1631
|
+
["MXN", { symbol: "$", thousands: ",", decimal: ".", symbolBefore: true }],
|
|
1632
|
+
["ZAR", { symbol: "R", thousands: " ", decimal: ",", symbolBefore: true }],
|
|
1633
|
+
["UAH", { symbol: "\u20B4", thousands: " ", decimal: ",", symbolBefore: true }]
|
|
1634
|
+
]);
|
|
1635
|
+
const DEF_FORMAT = {
|
|
1636
|
+
decimal: " ",
|
|
1637
|
+
thousands: ",",
|
|
1638
|
+
symbol: "",
|
|
1639
|
+
symbolBefore: false
|
|
1640
|
+
};
|
|
1641
|
+
function formatMoney(amount, formatOrCode = "USD", intMode = false) {
|
|
1642
|
+
if (intMode) {
|
|
1643
|
+
amount = round2digits(amount / 100, 2);
|
|
1644
|
+
}
|
|
1645
|
+
const format = isString(formatOrCode) ? CURRENCY_FORMAT.get(formatOrCode) || {
|
|
1646
|
+
...DEF_FORMAT,
|
|
1647
|
+
symbol: formatOrCode
|
|
1648
|
+
} : formatOrCode;
|
|
1649
|
+
const formattedNumber = formatNumber(amount, format);
|
|
1650
|
+
return format.symbolBefore ? format.symbol + formattedNumber : formattedNumber + format.symbol;
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
function humanize(input, decimals = 1) {
|
|
1654
|
+
if (input === null || input === void 0) {
|
|
1655
|
+
return String(input);
|
|
1656
|
+
}
|
|
1657
|
+
decimals = Math.max(decimals, 0);
|
|
1658
|
+
const number = parseInt(input, 10);
|
|
1659
|
+
if (!Number.isFinite(number)) {
|
|
1660
|
+
return String(input);
|
|
1661
|
+
}
|
|
1662
|
+
const signString = number < 0 ? "-" : "";
|
|
1663
|
+
const unsignedNumber = Math.abs(number);
|
|
1664
|
+
const unsignedNumberString = String(unsignedNumber);
|
|
1665
|
+
const numberLength = unsignedNumberString.length;
|
|
1666
|
+
const numberLengths = [13, 10, 7, 4];
|
|
1667
|
+
const bigNumPrefixes = ["T", "B", "M", "k"];
|
|
1668
|
+
if (unsignedNumber < 1e3) {
|
|
1669
|
+
return `${signString}${unsignedNumberString}`;
|
|
1670
|
+
}
|
|
1671
|
+
if (numberLength > numberLengths[0] + 3) {
|
|
1672
|
+
return number.toExponential(decimals).replace("e+", "x10^");
|
|
1673
|
+
}
|
|
1674
|
+
let length = 0;
|
|
1675
|
+
for (let i = 0; i < numberLengths.length; i++) {
|
|
1676
|
+
const _length = numberLengths[i];
|
|
1677
|
+
if (numberLength >= _length) {
|
|
1678
|
+
length = _length;
|
|
1679
|
+
break;
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
const decimalIndex = numberLength - length + 1;
|
|
1683
|
+
const unsignedNumberCharacterArray = unsignedNumberString.split("");
|
|
1684
|
+
const wholePartArray = unsignedNumberCharacterArray.slice(0, decimalIndex);
|
|
1685
|
+
const decimalPartArray = unsignedNumberCharacterArray.slice(
|
|
1686
|
+
decimalIndex,
|
|
1687
|
+
decimalIndex + decimals + 1
|
|
1688
|
+
);
|
|
1689
|
+
const wholePart = wholePartArray.join("");
|
|
1690
|
+
let decimalPart = decimalPartArray.join("");
|
|
1691
|
+
if (decimalPart.length < decimals) {
|
|
1692
|
+
decimalPart += `${Array(decimals - decimalPart.length + 1).join("0")}`;
|
|
1693
|
+
}
|
|
1694
|
+
if (decimalPart[0] === "0") {
|
|
1695
|
+
decimals = 0;
|
|
1696
|
+
}
|
|
1697
|
+
let output;
|
|
1698
|
+
if (decimals === 0) {
|
|
1699
|
+
output = `${signString}${wholePart}${bigNumPrefixes[numberLengths.indexOf(length)]}`;
|
|
1700
|
+
} else {
|
|
1701
|
+
const outputNumber = Number(`${wholePart}.${decimalPart}`).toFixed(
|
|
1702
|
+
decimals
|
|
1703
|
+
);
|
|
1704
|
+
output = `${signString}${outputNumber}${bigNumPrefixes[numberLengths.indexOf(length)]}`;
|
|
1705
|
+
}
|
|
1706
|
+
return output;
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
function parseAllNumbers(value) {
|
|
1710
|
+
if (isNumber(value)) {
|
|
1711
|
+
return [value];
|
|
1712
|
+
}
|
|
1713
|
+
if (!isString(value)) {
|
|
1714
|
+
return [];
|
|
1715
|
+
}
|
|
1716
|
+
const matches = value.replace(/,/g, ".").match(/-?\d+(\.\d+)?/g);
|
|
1717
|
+
if (!matches) {
|
|
1718
|
+
return [];
|
|
1719
|
+
}
|
|
1720
|
+
return matches.map(Number).filter(isNumber);
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
function percentOf(value, percent, digits) {
|
|
1724
|
+
let result = percent / 100 * value;
|
|
1725
|
+
if (digits) {
|
|
1726
|
+
result = round2digits(result, digits);
|
|
1727
|
+
}
|
|
1728
|
+
return result;
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
function timestamp(fromValue = Date.now()) {
|
|
1732
|
+
if (isDate(fromValue)) {
|
|
1733
|
+
fromValue = fromValue.getTime();
|
|
1734
|
+
}
|
|
1735
|
+
return Math.floor(fromValue / 1e3);
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
function timestampToDate(value) {
|
|
1739
|
+
if (!isNumber(value)) return null;
|
|
1740
|
+
return new Date(value * 1e3);
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
const rgb3Numbers = new RegExp(
|
|
1744
|
+
`^
|
|
1745
|
+
rgba?\\(
|
|
1746
|
+
\\s*${number}\\s*,
|
|
1747
|
+
\\s*${number}\\s*,
|
|
1748
|
+
\\s*${number}\\s*
|
|
1749
|
+
(?:,\\s*${numberOrPercentage}\\s*)?
|
|
1750
|
+
\\)
|
|
1751
|
+
$
|
|
1752
|
+
`.replace(/\n|\s/g, "")
|
|
1753
|
+
);
|
|
1754
|
+
const rgb3Percent = new RegExp(
|
|
1755
|
+
`^
|
|
1756
|
+
rgba?\\(
|
|
1757
|
+
\\s*${percentage}\\s*,
|
|
1758
|
+
\\s*${percentage}\\s*,
|
|
1759
|
+
\\s*${percentage}\\s*
|
|
1760
|
+
(?:,\\s*${numberOrPercentage}\\s*)?
|
|
1761
|
+
\\)
|
|
1762
|
+
$
|
|
1763
|
+
`.replace(/\n|\s/g, "")
|
|
1764
|
+
);
|
|
1765
|
+
const rgb4Numbers = new RegExp(
|
|
1766
|
+
`^
|
|
1767
|
+
rgba?\\(
|
|
1768
|
+
\\s*${number}
|
|
1769
|
+
\\s+${number}
|
|
1770
|
+
\\s+${number}
|
|
1771
|
+
\\s*(?:\\s*\\/\\s*${numberOrPercentage}\\s*)?
|
|
1772
|
+
\\)
|
|
1773
|
+
$
|
|
1774
|
+
`.replace(/\n|\s/g, "")
|
|
1775
|
+
);
|
|
1776
|
+
const rgb4Percent = new RegExp(
|
|
1777
|
+
`^
|
|
1778
|
+
rgba?\\(
|
|
1779
|
+
\\s*${percentage}
|
|
1780
|
+
\\s+${percentage}
|
|
1781
|
+
\\s+${percentage}
|
|
1782
|
+
\\s*(?:\\s*\\/\\s*${numberOrPercentage}\\s*)?
|
|
1783
|
+
\\)
|
|
1784
|
+
$
|
|
1785
|
+
`.replace(/\n|\s/g, "")
|
|
1786
|
+
);
|
|
1787
|
+
const parseValue$1 = (num) => {
|
|
1788
|
+
let n = num;
|
|
1789
|
+
if (!isNumber(n))
|
|
1790
|
+
n = n.endsWith("%") ? parseFloat(n) * 255 / 100 : parseFloat(n);
|
|
1791
|
+
return clamp(Math.round(n), 0, 255);
|
|
1792
|
+
};
|
|
1793
|
+
function parseRGB(value) {
|
|
1794
|
+
if (!isString(value)) return null;
|
|
1795
|
+
const rgb = rgb4Numbers.exec(value) || rgb4Percent.exec(value) || rgb3Numbers.exec(value) || rgb3Percent.exec(value);
|
|
1796
|
+
if (!rgb) return null;
|
|
1797
|
+
const [, r, g, b, a] = rgb;
|
|
1798
|
+
return {
|
|
1799
|
+
r: parseValue$1(r),
|
|
1800
|
+
g: parseValue$1(g),
|
|
1801
|
+
b: parseValue$1(b),
|
|
1802
|
+
a: parseAlpha(a)
|
|
1803
|
+
};
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
function buildCssColor([r, g, b, a = 1], opacity = 1) {
|
|
1807
|
+
return `rgba(${r}, ${g}, ${b}, ${a * opacity})`;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
function hexToChannels(hexWithAlpha) {
|
|
1811
|
+
const [hex, alpha] = hexWithAlpha.split("/");
|
|
1812
|
+
const channels = parseHEX(hex);
|
|
1813
|
+
if (!channels) return [0, 0, 0, 0];
|
|
1814
|
+
if (alpha) {
|
|
1815
|
+
channels[3] = parseAlpha(alpha);
|
|
1816
|
+
}
|
|
1817
|
+
return channels;
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
function hslToChannels(value) {
|
|
1821
|
+
const parsed = parseHSL(value);
|
|
1822
|
+
if (!parsed) return [0, 0, 0, 0];
|
|
1823
|
+
let { h, s, l, a } = parsed;
|
|
1824
|
+
s /= 100;
|
|
1825
|
+
l /= 100;
|
|
1826
|
+
const k = (n) => (n + h / 30) % 12;
|
|
1827
|
+
const p = s * Math.min(l, 1 - l);
|
|
1828
|
+
const f = (n) => l - p * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
|
|
1829
|
+
return [
|
|
1830
|
+
Math.round(255 * f(0)),
|
|
1831
|
+
Math.round(255 * f(8)),
|
|
1832
|
+
Math.round(255 * f(4)),
|
|
1833
|
+
a
|
|
1834
|
+
];
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
function rgbToChannels(value) {
|
|
1838
|
+
const rgb = parseRGB(value);
|
|
1839
|
+
if (!rgb) return [0, 0, 0, 0];
|
|
1840
|
+
return [rgb.r, rgb.g, rgb.b, rgb.a];
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
function colorToChannels(color) {
|
|
1844
|
+
if (isColorChannels(color)) {
|
|
1845
|
+
return color;
|
|
1846
|
+
}
|
|
1847
|
+
if (isString(color)) {
|
|
1848
|
+
color = color.trim();
|
|
1849
|
+
if (color[0] === "#") {
|
|
1850
|
+
return hexToChannels(color);
|
|
1851
|
+
} else if (color.startsWith("rgb")) {
|
|
1852
|
+
return rgbToChannels(color);
|
|
1853
|
+
} else if (color.startsWith("rgba")) {
|
|
1854
|
+
return rgbToChannels(color);
|
|
1855
|
+
} else if (color.startsWith("hsl")) {
|
|
1856
|
+
return hslToChannels(color);
|
|
1857
|
+
} else if (color.includes(",")) {
|
|
1858
|
+
const channels = color.split(",").map((v) => parseFloat(v)).filter(isNumber).slice(0, 4);
|
|
1859
|
+
while (channels.length < 3) {
|
|
1860
|
+
channels.push(0);
|
|
1861
|
+
}
|
|
1862
|
+
return [...channels, 1].slice(0, 4);
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
console.warn("Failed to convert color into channels", typeof color, color);
|
|
1866
|
+
return [0, 0, 0, 1];
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
function alpha(color, newAlpha) {
|
|
1870
|
+
const [r, g, b] = colorToChannels(color);
|
|
1871
|
+
return buildCssColor([r, g, b, parseAlpha(newAlpha)], 1);
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
function blendColors(color1, color2, factor) {
|
|
1875
|
+
const [r1, g1, b1, a1] = colorToChannels(color1);
|
|
1876
|
+
const [r2, g2, b2, a2] = colorToChannels(color2);
|
|
1877
|
+
return [
|
|
1878
|
+
Math.round(r1 * (1 - factor) + r2 * factor),
|
|
1879
|
+
Math.round(g1 * (1 - factor) + g2 * factor),
|
|
1880
|
+
Math.round(b1 * (1 - factor) + b2 * factor),
|
|
1881
|
+
Math.round(a1 * (1 - factor) + a2 * factor)
|
|
1882
|
+
];
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
function channelsToHex(channels, withAlpha = true) {
|
|
1886
|
+
const [r, g, b, a] = channels;
|
|
1887
|
+
const outParts = [
|
|
1888
|
+
r.toString(16).toUpperCase().padStart(2, "0"),
|
|
1889
|
+
g.toString(16).toUpperCase().padStart(2, "0"),
|
|
1890
|
+
b.toString(16).toUpperCase().padStart(2, "0")
|
|
1891
|
+
];
|
|
1892
|
+
if (withAlpha && isNumber(a)) {
|
|
1893
|
+
outParts.push(
|
|
1894
|
+
Math.round(a * 255).toString(16).substring(0, 2).toUpperCase().padStart(2, "0")
|
|
1895
|
+
);
|
|
1896
|
+
}
|
|
1897
|
+
return "#" + outParts.join("");
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
function channelsToHSL([r, g, b, a]) {
|
|
1901
|
+
r /= 255;
|
|
1902
|
+
g /= 255;
|
|
1903
|
+
b /= 255;
|
|
1904
|
+
const max = Math.max(r, g, b);
|
|
1905
|
+
const min = Math.min(r, g, b);
|
|
1906
|
+
const delta = max - min;
|
|
1907
|
+
const l = (max + min) / 2;
|
|
1908
|
+
let h = 0;
|
|
1909
|
+
let s = 0;
|
|
1910
|
+
if (delta !== 0) {
|
|
1911
|
+
s = delta / (1 - Math.abs(2 * l - 1));
|
|
1912
|
+
if (max === r) {
|
|
1913
|
+
h = (g - b) / delta % 6;
|
|
1914
|
+
} else if (max === g) {
|
|
1915
|
+
h = (b - r) / delta + 2;
|
|
1916
|
+
} else if (max === b) {
|
|
1917
|
+
h = (r - g) / delta + 4;
|
|
1918
|
+
}
|
|
1919
|
+
h *= 60;
|
|
1920
|
+
if (h < 0) {
|
|
1921
|
+
h += 360;
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
return {
|
|
1925
|
+
h: Math.round(h),
|
|
1926
|
+
s: Math.round(s * 100),
|
|
1927
|
+
l: Math.round(l * 100),
|
|
1928
|
+
a: parseAlpha(a)
|
|
1929
|
+
};
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
function channelsToRGB([r, g, b, a]) {
|
|
1933
|
+
return {
|
|
1934
|
+
r,
|
|
1935
|
+
g,
|
|
1936
|
+
b,
|
|
1937
|
+
a
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
function contrastRatio(l1, l2) {
|
|
1942
|
+
return round2digits((Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05), 4);
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
const defaultWindow$2 = globalThis?.window;
|
|
1946
|
+
function cssVariable(container) {
|
|
1947
|
+
if (!defaultWindow$2) return noop;
|
|
1948
|
+
const computedStyles = defaultWindow$2.getComputedStyle(container);
|
|
1949
|
+
return (name) => {
|
|
1950
|
+
const patterns = name.split("/", 2);
|
|
1951
|
+
if (patterns[0]?.startsWith("--")) {
|
|
1952
|
+
let value = computedStyles.getPropertyValue(patterns[0])?.trim();
|
|
1953
|
+
if (patterns[0].startsWith("--v")) {
|
|
1954
|
+
value = `rgb(${value})`;
|
|
1955
|
+
}
|
|
1956
|
+
patterns[0] = value;
|
|
1957
|
+
}
|
|
1958
|
+
return patterns.join("/");
|
|
1959
|
+
};
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
function interpolateColor(color1, color2, factor) {
|
|
1963
|
+
const [r1, g1, b1, a1] = colorToChannels(color1);
|
|
1964
|
+
const [r2, g2, b2, a2] = colorToChannels(color2);
|
|
1965
|
+
return [
|
|
1966
|
+
Math.round(r1 + factor * (r2 - r1)),
|
|
1967
|
+
Math.round(g1 + factor * (g2 - g1)),
|
|
1968
|
+
Math.round(b1 + factor * (b2 - b1)),
|
|
1969
|
+
a1 + factor * (a2 - a1)
|
|
1970
|
+
];
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
function luminance([r, g, b]) {
|
|
1974
|
+
const a = [r, g, b].map(function(v) {
|
|
1975
|
+
v /= 255;
|
|
1976
|
+
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
|
|
1977
|
+
});
|
|
1978
|
+
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
function tintedTextColor(background, tintPercentage = 0.2) {
|
|
1982
|
+
const bgColor = colorToChannels(background);
|
|
1983
|
+
const bgLuminance = luminance(bgColor);
|
|
1984
|
+
const whiteLuminance = luminance([255, 255, 255, 1]);
|
|
1985
|
+
const blackLuminance = luminance([0, 0, 0, 1]);
|
|
1986
|
+
const contrastWithWhite = contrastRatio(bgLuminance, whiteLuminance);
|
|
1987
|
+
const contrastWithBlack = contrastRatio(bgLuminance, blackLuminance);
|
|
1988
|
+
const baseTextColor = contrastWithWhite >= contrastWithBlack ? [255, 255, 255, 1] : [0, 0, 0, 1];
|
|
1989
|
+
const tintedColor = blendColors(baseTextColor, bgColor, tintPercentage);
|
|
1990
|
+
const tintedLuminance = luminance(tintedColor);
|
|
1991
|
+
const finalContrast = contrastRatio(bgLuminance, tintedLuminance);
|
|
1992
|
+
if (finalContrast < 4.5) {
|
|
1993
|
+
return baseTextColor;
|
|
1994
|
+
}
|
|
1995
|
+
return tintedColor;
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
const ColorParser = {
|
|
1999
|
+
HSL: parseHSL,
|
|
2000
|
+
RGB: parseRGB,
|
|
2001
|
+
HEX: parseHEX
|
|
2002
|
+
};
|
|
2003
|
+
|
|
2004
|
+
const T0 = signed_crc_table();
|
|
2005
|
+
function signed_crc_table() {
|
|
2006
|
+
var c = 0, table = new Array(256);
|
|
2007
|
+
for (var n = 0; n != 256; ++n) {
|
|
2008
|
+
c = n;
|
|
2009
|
+
c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
|
|
2010
|
+
c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
|
|
2011
|
+
c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
|
|
2012
|
+
c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
|
|
2013
|
+
c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
|
|
2014
|
+
c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
|
|
2015
|
+
c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
|
|
2016
|
+
c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
|
|
2017
|
+
table[n] = c;
|
|
2018
|
+
}
|
|
2019
|
+
return Int32Array ? new Int32Array(table) : table;
|
|
2020
|
+
}
|
|
2021
|
+
function crc32(str, seed = 0) {
|
|
2022
|
+
var C = seed ^ -1;
|
|
2023
|
+
for (var i = 0, L = str.length, c = 0, d = 0; i < L; ) {
|
|
2024
|
+
c = str.charCodeAt(i++);
|
|
2025
|
+
if (c < 128) {
|
|
2026
|
+
C = C >>> 8 ^ T0[(C ^ c) & 255];
|
|
2027
|
+
} else if (c < 2048) {
|
|
2028
|
+
C = C >>> 8 ^ T0[(C ^ (192 | c >> 6 & 31)) & 255];
|
|
2029
|
+
C = C >>> 8 ^ T0[(C ^ (128 | c & 63)) & 255];
|
|
2030
|
+
} else if (c >= 55296 && c < 57344) {
|
|
2031
|
+
c = (c & 1023) + 64;
|
|
2032
|
+
d = str.charCodeAt(i++) & 1023;
|
|
2033
|
+
C = C >>> 8 ^ T0[(C ^ (240 | c >> 8 & 7)) & 255];
|
|
2034
|
+
C = C >>> 8 ^ T0[(C ^ (128 | c >> 2 & 63)) & 255];
|
|
2035
|
+
C = C >>> 8 ^ T0[(C ^ (128 | d >> 6 & 15 | (c & 3) << 4)) & 255];
|
|
2036
|
+
C = C >>> 8 ^ T0[(C ^ (128 | d & 63)) & 255];
|
|
2037
|
+
} else {
|
|
2038
|
+
C = C >>> 8 ^ T0[(C ^ (224 | c >> 12 & 15)) & 255];
|
|
2039
|
+
C = C >>> 8 ^ T0[(C ^ (128 | c >> 6 & 63)) & 255];
|
|
2040
|
+
C = C >>> 8 ^ T0[(C ^ (128 | c & 63)) & 255];
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
return ~C;
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
const env = (() => {
|
|
2047
|
+
if (globalThis?.process) {
|
|
2048
|
+
return createEnvParser(process.env);
|
|
2049
|
+
} else {
|
|
2050
|
+
return createEnvParser(import.meta.env);
|
|
2051
|
+
}
|
|
2052
|
+
})();
|
|
2053
|
+
function createEnvParser(targetObject) {
|
|
2054
|
+
return Object.freeze({
|
|
2055
|
+
isDevelopment: targetObject.NODE_ENV === "development",
|
|
2056
|
+
isProduction: targetObject.NODE_ENV === "production",
|
|
2057
|
+
isStage: targetObject.NODE_ENV === "state",
|
|
2058
|
+
isTest: targetObject.NODE_ENV === "test",
|
|
2059
|
+
bool(key, defaultValue = false) {
|
|
2060
|
+
if (!(key in targetObject)) {
|
|
2061
|
+
return defaultValue;
|
|
2062
|
+
}
|
|
2063
|
+
return parseBoolean(targetObject[key]) ?? defaultValue;
|
|
2064
|
+
},
|
|
2065
|
+
int(key, defaultValue = 0) {
|
|
2066
|
+
if (!(key in targetObject)) {
|
|
2067
|
+
return defaultValue;
|
|
2068
|
+
}
|
|
2069
|
+
return _parseInt(targetObject[key]) ?? defaultValue;
|
|
2070
|
+
},
|
|
2071
|
+
decimal(key, dights = void 0, defaultValue = 0) {
|
|
2072
|
+
if (!(key in targetObject)) {
|
|
2073
|
+
return isNumber(dights) ? round2digits(defaultValue, dights) : defaultValue;
|
|
2074
|
+
}
|
|
2075
|
+
return parseDecimal(targetObject[key], dights) ?? defaultValue;
|
|
2076
|
+
},
|
|
2077
|
+
string(key, defaultValue = "") {
|
|
2078
|
+
return targetObject[key] || defaultValue;
|
|
2079
|
+
},
|
|
2080
|
+
list(key, type, defaultValue = []) {
|
|
2081
|
+
if (!(key in targetObject)) {
|
|
2082
|
+
return defaultValue;
|
|
2083
|
+
}
|
|
2084
|
+
const parsers = {
|
|
2085
|
+
int: _parseInt,
|
|
2086
|
+
bool: parseBoolean,
|
|
2087
|
+
decimal: (v) => parseDecimal(v, 2),
|
|
2088
|
+
string: (v) => v
|
|
2089
|
+
};
|
|
2090
|
+
return targetObject[key].split(",").map((value, idx) => {
|
|
2091
|
+
const parsedValue = parsers[type](value.trim());
|
|
2092
|
+
if (parsedValue === void 0) {
|
|
2093
|
+
console.warn("Warn! Failed to parse list item as " + type, {
|
|
2094
|
+
key,
|
|
2095
|
+
idx,
|
|
2096
|
+
type,
|
|
2097
|
+
value
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
return parsedValue;
|
|
2101
|
+
}).filter((v) => v !== void 0);
|
|
2102
|
+
},
|
|
2103
|
+
json(key, defaultValue = null) {
|
|
2104
|
+
if (!(key in targetObject)) {
|
|
2105
|
+
return defaultValue;
|
|
2106
|
+
}
|
|
2107
|
+
try {
|
|
2108
|
+
return JSON.parse(targetObject[key]);
|
|
2109
|
+
} catch (err) {
|
|
2110
|
+
console.warn("Failed to parse json env variable", key);
|
|
2111
|
+
return defaultValue;
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2116
|
+
function parseBoolean(value) {
|
|
2117
|
+
if (value === "true") return true;
|
|
2118
|
+
if (value === "false") return false;
|
|
2119
|
+
return void 0;
|
|
2120
|
+
}
|
|
2121
|
+
function _parseInt(value) {
|
|
2122
|
+
const parsed = parseInt(value);
|
|
2123
|
+
return isNumber(parsed) ? parsed : void 0;
|
|
2124
|
+
}
|
|
2125
|
+
function parseDecimal(value, dights) {
|
|
2126
|
+
const parsed = parseFloat(value);
|
|
2127
|
+
return isNumber(parsed) ? isNumber(dights) ? round2digits(parsed, dights) : parsed : void 0;
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
const CODE_TO_MESSAGE = Object.freeze({
|
|
2131
|
+
101: "Switching Protocols",
|
|
2132
|
+
102: "Processing",
|
|
2133
|
+
200: "Ok",
|
|
2134
|
+
201: "Created",
|
|
2135
|
+
204: "No Content",
|
|
2136
|
+
301: "Moved Permanently",
|
|
2137
|
+
400: "Bad Request",
|
|
2138
|
+
401: "Unauthorized",
|
|
2139
|
+
403: "Forbidden",
|
|
2140
|
+
404: "Not Found",
|
|
2141
|
+
409: "Already Exists",
|
|
2142
|
+
500: "Internal Server Error"
|
|
2143
|
+
});
|
|
2144
|
+
class AppError extends Error {
|
|
2145
|
+
code;
|
|
2146
|
+
constructor(messageOrCode, code = 500, options) {
|
|
2147
|
+
let message = "Unknown error";
|
|
2148
|
+
if (isNumber(messageOrCode)) {
|
|
2149
|
+
code = messageOrCode;
|
|
2150
|
+
message = CODE_TO_MESSAGE[code] || "Unknown error";
|
|
2151
|
+
} else {
|
|
2152
|
+
message = messageOrCode || CODE_TO_MESSAGE[code] || "Unknown error";
|
|
2153
|
+
}
|
|
2154
|
+
super(message, options);
|
|
2155
|
+
if (typeof Error.captureStackTrace !== "function") {
|
|
2156
|
+
this.stack = new Error().stack;
|
|
2157
|
+
} else {
|
|
2158
|
+
Error.captureStackTrace(this, AppError);
|
|
2159
|
+
}
|
|
2160
|
+
this.code = code;
|
|
2161
|
+
}
|
|
2162
|
+
/**
|
|
2163
|
+
* alias for `code` property
|
|
2164
|
+
*/
|
|
2165
|
+
get statusCode() {
|
|
2166
|
+
return this.code;
|
|
2167
|
+
}
|
|
2168
|
+
get name() {
|
|
2169
|
+
return "AppError";
|
|
2170
|
+
}
|
|
2171
|
+
static is(value) {
|
|
2172
|
+
return value instanceof AppError || value?.name === "AppError";
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
class BrowserAssertionError extends Error {
|
|
2177
|
+
/**
|
|
2178
|
+
* Set to the `actual` argument for methods such as {@link assert.strictEqual()}.
|
|
2179
|
+
*/
|
|
2180
|
+
actual;
|
|
2181
|
+
/**
|
|
2182
|
+
* Set to the `expected` argument for methods such as {@link assert.strictEqual()}.
|
|
2183
|
+
*/
|
|
2184
|
+
expected;
|
|
2185
|
+
/**
|
|
2186
|
+
* Set to the passed in operator value.
|
|
2187
|
+
*/
|
|
2188
|
+
operator;
|
|
2189
|
+
/**
|
|
2190
|
+
* Indicates if the message was auto-generated (`true`) or not.
|
|
2191
|
+
*/
|
|
2192
|
+
generatedMessage;
|
|
2193
|
+
/**
|
|
2194
|
+
* Value is always `ERR_ASSERTION` to show that the error is an assertion error.
|
|
2195
|
+
*/
|
|
2196
|
+
code;
|
|
2197
|
+
constructor(options) {
|
|
2198
|
+
super(options?.message);
|
|
2199
|
+
this.actual = options?.actual;
|
|
2200
|
+
this.expected = options?.expected;
|
|
2201
|
+
this.operator = options?.operator ?? "none";
|
|
2202
|
+
this.generatedMessage = false;
|
|
2203
|
+
this.code = "ERR_ASSERTION";
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
const BrowserAssertionError$1 = {
|
|
2208
|
+
__proto__: null,
|
|
2209
|
+
BrowserAssertionError: BrowserAssertionError
|
|
2210
|
+
};
|
|
2211
|
+
|
|
2212
|
+
function isSuccess(value) {
|
|
2213
|
+
return value.success === true;
|
|
2214
|
+
}
|
|
2215
|
+
function isSkip(value) {
|
|
2216
|
+
return value.skip === true;
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
function getFileExtension(name, withDot = true) {
|
|
2220
|
+
if (!isString(name)) {
|
|
2221
|
+
return null;
|
|
2222
|
+
}
|
|
2223
|
+
const ext = name.split(".").at(-1)?.split("?")?.at(0);
|
|
2224
|
+
return ext ? withDot ? ext : `.${ext}` : null;
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
const DEF_PROTOCOLS = ["http://", "https://"];
|
|
2228
|
+
function hasProtocol(url, protocols = DEF_PROTOCOLS) {
|
|
2229
|
+
if (!isString(url)) return false;
|
|
2230
|
+
return protocols.some((v) => url.startsWith(v));
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2233
|
+
function getFileName(value) {
|
|
2234
|
+
if (hasProtocol(value)) {
|
|
2235
|
+
return getFileName(decodeURI(value.split("/").at(-1)?.split("?")?.at(0)));
|
|
2236
|
+
}
|
|
2237
|
+
if (!isString(value)) return null;
|
|
2238
|
+
const ext = getFileExtension(value, true);
|
|
2239
|
+
if (!ext) {
|
|
2240
|
+
return value;
|
|
2241
|
+
}
|
|
2242
|
+
return value.slice(0, -ext.length - 1);
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
function humanFileSize(bytes, digits = 1, withSpace = true) {
|
|
2246
|
+
const thresh = 1024;
|
|
2247
|
+
const units = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
2248
|
+
if (Math.abs(bytes) < thresh) {
|
|
2249
|
+
return (bytes / thresh).toFixed(digits) + ` ${units[0]}`;
|
|
2250
|
+
}
|
|
2251
|
+
let u = -1;
|
|
2252
|
+
const r = 10 ** digits;
|
|
2253
|
+
do {
|
|
2254
|
+
bytes /= thresh;
|
|
2255
|
+
++u;
|
|
2256
|
+
} while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
|
|
2257
|
+
return bytes.toFixed(digits) + (withSpace ? " " : "") + units[u];
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
function sprintf(line, args, unusedArgs = []) {
|
|
2261
|
+
let result = "";
|
|
2262
|
+
const argsLen = args.length;
|
|
2263
|
+
const lineLen = line.length;
|
|
2264
|
+
let opened = false;
|
|
2265
|
+
let currentChar = -1;
|
|
2266
|
+
let lastPos = 0;
|
|
2267
|
+
let argsIndex = 0;
|
|
2268
|
+
for (let idx = 0; idx < lineLen; idx++) {
|
|
2269
|
+
currentChar = line.charCodeAt(idx);
|
|
2270
|
+
if (currentChar === 37) {
|
|
2271
|
+
opened = true;
|
|
2272
|
+
continue;
|
|
2273
|
+
}
|
|
2274
|
+
if (!opened) continue;
|
|
2275
|
+
opened = false;
|
|
2276
|
+
switch (currentChar) {
|
|
2277
|
+
// 'd'
|
|
2278
|
+
case 100:
|
|
2279
|
+
// 'f'
|
|
2280
|
+
case 102: {
|
|
2281
|
+
result += line.slice(lastPos, idx - 1);
|
|
2282
|
+
result += Number(args[argsIndex]);
|
|
2283
|
+
lastPos = idx + 1;
|
|
2284
|
+
argsIndex++;
|
|
2285
|
+
break;
|
|
2286
|
+
}
|
|
2287
|
+
// 'i'
|
|
2288
|
+
case 105: {
|
|
2289
|
+
result += line.slice(lastPos, idx - 1);
|
|
2290
|
+
result += Math.floor(Number(args[argsIndex]));
|
|
2291
|
+
lastPos = idx + 1;
|
|
2292
|
+
argsIndex++;
|
|
2293
|
+
break;
|
|
2294
|
+
}
|
|
2295
|
+
// 'O'
|
|
2296
|
+
case 79:
|
|
2297
|
+
// 'o'
|
|
2298
|
+
case 111:
|
|
2299
|
+
// 'j'
|
|
2300
|
+
case 106: {
|
|
2301
|
+
result += line.slice(lastPos, idx - 1);
|
|
2302
|
+
result += tryStringify(args[argsIndex]);
|
|
2303
|
+
lastPos = idx + 1;
|
|
2304
|
+
argsIndex++;
|
|
2305
|
+
break;
|
|
2306
|
+
}
|
|
2307
|
+
// 's'
|
|
2308
|
+
case 115: {
|
|
2309
|
+
result += line.slice(lastPos, idx - 1);
|
|
2310
|
+
result += String(args[argsIndex]);
|
|
2311
|
+
lastPos = idx + 1;
|
|
2312
|
+
argsIndex++;
|
|
2313
|
+
break;
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
if (argsIndex >= argsLen) break;
|
|
2317
|
+
}
|
|
2318
|
+
if (lastPos < lineLen) {
|
|
2319
|
+
result += line.slice(lastPos, lineLen);
|
|
2320
|
+
}
|
|
2321
|
+
if (argsIndex < argsLen) {
|
|
2322
|
+
unusedArgs.push(...args.slice(argsIndex, argsLen));
|
|
2323
|
+
}
|
|
2324
|
+
return result;
|
|
2325
|
+
}
|
|
2326
|
+
function tryStringify(o) {
|
|
2327
|
+
switch (typeof o) {
|
|
2328
|
+
case "function": {
|
|
2329
|
+
return o.name || "<anonymous>";
|
|
2330
|
+
}
|
|
2331
|
+
case "string": {
|
|
2332
|
+
return "'" + o + "'";
|
|
2333
|
+
}
|
|
2334
|
+
default: {
|
|
2335
|
+
try {
|
|
2336
|
+
return JSON.stringify(o);
|
|
2337
|
+
} catch (e) {
|
|
2338
|
+
return '"[Circular]"';
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2344
|
+
const IS_DEV = env.isDevelopment || env.bool("DEV", false);
|
|
2345
|
+
const logger = (...baseArgs) => {
|
|
2346
|
+
if (typeof baseArgs[0] === "string" && baseArgs[0][0] !== "[") {
|
|
2347
|
+
baseArgs[0] = `[${baseArgs[0].split("/").at(-1).split("?", 1)[0]}]`;
|
|
2348
|
+
}
|
|
2349
|
+
const writeLog = (level, ...[pattern, ...args]) => {
|
|
2350
|
+
if (!isString(pattern)) {
|
|
2351
|
+
console[level](...baseArgs, pattern, ...args);
|
|
2352
|
+
return;
|
|
2353
|
+
}
|
|
2354
|
+
const unusedArgs = [];
|
|
2355
|
+
const formatted = sprintf(pattern, args, unusedArgs);
|
|
2356
|
+
console[level](...baseArgs, ...formatted, ...unusedArgs);
|
|
2357
|
+
};
|
|
2358
|
+
const log = writeLog.bind(null, "log");
|
|
2359
|
+
const info = writeLog.bind(null, "info");
|
|
2360
|
+
const warn = writeLog.bind(null, "warn");
|
|
2361
|
+
const error = writeLog.bind(null, "error");
|
|
2362
|
+
const debug = writeLog.bind(null, "debug");
|
|
2363
|
+
const extend = (...args) => {
|
|
2364
|
+
return logger(...baseArgs, ...args);
|
|
2365
|
+
};
|
|
2366
|
+
const instance = {
|
|
2367
|
+
log,
|
|
2368
|
+
info,
|
|
2369
|
+
warn,
|
|
2370
|
+
error,
|
|
2371
|
+
debug,
|
|
2372
|
+
extend
|
|
2373
|
+
};
|
|
2374
|
+
Object.defineProperty(instance, "debug", {
|
|
2375
|
+
get: () => IS_DEV ? debug : noop
|
|
2376
|
+
});
|
|
2377
|
+
return instance;
|
|
2378
|
+
};
|
|
2379
|
+
|
|
2380
|
+
async function asyncFilter(array, predicate) {
|
|
2381
|
+
const result = [];
|
|
2382
|
+
const cooldown = nextTickIteration(10);
|
|
2383
|
+
for (let idx = 0; idx < array.length; idx++) {
|
|
2384
|
+
await cooldown();
|
|
2385
|
+
const value = array[idx];
|
|
2386
|
+
const valid = await predicate(value, idx, array);
|
|
2387
|
+
if (valid) {
|
|
2388
|
+
result.push(value);
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
return result;
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2394
|
+
const defaultWindow$1 = globalThis?.window;
|
|
2395
|
+
const idle = (() => {
|
|
2396
|
+
if (defaultWindow$1?.requestIdleCallback) {
|
|
2397
|
+
return defaultWindow$1.requestIdleCallback;
|
|
2398
|
+
} else if (defaultWindow$1?.requestAnimationFrame) {
|
|
2399
|
+
return defaultWindow$1.requestAnimationFrame;
|
|
2400
|
+
} else if (isFunction(process?.nextTick)) {
|
|
2401
|
+
return process.nextTick;
|
|
2402
|
+
} else {
|
|
2403
|
+
return (fn) => setTimeout(fn, 0);
|
|
2404
|
+
}
|
|
2405
|
+
})();
|
|
2406
|
+
function fastIdle(callback) {
|
|
2407
|
+
return idle(callback);
|
|
2408
|
+
}
|
|
2409
|
+
function fastIdlePromise() {
|
|
2410
|
+
return new Promise((resolve) => idle(resolve));
|
|
2411
|
+
}
|
|
2412
|
+
|
|
2413
|
+
function nextTickIteration(amount, delay = "tick") {
|
|
2414
|
+
let counter = 0;
|
|
2415
|
+
const tickInterval = delay === "tick";
|
|
2416
|
+
return () => {
|
|
2417
|
+
counter++;
|
|
2418
|
+
if (counter >= amount) {
|
|
2419
|
+
counter = 0;
|
|
2420
|
+
return new Promise((resolve) => {
|
|
2421
|
+
if (tickInterval) {
|
|
2422
|
+
fastIdle(resolve);
|
|
2423
|
+
} else {
|
|
2424
|
+
setTimeout(resolve, delay);
|
|
2425
|
+
}
|
|
2426
|
+
});
|
|
2427
|
+
}
|
|
2428
|
+
return Promise.resolve();
|
|
2429
|
+
};
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
async function asyncFind(array, callbackfn) {
|
|
2433
|
+
const cooldown = nextTickIteration(10);
|
|
2434
|
+
let i = 0;
|
|
2435
|
+
while (i < array.length) {
|
|
2436
|
+
await cooldown();
|
|
2437
|
+
const result = await callbackfn(array[i], i, array);
|
|
2438
|
+
if (Boolean(result)) {
|
|
2439
|
+
return array[i];
|
|
2440
|
+
}
|
|
2441
|
+
i++;
|
|
2442
|
+
}
|
|
2443
|
+
return void 0;
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
async function asyncForEach(array, callbackfn, { concurrency = 1 } = {}) {
|
|
2447
|
+
const cooldown = nextTickIteration(10);
|
|
2448
|
+
let i = 0;
|
|
2449
|
+
const handle = (value, index) => {
|
|
2450
|
+
return callbackfn(value, i + index, array);
|
|
2451
|
+
};
|
|
2452
|
+
while (i < array.length) {
|
|
2453
|
+
await cooldown();
|
|
2454
|
+
const batch = await Promise.all(
|
|
2455
|
+
array.slice(i, i + concurrency).map(handle)
|
|
2456
|
+
);
|
|
2457
|
+
i += batch.length;
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
function defer() {
|
|
2462
|
+
let resolve;
|
|
2463
|
+
let reject;
|
|
2464
|
+
const promise = new Promise((_resolve, _reject) => {
|
|
2465
|
+
resolve = _resolve;
|
|
2466
|
+
reject = _reject;
|
|
2467
|
+
});
|
|
2468
|
+
return {
|
|
2469
|
+
resolve,
|
|
2470
|
+
reject,
|
|
2471
|
+
promise
|
|
2472
|
+
};
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
const onError = (error) => {
|
|
2476
|
+
console.error(error);
|
|
2477
|
+
};
|
|
2478
|
+
class SimpleEventEmitter {
|
|
2479
|
+
#listeners = /* @__PURE__ */ new Map();
|
|
2480
|
+
constructor() {
|
|
2481
|
+
this.on("error", onError);
|
|
2482
|
+
}
|
|
2483
|
+
static once(emitter, eventName) {
|
|
2484
|
+
const q = defer();
|
|
2485
|
+
emitter.once(eventName, (...args) => q.resolve(args));
|
|
2486
|
+
return q.promise;
|
|
2487
|
+
}
|
|
2488
|
+
emit(eventName, ...args) {
|
|
2489
|
+
const set = this.#listeners.get(eventName);
|
|
2490
|
+
if (!set) return false;
|
|
2491
|
+
set.forEach((fn) => {
|
|
2492
|
+
try {
|
|
2493
|
+
const result = fn();
|
|
2494
|
+
if (isPromise(result)) {
|
|
2495
|
+
result.catch((err) => {
|
|
2496
|
+
this.emit("error", err);
|
|
2497
|
+
});
|
|
2498
|
+
}
|
|
2499
|
+
} catch (err) {
|
|
2500
|
+
this.emit("error", err);
|
|
2501
|
+
}
|
|
2502
|
+
});
|
|
2503
|
+
return true;
|
|
2504
|
+
}
|
|
2505
|
+
on(eventName, listener) {
|
|
2506
|
+
if (!this.#listeners.has(eventName)) {
|
|
2507
|
+
this.#listeners.set(eventName, /* @__PURE__ */ new Set());
|
|
2508
|
+
}
|
|
2509
|
+
const set = this.#listeners.get(eventName);
|
|
2510
|
+
set.add(listener);
|
|
2511
|
+
return this;
|
|
2512
|
+
}
|
|
2513
|
+
once(eventName, listener) {
|
|
2514
|
+
const wrapped = (...args) => {
|
|
2515
|
+
this.off(eventName, wrapped);
|
|
2516
|
+
listener(...args);
|
|
2517
|
+
};
|
|
2518
|
+
this.on(eventName, wrapped);
|
|
2519
|
+
return this;
|
|
2520
|
+
}
|
|
2521
|
+
off(eventName, listener) {
|
|
2522
|
+
const set = this.#listeners.get(eventName);
|
|
2523
|
+
if (set) {
|
|
2524
|
+
set.delete(listener);
|
|
2525
|
+
if (set.size === 0) {
|
|
2526
|
+
this.#listeners.delete(eventName);
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
return this;
|
|
2530
|
+
}
|
|
2531
|
+
removeAllListeners(eventName) {
|
|
2532
|
+
if (eventName === void 0) {
|
|
2533
|
+
this.#listeners.clear();
|
|
2534
|
+
return this;
|
|
2535
|
+
}
|
|
2536
|
+
this.#listeners.delete(eventName);
|
|
2537
|
+
return this;
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2541
|
+
class Queue {
|
|
2542
|
+
items = [];
|
|
2543
|
+
#limit;
|
|
2544
|
+
#events = new SimpleEventEmitter();
|
|
2545
|
+
constructor(limit) {
|
|
2546
|
+
this.#limit = limit;
|
|
2547
|
+
}
|
|
2548
|
+
async get() {
|
|
2549
|
+
if (this.items.length === 0) {
|
|
2550
|
+
await SimpleEventEmitter.once(this.#events, "put");
|
|
2551
|
+
}
|
|
2552
|
+
const item = this.items.shift();
|
|
2553
|
+
this.#events.emit("get");
|
|
2554
|
+
return item;
|
|
2555
|
+
}
|
|
2556
|
+
async put(item) {
|
|
2557
|
+
if (this.#limit && this.items.length >= this.#limit) {
|
|
2558
|
+
await SimpleEventEmitter.once(this.#events, "get");
|
|
2559
|
+
}
|
|
2560
|
+
this.items.push(item);
|
|
2561
|
+
this.#events.emit("put");
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2565
|
+
class AsyncIterableQueue {
|
|
2566
|
+
_queue;
|
|
2567
|
+
_closed = false;
|
|
2568
|
+
static QUEUE_END_MARKER = Symbol("QUEUE_END_MARKER");
|
|
2569
|
+
constructor() {
|
|
2570
|
+
this._queue = new Queue();
|
|
2571
|
+
}
|
|
2572
|
+
get closed() {
|
|
2573
|
+
return this._closed;
|
|
2574
|
+
}
|
|
2575
|
+
put(item) {
|
|
2576
|
+
if (this._closed) {
|
|
2577
|
+
throw new Error("Queue is closed");
|
|
2578
|
+
}
|
|
2579
|
+
this._queue.put(item);
|
|
2580
|
+
}
|
|
2581
|
+
close() {
|
|
2582
|
+
if (this._closed) return;
|
|
2583
|
+
this._closed = true;
|
|
2584
|
+
this._queue.put(AsyncIterableQueue.QUEUE_END_MARKER);
|
|
2585
|
+
}
|
|
2586
|
+
[Symbol.asyncIterator]() {
|
|
2587
|
+
return {
|
|
2588
|
+
next: async () => {
|
|
2589
|
+
if (this._closed && this._queue.items.length === 0) {
|
|
2590
|
+
return { value: void 0, done: true };
|
|
2591
|
+
}
|
|
2592
|
+
const item = await this._queue.get();
|
|
2593
|
+
if (item === AsyncIterableQueue.QUEUE_END_MARKER && this._closed) {
|
|
2594
|
+
return { value: void 0, done: true };
|
|
2595
|
+
}
|
|
2596
|
+
return { value: item, done: false };
|
|
2597
|
+
}
|
|
2598
|
+
};
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
|
|
2602
|
+
async function asyncMap(array, callbackfn, { concurrency = 1 } = {}) {
|
|
2603
|
+
let result = [];
|
|
2604
|
+
concurrency = Math.max(concurrency, 1);
|
|
2605
|
+
const cooldown = nextTickIteration(10);
|
|
2606
|
+
let i = 0;
|
|
2607
|
+
const handle = (value, index) => {
|
|
2608
|
+
return callbackfn(value, i + index, array);
|
|
2609
|
+
};
|
|
2610
|
+
while (i < array.length) {
|
|
2611
|
+
await cooldown();
|
|
2612
|
+
const batch = await Promise.all(
|
|
2613
|
+
array.slice(i, i + concurrency).map(handle)
|
|
2614
|
+
);
|
|
2615
|
+
result = result.concat(batch);
|
|
2616
|
+
i += batch.length;
|
|
2617
|
+
}
|
|
2618
|
+
return result;
|
|
2619
|
+
}
|
|
2620
|
+
|
|
2621
|
+
class CancellablePromise {
|
|
2622
|
+
#promise;
|
|
2623
|
+
#cancelFns;
|
|
2624
|
+
#isCancelled = false;
|
|
2625
|
+
#error = null;
|
|
2626
|
+
constructor(executor) {
|
|
2627
|
+
this.#cancelFns = [];
|
|
2628
|
+
this.#promise = new Promise((resolve, reject) => {
|
|
2629
|
+
executor(
|
|
2630
|
+
resolve,
|
|
2631
|
+
(reason) => {
|
|
2632
|
+
this.#error = toError(reason, "Unknown rejection reason.");
|
|
2633
|
+
reject(reason);
|
|
2634
|
+
},
|
|
2635
|
+
(fn) => {
|
|
2636
|
+
this.#cancelFns.push(fn);
|
|
2637
|
+
}
|
|
2638
|
+
);
|
|
2639
|
+
});
|
|
2640
|
+
}
|
|
2641
|
+
get [Symbol.toStringTag]() {
|
|
2642
|
+
return this.#promise[Symbol.toStringTag] + (this.isCancelled ? " (Cancelled)" : "");
|
|
2643
|
+
}
|
|
2644
|
+
get isCancelled() {
|
|
2645
|
+
return this.#isCancelled;
|
|
2646
|
+
}
|
|
2647
|
+
get error() {
|
|
2648
|
+
return this.#error;
|
|
2649
|
+
}
|
|
2650
|
+
then(onfulfilled, onrejected) {
|
|
2651
|
+
return this.#promise.then(onfulfilled, onrejected);
|
|
2652
|
+
}
|
|
2653
|
+
catch(onrejected) {
|
|
2654
|
+
return this.#promise.catch(onrejected);
|
|
2655
|
+
}
|
|
2656
|
+
finally(onfinally) {
|
|
2657
|
+
return this.#promise.finally(onfinally);
|
|
2658
|
+
}
|
|
2659
|
+
cancel() {
|
|
2660
|
+
if (this.#isCancelled) return;
|
|
2661
|
+
this.#isCancelled = true;
|
|
2662
|
+
for (const fn of this.#cancelFns) {
|
|
2663
|
+
catchError(fn);
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
static from(promise) {
|
|
2667
|
+
return new CancellablePromise((resolve, reject) => {
|
|
2668
|
+
promise.then(resolve).catch(reject);
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
function delay(amount = "tick") {
|
|
2674
|
+
const d = defer();
|
|
2675
|
+
if (amount === "tick") {
|
|
2676
|
+
fastIdle(d.resolve);
|
|
2677
|
+
} else {
|
|
2678
|
+
setTimeout(d.resolve, amount);
|
|
2679
|
+
}
|
|
2680
|
+
return d.promise;
|
|
2681
|
+
}
|
|
2682
|
+
|
|
2683
|
+
const FAST_RAF_TIMEOUT_FALLBACK_MS = 300;
|
|
2684
|
+
const defaultWindow = globalThis?.window;
|
|
2685
|
+
const raf = defaultWindow?.requestAnimationFrame || ((cb) => setTimeout(cb, 0));
|
|
2686
|
+
let fastRafCallbacks;
|
|
2687
|
+
let fastRafFallbackCallbacks;
|
|
2688
|
+
let fastRafFallbackTimeout;
|
|
2689
|
+
function fastRaf(callback, withTimeoutFallback = false) {
|
|
2690
|
+
if (!fastRafCallbacks) {
|
|
2691
|
+
fastRafCallbacks = /* @__PURE__ */ new Set([callback]);
|
|
2692
|
+
raf(() => {
|
|
2693
|
+
const currentCallbacks = fastRafCallbacks;
|
|
2694
|
+
fastRafCallbacks = void 0;
|
|
2695
|
+
fastRafFallbackCallbacks = void 0;
|
|
2696
|
+
if (fastRafFallbackTimeout) {
|
|
2697
|
+
clearTimeout(fastRafFallbackTimeout);
|
|
2698
|
+
fastRafFallbackTimeout = void 0;
|
|
2699
|
+
}
|
|
2700
|
+
currentCallbacks.forEach((cb) => cb());
|
|
2701
|
+
});
|
|
2702
|
+
} else {
|
|
2703
|
+
fastRafCallbacks.add(callback);
|
|
2704
|
+
}
|
|
2705
|
+
if (withTimeoutFallback) {
|
|
2706
|
+
if (!fastRafFallbackCallbacks) {
|
|
2707
|
+
fastRafFallbackCallbacks = /* @__PURE__ */ new Set([callback]);
|
|
2708
|
+
} else {
|
|
2709
|
+
fastRafFallbackCallbacks.add(callback);
|
|
2710
|
+
}
|
|
2711
|
+
if (!fastRafFallbackTimeout) {
|
|
2712
|
+
fastRafFallbackTimeout = setTimeout(() => {
|
|
2713
|
+
const currentTimeoutCallbacks = fastRafFallbackCallbacks;
|
|
2714
|
+
if (fastRafCallbacks) {
|
|
2715
|
+
currentTimeoutCallbacks.forEach(
|
|
2716
|
+
fastRafCallbacks.delete,
|
|
2717
|
+
fastRafCallbacks
|
|
2718
|
+
);
|
|
2719
|
+
}
|
|
2720
|
+
fastRafFallbackCallbacks = void 0;
|
|
2721
|
+
if (fastRafFallbackTimeout) {
|
|
2722
|
+
clearTimeout(fastRafFallbackTimeout);
|
|
2723
|
+
fastRafFallbackTimeout = void 0;
|
|
2724
|
+
}
|
|
2725
|
+
currentTimeoutCallbacks.forEach((cb) => cb());
|
|
2726
|
+
}, FAST_RAF_TIMEOUT_FALLBACK_MS);
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
function rafPromise() {
|
|
2731
|
+
return new Promise((resolve) => {
|
|
2732
|
+
fastRaf(resolve);
|
|
2733
|
+
});
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
function timeout(ms, promiseOrCallback, timeoutError = new Error("Timeout")) {
|
|
2737
|
+
const abortController = new AbortController();
|
|
2738
|
+
let taskResult;
|
|
2739
|
+
if (isFunction(promiseOrCallback)) {
|
|
2740
|
+
taskResult = promiseOrCallback(abortController.signal);
|
|
2741
|
+
} else if (isPromise(promiseOrCallback)) {
|
|
2742
|
+
taskResult = promiseOrCallback;
|
|
2743
|
+
} else {
|
|
2744
|
+
throw new TypeError(
|
|
2745
|
+
"Expected promise or callback as second argument, received: " + String(promiseOrCallback)
|
|
2746
|
+
);
|
|
2747
|
+
}
|
|
2748
|
+
if (!isPromise(taskResult)) {
|
|
2749
|
+
return Promise.resolve(taskResult);
|
|
2750
|
+
}
|
|
2751
|
+
let timer;
|
|
2752
|
+
return Promise.race([
|
|
2753
|
+
taskResult,
|
|
2754
|
+
new Promise((_, reject) => {
|
|
2755
|
+
timer = setTimeout(() => {
|
|
2756
|
+
abortController.abort();
|
|
2757
|
+
reject(timeoutError);
|
|
2758
|
+
}, ms);
|
|
2759
|
+
})
|
|
2760
|
+
]).finally(() => {
|
|
2761
|
+
timer && clearTimeout(timer);
|
|
2762
|
+
timer = void 0;
|
|
2763
|
+
});
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2766
|
+
function typeOf(value) {
|
|
2767
|
+
const type = typeof value;
|
|
2768
|
+
switch (type) {
|
|
2769
|
+
case "number":
|
|
2770
|
+
return isNumber(value) ? "number" : "unknown";
|
|
2771
|
+
case "object": {
|
|
2772
|
+
if (value === null) return "null";
|
|
2773
|
+
if (Array.isArray(value)) return "array";
|
|
2774
|
+
if (isSet(value)) return "set";
|
|
2775
|
+
if (isWeakSet$1(value)) return "weakset";
|
|
2776
|
+
if (isMap(value)) return "map";
|
|
2777
|
+
if (isWeakMap$1(value)) return "weakmap";
|
|
2778
|
+
if (isDate(value)) return "date";
|
|
2779
|
+
if (isObject(value)) return "object";
|
|
2780
|
+
return "unknown";
|
|
2781
|
+
}
|
|
2782
|
+
default: {
|
|
2783
|
+
return type;
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2788
|
+
const qs = {
|
|
2789
|
+
toParams,
|
|
2790
|
+
stringify,
|
|
2791
|
+
stringifyValue,
|
|
2792
|
+
parse,
|
|
2793
|
+
parseValue,
|
|
2794
|
+
merge
|
|
2795
|
+
};
|
|
2796
|
+
function merge(...values) {
|
|
2797
|
+
const result = {};
|
|
2798
|
+
for (const filter of values) {
|
|
2799
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
2800
|
+
const currentValue = result[key];
|
|
2801
|
+
const currentType = typeOf(currentValue);
|
|
2802
|
+
const filterType = typeOf(value);
|
|
2803
|
+
if (currentType !== filterType) {
|
|
2804
|
+
result[key] = value;
|
|
2805
|
+
continue;
|
|
2806
|
+
}
|
|
2807
|
+
switch (currentType) {
|
|
2808
|
+
case "array": {
|
|
2809
|
+
result[key] = Array.from(/* @__PURE__ */ new Set([...currentValue, ...value]));
|
|
2810
|
+
break;
|
|
2811
|
+
}
|
|
2812
|
+
case "object": {
|
|
2813
|
+
result[key] = {};
|
|
2814
|
+
deepAssign(result[key], currentValue);
|
|
2815
|
+
deepAssign(result[key], value);
|
|
2816
|
+
break;
|
|
2817
|
+
}
|
|
2818
|
+
case "map": {
|
|
2819
|
+
result[key] = new Map([
|
|
2820
|
+
...Array.from(currentValue.entries()),
|
|
2821
|
+
...Array.from(value.entries())
|
|
2822
|
+
]);
|
|
2823
|
+
break;
|
|
2824
|
+
}
|
|
2825
|
+
case "set": {
|
|
2826
|
+
result[key] = /* @__PURE__ */ new Set([
|
|
2827
|
+
...Array.from(currentValue),
|
|
2828
|
+
...Array.from(value)
|
|
2829
|
+
]);
|
|
2830
|
+
break;
|
|
2831
|
+
}
|
|
2832
|
+
default: {
|
|
2833
|
+
result[key] = value;
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
return result;
|
|
2839
|
+
}
|
|
2840
|
+
function stringify(obj, options) {
|
|
2841
|
+
return new URLSearchParams(toParams(obj, options)).toString();
|
|
2842
|
+
}
|
|
2843
|
+
function toParams(obj, options) {
|
|
2844
|
+
const result = {};
|
|
2845
|
+
const excludeEmpty = options?.excludeEmpty !== false;
|
|
2846
|
+
const excludeDefaults = options?.excludeDefaults;
|
|
2847
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
2848
|
+
if (excludeEmpty && isEmpty(value)) continue;
|
|
2849
|
+
if (excludeDefaults && key in excludeDefaults) {
|
|
2850
|
+
const defValue = excludeDefaults[key];
|
|
2851
|
+
if (isEqual(value, defValue)) continue;
|
|
2852
|
+
}
|
|
2853
|
+
const strValue = stringifyValue(value);
|
|
2854
|
+
if (excludeEmpty && strValue === "") {
|
|
2855
|
+
continue;
|
|
2856
|
+
}
|
|
2857
|
+
result[key] = strValue;
|
|
2858
|
+
}
|
|
2859
|
+
return result;
|
|
2860
|
+
}
|
|
2861
|
+
function parse(value, defaults) {
|
|
2862
|
+
const objValue = isString(value) ? Object.fromEntries(new URLSearchParams(value).entries()) : value;
|
|
2863
|
+
if (!defaults) {
|
|
2864
|
+
return { ...objValue };
|
|
2865
|
+
}
|
|
2866
|
+
const result = {};
|
|
2867
|
+
for (const [key, defValue] of Object.entries(defaults)) {
|
|
2868
|
+
const defType = typeOf(defValue);
|
|
2869
|
+
let parsedValue = parseValue(objValue[key], defType);
|
|
2870
|
+
if (parsedValue !== void 0 || defType === "undefined") {
|
|
2871
|
+
if (defType === "array" && defValue[0] !== void 0) {
|
|
2872
|
+
const itemValue = typeOf(defValue[0]);
|
|
2873
|
+
parsedValue = parsedValue.map((v) => parseValue(v, itemValue));
|
|
2874
|
+
}
|
|
2875
|
+
result[key] = parsedValue;
|
|
2876
|
+
} else {
|
|
2877
|
+
result[key] = defValue;
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
return result;
|
|
2881
|
+
}
|
|
2882
|
+
function stringifyValue(value) {
|
|
2883
|
+
const valueType = typeOf(value);
|
|
2884
|
+
switch (valueType) {
|
|
2885
|
+
case "undefined": {
|
|
2886
|
+
return "";
|
|
2887
|
+
}
|
|
2888
|
+
case "null": {
|
|
2889
|
+
return "";
|
|
2890
|
+
}
|
|
2891
|
+
case "array": {
|
|
2892
|
+
let result = "";
|
|
2893
|
+
let sep = "";
|
|
2894
|
+
for (const item of value) {
|
|
2895
|
+
if (item === void 0) continue;
|
|
2896
|
+
if (isObject(item) || Array.isArray(item) || isString(item) && item.includes(",")) {
|
|
2897
|
+
result = JSON.stringify(value);
|
|
2898
|
+
break;
|
|
2899
|
+
} else {
|
|
2900
|
+
result += sep + stringifyValue(item);
|
|
2901
|
+
sep = ",";
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
return result;
|
|
2905
|
+
}
|
|
2906
|
+
case "date": {
|
|
2907
|
+
return value.toISOString();
|
|
2908
|
+
}
|
|
2909
|
+
case "map": {
|
|
2910
|
+
return JSON.stringify(Array.from(value.entries()));
|
|
2911
|
+
}
|
|
2912
|
+
case "set": {
|
|
2913
|
+
return JSON.stringify(Array.from(value.values()));
|
|
2914
|
+
}
|
|
2915
|
+
case "boolean":
|
|
2916
|
+
case "number":
|
|
2917
|
+
case "string":
|
|
2918
|
+
case "bigint": {
|
|
2919
|
+
return String(value);
|
|
2920
|
+
}
|
|
2921
|
+
case "object": {
|
|
2922
|
+
return JSON.stringify(value);
|
|
2923
|
+
}
|
|
2924
|
+
case "unknown": {
|
|
2925
|
+
if (isFunction(value?.toString)) {
|
|
2926
|
+
return value.toString();
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
default: {
|
|
2930
|
+
throw new Error("Attempt to stringify unsupported type: " + valueType);
|
|
2931
|
+
}
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
function parseValue(value, asType) {
|
|
2935
|
+
const type = typeOf(value);
|
|
2936
|
+
if (type === asType) {
|
|
2937
|
+
return value;
|
|
2938
|
+
} else if (type !== "string") {
|
|
2939
|
+
return void 0;
|
|
2940
|
+
}
|
|
2941
|
+
try {
|
|
2942
|
+
switch (asType) {
|
|
2943
|
+
case "undefined": {
|
|
2944
|
+
return void 0;
|
|
2945
|
+
}
|
|
2946
|
+
case "array": {
|
|
2947
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
2948
|
+
return JSON.parse(value);
|
|
2949
|
+
}
|
|
2950
|
+
return value.split(",");
|
|
2951
|
+
}
|
|
2952
|
+
case "boolean": {
|
|
2953
|
+
return value === "true";
|
|
2954
|
+
}
|
|
2955
|
+
case "date": {
|
|
2956
|
+
const parsed = new Date(value);
|
|
2957
|
+
return isDate(parsed) ? parsed : void 0;
|
|
2958
|
+
}
|
|
2959
|
+
case "map": {
|
|
2960
|
+
return new Map(JSON.parse(value));
|
|
2961
|
+
}
|
|
2962
|
+
case "number": {
|
|
2963
|
+
const parsed = parseFloat(value);
|
|
2964
|
+
return isNumber(parsed) ? parsed : void 0;
|
|
2965
|
+
}
|
|
2966
|
+
case "object": {
|
|
2967
|
+
return JSON.parse(value);
|
|
2968
|
+
}
|
|
2969
|
+
case "set": {
|
|
2970
|
+
return new Set(JSON.parse(value));
|
|
2971
|
+
}
|
|
2972
|
+
case "null": {
|
|
2973
|
+
return value === "" || value === void 0 ? null : void 0;
|
|
2974
|
+
}
|
|
2975
|
+
case "string": {
|
|
2976
|
+
return value;
|
|
2977
|
+
}
|
|
2978
|
+
case "bigint": {
|
|
2979
|
+
return BigInt(value);
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
} catch (_) {
|
|
2983
|
+
}
|
|
2984
|
+
return void 0;
|
|
2985
|
+
}
|
|
2986
|
+
|
|
2987
|
+
function retryOnError({
|
|
2988
|
+
beforeRetryCallback,
|
|
2989
|
+
maxRetriesNumber,
|
|
2990
|
+
shouldRetryBasedOnError,
|
|
2991
|
+
delayFactor = 0,
|
|
2992
|
+
delayMaxMs = 1e3,
|
|
2993
|
+
delayMinMs = 100
|
|
2994
|
+
}, fn) {
|
|
2995
|
+
let retryCount = maxRetriesNumber;
|
|
2996
|
+
let delayMs = 0;
|
|
2997
|
+
delayMinMs = Math.max(delayMinMs, 1);
|
|
2998
|
+
delayMaxMs = Math.max(delayMaxMs, 1);
|
|
2999
|
+
const run = async (...args) => {
|
|
3000
|
+
if (delayFactor >= 1 && delayMs > 0) {
|
|
3001
|
+
await delay(delayMs);
|
|
3002
|
+
}
|
|
3003
|
+
const currentAttempt = 1 + maxRetriesNumber - retryCount;
|
|
3004
|
+
try {
|
|
3005
|
+
const res = await fn(...args);
|
|
3006
|
+
return res;
|
|
3007
|
+
} catch (e) {
|
|
3008
|
+
if (retryCount > 1 && shouldRetryBasedOnError(e, currentAttempt)) {
|
|
3009
|
+
retryCount--;
|
|
3010
|
+
delayMs = Math.floor(
|
|
3011
|
+
Math.min(Math.max(delayMs, delayMinMs) * delayFactor, delayMaxMs)
|
|
3012
|
+
);
|
|
3013
|
+
if (beforeRetryCallback) {
|
|
3014
|
+
const newParams = await beforeRetryCallback(
|
|
3015
|
+
currentAttempt,
|
|
3016
|
+
retryCount === 0
|
|
3017
|
+
);
|
|
3018
|
+
if (newParams) {
|
|
3019
|
+
return run(newParams);
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3022
|
+
return run(...args);
|
|
3023
|
+
}
|
|
3024
|
+
throw e;
|
|
3025
|
+
}
|
|
3026
|
+
};
|
|
3027
|
+
return run;
|
|
3028
|
+
}
|
|
3029
|
+
|
|
3030
|
+
function capitalize(str) {
|
|
3031
|
+
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
3032
|
+
}
|
|
3033
|
+
|
|
3034
|
+
const CASE_SPLIT_PATTERN = /\p{Lu}?\p{Ll}+|[0-9]+|\p{Lu}+(?!\p{Ll})|\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{L}+/gu;
|
|
3035
|
+
function getWords(str) {
|
|
3036
|
+
if (!isString(str)) return [];
|
|
3037
|
+
return Array.from(str.match(CASE_SPLIT_PATTERN) ?? []);
|
|
3038
|
+
}
|
|
3039
|
+
|
|
3040
|
+
function camelCase(str) {
|
|
3041
|
+
const words = getWords(str);
|
|
3042
|
+
if (words.length === 0) {
|
|
3043
|
+
return "";
|
|
3044
|
+
}
|
|
3045
|
+
const [first, ...rest] = words;
|
|
3046
|
+
return `${first.toLowerCase()}${rest.map((word) => capitalize(word)).join("")}`;
|
|
3047
|
+
}
|
|
3048
|
+
|
|
3049
|
+
function convertToUnit(str, unit = "px") {
|
|
3050
|
+
if (str == null || str === "") {
|
|
3051
|
+
return void 0;
|
|
3052
|
+
} else if (isNaN(+str)) {
|
|
3053
|
+
return String(str);
|
|
3054
|
+
} else {
|
|
3055
|
+
return `${Number(str)}${unit}`;
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3058
|
+
|
|
3059
|
+
const htmlEscapes = Object.freeze({
|
|
3060
|
+
38: "&",
|
|
3061
|
+
// &
|
|
3062
|
+
60: "<",
|
|
3063
|
+
// <
|
|
3064
|
+
62: ">",
|
|
3065
|
+
// >
|
|
3066
|
+
34: """,
|
|
3067
|
+
// "
|
|
3068
|
+
39: "'"
|
|
3069
|
+
// '
|
|
3070
|
+
});
|
|
3071
|
+
function escapeHtml(unsafe) {
|
|
3072
|
+
if (typeof unsafe !== "string") {
|
|
3073
|
+
return "";
|
|
3074
|
+
}
|
|
3075
|
+
let result = "";
|
|
3076
|
+
let strLen = unsafe.length;
|
|
3077
|
+
let char;
|
|
3078
|
+
for (let idx = 0; idx < strLen; idx++) {
|
|
3079
|
+
char = unsafe.charCodeAt(idx);
|
|
3080
|
+
result += htmlEscapes[char] || String.fromCharCode(char);
|
|
3081
|
+
}
|
|
3082
|
+
return result;
|
|
3083
|
+
}
|
|
3084
|
+
|
|
3085
|
+
function escapeNumeric(str) {
|
|
3086
|
+
const result = String(str).replace(/\D/g, "");
|
|
3087
|
+
if (!result.length) {
|
|
3088
|
+
return void 0;
|
|
3089
|
+
}
|
|
3090
|
+
return result;
|
|
3091
|
+
}
|
|
3092
|
+
|
|
3093
|
+
function escapeRegExp(str) {
|
|
3094
|
+
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
3095
|
+
}
|
|
3096
|
+
|
|
3097
|
+
const vs16RegExp = /\uFE0F/g;
|
|
3098
|
+
const zeroWidthJoiner = String.fromCharCode(8205);
|
|
3099
|
+
function removeVS16s(rawEmoji) {
|
|
3100
|
+
return rawEmoji.indexOf(zeroWidthJoiner) < 0 ? rawEmoji.replace(vs16RegExp, "") : rawEmoji;
|
|
3101
|
+
}
|
|
3102
|
+
const TWEMOJI_REGEX = /(?:\ud83d\udc68\ud83c\udffb\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc68\ud83c\udffc\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc68\ud83c\udffd\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc68\ud83c\udffe\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc68\ud83c\udfff\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffb\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffb\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc69\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffc\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffc\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc69\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffd\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffd\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc69\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffe\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffe\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc69\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udfff\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udfff\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc69\ud83c[\udffb-\udfff]|\ud83e\uddd1\ud83c\udffb\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83e\uddd1\ud83c[\udffc-\udfff]|\ud83e\uddd1\ud83c\udffc\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83e\uddd1\ud83c[\udffb\udffd-\udfff]|\ud83e\uddd1\ud83c\udffd\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83e\uddd1\ud83c[\udffb\udffc\udffe\udfff]|\ud83e\uddd1\ud83c\udffe\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83e\uddd1\ud83c[\udffb-\udffd\udfff]|\ud83e\uddd1\ud83c\udfff\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83e\uddd1\ud83c[\udffb-\udffe]|\ud83d\udc68\ud83c\udffb\u200d\u2764\ufe0f\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc68\ud83c\udffb\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffc-\udfff]|\ud83d\udc68\ud83c\udffc\u200d\u2764\ufe0f\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc68\ud83c\udffc\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb\udffd-\udfff]|\ud83d\udc68\ud83c\udffd\u200d\u2764\ufe0f\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc68\ud83c\udffd\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb\udffc\udffe\udfff]|\ud83d\udc68\ud83c\udffe\u200d\u2764\ufe0f\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc68\ud83c\udffe\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb-\udffd\udfff]|\ud83d\udc68\ud83c\udfff\u200d\u2764\ufe0f\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc68\ud83c\udfff\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb-\udffe]|\ud83d\udc69\ud83c\udffb\u200d\u2764\ufe0f\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffb\u200d\u2764\ufe0f\u200d\ud83d\udc69\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffb\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffc-\udfff]|\ud83d\udc69\ud83c\udffb\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffc-\udfff]|\ud83d\udc69\ud83c\udffc\u200d\u2764\ufe0f\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffc\u200d\u2764\ufe0f\u200d\ud83d\udc69\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffc\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb\udffd-\udfff]|\ud83d\udc69\ud83c\udffc\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffb\udffd-\udfff]|\ud83d\udc69\ud83c\udffd\u200d\u2764\ufe0f\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffd\u200d\u2764\ufe0f\u200d\ud83d\udc69\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffd\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb\udffc\udffe\udfff]|\ud83d\udc69\ud83c\udffd\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffb\udffc\udffe\udfff]|\ud83d\udc69\ud83c\udffe\u200d\u2764\ufe0f\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffe\u200d\u2764\ufe0f\u200d\ud83d\udc69\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udffe\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb-\udffd\udfff]|\ud83d\udc69\ud83c\udffe\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffb-\udffd\udfff]|\ud83d\udc69\ud83c\udfff\u200d\u2764\ufe0f\u200d\ud83d\udc68\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udfff\u200d\u2764\ufe0f\u200d\ud83d\udc69\ud83c[\udffb-\udfff]|\ud83d\udc69\ud83c\udfff\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb-\udffe]|\ud83d\udc69\ud83c\udfff\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffb-\udffe]|\ud83e\uddd1\ud83c\udffb\u200d\u2764\ufe0f\u200d\ud83e\uddd1\ud83c[\udffc-\udfff]|\ud83e\uddd1\ud83c\udffb\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83e\uddd1\ud83c\udffc\u200d\u2764\ufe0f\u200d\ud83e\uddd1\ud83c[\udffb\udffd-\udfff]|\ud83e\uddd1\ud83c\udffc\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83e\uddd1\ud83c\udffd\u200d\u2764\ufe0f\u200d\ud83e\uddd1\ud83c[\udffb\udffc\udffe\udfff]|\ud83e\uddd1\ud83c\udffd\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83e\uddd1\ud83c\udffe\u200d\u2764\ufe0f\u200d\ud83e\uddd1\ud83c[\udffb-\udffd\udfff]|\ud83e\uddd1\ud83c\udffe\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83e\uddd1\ud83c\udfff\u200d\u2764\ufe0f\u200d\ud83e\uddd1\ud83c[\udffb-\udffe]|\ud83e\uddd1\ud83c\udfff\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83d\udc68\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68|\ud83d\udc69\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d[\udc68\udc69]|\ud83e\udef1\ud83c\udffb\u200d\ud83e\udef2\ud83c[\udffc-\udfff]|\ud83e\udef1\ud83c\udffc\u200d\ud83e\udef2\ud83c[\udffb\udffd-\udfff]|\ud83e\udef1\ud83c\udffd\u200d\ud83e\udef2\ud83c[\udffb\udffc\udffe\udfff]|\ud83e\udef1\ud83c\udffe\u200d\ud83e\udef2\ud83c[\udffb-\udffd\udfff]|\ud83e\udef1\ud83c\udfff\u200d\ud83e\udef2\ud83c[\udffb-\udffe]|\ud83d\udc68\u200d\u2764\ufe0f\u200d\ud83d\udc68|\ud83d\udc69\u200d\u2764\ufe0f\u200d\ud83d[\udc68\udc69]|\ud83e\uddd1\u200d\ud83e\udd1d\u200d\ud83e\uddd1|\ud83d\udc6b\ud83c[\udffb-\udfff]|\ud83d\udc6c\ud83c[\udffb-\udfff]|\ud83d\udc6d\ud83c[\udffb-\udfff]|\ud83d\udc8f\ud83c[\udffb-\udfff]|\ud83d\udc91\ud83c[\udffb-\udfff]|\ud83e\udd1d\ud83c[\udffb-\udfff]|\ud83d[\udc6b-\udc6d\udc8f\udc91]|\ud83e\udd1d)|(?:\ud83d[\udc68\udc69]|\ud83e\uddd1)(?:\ud83c[\udffb-\udfff])?\u200d(?:\u2695\ufe0f|\u2696\ufe0f|\u2708\ufe0f|\ud83c[\udf3e\udf73\udf7c\udf84\udf93\udfa4\udfa8\udfeb\udfed]|\ud83d[\udcbb\udcbc\udd27\udd2c\ude80\ude92]|\ud83e[\uddaf-\uddb3\uddbc\uddbd])|(?:\ud83c[\udfcb\udfcc]|\ud83d[\udd74\udd75]|\u26f9)((?:\ud83c[\udffb-\udfff]|\ufe0f)\u200d[\u2640\u2642]\ufe0f)|(?:\ud83c[\udfc3\udfc4\udfca]|\ud83d[\udc6e\udc70\udc71\udc73\udc77\udc81\udc82\udc86\udc87\ude45-\ude47\ude4b\ude4d\ude4e\udea3\udeb4-\udeb6]|\ud83e[\udd26\udd35\udd37-\udd39\udd3d\udd3e\uddb8\uddb9\uddcd-\uddcf\uddd4\uddd6-\udddd])(?:\ud83c[\udffb-\udfff])?\u200d[\u2640\u2642]\ufe0f|(?:\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83c\udff3\ufe0f\u200d\u26a7\ufe0f|\ud83c\udff3\ufe0f\u200d\ud83c\udf08|\ud83d\ude36\u200d\ud83c\udf2b\ufe0f|\u2764\ufe0f\u200d\ud83d\udd25|\u2764\ufe0f\u200d\ud83e\ude79|\ud83c\udff4\u200d\u2620\ufe0f|\ud83d\udc15\u200d\ud83e\uddba|\ud83d\udc3b\u200d\u2744\ufe0f|\ud83d\udc41\u200d\ud83d\udde8|\ud83d\udc68\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83d\udc6f\u200d\u2640\ufe0f|\ud83d\udc6f\u200d\u2642\ufe0f|\ud83d\ude2e\u200d\ud83d\udca8|\ud83d\ude35\u200d\ud83d\udcab|\ud83e\udd3c\u200d\u2640\ufe0f|\ud83e\udd3c\u200d\u2642\ufe0f|\ud83e\uddde\u200d\u2640\ufe0f|\ud83e\uddde\u200d\u2642\ufe0f|\ud83e\udddf\u200d\u2640\ufe0f|\ud83e\udddf\u200d\u2642\ufe0f|\ud83d\udc08\u200d\u2b1b)|[#*0-9]\ufe0f?\u20e3|(?:[©®\u2122\u265f]\ufe0f)|(?:\ud83c[\udc04\udd70\udd71\udd7e\udd7f\ude02\ude1a\ude2f\ude37\udf21\udf24-\udf2c\udf36\udf7d\udf96\udf97\udf99-\udf9b\udf9e\udf9f\udfcd\udfce\udfd4-\udfdf\udff3\udff5\udff7]|\ud83d[\udc3f\udc41\udcfd\udd49\udd4a\udd6f\udd70\udd73\udd76-\udd79\udd87\udd8a-\udd8d\udda5\udda8\uddb1\uddb2\uddbc\uddc2-\uddc4\uddd1-\uddd3\udddc-\uddde\udde1\udde3\udde8\uddef\uddf3\uddfa\udecb\udecd-\udecf\udee0-\udee5\udee9\udef0\udef3]|[\u203c\u2049\u2139\u2194-\u2199\u21a9\u21aa\u231a\u231b\u2328\u23cf\u23ed-\u23ef\u23f1\u23f2\u23f8-\u23fa\u24c2\u25aa\u25ab\u25b6\u25c0\u25fb-\u25fe\u2600-\u2604\u260e\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262a\u262e\u262f\u2638-\u263a\u2640\u2642\u2648-\u2653\u2660\u2663\u2665\u2666\u2668\u267b\u267f\u2692-\u2697\u2699\u269b\u269c\u26a0\u26a1\u26a7\u26aa\u26ab\u26b0\u26b1\u26bd\u26be\u26c4\u26c5\u26c8\u26cf\u26d1\u26d3\u26d4\u26e9\u26ea\u26f0-\u26f5\u26f8\u26fa\u26fd\u2702\u2708\u2709\u270f\u2712\u2714\u2716\u271d\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u2764\u27a1\u2934\u2935\u2b05-\u2b07\u2b1b\u2b1c\u2b50\u2b55\u3030\u303d\u3297\u3299])(?:\ufe0f|(?!\ufe0e))|(?:(?:\ud83c[\udfcb\udfcc]|\ud83d[\udd74\udd75\udd90]|[\u261d\u26f7\u26f9\u270c\u270d])(?:\ufe0f|(?!\ufe0e))|(?:\ud83c[\udf85\udfc2-\udfc4\udfc7\udfca]|\ud83d[\udc42\udc43\udc46-\udc50\udc66-\udc69\udc6e\udc70-\udc78\udc7c\udc81-\udc83\udc85-\udc87\udcaa\udd7a\udd95\udd96\ude45-\ude47\ude4b-\ude4f\udea3\udeb4-\udeb6\udec0\udecc]|\ud83e[\udd0c\udd0f\udd18-\udd1c\udd1e\udd1f\udd26\udd30-\udd39\udd3d\udd3e\udd77\uddb5\uddb6\uddb8\uddb9\uddbb\uddcd-\uddcf\uddd1-\udddd\udec3-\udec5\udef0-\udef6]|[\u270a\u270b]))(?:\ud83c[\udffb-\udfff])?|(?:\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc65\udb40\udc6e\udb40\udc67\udb40\udc7f|\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc73\udb40\udc63\udb40\udc74\udb40\udc7f|\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc77\udb40\udc6c\udb40\udc73\udb40\udc7f|\ud83c\udde6\ud83c[\udde8-\uddec\uddee\uddf1\uddf2\uddf4\uddf6-\uddfa\uddfc\uddfd\uddff]|\ud83c\udde7\ud83c[\udde6\udde7\udde9-\uddef\uddf1-\uddf4\uddf6-\uddf9\uddfb\uddfc\uddfe\uddff]|\ud83c\udde8\ud83c[\udde6\udde8\udde9\uddeb-\uddee\uddf0-\uddf5\uddf7\uddfa-\uddff]|\ud83c\udde9\ud83c[\uddea\uddec\uddef\uddf0\uddf2\uddf4\uddff]|\ud83c\uddea\ud83c[\udde6\udde8\uddea\uddec\udded\uddf7-\uddfa]|\ud83c\uddeb\ud83c[\uddee-\uddf0\uddf2\uddf4\uddf7]|\ud83c\uddec\ud83c[\udde6\udde7\udde9-\uddee\uddf1-\uddf3\uddf5-\uddfa\uddfc\uddfe]|\ud83c\udded\ud83c[\uddf0\uddf2\uddf3\uddf7\uddf9\uddfa]|\ud83c\uddee\ud83c[\udde8-\uddea\uddf1-\uddf4\uddf6-\uddf9]|\ud83c\uddef\ud83c[\uddea\uddf2\uddf4\uddf5]|\ud83c\uddf0\ud83c[\uddea\uddec-\uddee\uddf2\uddf3\uddf5\uddf7\uddfc\uddfe\uddff]|\ud83c\uddf1\ud83c[\udde6-\udde8\uddee\uddf0\uddf7-\uddfb\uddfe]|\ud83c\uddf2\ud83c[\udde6\udde8-\udded\uddf0-\uddff]|\ud83c\uddf3\ud83c[\udde6\udde8\uddea-\uddec\uddee\uddf1\uddf4\uddf5\uddf7\uddfa\uddff]|\ud83c\uddf4\ud83c\uddf2|\ud83c\uddf5\ud83c[\udde6\uddea-\udded\uddf0-\uddf3\uddf7-\uddf9\uddfc\uddfe]|\ud83c\uddf6\ud83c\udde6|\ud83c\uddf7\ud83c[\uddea\uddf4\uddf8\uddfa\uddfc]|\ud83c\uddf8\ud83c[\udde6-\uddea\uddec-\uddf4\uddf7-\uddf9\uddfb\uddfd-\uddff]|\ud83c\uddf9\ud83c[\udde6\udde8\udde9\uddeb-\udded\uddef-\uddf4\uddf7\uddf9\uddfb\uddfc\uddff]|\ud83c\uddfa\ud83c[\udde6\uddec\uddf2\uddf3\uddf8\uddfe\uddff]|\ud83c\uddfb\ud83c[\udde6\udde8\uddea\uddec\uddee\uddf3\uddfa]|\ud83c\uddfc\ud83c[\uddeb\uddf8]|\ud83c\uddfd\ud83c\uddf0|\ud83c\uddfe\ud83c[\uddea\uddf9]|\ud83c\uddff\ud83c[\udde6\uddf2\uddfc]|\ud83c[\udccf\udd8e\udd91-\udd9a\udde6-\uddff\ude01\ude32-\ude36\ude38-\ude3a\ude50\ude51\udf00-\udf20\udf2d-\udf35\udf37-\udf7c\udf7e-\udf84\udf86-\udf93\udfa0-\udfc1\udfc5\udfc6\udfc8\udfc9\udfcf-\udfd3\udfe0-\udff0\udff4\udff8-\udfff]|\ud83d[\udc00-\udc3e\udc40\udc44\udc45\udc51-\udc65\udc6a\udc6f\udc79-\udc7b\udc7d-\udc80\udc84\udc88-\udc8e\udc90\udc92-\udca9\udcab-\udcfc\udcff-\udd3d\udd4b-\udd4e\udd50-\udd67\udda4\uddfb-\ude44\ude48-\ude4a\ude80-\udea2\udea4-\udeb3\udeb7-\udebf\udec1-\udec5\uded0-\uded2\uded5-\uded7\udedd-\udedf\udeeb\udeec\udef4-\udefc\udfe0-\udfeb\udff0]|\ud83e[\udd0d\udd0e\udd10-\udd17\udd20-\udd25\udd27-\udd2f\udd3a\udd3c\udd3f-\udd45\udd47-\udd76\udd78-\uddb4\uddb7\uddba\uddbc-\uddcc\uddd0\uddde-\uddff\ude70-\ude74\ude78-\ude7c\ude80-\ude86\ude90-\udeac\udeb0-\udeba\udec0-\udec2\uded0-\uded9\udee0-\udee7]|[\u23e9-\u23ec\u23f0\u23f3\u267e\u26ce\u2705\u2728\u274c\u274e\u2753-\u2755\u2795-\u2797\u27b0\u27bf\ue50a])|\ufe0f/g;
|
|
3103
|
+
|
|
3104
|
+
function isOneEmoji(text) {
|
|
3105
|
+
return !!(typeof text === "string" && text && (text.match(TWEMOJI_REGEX) || [])[0]?.length === text.length);
|
|
3106
|
+
}
|
|
3107
|
+
|
|
3108
|
+
const IGNORED_TITLES = Object.freeze(
|
|
3109
|
+
/* @__PURE__ */ new Set([
|
|
3110
|
+
"dr.",
|
|
3111
|
+
"mr.",
|
|
3112
|
+
"mrs.",
|
|
3113
|
+
"miss",
|
|
3114
|
+
"ms.",
|
|
3115
|
+
"prof.",
|
|
3116
|
+
"sir",
|
|
3117
|
+
"rev.",
|
|
3118
|
+
"hon."
|
|
3119
|
+
])
|
|
3120
|
+
);
|
|
3121
|
+
function getInitials(fullName) {
|
|
3122
|
+
if (!isString(fullName)) return "";
|
|
3123
|
+
let [first, ...rest] = fullName.replace(/\s{2,}/g, " ").replace(/[,+/#!$@%^&*;:{}=\-_`~()]/g, "").trim().split(" ").filter((word) => !IGNORED_TITLES.has(word.toLowerCase())).map((v) => v.replaceAll(".", "").trim()).filter(Boolean);
|
|
3124
|
+
let last = rest[rest.length - 1];
|
|
3125
|
+
if (rest.length > 1) {
|
|
3126
|
+
if (isOneEmoji(first)) {
|
|
3127
|
+
first = rest[0];
|
|
3128
|
+
} else if (isOneEmoji(last)) {
|
|
3129
|
+
last = rest[0];
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
return [first, last].filter(Boolean).map((letter = "") => [...letter.toUpperCase()][0]).join("");
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
const byteToHex = [];
|
|
3136
|
+
for (let n = 0; n <= 255; ++n) {
|
|
3137
|
+
const hexOctet = n.toString(16).padStart(2, "0");
|
|
3138
|
+
byteToHex.push(hexOctet);
|
|
3139
|
+
}
|
|
3140
|
+
function hex(value) {
|
|
3141
|
+
const buff = Array.isArray(value) ? new Uint8Array(value) : value;
|
|
3142
|
+
const hexOctets = new Array(buff.length);
|
|
3143
|
+
for (let i = 0; i < buff.length; ++i) {
|
|
3144
|
+
hexOctets[i] = byteToHex[buff[i]];
|
|
3145
|
+
}
|
|
3146
|
+
return hexOctets.join("");
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
function isoToFlagEmoji(iso) {
|
|
3150
|
+
const code = iso.toUpperCase();
|
|
3151
|
+
if (!/^[A-Z]{2}$/.test(code)) return iso;
|
|
3152
|
+
const codePoints = [...code].map((c) => c.codePointAt(0) + 127397);
|
|
3153
|
+
return String.fromCodePoint(...codePoints);
|
|
3154
|
+
}
|
|
3155
|
+
|
|
3156
|
+
function kebabCase(str) {
|
|
3157
|
+
const words = getWords(str);
|
|
3158
|
+
return words.map((word) => word.toLowerCase()).join("-");
|
|
3159
|
+
}
|
|
3160
|
+
|
|
3161
|
+
const lowerCase = (str) => {
|
|
3162
|
+
return getWords(str).map((word) => word.toLowerCase()).join(" ");
|
|
3163
|
+
};
|
|
3164
|
+
|
|
3165
|
+
function maskingWords(value, withChar = "*") {
|
|
3166
|
+
return getWords(value).map((word) => {
|
|
3167
|
+
const len = word.length;
|
|
3168
|
+
if (len < 2) {
|
|
3169
|
+
return "".padEnd(len, withChar);
|
|
3170
|
+
} else if (len < 3) {
|
|
3171
|
+
return word[0].padEnd(len, withChar);
|
|
3172
|
+
} else {
|
|
3173
|
+
return word[0].padEnd(len - 2, withChar) + word.at(-1);
|
|
3174
|
+
}
|
|
3175
|
+
}).join(" ");
|
|
3176
|
+
}
|
|
3177
|
+
|
|
3178
|
+
function maskingEmail(value) {
|
|
3179
|
+
if (!isString(value)) return "";
|
|
3180
|
+
const [username, host] = value.split("@", 2);
|
|
3181
|
+
if (!username || !host) return "";
|
|
3182
|
+
return `${maskingWords(username)}@${host}`;
|
|
3183
|
+
}
|
|
3184
|
+
|
|
3185
|
+
function maskingPhone(value, fromPosition = 2, toPosition = 4, withChar = "X") {
|
|
3186
|
+
if (!isString(value)) return "";
|
|
3187
|
+
const numbersAmount = value.replace(/\D/g, "").length;
|
|
3188
|
+
const fromIdx = fromPosition - 1;
|
|
3189
|
+
let toIdx = numbersAmount - toPosition;
|
|
3190
|
+
if (toIdx <= 0) {
|
|
3191
|
+
toIdx = numbersAmount;
|
|
3192
|
+
}
|
|
3193
|
+
let i = -1;
|
|
3194
|
+
return value.replace(/\d/g, (char) => {
|
|
3195
|
+
i++;
|
|
3196
|
+
return i > fromIdx && i < toIdx ? withChar : char;
|
|
3197
|
+
});
|
|
3198
|
+
}
|
|
3199
|
+
|
|
3200
|
+
let index = Math.floor(Math.random() * 16777215);
|
|
3201
|
+
const buffer = new Uint8Array(12);
|
|
3202
|
+
function objectId(fromValue = Date.now()) {
|
|
3203
|
+
const value = timestamp(fromValue);
|
|
3204
|
+
const inc = getInc();
|
|
3205
|
+
buffer[0] = value >> 24;
|
|
3206
|
+
buffer[1] = value >> 16;
|
|
3207
|
+
buffer[2] = value >> 8;
|
|
3208
|
+
buffer[3] = value;
|
|
3209
|
+
buffer[4] = Math.floor(Math.random() * 256);
|
|
3210
|
+
buffer[5] = Math.floor(Math.random() * 256);
|
|
3211
|
+
buffer[6] = Math.floor(Math.random() * 256);
|
|
3212
|
+
buffer[7] = Math.floor(Math.random() * 256);
|
|
3213
|
+
buffer[8] = Math.floor(Math.random() * 256);
|
|
3214
|
+
buffer[11] = inc & 255;
|
|
3215
|
+
buffer[10] = inc >> 8 & 255;
|
|
3216
|
+
buffer[9] = inc >> 16 & 255;
|
|
3217
|
+
return hex(buffer);
|
|
3218
|
+
}
|
|
3219
|
+
function getInc() {
|
|
3220
|
+
return index = (index + 1) % 16777215;
|
|
3221
|
+
}
|
|
3222
|
+
|
|
3223
|
+
const snakeCase = (str) => {
|
|
3224
|
+
return getWords(str).map((word) => word.toLowerCase()).join("_");
|
|
3225
|
+
};
|
|
3226
|
+
|
|
3227
|
+
const startCase = (value) => {
|
|
3228
|
+
return getWords(value).map(capitalize).join(" ");
|
|
3229
|
+
};
|
|
3230
|
+
|
|
3231
|
+
const DEF_STR_ASSIGN_REGEXP = /\{{([A-z-_. ]*)\}}/g;
|
|
3232
|
+
const DEF_STR_ASSIGN_METHOD = (obj, key) => obj[key];
|
|
3233
|
+
function strAssign(str, obj, method = DEF_STR_ASSIGN_METHOD) {
|
|
3234
|
+
return str.replace(DEF_STR_ASSIGN_REGEXP, (match, p1) => {
|
|
3235
|
+
const key = p1.trim();
|
|
3236
|
+
const value = method(obj, key);
|
|
3237
|
+
if (value === void 0 || value === null) {
|
|
3238
|
+
return match;
|
|
3239
|
+
}
|
|
3240
|
+
return value;
|
|
3241
|
+
});
|
|
3242
|
+
}
|
|
3243
|
+
|
|
3244
|
+
function truncate(value, maxLength = 120, insignificantThreshold = 0.05) {
|
|
3245
|
+
if (!shouldTruncate(value, maxLength, insignificantThreshold)) {
|
|
3246
|
+
return value;
|
|
3247
|
+
}
|
|
3248
|
+
let truncated = value.slice(0, maxLength).trim();
|
|
3249
|
+
const lastSpace = truncated.lastIndexOf(" ");
|
|
3250
|
+
if (lastSpace > 0) {
|
|
3251
|
+
truncated = truncated.slice(0, lastSpace);
|
|
3252
|
+
}
|
|
3253
|
+
return `${truncated}...`;
|
|
3254
|
+
}
|
|
3255
|
+
function shouldTruncate(text, maxLength, insignificantThreshold) {
|
|
3256
|
+
return text.length - maxLength > maxLength * insignificantThreshold;
|
|
3257
|
+
}
|
|
3258
|
+
|
|
3259
|
+
function wrapText(value, maxLength = 30) {
|
|
3260
|
+
if (value.length > maxLength) {
|
|
3261
|
+
return value.slice(0, maxLength) + "...";
|
|
3262
|
+
}
|
|
3263
|
+
return value;
|
|
3264
|
+
}
|
|
3265
|
+
|
|
3266
|
+
export { AppError, AsyncIterableQueue, BrowserAssertionError, CancellablePromise, ColorParser, FixedMap, FixedWeakMap, LruCache, Queue, SimpleEventEmitter, TWEMOJI_REGEX, TimeBucket, alpha, arrayable, assert, asyncFilter, asyncFind, asyncForEach, asyncMap, avg, blendColors, buildCssColor, cache, cacheBucket, cacheFixed, cacheLRU, camelCase, capitalize, captureStackTrace, catchError, channelsToHSL, channelsToHex, channelsToRGB, checkBitmask, chunk, chunkSeries, clamp, cleanEmpty, cleanObject, colorToChannels, contrastRatio, convertToUnit, crc32, createCustomizer, createCustomizerFactory, createDeepCloneWith, createEnvParser, createRandomizer, createSecureCustomizer, createWithCache, cssVariable, deepAssign, deepClone, deepCloneWith, deepDefaults, deepFreeze, def, defer, delay, dropCache, env, escapeHtml, escapeNumeric, escapeRegExp, fastIdle, fastIdlePromise, fastRaf, findMean, flagsToMap, flatten, formatMoney, formatNumber, get, getFileExtension, getFileName, getInitials, getRandomInt, getWords, has, hasOwn, hasProtocol, hex, hexToChannels, hslToChannels, humanFileSize, humanize, interpolateColor, isBigInt, isBoolean, isCached, isClient, isColorChannels, isCustomizerFactory, isDate, isDef, isEmpty, isEqual, isError, isFunction, isMap, isNullOrUndefined, isNumber, isObject, isOneEmoji, isPrimitive, isPromise, isSet, isSkip, isString, isSuccess, isSymbol, isWeakMap, isWeakSet, isWithCache, isoToFlagEmoji, kebabCase, keyBy, logger, lowerCase, luminance, maskingEmail, maskingPhone, maskingWords, nextTickIteration, noop, objectId, omit, omitPrefixed, orderBy, parseAllNumbers, parseAlpha, parsePercentage, percentOf, pick, pickPrefixed, qs, rafPromise, randomString, removeVS16s, retryOnError, rgbToChannels, round2digits, set, snakeCase, sprintf, startCase, strAssign, sum, timeout, timestamp, timestampToDate, tintedTextColor, toError, toMap, truncate, typeOf, unflatten, union, uniq, uniqBy, unset, withCache, withCacheBucket, withCacheBucketBatch, withCacheFixed, withCacheLRU, withDeepClone, withPointerCache, wrapText };
|
|
3267
|
+
//# sourceMappingURL=index.mjs.map
|