@oscarpalmer/atoms 0.184.1 → 0.185.0
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/array/index.d.mts +2 -2
- package/dist/array/index.mjs +2 -2
- package/dist/array/{position.d.mts → match.d.mts} +9 -6
- package/dist/array/{position.mjs → match.mjs} +16 -16
- package/dist/array/move.mjs +1 -1
- package/dist/array/single.mjs +2 -2
- package/dist/array/sort.d.mts +9 -4
- package/dist/array/sort.mjs +6 -6
- package/dist/array/swap.mjs +1 -1
- package/dist/beacon.d.mts +12 -0
- package/dist/beacon.mjs +9 -0
- package/dist/color/instance.d.mts +8 -0
- package/dist/color/instance.mjs +5 -2
- package/dist/color/misc/get.mjs +8 -8
- package/dist/color/misc/state.d.mts +2 -2
- package/dist/color/misc/state.mjs +2 -2
- package/dist/color/models.d.mts +30 -0
- package/dist/function/assert.d.mts +29 -8
- package/dist/function/assert.mjs +29 -8
- package/dist/function/memoize.d.mts +3 -0
- package/dist/function/memoize.mjs +3 -0
- package/dist/function/once.mjs +9 -9
- package/dist/function/retry.d.mts +3 -0
- package/dist/function/retry.mjs +11 -8
- package/dist/function/work.mjs +1 -1
- package/dist/index.d.mts +272 -160
- package/dist/index.mjs +279 -216
- package/dist/internal/number.d.mts +2 -1
- package/dist/internal/number.mjs +4 -1
- package/dist/internal/value/compare.d.mts +2 -1
- package/dist/internal/value/equal.d.mts +5 -0
- package/dist/internal/value/equal.mjs +5 -5
- package/dist/internal/value/get.d.mts +2 -2
- package/dist/internal/value/has.d.mts +3 -3
- package/dist/internal/value/has.mjs +1 -1
- package/dist/internal/value/misc.d.mts +2 -2
- package/dist/internal/value/misc.mjs +10 -4
- package/dist/logger.d.mts +11 -0
- package/dist/logger.mjs +11 -0
- package/dist/models.d.mts +1 -1
- package/dist/promise/helpers.mjs +3 -5
- package/dist/promise/index.d.mts +0 -6
- package/dist/promise/models.d.mts +36 -0
- package/dist/promise/models.mjs +6 -0
- package/dist/queue.d.mts +13 -1
- package/dist/queue.mjs +14 -7
- package/dist/result/index.d.mts +0 -8
- package/dist/result/index.mjs +0 -8
- package/dist/result/match.d.mts +4 -4
- package/dist/result/work/flow.d.mts +12 -36
- package/dist/result/work/pipe.d.mts +11 -33
- package/dist/sized/set.d.mts +3 -2
- package/dist/sized/set.mjs +3 -2
- package/dist/string/fuzzy.mjs +2 -2
- package/dist/value/handle.mjs +1 -1
- package/dist/value/merge.d.mts +0 -1
- package/dist/value/merge.mjs +0 -1
- package/dist/value/shake.d.mts +3 -0
- package/dist/value/smush.d.mts +3 -0
- package/dist/value/transform.d.mts +9 -0
- package/dist/value/unsmush.d.mts +3 -0
- package/package.json +3 -3
- package/src/array/difference.ts +4 -0
- package/src/array/from.ts +4 -0
- package/src/array/index.ts +1 -1
- package/src/array/intersection.ts +4 -0
- package/src/array/{position.ts → match.ts} +28 -25
- package/src/array/move.ts +5 -1
- package/src/array/reverse.ts +4 -0
- package/src/array/select.ts +2 -0
- package/src/array/single.ts +2 -2
- package/src/array/sort.ts +14 -9
- package/src/array/swap.ts +5 -1
- package/src/array/toggle.ts +4 -0
- package/src/array/union.ts +4 -0
- package/src/beacon.ts +12 -0
- package/src/color/index.ts +0 -3
- package/src/color/instance.ts +11 -3
- package/src/color/misc/get.ts +8 -8
- package/src/color/misc/state.ts +1 -1
- package/src/color/models.ts +30 -0
- package/src/function/assert.ts +66 -7
- package/src/function/memoize.ts +3 -0
- package/src/function/once.ts +13 -9
- package/src/function/retry.ts +11 -8
- package/src/internal/number.ts +6 -0
- package/src/internal/value/compare.ts +2 -1
- package/src/internal/value/equal.ts +10 -5
- package/src/internal/value/get.ts +2 -2
- package/src/internal/value/has.ts +6 -6
- package/src/internal/value/misc.ts +24 -13
- package/src/logger.ts +11 -0
- package/src/models.ts +1 -1
- package/src/promise/helpers.ts +3 -6
- package/src/promise/index.ts +0 -6
- package/src/promise/models.ts +36 -0
- package/src/queue.ts +23 -11
- package/src/result/index.ts +0 -8
- package/src/result/match.ts +4 -4
- package/src/result/work/flow.ts +12 -36
- package/src/result/work/pipe.ts +11 -33
- package/src/sized/set.ts +4 -3
- package/src/string/fuzzy.ts +2 -2
- package/src/value/merge.ts +0 -1
- package/src/value/shake.ts +3 -0
- package/src/value/smush.ts +3 -0
- package/src/value/transform.ts +9 -0
- package/src/value/unsmush.ts +3 -0
package/dist/index.mjs
CHANGED
|
@@ -525,16 +525,16 @@ function partition(array, ...parameters) {
|
|
|
525
525
|
return [matched, notMatched];
|
|
526
526
|
}
|
|
527
527
|
//#endregion
|
|
528
|
-
//#region src/array/
|
|
528
|
+
//#region src/array/match.ts
|
|
529
529
|
function endsWithArray(haystack, needle, key) {
|
|
530
530
|
return endings.has(getPosition(haystack, needle, key)[1]);
|
|
531
531
|
}
|
|
532
|
-
function
|
|
532
|
+
function getArrayComparison(haystack, needle, key) {
|
|
533
533
|
return getPosition(haystack, needle, key)[1];
|
|
534
534
|
}
|
|
535
535
|
function getName(start, haystack, needle) {
|
|
536
|
-
if (start === 0) return haystack === needle ?
|
|
537
|
-
return start + needle === haystack ?
|
|
536
|
+
if (start === 0) return haystack === needle ? COMPARISON_SAME : COMPARISON_START;
|
|
537
|
+
return start + needle === haystack ? COMPARISON_END : COMPARISON_INSIDE;
|
|
538
538
|
}
|
|
539
539
|
function getPosition(haystack, needle, key) {
|
|
540
540
|
if (!Array.isArray(haystack) || !Array.isArray(needle)) return invalid;
|
|
@@ -569,17 +569,17 @@ function indexOfArray(haystack, needle, key) {
|
|
|
569
569
|
function startsWithArray(haystack, needle, key) {
|
|
570
570
|
return starts.has(getPosition(haystack, needle, key)[1]);
|
|
571
571
|
}
|
|
572
|
-
const
|
|
573
|
-
const
|
|
574
|
-
const
|
|
575
|
-
const
|
|
576
|
-
const
|
|
577
|
-
const
|
|
578
|
-
const endings = new Set([
|
|
579
|
-
const invalid = [-1,
|
|
580
|
-
const outside = [-1,
|
|
581
|
-
const outsides = new Set([
|
|
582
|
-
const starts = new Set([
|
|
572
|
+
const COMPARISON_END = "end";
|
|
573
|
+
const COMPARISON_INSIDE = "inside";
|
|
574
|
+
const COMPARISON_INVALID = "invalid";
|
|
575
|
+
const COMPARISON_OUTSIDE = "outside";
|
|
576
|
+
const COMPARISON_SAME = "same";
|
|
577
|
+
const COMPARISON_START = "start";
|
|
578
|
+
const endings = new Set([COMPARISON_END, COMPARISON_SAME]);
|
|
579
|
+
const invalid = [-1, COMPARISON_INVALID];
|
|
580
|
+
const outside = [-1, COMPARISON_OUTSIDE];
|
|
581
|
+
const outsides = new Set([COMPARISON_INVALID, COMPARISON_OUTSIDE]);
|
|
582
|
+
const starts = new Set([COMPARISON_START, COMPARISON_SAME]);
|
|
583
583
|
//#endregion
|
|
584
584
|
//#region src/array/push.ts
|
|
585
585
|
/**
|
|
@@ -620,10 +620,10 @@ function select(array, ...parameters) {
|
|
|
620
620
|
//#region src/array/single.ts
|
|
621
621
|
function single(array, ...parameters) {
|
|
622
622
|
const { matched } = findValues("all", array, parameters);
|
|
623
|
-
if (matched.length > 1) throw new Error(
|
|
623
|
+
if (matched.length > 1) throw new Error(SINGLE_MESSAGE);
|
|
624
624
|
return matched[0];
|
|
625
625
|
}
|
|
626
|
-
const
|
|
626
|
+
const SINGLE_MESSAGE = "Multiple items were found";
|
|
627
627
|
//#endregion
|
|
628
628
|
//#region src/array/slice.ts
|
|
629
629
|
function drop(array, first, second) {
|
|
@@ -1170,9 +1170,9 @@ function isSortedArray(array, sorters) {
|
|
|
1170
1170
|
if (length < 2) return true;
|
|
1171
1171
|
const sortersLength = sorters.length;
|
|
1172
1172
|
let offset = 0;
|
|
1173
|
-
if (length >=
|
|
1174
|
-
offset = Math.round(length /
|
|
1175
|
-
offset = offset >
|
|
1173
|
+
if (length >= SORT_THRESHOLD) {
|
|
1174
|
+
offset = Math.round(length / SORT_PEEK_PERCENTAGE);
|
|
1175
|
+
offset = offset > SORT_THRESHOLD ? SORT_THRESHOLD : offset;
|
|
1176
1176
|
for (let index = 0; index < offset; index += 1) {
|
|
1177
1177
|
const [firstItem, firstOffset] = [array[index], array[index + 1]];
|
|
1178
1178
|
const [secondItem, secondOffset] = [array[length - index - 2], array[length - index - 1]];
|
|
@@ -1196,11 +1196,11 @@ function sortArray(array, sorters) {
|
|
|
1196
1196
|
const { length } = sorters;
|
|
1197
1197
|
return array.length > 1 ? array.sort((first, second) => getComparisonValue(first, second, sorters, length)) : array;
|
|
1198
1198
|
}
|
|
1199
|
-
sort.
|
|
1199
|
+
sort.getIndex = getSortedIndex;
|
|
1200
1200
|
sort.initialize = initializeSorter;
|
|
1201
1201
|
sort.is = isSorted;
|
|
1202
|
-
const
|
|
1203
|
-
const
|
|
1202
|
+
const SORT_PEEK_PERCENTAGE = 10;
|
|
1203
|
+
const SORT_THRESHOLD = 100;
|
|
1204
1204
|
const SORT_DIRECTION_ASCENDING = "ascending";
|
|
1205
1205
|
const SORT_DIRECTION_DESCENDING = "descending";
|
|
1206
1206
|
const modifiers = {
|
|
@@ -1299,12 +1299,132 @@ function toRecordArrays(array, first, second) {
|
|
|
1299
1299
|
return groupValues(array, first, second, true);
|
|
1300
1300
|
}
|
|
1301
1301
|
//#endregion
|
|
1302
|
+
//#region src/internal/result.ts
|
|
1303
|
+
function _isResult(value, okValue) {
|
|
1304
|
+
if (isNonPlainObject(value)) return false;
|
|
1305
|
+
return value.ok === okValue && (okValue ? PROPERTY_VALUE : PROPERTY_ERROR) in value;
|
|
1306
|
+
}
|
|
1307
|
+
function isError(value, extended) {
|
|
1308
|
+
return _isResult(value, false) && (extended === true ? value.original instanceof Error : true);
|
|
1309
|
+
}
|
|
1310
|
+
/**
|
|
1311
|
+
* Is the result ok?
|
|
1312
|
+
* @param result Result to check
|
|
1313
|
+
* @returns `true` if the result is ok, `false` otherwise
|
|
1314
|
+
*/
|
|
1315
|
+
function isOk(value) {
|
|
1316
|
+
return _isResult(value, true);
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Is the value a result?
|
|
1320
|
+
* @param value Value to check
|
|
1321
|
+
* @returns `true` if the value is a result, `false` otherwise
|
|
1322
|
+
*/
|
|
1323
|
+
function isResult(value) {
|
|
1324
|
+
return _isResult(value, true) || _isResult(value, false);
|
|
1325
|
+
}
|
|
1326
|
+
const PROPERTY_ERROR = "error";
|
|
1327
|
+
const PROPERTY_VALUE = "value";
|
|
1328
|
+
//#endregion
|
|
1329
|
+
//#region src/result/misc.ts
|
|
1330
|
+
function error(value, original) {
|
|
1331
|
+
return getError(value, original);
|
|
1332
|
+
}
|
|
1333
|
+
function getError(value, original) {
|
|
1334
|
+
const errorResult = {
|
|
1335
|
+
error: value,
|
|
1336
|
+
ok: false
|
|
1337
|
+
};
|
|
1338
|
+
if (original instanceof Error) errorResult.original = original;
|
|
1339
|
+
return errorResult;
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* Creates an ok result
|
|
1343
|
+
* @param value Value
|
|
1344
|
+
* @returns Ok result
|
|
1345
|
+
*/
|
|
1346
|
+
function ok(value) {
|
|
1347
|
+
return {
|
|
1348
|
+
ok: true,
|
|
1349
|
+
value
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Converts a result to a promise
|
|
1354
|
+
*
|
|
1355
|
+
* Resolves if ok, rejects for error
|
|
1356
|
+
* @param result Result to convert
|
|
1357
|
+
* @returns Promised result
|
|
1358
|
+
*/
|
|
1359
|
+
async function toPromise(result) {
|
|
1360
|
+
const actual = typeof result === "function" ? result() : result;
|
|
1361
|
+
if (!isResult(actual)) return Promise.reject(new Error(MESSAGE_PROMISE_RESULT));
|
|
1362
|
+
return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
|
|
1363
|
+
}
|
|
1364
|
+
function unwrap(value, defaultValue) {
|
|
1365
|
+
return isOk(value) ? value.value : defaultValue;
|
|
1366
|
+
}
|
|
1367
|
+
const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
|
|
1368
|
+
//#endregion
|
|
1369
|
+
//#region src/internal/value/misc.ts
|
|
1370
|
+
function findKey(needle, haystack) {
|
|
1371
|
+
const keys = Object.keys(haystack);
|
|
1372
|
+
const index = keys.map((key) => key.toLowerCase()).indexOf(needle.toLowerCase());
|
|
1373
|
+
return index > -1 ? keys[index] : needle;
|
|
1374
|
+
}
|
|
1375
|
+
function getNestedValue(data, path, ignoreCase) {
|
|
1376
|
+
if (typeof data !== "object" || data === null) return error(NESTED_MESSAGE_INPUT);
|
|
1377
|
+
if (typeof path !== "string" || path.trim().length === 0) return error(NESTED_MESSAGE_PATH);
|
|
1378
|
+
const shouldIgnoreCase = ignoreCase === true;
|
|
1379
|
+
const paths = getPaths(path, shouldIgnoreCase);
|
|
1380
|
+
if (typeof paths === "string") return handleValue(data, paths, null, true, shouldIgnoreCase);
|
|
1381
|
+
const { length } = paths;
|
|
1382
|
+
let current = data;
|
|
1383
|
+
for (let index = 0; index < length; index += 1) {
|
|
1384
|
+
const part = paths[index];
|
|
1385
|
+
const handled = handleValue(current, part, null, true, shouldIgnoreCase);
|
|
1386
|
+
if (!handled.ok) return handled;
|
|
1387
|
+
current = handled.value;
|
|
1388
|
+
}
|
|
1389
|
+
return ok(current);
|
|
1390
|
+
}
|
|
1391
|
+
function getPaths(path, lowercase) {
|
|
1392
|
+
const normalized = lowercase ? path.toLowerCase() : path;
|
|
1393
|
+
if (!EXPRESSION_NESTED.test(normalized)) return normalized;
|
|
1394
|
+
return normalized.replace(EXPRESSION_BRACKET, ".$1").replace(EXPRESSION_DOTS, "").split(".");
|
|
1395
|
+
}
|
|
1396
|
+
function handleValue(data, path, value, get, ignoreCase) {
|
|
1397
|
+
if (typeof data === "object" && data !== null) {
|
|
1398
|
+
if (ignoreKey(path)) return error(NESTED_MESSAGE_UNSAFE);
|
|
1399
|
+
const key = ignoreCase ? findKey(path, data) : path;
|
|
1400
|
+
if (get) return key in data ? ok(data[key]) : error(NESTED_MESSAGE_MISSING);
|
|
1401
|
+
data[key] = typeof value === "function" ? value(data[key]) : value;
|
|
1402
|
+
}
|
|
1403
|
+
if (get) return error(NESTED_MESSAGE_MISSING);
|
|
1404
|
+
}
|
|
1405
|
+
const EXPRESSION_BRACKET = /\[(\w+)\]/g;
|
|
1406
|
+
const EXPRESSION_DOTS = /^\.|\.$/g;
|
|
1407
|
+
const EXPRESSION_NESTED = /\.|\[\w+\]/;
|
|
1408
|
+
const NESTED_MESSAGE_INPUT = "Expected data to be an object";
|
|
1409
|
+
const NESTED_MESSAGE_MISSING = "Expected property to exist in object";
|
|
1410
|
+
const NESTED_MESSAGE_PATH = "Expected path to be a string";
|
|
1411
|
+
const NESTED_MESSAGE_UNSAFE = "Access to this property is not allowed";
|
|
1412
|
+
//#endregion
|
|
1413
|
+
//#region src/internal/value/has.ts
|
|
1414
|
+
function hasValue(data, path, ignoreCase) {
|
|
1415
|
+
return getNestedValue(data, path, ignoreCase === true).ok;
|
|
1416
|
+
}
|
|
1417
|
+
hasValue.get = hasValueResult;
|
|
1418
|
+
function hasValueResult(data, path, ignoreCase) {
|
|
1419
|
+
return getNestedValue(data, path, ignoreCase === true);
|
|
1420
|
+
}
|
|
1421
|
+
//#endregion
|
|
1302
1422
|
//#region src/function/assert.ts
|
|
1303
1423
|
/**
|
|
1304
1424
|
* Asserts that a condition is true, throwing an error if it is not
|
|
1305
1425
|
* @param condition Condition to assert
|
|
1306
1426
|
* @param message Error message
|
|
1307
|
-
* @param error Error constructor
|
|
1427
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
1308
1428
|
*/
|
|
1309
1429
|
function assert(condition, message, error) {
|
|
1310
1430
|
if (!condition()) throw new (error ?? Error)(message);
|
|
@@ -1313,13 +1433,14 @@ assert.condition = assertCondition;
|
|
|
1313
1433
|
assert.defined = assertDefined;
|
|
1314
1434
|
assert.instanceOf = assertInstanceOf;
|
|
1315
1435
|
assert.is = assertIs;
|
|
1436
|
+
assert.property = assertProperty;
|
|
1316
1437
|
/**
|
|
1317
1438
|
* Creates an asserter that asserts a condition is true, throwing an error if it is not
|
|
1318
1439
|
*
|
|
1319
1440
|
* Available as `assertCondition` and `assert.condition`
|
|
1320
1441
|
* @param condition Condition to assert
|
|
1321
1442
|
* @param message Error message
|
|
1322
|
-
* @param error Error constructor
|
|
1443
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
1323
1444
|
* @returns Asserter
|
|
1324
1445
|
*/
|
|
1325
1446
|
function assertCondition(condition, message, error) {
|
|
@@ -1328,14 +1449,15 @@ function assertCondition(condition, message, error) {
|
|
|
1328
1449
|
};
|
|
1329
1450
|
}
|
|
1330
1451
|
/**
|
|
1331
|
-
* Asserts that a value is defined throwing an error if it is not
|
|
1452
|
+
* Asserts that a value is defined, throwing an error if it is not
|
|
1332
1453
|
*
|
|
1333
1454
|
* Available as `assertDefined` and `assert.defined`
|
|
1334
1455
|
* @param value Value to assert
|
|
1335
1456
|
* @param message Error message
|
|
1457
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
1336
1458
|
*/
|
|
1337
|
-
function assertDefined(value, message) {
|
|
1338
|
-
assert(() => value != null, message ?? MESSAGE_VALUE_DEFINED);
|
|
1459
|
+
function assertDefined(value, message, error) {
|
|
1460
|
+
assert(() => value != null, message ?? MESSAGE_VALUE_DEFINED, error);
|
|
1339
1461
|
}
|
|
1340
1462
|
/**
|
|
1341
1463
|
* Creates an asserter that asserts a value is an instance of a constructor, throwing an error if it is not
|
|
@@ -1343,7 +1465,7 @@ function assertDefined(value, message) {
|
|
|
1343
1465
|
* Available as `assertInstanceOf` and `assert.instanceOf`
|
|
1344
1466
|
* @param constructor Constructor to check against
|
|
1345
1467
|
* @param message Error message
|
|
1346
|
-
* @param error Error constructor
|
|
1468
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
1347
1469
|
* @returns Asserter
|
|
1348
1470
|
*/
|
|
1349
1471
|
function assertInstanceOf(constructor, message, error) {
|
|
@@ -1357,7 +1479,7 @@ function assertInstanceOf(constructor, message, error) {
|
|
|
1357
1479
|
* Available as `assertIs` and `assert.is`
|
|
1358
1480
|
* @param condition Type guard function to check the value
|
|
1359
1481
|
* @param message Error message
|
|
1360
|
-
* @param error Error constructor
|
|
1482
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
1361
1483
|
* @returns Asserter
|
|
1362
1484
|
*/
|
|
1363
1485
|
function assertIs(condition, message, error) {
|
|
@@ -1365,6 +1487,24 @@ function assertIs(condition, message, error) {
|
|
|
1365
1487
|
assert(() => condition(value), message, error);
|
|
1366
1488
|
};
|
|
1367
1489
|
}
|
|
1490
|
+
/**
|
|
1491
|
+
* Creates an asserter that asserts a property of a value exists and satisfies a condition, throwing an error if it does not
|
|
1492
|
+
*
|
|
1493
|
+
* Available as `assertProperty` and `assert.property`
|
|
1494
|
+
* @param path Path to the property to check, e.g., `foo.bar.baz` for a nested property
|
|
1495
|
+
* @param condition Condition to assert for the property
|
|
1496
|
+
* @param message Error message
|
|
1497
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
1498
|
+
* @returns Asserter
|
|
1499
|
+
*/
|
|
1500
|
+
function assertProperty(path, condition, message, error) {
|
|
1501
|
+
return (value) => {
|
|
1502
|
+
assert(() => {
|
|
1503
|
+
const result = hasValueResult(value, path, false);
|
|
1504
|
+
return result.ok && condition(result.value);
|
|
1505
|
+
}, message, error);
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1368
1508
|
const MESSAGE_VALUE_DEFINED = "Expected value to be defined";
|
|
1369
1509
|
//#endregion
|
|
1370
1510
|
//#region src/internal/function/misc.ts
|
|
@@ -1427,6 +1567,9 @@ function getNumber(value) {
|
|
|
1427
1567
|
if (isBinary || EXPRESSION_OCTAL.test(trimmed)) return Number.parseInt(trimmed.slice(2), isBinary ? 2 : OCTAL_VALUE);
|
|
1428
1568
|
return Number(trimmed);
|
|
1429
1569
|
}
|
|
1570
|
+
function getNumberOrDefault(value, defaultValue, minimum) {
|
|
1571
|
+
return typeof value === "number" && !Number.isNaN(value) && value >= (minimum ?? 0) ? Math.floor(value) : defaultValue;
|
|
1572
|
+
}
|
|
1430
1573
|
const EXPRESSION_BINARY = /^0b[01]+$/i;
|
|
1431
1574
|
const EXPRESSION_OCTAL = /^0o[0-7]+$/i;
|
|
1432
1575
|
const EXPRESSION_ZEROISH = /^\s*0+\s*$/;
|
|
@@ -1497,6 +1640,9 @@ var SizedMap = class extends Map {
|
|
|
1497
1640
|
};
|
|
1498
1641
|
//#endregion
|
|
1499
1642
|
//#region src/function/memoize.ts
|
|
1643
|
+
/**
|
|
1644
|
+
* A memoized function, caching and retrieving results based on the its parameters _(or a custom cache key)_
|
|
1645
|
+
*/
|
|
1500
1646
|
var Memoized = class {
|
|
1501
1647
|
#state;
|
|
1502
1648
|
/**
|
|
@@ -1739,7 +1885,7 @@ throttle.async = asyncThrottle;
|
|
|
1739
1885
|
* @returns Once callback
|
|
1740
1886
|
*/
|
|
1741
1887
|
function asyncOnce(callback) {
|
|
1742
|
-
assert(() => typeof callback === "function",
|
|
1888
|
+
assert(() => typeof callback === "function", ONCE_MESSAGE_EXPECTATION);
|
|
1743
1889
|
const state = {
|
|
1744
1890
|
called: false,
|
|
1745
1891
|
cleared: false,
|
|
@@ -1749,7 +1895,7 @@ function asyncOnce(callback) {
|
|
|
1749
1895
|
value: void 0
|
|
1750
1896
|
};
|
|
1751
1897
|
const fn = (...parameters) => {
|
|
1752
|
-
if (state.cleared) return Promise.reject(new Error(
|
|
1898
|
+
if (state.cleared) return Promise.reject(new Error(ONCE_MESSAGE_CLEARED));
|
|
1753
1899
|
if (state.finished) return state.error ? Promise.reject(state.value) : Promise.resolve(state.value);
|
|
1754
1900
|
if (state.called) return new Promise((resolve, reject) => {
|
|
1755
1901
|
state.items.push({
|
|
@@ -1764,9 +1910,9 @@ function asyncOnce(callback) {
|
|
|
1764
1910
|
resolve
|
|
1765
1911
|
});
|
|
1766
1912
|
callback(...parameters).then((value) => {
|
|
1767
|
-
|
|
1913
|
+
handleOnceResult(state, value, false);
|
|
1768
1914
|
}).catch((error) => {
|
|
1769
|
-
|
|
1915
|
+
handleOnceResult(state, error, true);
|
|
1770
1916
|
});
|
|
1771
1917
|
});
|
|
1772
1918
|
};
|
|
@@ -1783,7 +1929,7 @@ function asyncOnce(callback) {
|
|
|
1783
1929
|
};
|
|
1784
1930
|
return fn;
|
|
1785
1931
|
}
|
|
1786
|
-
function
|
|
1932
|
+
function handleOnceResult(state, value, error) {
|
|
1787
1933
|
state.error = error;
|
|
1788
1934
|
state.finished = true;
|
|
1789
1935
|
state.value = value;
|
|
@@ -1801,14 +1947,14 @@ function handleResult$2(state, value, error) {
|
|
|
1801
1947
|
* @returns Once callback
|
|
1802
1948
|
*/
|
|
1803
1949
|
function once(callback) {
|
|
1804
|
-
assert(() => typeof callback === "function",
|
|
1950
|
+
assert(() => typeof callback === "function", ONCE_MESSAGE_EXPECTATION);
|
|
1805
1951
|
const state = {
|
|
1806
1952
|
called: false,
|
|
1807
1953
|
cleared: false,
|
|
1808
1954
|
value: void 0
|
|
1809
1955
|
};
|
|
1810
1956
|
const fn = (...parameters) => {
|
|
1811
|
-
if (state.cleared) throw new Error(
|
|
1957
|
+
if (state.cleared) throw new Error(ONCE_MESSAGE_CLEARED);
|
|
1812
1958
|
if (state.called) return state.value;
|
|
1813
1959
|
state.called = true;
|
|
1814
1960
|
state.value = callback(...parameters);
|
|
@@ -1826,15 +1972,18 @@ function once(callback) {
|
|
|
1826
1972
|
return fn;
|
|
1827
1973
|
}
|
|
1828
1974
|
once.async = asyncOnce;
|
|
1829
|
-
const
|
|
1830
|
-
const
|
|
1975
|
+
const ONCE_MESSAGE_CLEARED = "Once has been cleared";
|
|
1976
|
+
const ONCE_MESSAGE_EXPECTATION = "Once expected a function";
|
|
1831
1977
|
//#endregion
|
|
1832
1978
|
//#region src/function/retry.ts
|
|
1979
|
+
/**
|
|
1980
|
+
* An error thrown when a retry fails
|
|
1981
|
+
*/
|
|
1833
1982
|
var RetryError = class extends Error {
|
|
1834
1983
|
constructor(message, original) {
|
|
1835
1984
|
super(message);
|
|
1836
1985
|
this.original = original;
|
|
1837
|
-
this.name =
|
|
1986
|
+
this.name = RETRY_ERROR_NAME;
|
|
1838
1987
|
}
|
|
1839
1988
|
};
|
|
1840
1989
|
/**
|
|
@@ -1846,13 +1995,13 @@ var RetryError = class extends Error {
|
|
|
1846
1995
|
* @returns Callback result
|
|
1847
1996
|
*/
|
|
1848
1997
|
async function asyncRetry(callback, options) {
|
|
1849
|
-
if (typeof callback !== "function") throw new TypeError(
|
|
1998
|
+
if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
1850
1999
|
async function handle() {
|
|
1851
2000
|
try {
|
|
1852
2001
|
const result = await callback();
|
|
1853
2002
|
resolver(result);
|
|
1854
2003
|
} catch (error) {
|
|
1855
|
-
if (attempts >= times || !when(error)) rejector(new RetryError(
|
|
2004
|
+
if (attempts >= times || !when(error)) rejector(new RetryError(RETRY_MESSAGE_FAILED, error));
|
|
1856
2005
|
else {
|
|
1857
2006
|
attempts += 1;
|
|
1858
2007
|
timer();
|
|
@@ -1888,7 +2037,7 @@ function getRetryOptions(input) {
|
|
|
1888
2037
|
* @returns Callback result
|
|
1889
2038
|
*/
|
|
1890
2039
|
function retry(callback, options) {
|
|
1891
|
-
if (typeof callback !== "function") throw new TypeError(
|
|
2040
|
+
if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
1892
2041
|
const { times, when } = getRetryOptions(options);
|
|
1893
2042
|
let last;
|
|
1894
2043
|
for (let index = 0; index <= times; index += 1) try {
|
|
@@ -1899,42 +2048,15 @@ function retry(callback, options) {
|
|
|
1899
2048
|
break;
|
|
1900
2049
|
}
|
|
1901
2050
|
}
|
|
1902
|
-
throw new RetryError(
|
|
2051
|
+
throw new RetryError(RETRY_MESSAGE_FAILED, last);
|
|
1903
2052
|
}
|
|
1904
2053
|
retry.async = asyncRetry;
|
|
1905
2054
|
function shouldRetry() {
|
|
1906
2055
|
return true;
|
|
1907
2056
|
}
|
|
1908
|
-
const
|
|
1909
|
-
const
|
|
1910
|
-
const
|
|
1911
|
-
//#endregion
|
|
1912
|
-
//#region src/internal/result.ts
|
|
1913
|
-
function _isResult(value, okValue) {
|
|
1914
|
-
if (isNonPlainObject(value)) return false;
|
|
1915
|
-
return value.ok === okValue && (okValue ? PROPERTY_VALUE : PROPERTY_ERROR) in value;
|
|
1916
|
-
}
|
|
1917
|
-
function isError(value, extended) {
|
|
1918
|
-
return _isResult(value, false) && (extended === true ? value.original instanceof Error : true);
|
|
1919
|
-
}
|
|
1920
|
-
/**
|
|
1921
|
-
* Is the result ok?
|
|
1922
|
-
* @param result Result to check
|
|
1923
|
-
* @returns `true` if the result is ok, `false` otherwise
|
|
1924
|
-
*/
|
|
1925
|
-
function isOk(value) {
|
|
1926
|
-
return _isResult(value, true);
|
|
1927
|
-
}
|
|
1928
|
-
/**
|
|
1929
|
-
* Is the value a result?
|
|
1930
|
-
* @param value Value to check
|
|
1931
|
-
* @returns `true` if the value is a result, `false` otherwise
|
|
1932
|
-
*/
|
|
1933
|
-
function isResult(value) {
|
|
1934
|
-
return _isResult(value, true) || _isResult(value, false);
|
|
1935
|
-
}
|
|
1936
|
-
const PROPERTY_ERROR = "error";
|
|
1937
|
-
const PROPERTY_VALUE = "value";
|
|
2057
|
+
const RETRY_ERROR_NAME = "RetryError";
|
|
2058
|
+
const RETRY_MESSAGE_EXPECTATION = "Retry expected a function";
|
|
2059
|
+
const RETRY_MESSAGE_FAILED = "Retry failed";
|
|
1938
2060
|
//#endregion
|
|
1939
2061
|
//#region src/function/work.ts
|
|
1940
2062
|
function asyncFlow(...fns) {
|
|
@@ -2023,9 +2145,9 @@ function equalArray(first, second, options) {
|
|
|
2023
2145
|
const { length } = first;
|
|
2024
2146
|
if (length !== second.length) return false;
|
|
2025
2147
|
let offset = 0;
|
|
2026
|
-
if (length >=
|
|
2027
|
-
offset = Math.round(length /
|
|
2028
|
-
offset = offset >
|
|
2148
|
+
if (length >= EQUAL_ARRAY_THRESHOLD) {
|
|
2149
|
+
offset = Math.round(length / EQUAL_ARRAY_PEEK_PERCENTAGE);
|
|
2150
|
+
offset = offset > EQUAL_ARRAY_THRESHOLD ? EQUAL_ARRAY_THRESHOLD : offset;
|
|
2029
2151
|
for (let index = 0; index < offset; index += 1) if (!(equalValue(first[index], second[index], options) && equalValue(first[length - index - 1], second[length - index - 1], options))) return false;
|
|
2030
2152
|
}
|
|
2031
2153
|
const end = length - offset;
|
|
@@ -2160,104 +2282,17 @@ function initializeEqualizer(options) {
|
|
|
2160
2282
|
function registerEqualizer(constructor, handler) {
|
|
2161
2283
|
equal.handlers.register(constructor, handler);
|
|
2162
2284
|
}
|
|
2163
|
-
const
|
|
2164
|
-
const
|
|
2285
|
+
const EQUAL_ARRAY_PEEK_PERCENTAGE = 10;
|
|
2286
|
+
const EQUAL_ARRAY_THRESHOLD = 100;
|
|
2165
2287
|
const ERROR_PROPERTIES = ["name", "message"];
|
|
2166
2288
|
const EXPRESSION_PROPERTIES = ["source", "flags"];
|
|
2167
2289
|
const MINIMUM_LENGTH_FOR_SET = 16;
|
|
2168
2290
|
//#endregion
|
|
2169
|
-
//#region src/result/misc.ts
|
|
2170
|
-
function error(value, original) {
|
|
2171
|
-
return getError(value, original);
|
|
2172
|
-
}
|
|
2173
|
-
function getError(value, original) {
|
|
2174
|
-
const errorResult = {
|
|
2175
|
-
error: value,
|
|
2176
|
-
ok: false
|
|
2177
|
-
};
|
|
2178
|
-
if (original instanceof Error) errorResult.original = original;
|
|
2179
|
-
return errorResult;
|
|
2180
|
-
}
|
|
2181
|
-
/**
|
|
2182
|
-
* Creates an ok result
|
|
2183
|
-
* @param value Value
|
|
2184
|
-
* @returns Ok result
|
|
2185
|
-
*/
|
|
2186
|
-
function ok(value) {
|
|
2187
|
-
return {
|
|
2188
|
-
ok: true,
|
|
2189
|
-
value
|
|
2190
|
-
};
|
|
2191
|
-
}
|
|
2192
|
-
/**
|
|
2193
|
-
* Converts a result to a promise
|
|
2194
|
-
*
|
|
2195
|
-
* Resolves if ok, rejects for error
|
|
2196
|
-
* @param result Result to convert
|
|
2197
|
-
* @returns Promised result
|
|
2198
|
-
*/
|
|
2199
|
-
async function toPromise(result) {
|
|
2200
|
-
const actual = typeof result === "function" ? result() : result;
|
|
2201
|
-
if (!isResult(actual)) return Promise.reject(new Error(MESSAGE_PROMISE_RESULT));
|
|
2202
|
-
return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
|
|
2203
|
-
}
|
|
2204
|
-
function unwrap(value, defaultValue) {
|
|
2205
|
-
return isOk(value) ? value.value : defaultValue;
|
|
2206
|
-
}
|
|
2207
|
-
const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
|
|
2208
|
-
//#endregion
|
|
2209
|
-
//#region src/internal/value/misc.ts
|
|
2210
|
-
function findKey(needle, haystack) {
|
|
2211
|
-
const keys = Object.keys(haystack);
|
|
2212
|
-
const index = keys.map((key) => key.toLowerCase()).indexOf(needle.toLowerCase());
|
|
2213
|
-
return index > -1 ? keys[index] : needle;
|
|
2214
|
-
}
|
|
2215
|
-
function getNestedValue(data, path, ignoreCase) {
|
|
2216
|
-
if (typeof data !== "object" || data === null || typeof path !== "string" || path.trim().length === 0) return error(void 0);
|
|
2217
|
-
const shouldIgnoreCase = ignoreCase === true;
|
|
2218
|
-
const paths = getPaths(path, shouldIgnoreCase);
|
|
2219
|
-
if (typeof paths === "string") return handleValue(data, paths, null, true, shouldIgnoreCase);
|
|
2220
|
-
const { length } = paths;
|
|
2221
|
-
let current = data;
|
|
2222
|
-
for (let index = 0; index < length; index += 1) {
|
|
2223
|
-
const part = paths[index];
|
|
2224
|
-
const handled = handleValue(current, part, null, true, shouldIgnoreCase);
|
|
2225
|
-
if (!handled.ok) return handled;
|
|
2226
|
-
current = handled.value;
|
|
2227
|
-
}
|
|
2228
|
-
return ok(current);
|
|
2229
|
-
}
|
|
2230
|
-
function getPaths(path, lowercase) {
|
|
2231
|
-
const normalized = lowercase ? path.toLowerCase() : path;
|
|
2232
|
-
if (!EXPRESSION_NESTED.test(normalized)) return normalized;
|
|
2233
|
-
return normalized.replace(EXPRESSION_BRACKET, ".$1").replace(EXPRESSION_DOTS, "").split(".");
|
|
2234
|
-
}
|
|
2235
|
-
function handleValue(data, path, value, get, ignoreCase) {
|
|
2236
|
-
if (typeof data === "object" && data !== null && !ignoreKey(path)) {
|
|
2237
|
-
const key = ignoreCase ? findKey(path, data) : path;
|
|
2238
|
-
if (get) return key in data ? ok(data[key]) : error(void 0);
|
|
2239
|
-
data[key] = typeof value === "function" ? value(data[key]) : value;
|
|
2240
|
-
}
|
|
2241
|
-
if (get) return error(void 0);
|
|
2242
|
-
}
|
|
2243
|
-
const EXPRESSION_BRACKET = /\[(\w+)\]/g;
|
|
2244
|
-
const EXPRESSION_DOTS = /^\.|\.$/g;
|
|
2245
|
-
const EXPRESSION_NESTED = /\.|\[\w+\]/;
|
|
2246
|
-
//#endregion
|
|
2247
2291
|
//#region src/internal/value/get.ts
|
|
2248
2292
|
function getValue(data, path, ignoreCase) {
|
|
2249
2293
|
return getNestedValue(data, path, ignoreCase === true).value;
|
|
2250
2294
|
}
|
|
2251
2295
|
//#endregion
|
|
2252
|
-
//#region src/internal/value/has.ts
|
|
2253
|
-
function hasValue(data, path, ignoreCase) {
|
|
2254
|
-
return getNestedValue(data, path, ignoreCase === true).ok;
|
|
2255
|
-
}
|
|
2256
|
-
hasValue.get = hasValueResult;
|
|
2257
|
-
function hasValueResult(data, path, ignoreCase) {
|
|
2258
|
-
return getNestedValue(data, path, ignoreCase === true);
|
|
2259
|
-
}
|
|
2260
|
-
//#endregion
|
|
2261
2296
|
//#region src/internal/value/set.ts
|
|
2262
2297
|
function setValue(data, path, value, ignoreCase) {
|
|
2263
2298
|
if (typeof data !== "object" || data === null || typeof path !== "string" || path.trim().length === 0) return data;
|
|
@@ -2710,7 +2745,7 @@ function getFuzzyOptions(input, state) {
|
|
|
2710
2745
|
options.tolerance = getTolerance(options.tolerance, state);
|
|
2711
2746
|
return options;
|
|
2712
2747
|
}
|
|
2713
|
-
function
|
|
2748
|
+
function getFuzzyState(items, input) {
|
|
2714
2749
|
const handler = getHandler(input);
|
|
2715
2750
|
const options = getFuzzyOptions(input);
|
|
2716
2751
|
return {
|
|
@@ -2727,7 +2762,7 @@ function getTolerance(input, state) {
|
|
|
2727
2762
|
}
|
|
2728
2763
|
function fuzzy(items, configuration) {
|
|
2729
2764
|
if (!Array.isArray(items)) throw new TypeError(MESSAGE_ARRAY);
|
|
2730
|
-
return new Fuzzy(
|
|
2765
|
+
return new Fuzzy(getFuzzyState(items, configuration));
|
|
2731
2766
|
}
|
|
2732
2767
|
fuzzy.match = fuzzyMatch;
|
|
2733
2768
|
/**
|
|
@@ -3537,7 +3572,6 @@ function initializeMerger(options) {
|
|
|
3537
3572
|
function merge(values, options) {
|
|
3538
3573
|
return handleMerge(values, getMergeOptions(options));
|
|
3539
3574
|
}
|
|
3540
|
-
merge.assign = assign;
|
|
3541
3575
|
merge.initialize = initializeMerger;
|
|
3542
3576
|
function mergeObjects(values, options, prefix) {
|
|
3543
3577
|
const { length } = values;
|
|
@@ -3601,6 +3635,9 @@ function transformValue(value, transformer) {
|
|
|
3601
3635
|
}
|
|
3602
3636
|
//#endregion
|
|
3603
3637
|
//#region src/beacon.ts
|
|
3638
|
+
/**
|
|
3639
|
+
* A beacon is a lighthouse, holding an observable value that can be subscribed to and emitted from
|
|
3640
|
+
*/
|
|
3604
3641
|
var Beacon = class {
|
|
3605
3642
|
#options;
|
|
3606
3643
|
#state;
|
|
@@ -3671,6 +3708,9 @@ var Beacon = class {
|
|
|
3671
3708
|
if (finish === true) finishBeacon(this.#state, true);
|
|
3672
3709
|
}
|
|
3673
3710
|
};
|
|
3711
|
+
/**
|
|
3712
|
+
* An observable holds a value and allows observers to subscribe to changes in that value
|
|
3713
|
+
*/
|
|
3674
3714
|
var Observable = class {
|
|
3675
3715
|
#state;
|
|
3676
3716
|
constructor(instance, observers) {
|
|
@@ -3695,6 +3735,9 @@ var Observable = class {
|
|
|
3695
3735
|
return instance;
|
|
3696
3736
|
}
|
|
3697
3737
|
};
|
|
3738
|
+
/**
|
|
3739
|
+
* A subscription represents an active subscription to an observable, holding its state and allowing it to be destroyed or unsubscribed from
|
|
3740
|
+
*/
|
|
3698
3741
|
var Subscription = class {
|
|
3699
3742
|
#state;
|
|
3700
3743
|
constructor(state) {
|
|
@@ -3954,7 +3997,7 @@ function getClampedValue(value, minimum, maximum) {
|
|
|
3954
3997
|
* @returns Foreground color
|
|
3955
3998
|
*/
|
|
3956
3999
|
function getForegroundColor(value) {
|
|
3957
|
-
const { blue, green, red } =
|
|
4000
|
+
const { blue, green, red } = getColorState(value).rgb;
|
|
3958
4001
|
const values = [
|
|
3959
4002
|
blue / 255,
|
|
3960
4003
|
green / 255,
|
|
@@ -3974,7 +4017,7 @@ function getForegroundColor(value) {
|
|
|
3974
4017
|
* @returns Hex color
|
|
3975
4018
|
*/
|
|
3976
4019
|
function getHexaColor(value) {
|
|
3977
|
-
const { alpha, hex } =
|
|
4020
|
+
const { alpha, hex } = getColorState(value);
|
|
3978
4021
|
return `${hex}${alpha.hex}`;
|
|
3979
4022
|
}
|
|
3980
4023
|
/**
|
|
@@ -3983,7 +4026,7 @@ function getHexaColor(value) {
|
|
|
3983
4026
|
* @returns Hex color
|
|
3984
4027
|
*/
|
|
3985
4028
|
function getHexColor(value) {
|
|
3986
|
-
return
|
|
4029
|
+
return getColorState(value).hex;
|
|
3987
4030
|
}
|
|
3988
4031
|
function getHexValue(value) {
|
|
3989
4032
|
return getClampedValue(value, 0, 255);
|
|
@@ -3997,7 +4040,7 @@ function getDegrees(value) {
|
|
|
3997
4040
|
* @returns HSLA color
|
|
3998
4041
|
*/
|
|
3999
4042
|
function getHslaColor(value) {
|
|
4000
|
-
const { alpha, hsl } =
|
|
4043
|
+
const { alpha, hsl } = getColorState(value);
|
|
4001
4044
|
return {
|
|
4002
4045
|
...hsl,
|
|
4003
4046
|
alpha: alpha.value
|
|
@@ -4009,7 +4052,7 @@ function getHslaColor(value) {
|
|
|
4009
4052
|
* @returns HSL color
|
|
4010
4053
|
*/
|
|
4011
4054
|
function getHslColor(value) {
|
|
4012
|
-
return
|
|
4055
|
+
return getColorState(value).hsl;
|
|
4013
4056
|
}
|
|
4014
4057
|
function getPercentage(value) {
|
|
4015
4058
|
return getClampedValue(value, 0, 100);
|
|
@@ -4020,7 +4063,7 @@ function getPercentage(value) {
|
|
|
4020
4063
|
* @returns RGBA color
|
|
4021
4064
|
*/
|
|
4022
4065
|
function getRgbaColor(value) {
|
|
4023
|
-
const { alpha, rgb } =
|
|
4066
|
+
const { alpha, rgb } = getColorState(value);
|
|
4024
4067
|
return {
|
|
4025
4068
|
...rgb,
|
|
4026
4069
|
alpha: alpha.value
|
|
@@ -4032,7 +4075,7 @@ function getRgbaColor(value) {
|
|
|
4032
4075
|
* @returns RGB color
|
|
4033
4076
|
*/
|
|
4034
4077
|
function getRgbColor(value) {
|
|
4035
|
-
return
|
|
4078
|
+
return getColorState(value).rgb;
|
|
4036
4079
|
}
|
|
4037
4080
|
//#endregion
|
|
4038
4081
|
//#region src/color/space/rgb.ts
|
|
@@ -4238,7 +4281,7 @@ function hslToRgba(hsl) {
|
|
|
4238
4281
|
}
|
|
4239
4282
|
//#endregion
|
|
4240
4283
|
//#region src/color/misc/state.ts
|
|
4241
|
-
function
|
|
4284
|
+
function getColorState(value) {
|
|
4242
4285
|
if (typeof value === "string") {
|
|
4243
4286
|
const normalized = getNormalizedHex(value, true);
|
|
4244
4287
|
const hex = normalized.slice(0, 6);
|
|
@@ -4315,6 +4358,9 @@ function setRGBColor(state, value, alpha) {
|
|
|
4315
4358
|
}
|
|
4316
4359
|
//#endregion
|
|
4317
4360
|
//#region src/color/instance.ts
|
|
4361
|
+
/**
|
|
4362
|
+
* A color that is represented in multiple color formats
|
|
4363
|
+
*/
|
|
4318
4364
|
var Color = class {
|
|
4319
4365
|
#state;
|
|
4320
4366
|
/**
|
|
@@ -4408,7 +4454,7 @@ var Color = class {
|
|
|
4408
4454
|
setRGBColor(this.#state, value, true);
|
|
4409
4455
|
}
|
|
4410
4456
|
constructor(value) {
|
|
4411
|
-
this.#state =
|
|
4457
|
+
this.#state = getColorState(value);
|
|
4412
4458
|
Object.defineProperty(this, "$color", { value: true });
|
|
4413
4459
|
}
|
|
4414
4460
|
toHexString(alpha) {
|
|
@@ -4436,6 +4482,11 @@ function getColor(value) {
|
|
|
4436
4482
|
}
|
|
4437
4483
|
//#endregion
|
|
4438
4484
|
//#region src/logger.ts
|
|
4485
|
+
/**
|
|
4486
|
+
* A logger that can be used to log messages to the console
|
|
4487
|
+
*
|
|
4488
|
+
* _(Logging can be enabled or disabled by setting the `enabled` property)_
|
|
4489
|
+
*/
|
|
4439
4490
|
var Logger = class {
|
|
4440
4491
|
/**
|
|
4441
4492
|
* Log any number of values at the "debug" log level
|
|
@@ -4506,10 +4557,16 @@ var Logger = class {
|
|
|
4506
4557
|
return new Time(label);
|
|
4507
4558
|
}
|
|
4508
4559
|
};
|
|
4560
|
+
/**
|
|
4561
|
+
* A named timer that can be used to log durations to the console
|
|
4562
|
+
*/
|
|
4509
4563
|
var Time = class {
|
|
4510
4564
|
#logger;
|
|
4511
4565
|
#stopper;
|
|
4512
4566
|
#state;
|
|
4567
|
+
/**
|
|
4568
|
+
* Is the timer active? _(i.e. has it been started and not stopped, and is logging enabled?)_
|
|
4569
|
+
*/
|
|
4513
4570
|
get active() {
|
|
4514
4571
|
return this.#state.started && !this.#state.stopped && enabled;
|
|
4515
4572
|
}
|
|
@@ -4622,6 +4679,9 @@ function sum(array, key) {
|
|
|
4622
4679
|
}
|
|
4623
4680
|
//#endregion
|
|
4624
4681
|
//#region src/promise/models.ts
|
|
4682
|
+
/**
|
|
4683
|
+
* A promise that can be canceled
|
|
4684
|
+
*/
|
|
4625
4685
|
var CancelablePromise = class extends Promise {
|
|
4626
4686
|
#rejector;
|
|
4627
4687
|
constructor(executor) {
|
|
@@ -4640,6 +4700,9 @@ var CancelablePromise = class extends Promise {
|
|
|
4640
4700
|
this.#rejector(reason);
|
|
4641
4701
|
}
|
|
4642
4702
|
};
|
|
4703
|
+
/**
|
|
4704
|
+
* An error thrown when a promise times out
|
|
4705
|
+
*/
|
|
4643
4706
|
var PromiseTimeoutError = class extends Error {
|
|
4644
4707
|
constructor() {
|
|
4645
4708
|
super(PROMISE_MESSAGE_TIMEOUT);
|
|
@@ -4659,11 +4722,8 @@ const PROMISE_TYPE_FULFILLED = "fulfilled";
|
|
|
4659
4722
|
const PROMISE_TYPE_REJECTED = "rejected";
|
|
4660
4723
|
//#endregion
|
|
4661
4724
|
//#region src/promise/helpers.ts
|
|
4662
|
-
function getNumberOrDefault$1(value) {
|
|
4663
|
-
return typeof value === "number" && value > 0 ? value : 0;
|
|
4664
|
-
}
|
|
4665
4725
|
function getPromiseOptions(input) {
|
|
4666
|
-
if (typeof input === "number") return { time: getNumberOrDefault
|
|
4726
|
+
if (typeof input === "number") return { time: getNumberOrDefault(input, 0) };
|
|
4667
4727
|
if (input instanceof AbortSignal) return {
|
|
4668
4728
|
signal: input,
|
|
4669
4729
|
time: 0
|
|
@@ -4671,7 +4731,7 @@ function getPromiseOptions(input) {
|
|
|
4671
4731
|
const options = typeof input === "object" && input !== null ? input : {};
|
|
4672
4732
|
return {
|
|
4673
4733
|
signal: options.signal instanceof AbortSignal ? options.signal : void 0,
|
|
4674
|
-
time: getNumberOrDefault
|
|
4734
|
+
time: getNumberOrDefault(options.time, 0)
|
|
4675
4735
|
};
|
|
4676
4736
|
}
|
|
4677
4737
|
function getPromisesOptions(input) {
|
|
@@ -4942,6 +5002,9 @@ const TYPES = new Set([
|
|
|
4942
5002
|
]);
|
|
4943
5003
|
//#endregion
|
|
4944
5004
|
//#region src/queue.ts
|
|
5005
|
+
/**
|
|
5006
|
+
* A queue that can be used to manage (a)synchronous tasks with a specific key
|
|
5007
|
+
*/
|
|
4945
5008
|
var KeyedQueue = class {
|
|
4946
5009
|
#callback;
|
|
4947
5010
|
#options;
|
|
@@ -5091,6 +5154,9 @@ var KeyedQueue = class {
|
|
|
5091
5154
|
for (const queue of queues) queue[type]();
|
|
5092
5155
|
}
|
|
5093
5156
|
};
|
|
5157
|
+
/**
|
|
5158
|
+
* A queue that can be used to manage (a)synchronous tasks
|
|
5159
|
+
*/
|
|
5094
5160
|
var Queue = class {
|
|
5095
5161
|
#callback;
|
|
5096
5162
|
#handled = [];
|
|
@@ -5258,16 +5324,19 @@ var Queue = class {
|
|
|
5258
5324
|
if (this.#paused) {
|
|
5259
5325
|
const paused = item;
|
|
5260
5326
|
this.#handled.push(() => {
|
|
5261
|
-
|
|
5327
|
+
handleQueuedResult(paused, error, result, this.#items.length === 0);
|
|
5262
5328
|
});
|
|
5263
5329
|
break;
|
|
5264
5330
|
}
|
|
5265
|
-
|
|
5331
|
+
handleQueuedResult(item, error, result, this.#items.length === 0);
|
|
5266
5332
|
item = this.#items.shift();
|
|
5267
5333
|
}
|
|
5268
5334
|
this.#runners -= 1;
|
|
5269
5335
|
}
|
|
5270
5336
|
};
|
|
5337
|
+
/**
|
|
5338
|
+
* An error thrown by the Queue when an operation fails
|
|
5339
|
+
*/
|
|
5271
5340
|
var QueueError = class extends Error {
|
|
5272
5341
|
constructor(message) {
|
|
5273
5342
|
super(message);
|
|
@@ -5277,18 +5346,15 @@ var QueueError = class extends Error {
|
|
|
5277
5346
|
function getBooleanOrDefault(value, defaultValue) {
|
|
5278
5347
|
return typeof value === "boolean" ? value : defaultValue;
|
|
5279
5348
|
}
|
|
5280
|
-
function getNumberOrDefault(value, defaultValue) {
|
|
5281
|
-
return typeof value === "number" && value > 0 ? Math.floor(value) : defaultValue;
|
|
5282
|
-
}
|
|
5283
5349
|
function getOptions(input) {
|
|
5284
5350
|
const options = typeof input === "object" && input != null ? input : {};
|
|
5285
5351
|
return {
|
|
5286
5352
|
autostart: getBooleanOrDefault(options.autostart, true),
|
|
5287
|
-
concurrency: getNumberOrDefault(options.concurrency, 1),
|
|
5353
|
+
concurrency: getNumberOrDefault(options.concurrency, 1, 1),
|
|
5288
5354
|
maximum: getNumberOrDefault(options.maximum, 0)
|
|
5289
5355
|
};
|
|
5290
5356
|
}
|
|
5291
|
-
function
|
|
5357
|
+
function handleQueuedResult(item, error, result, finished) {
|
|
5292
5358
|
item.signal?.removeEventListener(EVENT_NAME, item.abort);
|
|
5293
5359
|
if (item.signal?.aborted ?? false) item.reject();
|
|
5294
5360
|
else if (error) item.reject(result);
|
|
@@ -5378,6 +5444,25 @@ const BOOLEAN_MODIFIER = .5;
|
|
|
5378
5444
|
const HEX_CHARACTERS = "0123456789ABCDEF";
|
|
5379
5445
|
const HEX_MAXIMUM = 15;
|
|
5380
5446
|
//#endregion
|
|
5447
|
+
//#region src/result/index.ts
|
|
5448
|
+
async function asyncAttempt(value, err) {
|
|
5449
|
+
try {
|
|
5450
|
+
let result = typeof value === "function" ? value() : await value;
|
|
5451
|
+
if (result instanceof Promise) result = await result;
|
|
5452
|
+
return ok(result);
|
|
5453
|
+
} catch (thrown) {
|
|
5454
|
+
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
5455
|
+
}
|
|
5456
|
+
}
|
|
5457
|
+
function attempt(callback, err) {
|
|
5458
|
+
try {
|
|
5459
|
+
return ok(callback());
|
|
5460
|
+
} catch (thrown) {
|
|
5461
|
+
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
5462
|
+
}
|
|
5463
|
+
}
|
|
5464
|
+
attempt.async = asyncAttempt;
|
|
5465
|
+
//#endregion
|
|
5381
5466
|
//#region src/result/match.ts
|
|
5382
5467
|
async function asyncMatchResult(result, first, error) {
|
|
5383
5468
|
let value;
|
|
@@ -5445,33 +5530,11 @@ function attemptPipe(initial, first, ...seconds) {
|
|
|
5445
5530
|
}
|
|
5446
5531
|
attemptPipe.async = attemptAsyncPipe;
|
|
5447
5532
|
//#endregion
|
|
5448
|
-
//#region src/result/index.ts
|
|
5449
|
-
async function asyncAttempt(value, err) {
|
|
5450
|
-
try {
|
|
5451
|
-
let result = typeof value === "function" ? value() : await value;
|
|
5452
|
-
if (result instanceof Promise) result = await result;
|
|
5453
|
-
return ok(result);
|
|
5454
|
-
} catch (thrown) {
|
|
5455
|
-
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
5456
|
-
}
|
|
5457
|
-
}
|
|
5458
|
-
function attempt(callback, err) {
|
|
5459
|
-
try {
|
|
5460
|
-
return ok(callback());
|
|
5461
|
-
} catch (thrown) {
|
|
5462
|
-
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
5463
|
-
}
|
|
5464
|
-
}
|
|
5465
|
-
attempt.async = asyncAttempt;
|
|
5466
|
-
attempt.flow = attemptFlow;
|
|
5467
|
-
attempt.match = matchResult;
|
|
5468
|
-
attempt.pipe = attemptPipe;
|
|
5469
|
-
attempt.promise = attemptPromise;
|
|
5470
|
-
//#endregion
|
|
5471
5533
|
//#region src/sized/set.ts
|
|
5472
5534
|
/**
|
|
5473
|
-
*
|
|
5474
|
-
*
|
|
5535
|
+
* A Set with a maximum size
|
|
5536
|
+
*
|
|
5537
|
+
* Behavior is similar to a _LRU_-cache, where the oldest values are removed
|
|
5475
5538
|
*/
|
|
5476
5539
|
var SizedSet = class extends Set {
|
|
5477
5540
|
/**
|
|
@@ -5522,4 +5585,4 @@ var SizedSet = class extends Set {
|
|
|
5522
5585
|
}
|
|
5523
5586
|
};
|
|
5524
5587
|
//#endregion
|
|
5525
|
-
export { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray,
|
|
5588
|
+
export { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kalas, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|