@andrew_l/toolkit 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +250 -109
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +484 -422
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -220,6 +220,17 @@ function difference(...arrays) {
|
|
|
220
220
|
}
|
|
221
221
|
return Array.from(set);
|
|
222
222
|
}
|
|
223
|
+
var SPECIAL_VALUE = Symbol("toolkit.special.value");
|
|
224
|
+
var SPECIAL_VALUE_2 = Symbol("toolkit.special.value_2");
|
|
225
|
+
function filterMap(array, callbackfn) {
|
|
226
|
+
var mapped = [];
|
|
227
|
+
var mappedValue;
|
|
228
|
+
for (var index = 0; index < array.length; index++) {
|
|
229
|
+
mappedValue = callbackfn(array[index], SPECIAL_VALUE, index, array);
|
|
230
|
+
if (mappedValue !== SPECIAL_VALUE) mapped.push(mappedValue);
|
|
231
|
+
}
|
|
232
|
+
return mapped;
|
|
233
|
+
}
|
|
223
234
|
function groupBy(array, keyBy, objectMode) {
|
|
224
235
|
const getItemKey = isFunction(keyBy) ? keyBy : (item) => item?.[keyBy];
|
|
225
236
|
let key;
|
|
@@ -1242,116 +1253,452 @@ var AssertionError = class extends Error {
|
|
|
1242
1253
|
this.code = "ERR_ASSERTION";
|
|
1243
1254
|
}
|
|
1244
1255
|
};
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
arrayNumbers: () => arrayNumbers,
|
|
1248
|
-
arrayStrings: () => arrayStrings,
|
|
1249
|
-
boolean: () => boolean,
|
|
1250
|
-
date: () => date,
|
|
1251
|
-
equal: () => equal,
|
|
1252
|
-
fn: () => fn,
|
|
1253
|
-
greaterThan: () => greaterThan,
|
|
1254
|
-
lessThan: () => lessThan,
|
|
1255
|
-
notEmpty: () => notEmpty,
|
|
1256
|
-
notEmptyString: () => notEmptyString,
|
|
1257
|
-
number: () => number$1,
|
|
1258
|
-
object: () => object,
|
|
1259
|
-
ok: () => ok,
|
|
1260
|
-
string: () => string
|
|
1261
|
-
});
|
|
1262
|
-
function ok(value, message) {
|
|
1263
|
-
if (!value) throw toError$1(ok, value, message, "The expression evaluated to a falsy value.");
|
|
1264
|
-
}
|
|
1265
|
-
function equal(actual, expected, message) {
|
|
1266
|
-
if (actual !== expected) new AssertionError({
|
|
1267
|
-
actual,
|
|
1268
|
-
expected,
|
|
1269
|
-
message: isString(message) ? message : "The actual value not as expected.",
|
|
1270
|
-
operator: "equal",
|
|
1271
|
-
stackStartFn: equal
|
|
1272
|
-
});
|
|
1273
|
-
}
|
|
1274
|
-
function notEmpty(value, message) {
|
|
1275
|
-
if (isEmpty(value)) throw toError$1(notEmpty, value, message, "Expected not empty value.");
|
|
1276
|
-
}
|
|
1277
|
-
function object(value, message) {
|
|
1278
|
-
if (!isObject(value)) throw toError$1(object, value, message, "Expected object value.");
|
|
1279
|
-
}
|
|
1280
|
-
function string(value, message) {
|
|
1281
|
-
if (!isString(value)) throw toError$1(string, value, message, "Expected string value.");
|
|
1282
|
-
}
|
|
1283
|
-
function boolean(value, message) {
|
|
1284
|
-
if (!isBoolean(value)) throw toError$1(boolean, value, message, "Expected boolean value.");
|
|
1256
|
+
function constant(value) {
|
|
1257
|
+
return () => value;
|
|
1285
1258
|
}
|
|
1286
|
-
function
|
|
1287
|
-
if (
|
|
1259
|
+
function toError(value, unknownMessage = "Unknown error") {
|
|
1260
|
+
if (isError(value)) return value;
|
|
1261
|
+
const error = new Error(unknownMessage, { cause: value });
|
|
1262
|
+
Error.captureStackTrace(error, toError);
|
|
1263
|
+
return error;
|
|
1288
1264
|
}
|
|
1289
|
-
function
|
|
1290
|
-
|
|
1265
|
+
function createFunction(fnName, code, ...args) {
|
|
1266
|
+
try {
|
|
1267
|
+
const fn = new Function(...args, code);
|
|
1268
|
+
fn.code = code;
|
|
1269
|
+
return fn;
|
|
1270
|
+
} catch (err) {
|
|
1271
|
+
throw new Error(`failed to create bitPack.${fnName}()\nError: ${toError(err).message}\n-- CODE START --\n${code}\n-- CODE END--`);
|
|
1272
|
+
}
|
|
1291
1273
|
}
|
|
1292
|
-
function
|
|
1293
|
-
|
|
1274
|
+
function debounce(func, debounceMs, { signal, edges } = {}) {
|
|
1275
|
+
let pendingThis = void 0;
|
|
1276
|
+
let pendingArgs = null;
|
|
1277
|
+
const leading = edges != null && edges.includes("leading");
|
|
1278
|
+
const trailing = edges == null || edges.includes("trailing");
|
|
1279
|
+
const invoke = () => {
|
|
1280
|
+
if (pendingArgs !== null) {
|
|
1281
|
+
func.apply(pendingThis, pendingArgs);
|
|
1282
|
+
pendingThis = void 0;
|
|
1283
|
+
pendingArgs = null;
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
const onTimerEnd = () => {
|
|
1287
|
+
if (trailing) invoke();
|
|
1288
|
+
cancel();
|
|
1289
|
+
};
|
|
1290
|
+
let timeoutId = null;
|
|
1291
|
+
const schedule = () => {
|
|
1292
|
+
if (timeoutId != null) clearTimeout(timeoutId);
|
|
1293
|
+
timeoutId = setTimeout(() => {
|
|
1294
|
+
timeoutId = null;
|
|
1295
|
+
onTimerEnd();
|
|
1296
|
+
}, debounceMs);
|
|
1297
|
+
};
|
|
1298
|
+
const cancelTimer = () => {
|
|
1299
|
+
if (timeoutId !== null) {
|
|
1300
|
+
clearTimeout(timeoutId);
|
|
1301
|
+
timeoutId = null;
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
const cancel = () => {
|
|
1305
|
+
cancelTimer();
|
|
1306
|
+
pendingThis = void 0;
|
|
1307
|
+
pendingArgs = null;
|
|
1308
|
+
};
|
|
1309
|
+
const flush = () => {
|
|
1310
|
+
cancelTimer();
|
|
1311
|
+
invoke();
|
|
1312
|
+
};
|
|
1313
|
+
const debounced = function(...args) {
|
|
1314
|
+
if (signal?.aborted) return;
|
|
1315
|
+
pendingThis = this;
|
|
1316
|
+
pendingArgs = args;
|
|
1317
|
+
const isFirstCall = timeoutId == null;
|
|
1318
|
+
schedule();
|
|
1319
|
+
if (leading && isFirstCall) invoke();
|
|
1320
|
+
};
|
|
1321
|
+
debounced.schedule = schedule;
|
|
1322
|
+
debounced.cancel = cancel;
|
|
1323
|
+
debounced.flush = flush;
|
|
1324
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
1325
|
+
return debounced;
|
|
1294
1326
|
}
|
|
1295
|
-
function
|
|
1296
|
-
|
|
1327
|
+
function isSuccess(value) {
|
|
1328
|
+
return isObject(value) && "success" in value && "code" in value && value.success === true && isString(value.code) && (!("reason" in value) || isString(value.reason));
|
|
1297
1329
|
}
|
|
1298
|
-
function
|
|
1299
|
-
|
|
1330
|
+
function isSkip(value) {
|
|
1331
|
+
return isObject(value) && "skip" in value && "code" in value && value.skip === true && isString(value.code) && (!("reason" in value) || isString(value.reason));
|
|
1300
1332
|
}
|
|
1301
|
-
function
|
|
1302
|
-
if (
|
|
1333
|
+
function stringifyExecResult(value) {
|
|
1334
|
+
if (value.success) return `ExecSuccess(code=${value.code}, reason="${value.reason || "no reason"}")`;
|
|
1335
|
+
return `ExecSkip(code=${value.code}, reason="${value.reason || "no reason"}")`;
|
|
1303
1336
|
}
|
|
1304
|
-
function
|
|
1305
|
-
|
|
1337
|
+
function identity(x) {
|
|
1338
|
+
return x;
|
|
1306
1339
|
}
|
|
1307
|
-
function
|
|
1308
|
-
|
|
1340
|
+
function negate(func) {
|
|
1341
|
+
return function(...args) {
|
|
1342
|
+
return !func.apply(this, args);
|
|
1343
|
+
};
|
|
1309
1344
|
}
|
|
1310
|
-
|
|
1311
|
-
|
|
1345
|
+
var tagToType = {
|
|
1346
|
+
[nullTag]: "null",
|
|
1347
|
+
[undefinedTag]: "undefined",
|
|
1348
|
+
[stringTag]: "string",
|
|
1349
|
+
[functionTag]: "function",
|
|
1350
|
+
[arrayTag]: "array",
|
|
1351
|
+
[setTag]: "set",
|
|
1352
|
+
[mapTag]: "map",
|
|
1353
|
+
[dateTag]: (v) => isDate(v) ? "date" : "unknown",
|
|
1354
|
+
[objectTag]: "object",
|
|
1355
|
+
[symbolTag]: "symbol",
|
|
1356
|
+
[bigintTag]: "bigint",
|
|
1357
|
+
[booleanTag]: "boolean",
|
|
1358
|
+
[weakmapTag]: "weakmap",
|
|
1359
|
+
[weaksetTag]: "weakset",
|
|
1360
|
+
[numberTag]: (v) => isNumber(v) ? "number" : "unknown"
|
|
1361
|
+
};
|
|
1362
|
+
function typeOf(value) {
|
|
1363
|
+
var typeOrGetter = tagToType[getTag(value)] || "unknown";
|
|
1364
|
+
if (isFunction(typeOrGetter)) return typeOrGetter(value);
|
|
1365
|
+
return typeOrGetter;
|
|
1312
1366
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1367
|
+
const qs = {
|
|
1368
|
+
toParams,
|
|
1369
|
+
stringify,
|
|
1370
|
+
stringifyValue,
|
|
1371
|
+
parse,
|
|
1372
|
+
parseValue: parseValue$1,
|
|
1373
|
+
merge
|
|
1374
|
+
};
|
|
1375
|
+
function merge(...values) {
|
|
1376
|
+
const result = {};
|
|
1377
|
+
for (const filter of values) for (const [key, value] of Object.entries(filter)) {
|
|
1378
|
+
const currentValue = result[key];
|
|
1379
|
+
const currentType = typeOf(currentValue);
|
|
1380
|
+
if (currentType !== typeOf(value)) {
|
|
1381
|
+
result[key] = value;
|
|
1382
|
+
continue;
|
|
1383
|
+
}
|
|
1384
|
+
switch (currentType) {
|
|
1385
|
+
case "array":
|
|
1386
|
+
result[key] = Array.from(/* @__PURE__ */ new Set([...currentValue, ...value]));
|
|
1387
|
+
break;
|
|
1388
|
+
case "object":
|
|
1389
|
+
result[key] = {};
|
|
1390
|
+
deepAssign(result[key], currentValue);
|
|
1391
|
+
deepAssign(result[key], value);
|
|
1392
|
+
break;
|
|
1393
|
+
case "map":
|
|
1394
|
+
result[key] = new Map([...Array.from(currentValue.entries()), ...Array.from(value.entries())]);
|
|
1395
|
+
break;
|
|
1396
|
+
case "set":
|
|
1397
|
+
result[key] = /* @__PURE__ */ new Set([...Array.from(currentValue), ...Array.from(value)]);
|
|
1398
|
+
break;
|
|
1399
|
+
default: result[key] = value;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
return result;
|
|
1321
1403
|
}
|
|
1322
|
-
function
|
|
1323
|
-
|
|
1324
|
-
const instance = new WeightedRoundRobin(arr.map((v) => ({
|
|
1325
|
-
item: v.item,
|
|
1326
|
-
weight: Math.min(v.weight ?? 1, 1)
|
|
1327
|
-
})));
|
|
1328
|
-
return () => instance.nextItem();
|
|
1404
|
+
function stringify(obj, options) {
|
|
1405
|
+
return new URLSearchParams(toParams(obj, options)).toString();
|
|
1329
1406
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
return Math.max(...this.items.map((s) => s.weight));
|
|
1407
|
+
function toParams(obj, options) {
|
|
1408
|
+
const result = {};
|
|
1409
|
+
const excludeEmpty = options?.excludeEmpty !== false;
|
|
1410
|
+
const excludeDefaults = options?.excludeDefaults;
|
|
1411
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1412
|
+
if (excludeEmpty && isEmpty(value)) continue;
|
|
1413
|
+
if (excludeDefaults && key in excludeDefaults) {
|
|
1414
|
+
const defValue = excludeDefaults[key];
|
|
1415
|
+
if (isEqual(value, defValue)) continue;
|
|
1416
|
+
}
|
|
1417
|
+
const strValue = stringifyValue(value);
|
|
1418
|
+
if (excludeEmpty && strValue === "") continue;
|
|
1419
|
+
result[key] = strValue;
|
|
1344
1420
|
}
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1421
|
+
return result;
|
|
1422
|
+
}
|
|
1423
|
+
function parse(value, defaults) {
|
|
1424
|
+
const objValue = isString(value) ? Object.fromEntries(new URLSearchParams(value).entries()) : value;
|
|
1425
|
+
if (!defaults) return { ...objValue };
|
|
1426
|
+
const result = {};
|
|
1427
|
+
for (const [key, defValue] of Object.entries(defaults)) {
|
|
1428
|
+
const defType = typeOf(defValue);
|
|
1429
|
+
let parsedValue = parseValue$1(objValue[key], defType);
|
|
1430
|
+
if (parsedValue !== void 0 || defType === "undefined") {
|
|
1431
|
+
if (defType === "array" && defValue[0] !== void 0) {
|
|
1432
|
+
const itemValue = typeOf(defValue[0]);
|
|
1433
|
+
parsedValue = parsedValue.map((v) => parseValue$1(v, itemValue));
|
|
1352
1434
|
}
|
|
1353
|
-
|
|
1354
|
-
}
|
|
1435
|
+
result[key] = parsedValue;
|
|
1436
|
+
} else result[key] = defValue;
|
|
1437
|
+
}
|
|
1438
|
+
return result;
|
|
1439
|
+
}
|
|
1440
|
+
function stringifyValue(value) {
|
|
1441
|
+
const valueType = typeOf(value);
|
|
1442
|
+
switch (valueType) {
|
|
1443
|
+
case "undefined": return "";
|
|
1444
|
+
case "null": return "";
|
|
1445
|
+
case "array": {
|
|
1446
|
+
let result = "";
|
|
1447
|
+
let sep = "";
|
|
1448
|
+
for (const item of value) {
|
|
1449
|
+
if (item === void 0) continue;
|
|
1450
|
+
if (isObject(item) || Array.isArray(item) || isString(item) && item.includes(",")) {
|
|
1451
|
+
result = JSON.stringify(value);
|
|
1452
|
+
break;
|
|
1453
|
+
} else {
|
|
1454
|
+
result += sep + stringifyValue(item);
|
|
1455
|
+
sep = ",";
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
return result;
|
|
1459
|
+
}
|
|
1460
|
+
case "date": return value.toISOString();
|
|
1461
|
+
case "map": return JSON.stringify(Array.from(value.entries()));
|
|
1462
|
+
case "set": return JSON.stringify(Array.from(value.values()));
|
|
1463
|
+
case "boolean":
|
|
1464
|
+
case "number":
|
|
1465
|
+
case "string":
|
|
1466
|
+
case "bigint": return String(value);
|
|
1467
|
+
case "object": return JSON.stringify(value);
|
|
1468
|
+
case "unknown": if (isFunction(value?.toString)) return value.toString();
|
|
1469
|
+
default: throw new Error("Attempt to stringify unsupported type: " + valueType);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
function parseValue$1(value, asType) {
|
|
1473
|
+
const type = typeOf(value);
|
|
1474
|
+
if (type === asType) return value;
|
|
1475
|
+
else if (type !== "string") return;
|
|
1476
|
+
try {
|
|
1477
|
+
switch (asType) {
|
|
1478
|
+
case "undefined": return;
|
|
1479
|
+
case "array":
|
|
1480
|
+
if (value.startsWith("[") && value.endsWith("]")) return JSON.parse(value);
|
|
1481
|
+
return value.split(",");
|
|
1482
|
+
case "boolean": return value === "true";
|
|
1483
|
+
case "date": {
|
|
1484
|
+
const parsed = new Date(value);
|
|
1485
|
+
return isDate(parsed) ? parsed : void 0;
|
|
1486
|
+
}
|
|
1487
|
+
case "map": return new Map(JSON.parse(value));
|
|
1488
|
+
case "number": {
|
|
1489
|
+
const parsed = parseFloat(value);
|
|
1490
|
+
return isNumber(parsed) ? parsed : void 0;
|
|
1491
|
+
}
|
|
1492
|
+
case "object": return JSON.parse(value);
|
|
1493
|
+
case "set": return new Set(JSON.parse(value));
|
|
1494
|
+
case "null": return value === "" || value === void 0 ? null : void 0;
|
|
1495
|
+
case "string": return value;
|
|
1496
|
+
case "bigint": return BigInt(value);
|
|
1497
|
+
}
|
|
1498
|
+
} catch (_) {}
|
|
1499
|
+
}
|
|
1500
|
+
const clamp = (num, min, max) => {
|
|
1501
|
+
if (!isNumber(num)) return min;
|
|
1502
|
+
return Math.min(max, Math.max(min, num));
|
|
1503
|
+
};
|
|
1504
|
+
function defer() {
|
|
1505
|
+
let resolve;
|
|
1506
|
+
let reject;
|
|
1507
|
+
const promise = new Promise((_resolve, _reject) => {
|
|
1508
|
+
resolve = _resolve;
|
|
1509
|
+
reject = _reject;
|
|
1510
|
+
});
|
|
1511
|
+
return {
|
|
1512
|
+
resolve,
|
|
1513
|
+
reject,
|
|
1514
|
+
promise
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
const defaultWindow$1 = globalThis?.window;
|
|
1518
|
+
const idle = (() => {
|
|
1519
|
+
if (defaultWindow$1?.requestIdleCallback) return defaultWindow$1.requestIdleCallback;
|
|
1520
|
+
else if (defaultWindow$1?.requestAnimationFrame) return defaultWindow$1.requestAnimationFrame;
|
|
1521
|
+
else if (isFunction(process?.nextTick)) return process.nextTick;
|
|
1522
|
+
else return (fn) => setTimeout(fn, 0);
|
|
1523
|
+
})();
|
|
1524
|
+
function fastIdle(callback) {
|
|
1525
|
+
return idle(callback);
|
|
1526
|
+
}
|
|
1527
|
+
function fastIdlePromise() {
|
|
1528
|
+
return new Promise((resolve) => idle(resolve));
|
|
1529
|
+
}
|
|
1530
|
+
function delay(amount = "tick") {
|
|
1531
|
+
const d = defer();
|
|
1532
|
+
if (amount === "tick") fastIdle(d.resolve);
|
|
1533
|
+
else setTimeout(d.resolve, amount);
|
|
1534
|
+
return d.promise;
|
|
1535
|
+
}
|
|
1536
|
+
var NOOP_SHOULD_RETRY_BASED_ON_ERROR = () => true;
|
|
1537
|
+
function retryOnError({ beforeRetryCallback = noop, shouldRetryBasedOnError = NOOP_SHOULD_RETRY_BASED_ON_ERROR, maxAttempts, maxRetriesNumber = 1, delayFactor = 0, delayMaxMs = 1e3, delayMinMs = 100 }, fn) {
|
|
1538
|
+
delayMinMs = Math.max(delayMinMs, 1);
|
|
1539
|
+
delayMaxMs = Math.max(delayMaxMs, 1);
|
|
1540
|
+
return function(...args) {
|
|
1541
|
+
var delayMs = 0;
|
|
1542
|
+
var currentAttempt = 0;
|
|
1543
|
+
var leftAttempts = isNumber(maxAttempts) ? maxAttempts : maxRetriesNumber + 1;
|
|
1544
|
+
var run = () => {
|
|
1545
|
+
currentAttempt++;
|
|
1546
|
+
leftAttempts--;
|
|
1547
|
+
return Promise.resolve().then(() => fn.apply(this, args)).catch((e) => {
|
|
1548
|
+
if (leftAttempts < 1 || !shouldRetryBasedOnError(e, currentAttempt)) return Promise.reject(e);
|
|
1549
|
+
delayMs = clamp(delayMs * delayFactor, delayMinMs, delayMaxMs);
|
|
1550
|
+
return Promise.resolve().then(() => beforeRetryCallback(currentAttempt, leftAttempts <= 1)).then((newParams) => {
|
|
1551
|
+
if (Array.isArray(newParams)) args = newParams;
|
|
1552
|
+
return delay(delayMs).then(() => run());
|
|
1553
|
+
});
|
|
1554
|
+
});
|
|
1555
|
+
};
|
|
1556
|
+
return run();
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
function throttle(func, throttleMs, { signal, edges = ["leading", "trailing"] } = {}) {
|
|
1560
|
+
let pendingAt = null;
|
|
1561
|
+
const debounced = debounce(func, throttleMs, {
|
|
1562
|
+
signal,
|
|
1563
|
+
edges
|
|
1564
|
+
});
|
|
1565
|
+
const throttled = function(...args) {
|
|
1566
|
+
if (pendingAt == null) pendingAt = Date.now();
|
|
1567
|
+
else if (Date.now() - pendingAt >= throttleMs) {
|
|
1568
|
+
pendingAt = Date.now();
|
|
1569
|
+
debounced.cancel();
|
|
1570
|
+
debounced(...args);
|
|
1571
|
+
}
|
|
1572
|
+
debounced(...args);
|
|
1573
|
+
};
|
|
1574
|
+
throttled.cancel = debounced.cancel;
|
|
1575
|
+
throttled.flush = debounced.flush;
|
|
1576
|
+
return throttled;
|
|
1577
|
+
}
|
|
1578
|
+
var assert_exports = /* @__PURE__ */ __exportAll({
|
|
1579
|
+
array: () => array,
|
|
1580
|
+
arrayNumbers: () => arrayNumbers,
|
|
1581
|
+
arrayStrings: () => arrayStrings,
|
|
1582
|
+
bigint: () => bigint,
|
|
1583
|
+
boolean: () => boolean,
|
|
1584
|
+
date: () => date,
|
|
1585
|
+
equal: () => equal,
|
|
1586
|
+
execSkip: () => execSkip,
|
|
1587
|
+
execSuccess: () => execSuccess,
|
|
1588
|
+
fn: () => fn,
|
|
1589
|
+
greaterThan: () => greaterThan,
|
|
1590
|
+
lessThan: () => lessThan,
|
|
1591
|
+
notEmpty: () => notEmpty,
|
|
1592
|
+
notEmptyString: () => notEmptyString,
|
|
1593
|
+
number: () => number$1,
|
|
1594
|
+
object: () => object,
|
|
1595
|
+
ok: () => ok,
|
|
1596
|
+
string: () => string
|
|
1597
|
+
});
|
|
1598
|
+
function ok(value, message) {
|
|
1599
|
+
if (!value) throw toError$1(ok, value, message, "The expression evaluated to a falsy value.");
|
|
1600
|
+
}
|
|
1601
|
+
function equal(actual, expected, message) {
|
|
1602
|
+
if (actual !== expected) throw new AssertionError({
|
|
1603
|
+
actual,
|
|
1604
|
+
expected,
|
|
1605
|
+
message: isString(message) ? message : "The actual value not as expected.",
|
|
1606
|
+
operator: "equal",
|
|
1607
|
+
stackStartFn: equal
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
function notEmpty(value, message) {
|
|
1611
|
+
if (isEmpty(value)) throw toError$1(notEmpty, value, message, "Expected not empty value.");
|
|
1612
|
+
}
|
|
1613
|
+
function object(value, message) {
|
|
1614
|
+
if (!isObject(value)) throw toError$1(object, value, message, "Expected object value.");
|
|
1615
|
+
}
|
|
1616
|
+
function string(value, message) {
|
|
1617
|
+
if (!isString(value)) throw toError$1(string, value, message, "Expected string value.");
|
|
1618
|
+
}
|
|
1619
|
+
function boolean(value, message) {
|
|
1620
|
+
if (!isBoolean(value)) throw toError$1(boolean, value, message, "Expected boolean value.");
|
|
1621
|
+
}
|
|
1622
|
+
function notEmptyString(value, message) {
|
|
1623
|
+
if (!isString(value) || !value.trim()) throw toError$1(notEmptyString, value, message, "Expected not empty string value.");
|
|
1624
|
+
}
|
|
1625
|
+
function number$1(value, message) {
|
|
1626
|
+
if (!isNumber(value)) throw toError$1(number$1, value, message, "Expected number value.");
|
|
1627
|
+
}
|
|
1628
|
+
function bigint(value, message) {
|
|
1629
|
+
if (!isBigInt(value)) throw toError$1(bigint, value, message, "Expected bigint value.");
|
|
1630
|
+
}
|
|
1631
|
+
function date(value, message) {
|
|
1632
|
+
if (!isDate(value)) throw toError$1(date, value, message, "Expected date value.");
|
|
1633
|
+
}
|
|
1634
|
+
function fn(value, message) {
|
|
1635
|
+
if (!isFunction(value)) throw toError$1(fn, value, message, "Expected function value.");
|
|
1636
|
+
}
|
|
1637
|
+
function greaterThan(value, target, message) {
|
|
1638
|
+
if (!isNumber(value) || value <= target) throw toError$1(greaterThan, value, message, "Expected number value greater then " + target + ".");
|
|
1639
|
+
}
|
|
1640
|
+
function lessThan(value, target, message) {
|
|
1641
|
+
if (!isNumber(value) || value > target) throw toError$1(lessThan, value, message, "Expected number value less then " + target + ".");
|
|
1642
|
+
}
|
|
1643
|
+
function array(value, message) {
|
|
1644
|
+
if (!Array.isArray(value)) throw toError$1(array, value, message, "Expected array value.");
|
|
1645
|
+
}
|
|
1646
|
+
function arrayStrings(value, message) {
|
|
1647
|
+
if (!Array.isArray(value) || !value.every(isString)) throw toError$1(arrayStrings, value, message, "Expected strings list value.");
|
|
1648
|
+
}
|
|
1649
|
+
function arrayNumbers(value, message) {
|
|
1650
|
+
if (!Array.isArray(value) || !value.every(isNumber)) throw toError$1(arrayNumbers, value, message, "Expected numbers list value.");
|
|
1651
|
+
}
|
|
1652
|
+
function execSuccess(value, message) {
|
|
1653
|
+
if (isSkip(value)) throw toError$1(execSuccess, value, message, `Unexpected ${stringifyExecResult(value)}`);
|
|
1654
|
+
if (!isSuccess(value)) throw toError$1(execSuccess, value, message, "Expected ExecSuccess value.");
|
|
1655
|
+
}
|
|
1656
|
+
function execSkip(value, message) {
|
|
1657
|
+
if (isSuccess(value)) throw toError$1(execSkip, value, message, `Unexpected ${stringifyExecResult(value)}`);
|
|
1658
|
+
if (!isSkip(value)) throw toError$1(execSkip, value, message, "Expected ExecSkip value.");
|
|
1659
|
+
}
|
|
1660
|
+
function toError$1(operator, actual, message, unknownMessage = "Unknown error") {
|
|
1661
|
+
if (isError(message)) return message;
|
|
1662
|
+
return new AssertionError({
|
|
1663
|
+
actual,
|
|
1664
|
+
message: isString(message) ? message : unknownMessage,
|
|
1665
|
+
operator: operator.name,
|
|
1666
|
+
stackStartFn: operator
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
function weightedRoundRobin(arr) {
|
|
1670
|
+
ok(arr.length > 0, "Array must contain at least one item.");
|
|
1671
|
+
const instance = new WeightedRoundRobin(arr.map((v) => ({
|
|
1672
|
+
item: v.item,
|
|
1673
|
+
weight: Math.min(v.weight ?? 1, 1)
|
|
1674
|
+
})));
|
|
1675
|
+
return () => instance.nextItem();
|
|
1676
|
+
}
|
|
1677
|
+
const gcd = (a, b) => !b ? a : gcd(b, a % b);
|
|
1678
|
+
var WeightedRoundRobin = class {
|
|
1679
|
+
constructor(items) {
|
|
1680
|
+
this.items = items;
|
|
1681
|
+
this.currentIndex = -1;
|
|
1682
|
+
this.currentWeight = 0;
|
|
1683
|
+
this.maxWeight = this._calculateMaxWeight();
|
|
1684
|
+
this.gcdWeight = this._calculateGCD();
|
|
1685
|
+
}
|
|
1686
|
+
_calculateGCD() {
|
|
1687
|
+
return this.items.reduce((acc, curr) => gcd(acc, curr.weight), this.items[0].weight);
|
|
1688
|
+
}
|
|
1689
|
+
_calculateMaxWeight() {
|
|
1690
|
+
return Math.max(...this.items.map((s) => s.weight));
|
|
1691
|
+
}
|
|
1692
|
+
nextItem() {
|
|
1693
|
+
const n = this.items.length;
|
|
1694
|
+
while (true) {
|
|
1695
|
+
this.currentIndex = (this.currentIndex + 1) % n;
|
|
1696
|
+
if (this.currentIndex === 0) {
|
|
1697
|
+
this.currentWeight -= this.gcdWeight;
|
|
1698
|
+
if (this.currentWeight <= 0) this.currentWeight = this.maxWeight;
|
|
1699
|
+
}
|
|
1700
|
+
if (this.items[this.currentIndex].weight >= this.currentWeight) return this.items[this.currentIndex].item;
|
|
1701
|
+
}
|
|
1355
1702
|
}
|
|
1356
1703
|
};
|
|
1357
1704
|
function basex(alphabet) {
|
|
@@ -1583,21 +1930,6 @@ function bigIntFromBytes(bytes) {
|
|
|
1583
1930
|
for (let i = 0; i < bytes.byteLength; i++) decoded += BigInt(bytes[i]) << BigInt((bytes.byteLength - 1 - i) * 8);
|
|
1584
1931
|
return decoded;
|
|
1585
1932
|
}
|
|
1586
|
-
function toError(value, unknownMessage = "Unknown error") {
|
|
1587
|
-
if (isError(value)) return value;
|
|
1588
|
-
const error = new Error(unknownMessage, { cause: value });
|
|
1589
|
-
Error.captureStackTrace(error, toError);
|
|
1590
|
-
return error;
|
|
1591
|
-
}
|
|
1592
|
-
function createFunction(fnName, code, ...args) {
|
|
1593
|
-
try {
|
|
1594
|
-
const fn = new Function(...args, code);
|
|
1595
|
-
fn.code = code;
|
|
1596
|
-
return fn;
|
|
1597
|
-
} catch (err) {
|
|
1598
|
-
throw new Error(`failed to create bitPack.${fnName}()\nError: ${toError(err).message}\n-- CODE START --\n${code}\n-- CODE END--`);
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
1933
|
function bitPack(options) {
|
|
1602
1934
|
notEmpty(options.fields, "fields cannot be empty");
|
|
1603
1935
|
greaterThan(options.totalBits, 0, "totalBits must be greater than 0");
|
|
@@ -2862,10 +3194,6 @@ function catchError(fn) {
|
|
|
2862
3194
|
function onError$1(error) {
|
|
2863
3195
|
return [toError(error), void 0];
|
|
2864
3196
|
}
|
|
2865
|
-
const clamp = (num, min, max) => {
|
|
2866
|
-
if (!isNumber(num)) return min;
|
|
2867
|
-
return Math.min(max, Math.max(min, num));
|
|
2868
|
-
};
|
|
2869
3197
|
function parseAlpha(value, fallback = 1) {
|
|
2870
3198
|
let a = value;
|
|
2871
3199
|
if (isString(value)) a = value.endsWith("%") ? parseFloat(value) / 100 : parseFloat(value);
|
|
@@ -3249,7 +3577,7 @@ const rgb4Percent = new RegExp(`^
|
|
|
3249
3577
|
\\)
|
|
3250
3578
|
$
|
|
3251
3579
|
`.replace(/\n|\s/g, ""));
|
|
3252
|
-
const parseValue
|
|
3580
|
+
const parseValue = (num) => {
|
|
3253
3581
|
let n = num;
|
|
3254
3582
|
if (!isNumber(n)) n = n.endsWith("%") ? parseFloat(n) * 255 / 100 : parseFloat(n);
|
|
3255
3583
|
return clamp(Math.round(n), 0, 255);
|
|
@@ -3260,9 +3588,9 @@ function parseRGB(value) {
|
|
|
3260
3588
|
if (!rgb) return null;
|
|
3261
3589
|
const [, r, g, b, a] = rgb;
|
|
3262
3590
|
return {
|
|
3263
|
-
r: parseValue
|
|
3264
|
-
g: parseValue
|
|
3265
|
-
b: parseValue
|
|
3591
|
+
r: parseValue(r),
|
|
3592
|
+
g: parseValue(g),
|
|
3593
|
+
b: parseValue(b),
|
|
3266
3594
|
a: parseAlpha(a)
|
|
3267
3595
|
};
|
|
3268
3596
|
}
|
|
@@ -3404,10 +3732,10 @@ function channelsToRGB([r, g, b, a]) {
|
|
|
3404
3732
|
function contrastRatio(l1, l2) {
|
|
3405
3733
|
return round2digits((Math.max(l1, l2) + .05) / (Math.min(l1, l2) + .05), 4);
|
|
3406
3734
|
}
|
|
3407
|
-
const defaultWindow
|
|
3735
|
+
const defaultWindow = globalThis?.window;
|
|
3408
3736
|
function cssVariable(container) {
|
|
3409
|
-
if (!defaultWindow
|
|
3410
|
-
const computedStyles = defaultWindow
|
|
3737
|
+
if (!defaultWindow) return noop;
|
|
3738
|
+
const computedStyles = defaultWindow.getComputedStyle(container);
|
|
3411
3739
|
return (name) => {
|
|
3412
3740
|
const patterns = name.split("/", 2);
|
|
3413
3741
|
if (patterns[0]?.startsWith("--")) {
|
|
@@ -4129,305 +4457,6 @@ function humanFileSize(bytes, digits = 1, withSpace = true) {
|
|
|
4129
4457
|
} while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
|
|
4130
4458
|
return bytes.toFixed(digits) + (withSpace ? " " : "") + units[u];
|
|
4131
4459
|
}
|
|
4132
|
-
function constant(value) {
|
|
4133
|
-
return () => value;
|
|
4134
|
-
}
|
|
4135
|
-
function debounce(func, debounceMs, { signal, edges } = {}) {
|
|
4136
|
-
let pendingThis = void 0;
|
|
4137
|
-
let pendingArgs = null;
|
|
4138
|
-
const leading = edges != null && edges.includes("leading");
|
|
4139
|
-
const trailing = edges == null || edges.includes("trailing");
|
|
4140
|
-
const invoke = () => {
|
|
4141
|
-
if (pendingArgs !== null) {
|
|
4142
|
-
func.apply(pendingThis, pendingArgs);
|
|
4143
|
-
pendingThis = void 0;
|
|
4144
|
-
pendingArgs = null;
|
|
4145
|
-
}
|
|
4146
|
-
};
|
|
4147
|
-
const onTimerEnd = () => {
|
|
4148
|
-
if (trailing) invoke();
|
|
4149
|
-
cancel();
|
|
4150
|
-
};
|
|
4151
|
-
let timeoutId = null;
|
|
4152
|
-
const schedule = () => {
|
|
4153
|
-
if (timeoutId != null) clearTimeout(timeoutId);
|
|
4154
|
-
timeoutId = setTimeout(() => {
|
|
4155
|
-
timeoutId = null;
|
|
4156
|
-
onTimerEnd();
|
|
4157
|
-
}, debounceMs);
|
|
4158
|
-
};
|
|
4159
|
-
const cancelTimer = () => {
|
|
4160
|
-
if (timeoutId !== null) {
|
|
4161
|
-
clearTimeout(timeoutId);
|
|
4162
|
-
timeoutId = null;
|
|
4163
|
-
}
|
|
4164
|
-
};
|
|
4165
|
-
const cancel = () => {
|
|
4166
|
-
cancelTimer();
|
|
4167
|
-
pendingThis = void 0;
|
|
4168
|
-
pendingArgs = null;
|
|
4169
|
-
};
|
|
4170
|
-
const flush = () => {
|
|
4171
|
-
cancelTimer();
|
|
4172
|
-
invoke();
|
|
4173
|
-
};
|
|
4174
|
-
const debounced = function(...args) {
|
|
4175
|
-
if (signal?.aborted) return;
|
|
4176
|
-
pendingThis = this;
|
|
4177
|
-
pendingArgs = args;
|
|
4178
|
-
const isFirstCall = timeoutId == null;
|
|
4179
|
-
schedule();
|
|
4180
|
-
if (leading && isFirstCall) invoke();
|
|
4181
|
-
};
|
|
4182
|
-
debounced.schedule = schedule;
|
|
4183
|
-
debounced.cancel = cancel;
|
|
4184
|
-
debounced.flush = flush;
|
|
4185
|
-
signal?.addEventListener("abort", cancel, { once: true });
|
|
4186
|
-
return debounced;
|
|
4187
|
-
}
|
|
4188
|
-
function isSuccess(value) {
|
|
4189
|
-
return value.success === true;
|
|
4190
|
-
}
|
|
4191
|
-
function isSkip(value) {
|
|
4192
|
-
return value.skip === true;
|
|
4193
|
-
}
|
|
4194
|
-
function identity(x) {
|
|
4195
|
-
return x;
|
|
4196
|
-
}
|
|
4197
|
-
function negate(func) {
|
|
4198
|
-
return function(...args) {
|
|
4199
|
-
return !func.apply(this, args);
|
|
4200
|
-
};
|
|
4201
|
-
}
|
|
4202
|
-
var tagToType = {
|
|
4203
|
-
[nullTag]: "null",
|
|
4204
|
-
[undefinedTag]: "undefined",
|
|
4205
|
-
[stringTag]: "string",
|
|
4206
|
-
[functionTag]: "function",
|
|
4207
|
-
[arrayTag]: "array",
|
|
4208
|
-
[setTag]: "set",
|
|
4209
|
-
[mapTag]: "map",
|
|
4210
|
-
[dateTag]: (v) => isDate(v) ? "date" : "unknown",
|
|
4211
|
-
[objectTag]: "object",
|
|
4212
|
-
[symbolTag]: "symbol",
|
|
4213
|
-
[bigintTag]: "bigint",
|
|
4214
|
-
[booleanTag]: "boolean",
|
|
4215
|
-
[weakmapTag]: "weakmap",
|
|
4216
|
-
[weaksetTag]: "weakset",
|
|
4217
|
-
[numberTag]: (v) => isNumber(v) ? "number" : "unknown"
|
|
4218
|
-
};
|
|
4219
|
-
function typeOf(value) {
|
|
4220
|
-
var typeOrGetter = tagToType[getTag(value)] || "unknown";
|
|
4221
|
-
if (isFunction(typeOrGetter)) return typeOrGetter(value);
|
|
4222
|
-
return typeOrGetter;
|
|
4223
|
-
}
|
|
4224
|
-
const qs = {
|
|
4225
|
-
toParams,
|
|
4226
|
-
stringify,
|
|
4227
|
-
stringifyValue,
|
|
4228
|
-
parse,
|
|
4229
|
-
parseValue,
|
|
4230
|
-
merge
|
|
4231
|
-
};
|
|
4232
|
-
function merge(...values) {
|
|
4233
|
-
const result = {};
|
|
4234
|
-
for (const filter of values) for (const [key, value] of Object.entries(filter)) {
|
|
4235
|
-
const currentValue = result[key];
|
|
4236
|
-
const currentType = typeOf(currentValue);
|
|
4237
|
-
if (currentType !== typeOf(value)) {
|
|
4238
|
-
result[key] = value;
|
|
4239
|
-
continue;
|
|
4240
|
-
}
|
|
4241
|
-
switch (currentType) {
|
|
4242
|
-
case "array":
|
|
4243
|
-
result[key] = Array.from(/* @__PURE__ */ new Set([...currentValue, ...value]));
|
|
4244
|
-
break;
|
|
4245
|
-
case "object":
|
|
4246
|
-
result[key] = {};
|
|
4247
|
-
deepAssign(result[key], currentValue);
|
|
4248
|
-
deepAssign(result[key], value);
|
|
4249
|
-
break;
|
|
4250
|
-
case "map":
|
|
4251
|
-
result[key] = new Map([...Array.from(currentValue.entries()), ...Array.from(value.entries())]);
|
|
4252
|
-
break;
|
|
4253
|
-
case "set":
|
|
4254
|
-
result[key] = /* @__PURE__ */ new Set([...Array.from(currentValue), ...Array.from(value)]);
|
|
4255
|
-
break;
|
|
4256
|
-
default: result[key] = value;
|
|
4257
|
-
}
|
|
4258
|
-
}
|
|
4259
|
-
return result;
|
|
4260
|
-
}
|
|
4261
|
-
function stringify(obj, options) {
|
|
4262
|
-
return new URLSearchParams(toParams(obj, options)).toString();
|
|
4263
|
-
}
|
|
4264
|
-
function toParams(obj, options) {
|
|
4265
|
-
const result = {};
|
|
4266
|
-
const excludeEmpty = options?.excludeEmpty !== false;
|
|
4267
|
-
const excludeDefaults = options?.excludeDefaults;
|
|
4268
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
4269
|
-
if (excludeEmpty && isEmpty(value)) continue;
|
|
4270
|
-
if (excludeDefaults && key in excludeDefaults) {
|
|
4271
|
-
const defValue = excludeDefaults[key];
|
|
4272
|
-
if (isEqual(value, defValue)) continue;
|
|
4273
|
-
}
|
|
4274
|
-
const strValue = stringifyValue(value);
|
|
4275
|
-
if (excludeEmpty && strValue === "") continue;
|
|
4276
|
-
result[key] = strValue;
|
|
4277
|
-
}
|
|
4278
|
-
return result;
|
|
4279
|
-
}
|
|
4280
|
-
function parse(value, defaults) {
|
|
4281
|
-
const objValue = isString(value) ? Object.fromEntries(new URLSearchParams(value).entries()) : value;
|
|
4282
|
-
if (!defaults) return { ...objValue };
|
|
4283
|
-
const result = {};
|
|
4284
|
-
for (const [key, defValue] of Object.entries(defaults)) {
|
|
4285
|
-
const defType = typeOf(defValue);
|
|
4286
|
-
let parsedValue = parseValue(objValue[key], defType);
|
|
4287
|
-
if (parsedValue !== void 0 || defType === "undefined") {
|
|
4288
|
-
if (defType === "array" && defValue[0] !== void 0) {
|
|
4289
|
-
const itemValue = typeOf(defValue[0]);
|
|
4290
|
-
parsedValue = parsedValue.map((v) => parseValue(v, itemValue));
|
|
4291
|
-
}
|
|
4292
|
-
result[key] = parsedValue;
|
|
4293
|
-
} else result[key] = defValue;
|
|
4294
|
-
}
|
|
4295
|
-
return result;
|
|
4296
|
-
}
|
|
4297
|
-
function stringifyValue(value) {
|
|
4298
|
-
const valueType = typeOf(value);
|
|
4299
|
-
switch (valueType) {
|
|
4300
|
-
case "undefined": return "";
|
|
4301
|
-
case "null": return "";
|
|
4302
|
-
case "array": {
|
|
4303
|
-
let result = "";
|
|
4304
|
-
let sep = "";
|
|
4305
|
-
for (const item of value) {
|
|
4306
|
-
if (item === void 0) continue;
|
|
4307
|
-
if (isObject(item) || Array.isArray(item) || isString(item) && item.includes(",")) {
|
|
4308
|
-
result = JSON.stringify(value);
|
|
4309
|
-
break;
|
|
4310
|
-
} else {
|
|
4311
|
-
result += sep + stringifyValue(item);
|
|
4312
|
-
sep = ",";
|
|
4313
|
-
}
|
|
4314
|
-
}
|
|
4315
|
-
return result;
|
|
4316
|
-
}
|
|
4317
|
-
case "date": return value.toISOString();
|
|
4318
|
-
case "map": return JSON.stringify(Array.from(value.entries()));
|
|
4319
|
-
case "set": return JSON.stringify(Array.from(value.values()));
|
|
4320
|
-
case "boolean":
|
|
4321
|
-
case "number":
|
|
4322
|
-
case "string":
|
|
4323
|
-
case "bigint": return String(value);
|
|
4324
|
-
case "object": return JSON.stringify(value);
|
|
4325
|
-
case "unknown": if (isFunction(value?.toString)) return value.toString();
|
|
4326
|
-
default: throw new Error("Attempt to stringify unsupported type: " + valueType);
|
|
4327
|
-
}
|
|
4328
|
-
}
|
|
4329
|
-
function parseValue(value, asType) {
|
|
4330
|
-
const type = typeOf(value);
|
|
4331
|
-
if (type === asType) return value;
|
|
4332
|
-
else if (type !== "string") return;
|
|
4333
|
-
try {
|
|
4334
|
-
switch (asType) {
|
|
4335
|
-
case "undefined": return;
|
|
4336
|
-
case "array":
|
|
4337
|
-
if (value.startsWith("[") && value.endsWith("]")) return JSON.parse(value);
|
|
4338
|
-
return value.split(",");
|
|
4339
|
-
case "boolean": return value === "true";
|
|
4340
|
-
case "date": {
|
|
4341
|
-
const parsed = new Date(value);
|
|
4342
|
-
return isDate(parsed) ? parsed : void 0;
|
|
4343
|
-
}
|
|
4344
|
-
case "map": return new Map(JSON.parse(value));
|
|
4345
|
-
case "number": {
|
|
4346
|
-
const parsed = parseFloat(value);
|
|
4347
|
-
return isNumber(parsed) ? parsed : void 0;
|
|
4348
|
-
}
|
|
4349
|
-
case "object": return JSON.parse(value);
|
|
4350
|
-
case "set": return new Set(JSON.parse(value));
|
|
4351
|
-
case "null": return value === "" || value === void 0 ? null : void 0;
|
|
4352
|
-
case "string": return value;
|
|
4353
|
-
case "bigint": return BigInt(value);
|
|
4354
|
-
}
|
|
4355
|
-
} catch (_) {}
|
|
4356
|
-
}
|
|
4357
|
-
function defer() {
|
|
4358
|
-
let resolve;
|
|
4359
|
-
let reject;
|
|
4360
|
-
const promise = new Promise((_resolve, _reject) => {
|
|
4361
|
-
resolve = _resolve;
|
|
4362
|
-
reject = _reject;
|
|
4363
|
-
});
|
|
4364
|
-
return {
|
|
4365
|
-
resolve,
|
|
4366
|
-
reject,
|
|
4367
|
-
promise
|
|
4368
|
-
};
|
|
4369
|
-
}
|
|
4370
|
-
const defaultWindow = globalThis?.window;
|
|
4371
|
-
const idle = (() => {
|
|
4372
|
-
if (defaultWindow?.requestIdleCallback) return defaultWindow.requestIdleCallback;
|
|
4373
|
-
else if (defaultWindow?.requestAnimationFrame) return defaultWindow.requestAnimationFrame;
|
|
4374
|
-
else if (isFunction(process?.nextTick)) return process.nextTick;
|
|
4375
|
-
else return (fn) => setTimeout(fn, 0);
|
|
4376
|
-
})();
|
|
4377
|
-
function fastIdle(callback) {
|
|
4378
|
-
return idle(callback);
|
|
4379
|
-
}
|
|
4380
|
-
function fastIdlePromise() {
|
|
4381
|
-
return new Promise((resolve) => idle(resolve));
|
|
4382
|
-
}
|
|
4383
|
-
function delay(amount = "tick") {
|
|
4384
|
-
const d = defer();
|
|
4385
|
-
if (amount === "tick") fastIdle(d.resolve);
|
|
4386
|
-
else setTimeout(d.resolve, amount);
|
|
4387
|
-
return d.promise;
|
|
4388
|
-
}
|
|
4389
|
-
var NOOP_SHOULD_RETRY_BASED_ON_ERROR = () => true;
|
|
4390
|
-
function retryOnError({ beforeRetryCallback = noop, shouldRetryBasedOnError = NOOP_SHOULD_RETRY_BASED_ON_ERROR, maxAttempts, maxRetriesNumber = 1, delayFactor = 0, delayMaxMs = 1e3, delayMinMs = 100 }, fn) {
|
|
4391
|
-
delayMinMs = Math.max(delayMinMs, 1);
|
|
4392
|
-
delayMaxMs = Math.max(delayMaxMs, 1);
|
|
4393
|
-
return function(...args) {
|
|
4394
|
-
var delayMs = 0;
|
|
4395
|
-
var currentAttempt = 0;
|
|
4396
|
-
var leftAttempts = isNumber(maxAttempts) ? maxAttempts : maxRetriesNumber + 1;
|
|
4397
|
-
var run = () => {
|
|
4398
|
-
currentAttempt++;
|
|
4399
|
-
leftAttempts--;
|
|
4400
|
-
return Promise.resolve().then(() => fn.apply(this, args)).catch((e) => {
|
|
4401
|
-
if (leftAttempts < 1 || !shouldRetryBasedOnError(e, currentAttempt)) return Promise.reject(e);
|
|
4402
|
-
delayMs = clamp(delayMs * delayFactor, delayMinMs, delayMaxMs);
|
|
4403
|
-
return Promise.resolve().then(() => beforeRetryCallback(currentAttempt, leftAttempts <= 1)).then((newParams) => {
|
|
4404
|
-
if (Array.isArray(newParams)) args = newParams;
|
|
4405
|
-
return delay(delayMs).then(() => run());
|
|
4406
|
-
});
|
|
4407
|
-
});
|
|
4408
|
-
};
|
|
4409
|
-
return run();
|
|
4410
|
-
};
|
|
4411
|
-
}
|
|
4412
|
-
function throttle(func, throttleMs, { signal, edges = ["leading", "trailing"] } = {}) {
|
|
4413
|
-
let pendingAt = null;
|
|
4414
|
-
const debounced = debounce(func, throttleMs, {
|
|
4415
|
-
signal,
|
|
4416
|
-
edges
|
|
4417
|
-
});
|
|
4418
|
-
const throttled = function(...args) {
|
|
4419
|
-
if (pendingAt == null) pendingAt = Date.now();
|
|
4420
|
-
else if (Date.now() - pendingAt >= throttleMs) {
|
|
4421
|
-
pendingAt = Date.now();
|
|
4422
|
-
debounced.cancel();
|
|
4423
|
-
debounced(...args);
|
|
4424
|
-
}
|
|
4425
|
-
debounced(...args);
|
|
4426
|
-
};
|
|
4427
|
-
throttled.cancel = debounced.cancel;
|
|
4428
|
-
throttled.flush = debounced.flush;
|
|
4429
|
-
return throttled;
|
|
4430
|
-
}
|
|
4431
4460
|
const LEVEL_NAME_TO_NUM = {
|
|
4432
4461
|
debug: 0,
|
|
4433
4462
|
log: 1,
|
|
@@ -4523,6 +4552,39 @@ function asyncFilter(array, predicate, { concurrency = 1 } = {}) {
|
|
|
4523
4552
|
for (; currentIndex < concurrency; currentIndex++) processItem(currentIndex);
|
|
4524
4553
|
});
|
|
4525
4554
|
}
|
|
4555
|
+
function asyncFilterMap(array, callbackfn, { concurrency = 1 } = {}) {
|
|
4556
|
+
concurrency = Math.max(concurrency, 1);
|
|
4557
|
+
var mapped = [];
|
|
4558
|
+
if (array.length === 0) return Promise.resolve(mapped);
|
|
4559
|
+
var hasError = false;
|
|
4560
|
+
var buffer = Array(array.length).fill(SPECIAL_VALUE_2);
|
|
4561
|
+
var flushIndex = 0;
|
|
4562
|
+
var completed = 0;
|
|
4563
|
+
var currentIndex = 0;
|
|
4564
|
+
var cooldown = nextTickIteration(10);
|
|
4565
|
+
return new Promise((resolve, reject) => {
|
|
4566
|
+
var processItem = (index) => {
|
|
4567
|
+
if (hasError || index >= array.length) return;
|
|
4568
|
+
cooldown().then(() => callbackfn(array[index], SPECIAL_VALUE, index, array)).then((transformed) => {
|
|
4569
|
+
if (hasError) return;
|
|
4570
|
+
buffer[index] = transformed;
|
|
4571
|
+
while (flushIndex < array.length && buffer[flushIndex] !== SPECIAL_VALUE_2) {
|
|
4572
|
+
if (buffer[flushIndex] !== SPECIAL_VALUE) mapped.push(buffer[flushIndex]);
|
|
4573
|
+
flushIndex++;
|
|
4574
|
+
}
|
|
4575
|
+
completed++;
|
|
4576
|
+
if (completed >= array.length) resolve(mapped);
|
|
4577
|
+
else if (currentIndex < array.length) processItem(currentIndex++);
|
|
4578
|
+
}).catch((error) => {
|
|
4579
|
+
if (!hasError) {
|
|
4580
|
+
hasError = true;
|
|
4581
|
+
reject(error);
|
|
4582
|
+
}
|
|
4583
|
+
});
|
|
4584
|
+
};
|
|
4585
|
+
for (; currentIndex < concurrency; currentIndex++) processItem(currentIndex);
|
|
4586
|
+
});
|
|
4587
|
+
}
|
|
4526
4588
|
function asyncFind(array, callbackfn) {
|
|
4527
4589
|
var i = 0;
|
|
4528
4590
|
var cooldown = nextTickIteration(10);
|
|
@@ -5103,6 +5165,6 @@ function withResolve(fn, getCacheKey) {
|
|
|
5103
5165
|
}
|
|
5104
5166
|
}
|
|
5105
5167
|
}
|
|
5106
|
-
export { AppError, AssertionError, AsyncIterableQueue, CancellablePromise, ColorParser, instance as EJSON, EJSON as EJSONInstance, EJSONStream, FindMean, FixedMap, FixedWeakMap, LruCache, Queue, ResourcePool, SCHEDULER_JOB_FLAGS, Scheduler, SimpleEventEmitter, SortedArray, twemojiRegex_default as TWEMOJI_REGEX, TimeBucket, TimeSpan, alpha, argumentsTag, arrayBufferTag, arrayTag, arrayable, assert_exports as assert, asyncFilter, asyncFind, asyncForEach, asyncMap, avg, avgCircular, base62, base62Fast, base64, base64ToBytes, base64url, basex, bigInt64ArrayTag, bigIntBytes, bigIntFromBytes, bigUint64ArrayTag, bigintTag, bitPack, bitUnpack, blendColors, booleanTag, buildCssColor, bytesToBase64, cache, cacheBucket, cacheFixed, cacheLRU, camelCase, capitalize, captureStackTrace, catchError, channelsToHSL, channelsToHex, channelsToRGB, checkBitmask, chunk, chunkSeries, clamp, cleanEmpty, cleanObject, colorToChannels, compareBytes, concatenateBytes, constant, contrastRatio, convertToUnit, crc32, createCustomizer, createCustomizerFactory, createDateObject, createDeepCloneWith, createEJSON, createEJSONStream, createEnvParser, createFunction, createRandomizer, createScheduler, createSecureCustomizer, createTimeObject, createTimeSpan, createWithCache, cssVariable, dataViewTag, dateInDays, dateInSeconds, dateTag, debounce, deepAssign, deepClone, deepCloneWith, deepDefaults, deepFreeze, def, defer, delay, difference, dropCache, env, errorTag, escapeHtml, escapeNumeric, escapeRegExp, fastIdle, fastIdlePromise, fastRaf, findMean, flagsToMap, flatten, float32ArrayTag, float64ArrayTag, formatMoney, formatNumber, functionTag, get, getFileExtension, getFileName, getInitials, getLoggerLevel, getMostSpecificPaths, getRandomInt, getRandomTime, getTag, getWords, groupBy, has, hasOwn, hasProtocol, hex, hexToChannels, hmToSeconds, hslToChannels, humanFileSize, humanize, identity, int16ArrayTag, int32ArrayTag, int8ArrayTag, interpolateColor, intersection, intersectionBy, isBigInt, isBoolean, isBuffer, isCached, isClient, isColorChannels, isCustomizerFactory, isDate, isDateObject, isDeepKey, isDef, isEmpty, isEqual, isError, isFunction, isIndex, isInfinity, isMap, isNode, isNullOrUndefined, isNumber, isObject, isOneEmoji, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isSkip, isString, isSuccess, isSymbol, isTimeObject, isTimeString, isTimeValue, isTypedArray, isValidWeekDay, isWeakMap, isWeakSet, isWithCache, isoToFlagEmoji, kebabCase, keyBy, logger, lowerCase, luminance, mapTag, maskingEmail, maskingPhone, maskingWords, negate, nextTickIteration, noop, nullTag, numberTag, objectId, objectTag, omit, omitPrefixed, orderBy, parseAllNumbers, parseAlpha, parsePercentage, percentOf, pick, pickPrefixed, qs, rafPromise, randomString, regexpTag, removeVS16s, retryOnError, rgbToChannels, rleDecode, rleEncode, round2digits, secondsToHm, set, setLoggerLevel, setTag, shuffle, snakeCase, sprintf, startCase, strAssign, stringTag, sum, symbolTag, textDecoder, textEncoder, throttle, timeFromMinutes, timeStringify, timeToMinutes, timeout, timestamp, timestampMs, timestampToDate, tintedTextColor, toError, toKey, toMap, toPath, toPromise, toString, truncate, typeOf, uint16ArrayTag, uint16ToUint8, uint32ArrayTag, uint32ToUint8, uint8ArrayTag, uint8ClampedArrayTag, uint8ToUint16, uint8ToUint32, undefinedTag, unflatten, union, uniq, uniqBy, unset, updateWith, weakmapTag, weaksetTag, weeksInYear, weightedRoundRobin, withCache, withCacheBucket, withCacheBucketBatch, withCacheFixed, withCacheLRU, withDeepClone, withPointerCache, withResolve, wrapText };
|
|
5168
|
+
export { AppError, AssertionError, AsyncIterableQueue, CancellablePromise, ColorParser, instance as EJSON, EJSON as EJSONInstance, EJSONStream, FindMean, FixedMap, FixedWeakMap, LruCache, Queue, ResourcePool, SCHEDULER_JOB_FLAGS, Scheduler, SimpleEventEmitter, SortedArray, twemojiRegex_default as TWEMOJI_REGEX, TimeBucket, TimeSpan, alpha, argumentsTag, arrayBufferTag, arrayTag, arrayable, assert_exports as assert, asyncFilter, asyncFilterMap, asyncFind, asyncForEach, asyncMap, avg, avgCircular, base62, base62Fast, base64, base64ToBytes, base64url, basex, bigInt64ArrayTag, bigIntBytes, bigIntFromBytes, bigUint64ArrayTag, bigintTag, bitPack, bitUnpack, blendColors, booleanTag, buildCssColor, bytesToBase64, cache, cacheBucket, cacheFixed, cacheLRU, camelCase, capitalize, captureStackTrace, catchError, channelsToHSL, channelsToHex, channelsToRGB, checkBitmask, chunk, chunkSeries, clamp, cleanEmpty, cleanObject, colorToChannels, compareBytes, concatenateBytes, constant, contrastRatio, convertToUnit, crc32, createCustomizer, createCustomizerFactory, createDateObject, createDeepCloneWith, createEJSON, createEJSONStream, createEnvParser, createFunction, createRandomizer, createScheduler, createSecureCustomizer, createTimeObject, createTimeSpan, createWithCache, cssVariable, dataViewTag, dateInDays, dateInSeconds, dateTag, debounce, deepAssign, deepClone, deepCloneWith, deepDefaults, deepFreeze, def, defer, delay, difference, dropCache, env, errorTag, escapeHtml, escapeNumeric, escapeRegExp, fastIdle, fastIdlePromise, fastRaf, filterMap, findMean, flagsToMap, flatten, float32ArrayTag, float64ArrayTag, formatMoney, formatNumber, functionTag, get, getFileExtension, getFileName, getInitials, getLoggerLevel, getMostSpecificPaths, getRandomInt, getRandomTime, getTag, getWords, groupBy, has, hasOwn, hasProtocol, hex, hexToChannels, hmToSeconds, hslToChannels, humanFileSize, humanize, identity, int16ArrayTag, int32ArrayTag, int8ArrayTag, interpolateColor, intersection, intersectionBy, isBigInt, isBoolean, isBuffer, isCached, isClient, isColorChannels, isCustomizerFactory, isDate, isDateObject, isDeepKey, isDef, isEmpty, isEqual, isError, isFunction, isIndex, isInfinity, isMap, isNode, isNullOrUndefined, isNumber, isObject, isOneEmoji, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isSkip, isString, isSuccess, isSymbol, isTimeObject, isTimeString, isTimeValue, isTypedArray, isValidWeekDay, isWeakMap, isWeakSet, isWithCache, isoToFlagEmoji, kebabCase, keyBy, logger, lowerCase, luminance, mapTag, maskingEmail, maskingPhone, maskingWords, negate, nextTickIteration, noop, nullTag, numberTag, objectId, objectTag, omit, omitPrefixed, orderBy, parseAllNumbers, parseAlpha, parsePercentage, percentOf, pick, pickPrefixed, qs, rafPromise, randomString, regexpTag, removeVS16s, retryOnError, rgbToChannels, rleDecode, rleEncode, round2digits, secondsToHm, set, setLoggerLevel, setTag, shuffle, snakeCase, sprintf, startCase, strAssign, stringTag, stringifyExecResult, sum, symbolTag, textDecoder, textEncoder, throttle, timeFromMinutes, timeStringify, timeToMinutes, timeout, timestamp, timestampMs, timestampToDate, tintedTextColor, toError, toKey, toMap, toPath, toPromise, toString, truncate, typeOf, uint16ArrayTag, uint16ToUint8, uint32ArrayTag, uint32ToUint8, uint8ArrayTag, uint8ClampedArrayTag, uint8ToUint16, uint8ToUint32, undefinedTag, unflatten, union, uniq, uniqBy, unset, updateWith, weakmapTag, weaksetTag, weeksInYear, weightedRoundRobin, withCache, withCacheBucket, withCacheBucketBatch, withCacheFixed, withCacheLRU, withDeepClone, withPointerCache, withResolve, wrapText };
|
|
5107
5169
|
|
|
5108
5170
|
//# sourceMappingURL=index.mjs.map
|