@oscarpalmer/atoms 0.184.2 → 0.186.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/difference.d.mts +29 -0
- package/dist/array/exists.d.mts +35 -0
- package/dist/array/filter.d.mts +72 -2
- package/dist/array/find.d.mts +70 -0
- package/dist/array/first.d.mts +77 -2
- package/dist/array/flatten.d.mts +6 -0
- package/dist/array/flatten.mjs +6 -0
- package/dist/array/from.d.mts +36 -0
- package/dist/array/get.d.mts +21 -13
- package/dist/array/group-by.d.mts +142 -0
- package/dist/array/index.d.mts +2 -2
- package/dist/array/index.mjs +2 -2
- package/dist/array/insert.d.mts +16 -0
- package/dist/array/intersection.d.mts +29 -0
- package/dist/array/last.d.mts +75 -2
- package/dist/array/{position.d.mts → match.d.mts} +168 -36
- package/dist/array/{position.mjs → match.mjs} +16 -16
- package/dist/array/move.d.mts +78 -8
- package/dist/array/move.mjs +11 -1
- package/dist/array/partition.d.mts +35 -0
- package/dist/array/push.d.mts +8 -0
- package/dist/array/push.mjs +8 -0
- package/dist/array/reverse.d.mts +1 -0
- package/dist/array/reverse.mjs +1 -0
- package/dist/array/select.d.mts +94 -8
- package/dist/array/single.d.mts +29 -0
- package/dist/array/slice.d.mts +106 -16
- package/dist/array/sort.d.mts +30 -4
- package/dist/array/sort.mjs +1 -1
- package/dist/array/splice.d.mts +48 -0
- package/dist/array/splice.mjs +2 -1
- package/dist/array/swap.d.mts +113 -8
- package/dist/array/swap.mjs +2 -1
- package/dist/array/to-map.d.mts +124 -0
- package/dist/array/to-record.d.mts +124 -0
- package/dist/array/to-set.d.mts +24 -0
- package/dist/array/toggle.d.mts +38 -3
- package/dist/array/union.d.mts +29 -0
- package/dist/array/unique.d.mts +24 -0
- package/dist/array/update.d.mts +38 -3
- 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 +3 -0
- 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/retry.d.mts +3 -0
- package/dist/function/retry.mjs +3 -0
- package/dist/function/work.mjs +1 -1
- package/dist/index.d.mts +2158 -288
- package/dist/index.mjs +294 -181
- package/dist/internal/array/chunk.d.mts +6 -0
- package/dist/internal/array/chunk.mjs +6 -0
- package/dist/internal/array/compact.d.mts +12 -0
- package/dist/internal/array/index-of.d.mts +70 -0
- package/dist/internal/math/aggregate.d.mts +29 -0
- package/dist/internal/value/compare.d.mts +2 -1
- package/dist/internal/value/equal.d.mts +5 -0
- package/dist/internal/value/get.d.mts +27 -5
- package/dist/internal/value/has.d.mts +7 -7
- 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 +14 -1
- package/dist/promise/helpers.mjs +1 -1
- 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 +9 -0
- 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/value/collection.d.mts +1 -1
- package/dist/value/handle.mjs +1 -1
- package/dist/value/merge.d.mts +28 -25
- package/dist/value/merge.mjs +29 -18
- package/dist/value/shake.d.mts +3 -0
- package/dist/value/smush.d.mts +3 -0
- package/dist/value/transform.d.mts +10 -1
- package/dist/value/unsmush.d.mts +2 -3
- package/package.json +5 -5
- package/src/array/difference.ts +33 -0
- package/src/array/exists.ts +35 -0
- package/src/array/filter.ts +72 -2
- package/src/array/find.ts +70 -0
- package/src/array/first.ts +77 -3
- package/src/array/flatten.ts +6 -0
- package/src/array/from.ts +40 -0
- package/src/array/get.ts +21 -15
- package/src/array/group-by.ts +142 -0
- package/src/array/index.ts +1 -1
- package/src/array/insert.ts +16 -2
- package/src/array/intersection.ts +33 -0
- package/src/array/last.ts +75 -2
- package/src/array/{position.ts → match.ts} +197 -65
- package/src/array/move.ts +87 -13
- package/src/array/partition.ts +35 -0
- package/src/array/push.ts +8 -2
- package/src/array/reverse.ts +5 -0
- package/src/array/select.ts +96 -13
- package/src/array/single.ts +29 -0
- package/src/array/slice.ts +114 -24
- package/src/array/sort.ts +30 -4
- package/src/array/splice.ts +52 -4
- package/src/array/swap.ts +122 -13
- package/src/array/to-map.ts +124 -0
- package/src/array/to-record.ts +124 -0
- package/src/array/to-set.ts +24 -0
- package/src/array/toggle.ts +42 -3
- package/src/array/union.ts +33 -0
- package/src/array/unique.ts +24 -0
- package/src/array/update.ts +38 -3
- package/src/beacon.ts +12 -0
- package/src/color/index.ts +0 -3
- package/src/color/instance.ts +9 -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 +5 -1
- package/src/function/retry.ts +3 -0
- package/src/internal/array/chunk.ts +6 -0
- package/src/internal/array/compact.ts +12 -0
- package/src/internal/array/index-of.ts +70 -0
- package/src/internal/math/aggregate.ts +29 -0
- package/src/internal/string.ts +0 -2
- package/src/internal/value/compare.ts +2 -1
- package/src/internal/value/equal.ts +5 -0
- package/src/internal/value/get.ts +27 -5
- package/src/internal/value/has.ts +10 -10
- package/src/internal/value/misc.ts +24 -13
- package/src/logger.ts +11 -0
- package/src/models.ts +18 -0
- package/src/promise/index.ts +0 -6
- package/src/promise/models.ts +36 -0
- package/src/queue.ts +13 -1
- 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/value/collection.ts +1 -1
- package/src/value/merge.ts +88 -66
- package/src/value/shake.ts +3 -0
- package/src/value/smush.ts +3 -0
- package/src/value/transform.ts +10 -1
- package/src/value/unsmush.ts +2 -8
package/dist/index.mjs
CHANGED
|
@@ -143,9 +143,15 @@ function groupArraysBy(array, first, second) {
|
|
|
143
143
|
//#region src/internal/array/chunk.ts
|
|
144
144
|
/**
|
|
145
145
|
* Chunk an array into smaller arrays
|
|
146
|
+
*
|
|
146
147
|
* @param array Array to chunk
|
|
147
148
|
* @param size Size of each chunk _(minimum is `1`, maximum is `5000`; defaults to `5000`)_
|
|
148
149
|
* @returns Array of arrays
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* chunk([1, 2, 3, 4, 5], 2); // => [[1, 2], [3, 4], [5]]
|
|
154
|
+
* ```
|
|
149
155
|
*/
|
|
150
156
|
function chunk(array, size) {
|
|
151
157
|
if (!Array.isArray(array)) return [];
|
|
@@ -441,8 +447,14 @@ function findLast(array, ...parameters) {
|
|
|
441
447
|
//#region src/array/flatten.ts
|
|
442
448
|
/**
|
|
443
449
|
* Flatten an array _(using native `flat` and maximum depth)_
|
|
450
|
+
*
|
|
444
451
|
* @param array Array to flatten
|
|
445
452
|
* @returns Flattened array
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```typescript
|
|
456
|
+
* flatten([1, [2, [3, 4], 5], 6]); // => [1, 2, 3, 4, 5, 6]
|
|
457
|
+
* ```
|
|
446
458
|
*/
|
|
447
459
|
function flatten(array) {
|
|
448
460
|
return Array.isArray(array) ? array.flat(Number.POSITIVE_INFINITY) : [];
|
|
@@ -525,16 +537,16 @@ function partition(array, ...parameters) {
|
|
|
525
537
|
return [matched, notMatched];
|
|
526
538
|
}
|
|
527
539
|
//#endregion
|
|
528
|
-
//#region src/array/
|
|
540
|
+
//#region src/array/match.ts
|
|
529
541
|
function endsWithArray(haystack, needle, key) {
|
|
530
542
|
return endings.has(getPosition(haystack, needle, key)[1]);
|
|
531
543
|
}
|
|
532
|
-
function
|
|
544
|
+
function getArrayComparison(haystack, needle, key) {
|
|
533
545
|
return getPosition(haystack, needle, key)[1];
|
|
534
546
|
}
|
|
535
547
|
function getName(start, haystack, needle) {
|
|
536
|
-
if (start === 0) return haystack === needle ?
|
|
537
|
-
return start + needle === haystack ?
|
|
548
|
+
if (start === 0) return haystack === needle ? COMPARISON_SAME : COMPARISON_START;
|
|
549
|
+
return start + needle === haystack ? COMPARISON_END : COMPARISON_INSIDE;
|
|
538
550
|
}
|
|
539
551
|
function getPosition(haystack, needle, key) {
|
|
540
552
|
if (!Array.isArray(haystack) || !Array.isArray(needle)) return invalid;
|
|
@@ -569,24 +581,32 @@ function indexOfArray(haystack, needle, key) {
|
|
|
569
581
|
function startsWithArray(haystack, needle, key) {
|
|
570
582
|
return starts.has(getPosition(haystack, needle, key)[1]);
|
|
571
583
|
}
|
|
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([
|
|
584
|
+
const COMPARISON_END = "end";
|
|
585
|
+
const COMPARISON_INSIDE = "inside";
|
|
586
|
+
const COMPARISON_INVALID = "invalid";
|
|
587
|
+
const COMPARISON_OUTSIDE = "outside";
|
|
588
|
+
const COMPARISON_SAME = "same";
|
|
589
|
+
const COMPARISON_START = "start";
|
|
590
|
+
const endings = new Set([COMPARISON_END, COMPARISON_SAME]);
|
|
591
|
+
const invalid = [-1, COMPARISON_INVALID];
|
|
592
|
+
const outside = [-1, COMPARISON_OUTSIDE];
|
|
593
|
+
const outsides = new Set([COMPARISON_INVALID, COMPARISON_OUTSIDE]);
|
|
594
|
+
const starts = new Set([COMPARISON_START, COMPARISON_SAME]);
|
|
583
595
|
//#endregion
|
|
584
596
|
//#region src/array/push.ts
|
|
585
597
|
/**
|
|
586
598
|
* Push items into an array _(at the end)_
|
|
599
|
+
*
|
|
600
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
601
|
+
*
|
|
587
602
|
* @param array Original array
|
|
588
603
|
* @param pushed Pushed items
|
|
589
604
|
* @returns New length of the array
|
|
605
|
+
*
|
|
606
|
+
* @example
|
|
607
|
+
* ```typescript
|
|
608
|
+
* push([1, 2, 3], [4, 5]); // => 5 (new length); array becomes [1, 2, 3, 4, 5]
|
|
609
|
+
* ```
|
|
590
610
|
*/
|
|
591
611
|
function push(array, pushed) {
|
|
592
612
|
return insertValues(INSERT_TYPE_PUSH, array, pushed, array.length, 0);
|
|
@@ -595,6 +615,7 @@ function push(array, pushed) {
|
|
|
595
615
|
//#region src/array/reverse.ts
|
|
596
616
|
/**
|
|
597
617
|
* Reverse the order of items in an array
|
|
618
|
+
*
|
|
598
619
|
* @param array Array to reverse
|
|
599
620
|
* @returns Reversed array
|
|
600
621
|
*/
|
|
@@ -678,7 +699,8 @@ const EXTRACT_TAKE = "take";
|
|
|
678
699
|
//#endregion
|
|
679
700
|
//#region src/array/splice.ts
|
|
680
701
|
function splice(array, start, deleteCountOrItems, items) {
|
|
681
|
-
|
|
702
|
+
const deleteCountIsNumber = typeof deleteCountOrItems === "number";
|
|
703
|
+
return insertValues(INSERT_TYPE_SPLICE, array, deleteCountIsNumber ? items : deleteCountOrItems, start, deleteCountIsNumber ? deleteCountOrItems : 0);
|
|
682
704
|
}
|
|
683
705
|
//#endregion
|
|
684
706
|
//#region src/array/to-set.ts
|
|
@@ -795,10 +817,20 @@ move.toIndex = moveToIndex;
|
|
|
795
817
|
* If the from index is out of bounds, the array will be returned unchanged
|
|
796
818
|
*
|
|
797
819
|
* Available as `moveIndices` and `move.indices`
|
|
820
|
+
*
|
|
798
821
|
* @param array Array to move within
|
|
799
822
|
* @param from Index to move from
|
|
800
823
|
* @param to Index to move to
|
|
801
824
|
* @returns Original array with item moved _(or unchanged if unable to move)_
|
|
825
|
+
*
|
|
826
|
+
* @example
|
|
827
|
+
* ```typescript
|
|
828
|
+
* const array = [1, 2, 3, 4];
|
|
829
|
+
*
|
|
830
|
+
* moveIndices(array, 0, 2); // => [2, 3, 1, 4]
|
|
831
|
+
* moveIndices(array, -1, 0); // => [4, 2, 3, 1]
|
|
832
|
+
* moveIndices(array, 5, 1); // => [4, 2, 3, 1] (unchanged)
|
|
833
|
+
* ```
|
|
802
834
|
*/
|
|
803
835
|
function moveIndices(array, from, to) {
|
|
804
836
|
if (!Array.isArray(array)) return [];
|
|
@@ -1196,7 +1228,7 @@ function sortArray(array, sorters) {
|
|
|
1196
1228
|
const { length } = sorters;
|
|
1197
1229
|
return array.length > 1 ? array.sort((first, second) => getComparisonValue(first, second, sorters, length)) : array;
|
|
1198
1230
|
}
|
|
1199
|
-
sort.
|
|
1231
|
+
sort.getIndex = getSortedIndex;
|
|
1200
1232
|
sort.initialize = initializeSorter;
|
|
1201
1233
|
sort.is = isSorted;
|
|
1202
1234
|
const SORT_PEEK_PERCENTAGE = 10;
|
|
@@ -1240,6 +1272,7 @@ function swapArrays(array, from, to, key) {
|
|
|
1240
1272
|
* If either index is out of bounds, the array will be returned unchanged
|
|
1241
1273
|
*
|
|
1242
1274
|
* Available as `swapIndices` and `swap.indices`
|
|
1275
|
+
*
|
|
1243
1276
|
* @param array Array of items to swap
|
|
1244
1277
|
* @param first First index _(can be negative to count from the end)_
|
|
1245
1278
|
* @param second Second index _(can be negative to count from the end)_
|
|
@@ -1299,12 +1332,132 @@ function toRecordArrays(array, first, second) {
|
|
|
1299
1332
|
return groupValues(array, first, second, true);
|
|
1300
1333
|
}
|
|
1301
1334
|
//#endregion
|
|
1335
|
+
//#region src/internal/result.ts
|
|
1336
|
+
function _isResult(value, okValue) {
|
|
1337
|
+
if (isNonPlainObject(value)) return false;
|
|
1338
|
+
return value.ok === okValue && (okValue ? PROPERTY_VALUE : PROPERTY_ERROR) in value;
|
|
1339
|
+
}
|
|
1340
|
+
function isError(value, extended) {
|
|
1341
|
+
return _isResult(value, false) && (extended === true ? value.original instanceof Error : true);
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Is the result ok?
|
|
1345
|
+
* @param result Result to check
|
|
1346
|
+
* @returns `true` if the result is ok, `false` otherwise
|
|
1347
|
+
*/
|
|
1348
|
+
function isOk(value) {
|
|
1349
|
+
return _isResult(value, true);
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Is the value a result?
|
|
1353
|
+
* @param value Value to check
|
|
1354
|
+
* @returns `true` if the value is a result, `false` otherwise
|
|
1355
|
+
*/
|
|
1356
|
+
function isResult(value) {
|
|
1357
|
+
return _isResult(value, true) || _isResult(value, false);
|
|
1358
|
+
}
|
|
1359
|
+
const PROPERTY_ERROR = "error";
|
|
1360
|
+
const PROPERTY_VALUE = "value";
|
|
1361
|
+
//#endregion
|
|
1362
|
+
//#region src/result/misc.ts
|
|
1363
|
+
function error(value, original) {
|
|
1364
|
+
return getError(value, original);
|
|
1365
|
+
}
|
|
1366
|
+
function getError(value, original) {
|
|
1367
|
+
const errorResult = {
|
|
1368
|
+
error: value,
|
|
1369
|
+
ok: false
|
|
1370
|
+
};
|
|
1371
|
+
if (original instanceof Error) errorResult.original = original;
|
|
1372
|
+
return errorResult;
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Creates an ok result
|
|
1376
|
+
* @param value Value
|
|
1377
|
+
* @returns Ok result
|
|
1378
|
+
*/
|
|
1379
|
+
function ok(value) {
|
|
1380
|
+
return {
|
|
1381
|
+
ok: true,
|
|
1382
|
+
value
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
/**
|
|
1386
|
+
* Converts a result to a promise
|
|
1387
|
+
*
|
|
1388
|
+
* Resolves if ok, rejects for error
|
|
1389
|
+
* @param result Result to convert
|
|
1390
|
+
* @returns Promised result
|
|
1391
|
+
*/
|
|
1392
|
+
async function toPromise(result) {
|
|
1393
|
+
const actual = typeof result === "function" ? result() : result;
|
|
1394
|
+
if (!isResult(actual)) return Promise.reject(new Error(MESSAGE_PROMISE_RESULT));
|
|
1395
|
+
return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
|
|
1396
|
+
}
|
|
1397
|
+
function unwrap(value, defaultValue) {
|
|
1398
|
+
return isOk(value) ? value.value : defaultValue;
|
|
1399
|
+
}
|
|
1400
|
+
const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
|
|
1401
|
+
//#endregion
|
|
1402
|
+
//#region src/internal/value/misc.ts
|
|
1403
|
+
function findKey(needle, haystack) {
|
|
1404
|
+
const keys = Object.keys(haystack);
|
|
1405
|
+
const index = keys.map((key) => key.toLowerCase()).indexOf(needle.toLowerCase());
|
|
1406
|
+
return index > -1 ? keys[index] : needle;
|
|
1407
|
+
}
|
|
1408
|
+
function getNestedValue(data, path, ignoreCase) {
|
|
1409
|
+
if (typeof data !== "object" || data === null) return error(NESTED_MESSAGE_INPUT);
|
|
1410
|
+
if (typeof path !== "string" || path.trim().length === 0) return error(NESTED_MESSAGE_PATH);
|
|
1411
|
+
const shouldIgnoreCase = ignoreCase === true;
|
|
1412
|
+
const paths = getPaths(path, shouldIgnoreCase);
|
|
1413
|
+
if (typeof paths === "string") return handleValue(data, paths, null, true, shouldIgnoreCase);
|
|
1414
|
+
const { length } = paths;
|
|
1415
|
+
let current = data;
|
|
1416
|
+
for (let index = 0; index < length; index += 1) {
|
|
1417
|
+
const part = paths[index];
|
|
1418
|
+
const handled = handleValue(current, part, null, true, shouldIgnoreCase);
|
|
1419
|
+
if (!handled.ok) return handled;
|
|
1420
|
+
current = handled.value;
|
|
1421
|
+
}
|
|
1422
|
+
return ok(current);
|
|
1423
|
+
}
|
|
1424
|
+
function getPaths(path, lowercase) {
|
|
1425
|
+
const normalized = lowercase ? path.toLowerCase() : path;
|
|
1426
|
+
if (!EXPRESSION_NESTED.test(normalized)) return normalized;
|
|
1427
|
+
return normalized.replace(EXPRESSION_BRACKET, ".$1").replace(EXPRESSION_DOTS, "").split(".");
|
|
1428
|
+
}
|
|
1429
|
+
function handleValue(data, path, value, get, ignoreCase) {
|
|
1430
|
+
if (typeof data === "object" && data !== null) {
|
|
1431
|
+
if (ignoreKey(path)) return error(NESTED_MESSAGE_UNSAFE);
|
|
1432
|
+
const key = ignoreCase ? findKey(path, data) : path;
|
|
1433
|
+
if (get) return key in data ? ok(data[key]) : error(NESTED_MESSAGE_MISSING);
|
|
1434
|
+
data[key] = typeof value === "function" ? value(data[key]) : value;
|
|
1435
|
+
}
|
|
1436
|
+
if (get) return error(NESTED_MESSAGE_MISSING);
|
|
1437
|
+
}
|
|
1438
|
+
const EXPRESSION_BRACKET = /\[(\w+)\]/g;
|
|
1439
|
+
const EXPRESSION_DOTS = /^\.|\.$/g;
|
|
1440
|
+
const EXPRESSION_NESTED = /\.|\[\w+\]/;
|
|
1441
|
+
const NESTED_MESSAGE_INPUT = "Expected data to be an object";
|
|
1442
|
+
const NESTED_MESSAGE_MISSING = "Expected property to exist in object";
|
|
1443
|
+
const NESTED_MESSAGE_PATH = "Expected path to be a string";
|
|
1444
|
+
const NESTED_MESSAGE_UNSAFE = "Access to this property is not allowed";
|
|
1445
|
+
//#endregion
|
|
1446
|
+
//#region src/internal/value/has.ts
|
|
1447
|
+
function hasValue(data, path, ignoreCase) {
|
|
1448
|
+
return getNestedValue(data, path, ignoreCase === true).ok;
|
|
1449
|
+
}
|
|
1450
|
+
hasValue.get = hasValueResult;
|
|
1451
|
+
function hasValueResult(data, path, ignoreCase) {
|
|
1452
|
+
return getNestedValue(data, path, ignoreCase === true);
|
|
1453
|
+
}
|
|
1454
|
+
//#endregion
|
|
1302
1455
|
//#region src/function/assert.ts
|
|
1303
1456
|
/**
|
|
1304
1457
|
* Asserts that a condition is true, throwing an error if it is not
|
|
1305
1458
|
* @param condition Condition to assert
|
|
1306
1459
|
* @param message Error message
|
|
1307
|
-
* @param error Error constructor
|
|
1460
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
1308
1461
|
*/
|
|
1309
1462
|
function assert(condition, message, error) {
|
|
1310
1463
|
if (!condition()) throw new (error ?? Error)(message);
|
|
@@ -1313,13 +1466,14 @@ assert.condition = assertCondition;
|
|
|
1313
1466
|
assert.defined = assertDefined;
|
|
1314
1467
|
assert.instanceOf = assertInstanceOf;
|
|
1315
1468
|
assert.is = assertIs;
|
|
1469
|
+
assert.property = assertProperty;
|
|
1316
1470
|
/**
|
|
1317
1471
|
* Creates an asserter that asserts a condition is true, throwing an error if it is not
|
|
1318
1472
|
*
|
|
1319
1473
|
* Available as `assertCondition` and `assert.condition`
|
|
1320
1474
|
* @param condition Condition to assert
|
|
1321
1475
|
* @param message Error message
|
|
1322
|
-
* @param error Error constructor
|
|
1476
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
1323
1477
|
* @returns Asserter
|
|
1324
1478
|
*/
|
|
1325
1479
|
function assertCondition(condition, message, error) {
|
|
@@ -1328,14 +1482,15 @@ function assertCondition(condition, message, error) {
|
|
|
1328
1482
|
};
|
|
1329
1483
|
}
|
|
1330
1484
|
/**
|
|
1331
|
-
* Asserts that a value is defined throwing an error if it is not
|
|
1485
|
+
* Asserts that a value is defined, throwing an error if it is not
|
|
1332
1486
|
*
|
|
1333
1487
|
* Available as `assertDefined` and `assert.defined`
|
|
1334
1488
|
* @param value Value to assert
|
|
1335
1489
|
* @param message Error message
|
|
1490
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
1336
1491
|
*/
|
|
1337
|
-
function assertDefined(value, message) {
|
|
1338
|
-
assert(() => value != null, message ?? MESSAGE_VALUE_DEFINED);
|
|
1492
|
+
function assertDefined(value, message, error) {
|
|
1493
|
+
assert(() => value != null, message ?? MESSAGE_VALUE_DEFINED, error);
|
|
1339
1494
|
}
|
|
1340
1495
|
/**
|
|
1341
1496
|
* Creates an asserter that asserts a value is an instance of a constructor, throwing an error if it is not
|
|
@@ -1343,7 +1498,7 @@ function assertDefined(value, message) {
|
|
|
1343
1498
|
* Available as `assertInstanceOf` and `assert.instanceOf`
|
|
1344
1499
|
* @param constructor Constructor to check against
|
|
1345
1500
|
* @param message Error message
|
|
1346
|
-
* @param error Error constructor
|
|
1501
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
1347
1502
|
* @returns Asserter
|
|
1348
1503
|
*/
|
|
1349
1504
|
function assertInstanceOf(constructor, message, error) {
|
|
@@ -1357,7 +1512,7 @@ function assertInstanceOf(constructor, message, error) {
|
|
|
1357
1512
|
* Available as `assertIs` and `assert.is`
|
|
1358
1513
|
* @param condition Type guard function to check the value
|
|
1359
1514
|
* @param message Error message
|
|
1360
|
-
* @param error Error constructor
|
|
1515
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
1361
1516
|
* @returns Asserter
|
|
1362
1517
|
*/
|
|
1363
1518
|
function assertIs(condition, message, error) {
|
|
@@ -1365,6 +1520,24 @@ function assertIs(condition, message, error) {
|
|
|
1365
1520
|
assert(() => condition(value), message, error);
|
|
1366
1521
|
};
|
|
1367
1522
|
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Creates an asserter that asserts a property of a value exists and satisfies a condition, throwing an error if it does not
|
|
1525
|
+
*
|
|
1526
|
+
* Available as `assertProperty` and `assert.property`
|
|
1527
|
+
* @param path Path to the property to check, e.g., `foo.bar.baz` for a nested property
|
|
1528
|
+
* @param condition Condition to assert for the property
|
|
1529
|
+
* @param message Error message
|
|
1530
|
+
* @param error Error constructor _(defaults to `Error`)_
|
|
1531
|
+
* @returns Asserter
|
|
1532
|
+
*/
|
|
1533
|
+
function assertProperty(path, condition, message, error) {
|
|
1534
|
+
return (value) => {
|
|
1535
|
+
assert(() => {
|
|
1536
|
+
const result = hasValueResult(value, path, false);
|
|
1537
|
+
return result.ok && condition(result.value);
|
|
1538
|
+
}, message, error);
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1368
1541
|
const MESSAGE_VALUE_DEFINED = "Expected value to be defined";
|
|
1369
1542
|
//#endregion
|
|
1370
1543
|
//#region src/internal/function/misc.ts
|
|
@@ -1500,6 +1673,9 @@ var SizedMap = class extends Map {
|
|
|
1500
1673
|
};
|
|
1501
1674
|
//#endregion
|
|
1502
1675
|
//#region src/function/memoize.ts
|
|
1676
|
+
/**
|
|
1677
|
+
* A memoized function, caching and retrieving results based on the its parameters _(or a custom cache key)_
|
|
1678
|
+
*/
|
|
1503
1679
|
var Memoized = class {
|
|
1504
1680
|
#state;
|
|
1505
1681
|
/**
|
|
@@ -1833,7 +2009,11 @@ const ONCE_MESSAGE_CLEARED = "Once has been cleared";
|
|
|
1833
2009
|
const ONCE_MESSAGE_EXPECTATION = "Once expected a function";
|
|
1834
2010
|
//#endregion
|
|
1835
2011
|
//#region src/function/retry.ts
|
|
2012
|
+
/**
|
|
2013
|
+
* An error thrown when a retry fails
|
|
2014
|
+
*/
|
|
1836
2015
|
var RetryError = class extends Error {
|
|
2016
|
+
original;
|
|
1837
2017
|
constructor(message, original) {
|
|
1838
2018
|
super(message);
|
|
1839
2019
|
this.original = original;
|
|
@@ -1912,33 +2092,6 @@ const RETRY_ERROR_NAME = "RetryError";
|
|
|
1912
2092
|
const RETRY_MESSAGE_EXPECTATION = "Retry expected a function";
|
|
1913
2093
|
const RETRY_MESSAGE_FAILED = "Retry failed";
|
|
1914
2094
|
//#endregion
|
|
1915
|
-
//#region src/internal/result.ts
|
|
1916
|
-
function _isResult(value, okValue) {
|
|
1917
|
-
if (isNonPlainObject(value)) return false;
|
|
1918
|
-
return value.ok === okValue && (okValue ? PROPERTY_VALUE : PROPERTY_ERROR) in value;
|
|
1919
|
-
}
|
|
1920
|
-
function isError(value, extended) {
|
|
1921
|
-
return _isResult(value, false) && (extended === true ? value.original instanceof Error : true);
|
|
1922
|
-
}
|
|
1923
|
-
/**
|
|
1924
|
-
* Is the result ok?
|
|
1925
|
-
* @param result Result to check
|
|
1926
|
-
* @returns `true` if the result is ok, `false` otherwise
|
|
1927
|
-
*/
|
|
1928
|
-
function isOk(value) {
|
|
1929
|
-
return _isResult(value, true);
|
|
1930
|
-
}
|
|
1931
|
-
/**
|
|
1932
|
-
* Is the value a result?
|
|
1933
|
-
* @param value Value to check
|
|
1934
|
-
* @returns `true` if the value is a result, `false` otherwise
|
|
1935
|
-
*/
|
|
1936
|
-
function isResult(value) {
|
|
1937
|
-
return _isResult(value, true) || _isResult(value, false);
|
|
1938
|
-
}
|
|
1939
|
-
const PROPERTY_ERROR = "error";
|
|
1940
|
-
const PROPERTY_VALUE = "value";
|
|
1941
|
-
//#endregion
|
|
1942
2095
|
//#region src/function/work.ts
|
|
1943
2096
|
function asyncFlow(...fns) {
|
|
1944
2097
|
assertFlowFunctions(fns);
|
|
@@ -2169,98 +2322,11 @@ const ERROR_PROPERTIES = ["name", "message"];
|
|
|
2169
2322
|
const EXPRESSION_PROPERTIES = ["source", "flags"];
|
|
2170
2323
|
const MINIMUM_LENGTH_FOR_SET = 16;
|
|
2171
2324
|
//#endregion
|
|
2172
|
-
//#region src/result/misc.ts
|
|
2173
|
-
function error(value, original) {
|
|
2174
|
-
return getError(value, original);
|
|
2175
|
-
}
|
|
2176
|
-
function getError(value, original) {
|
|
2177
|
-
const errorResult = {
|
|
2178
|
-
error: value,
|
|
2179
|
-
ok: false
|
|
2180
|
-
};
|
|
2181
|
-
if (original instanceof Error) errorResult.original = original;
|
|
2182
|
-
return errorResult;
|
|
2183
|
-
}
|
|
2184
|
-
/**
|
|
2185
|
-
* Creates an ok result
|
|
2186
|
-
* @param value Value
|
|
2187
|
-
* @returns Ok result
|
|
2188
|
-
*/
|
|
2189
|
-
function ok(value) {
|
|
2190
|
-
return {
|
|
2191
|
-
ok: true,
|
|
2192
|
-
value
|
|
2193
|
-
};
|
|
2194
|
-
}
|
|
2195
|
-
/**
|
|
2196
|
-
* Converts a result to a promise
|
|
2197
|
-
*
|
|
2198
|
-
* Resolves if ok, rejects for error
|
|
2199
|
-
* @param result Result to convert
|
|
2200
|
-
* @returns Promised result
|
|
2201
|
-
*/
|
|
2202
|
-
async function toPromise(result) {
|
|
2203
|
-
const actual = typeof result === "function" ? result() : result;
|
|
2204
|
-
if (!isResult(actual)) return Promise.reject(new Error(MESSAGE_PROMISE_RESULT));
|
|
2205
|
-
return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
|
|
2206
|
-
}
|
|
2207
|
-
function unwrap(value, defaultValue) {
|
|
2208
|
-
return isOk(value) ? value.value : defaultValue;
|
|
2209
|
-
}
|
|
2210
|
-
const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
|
|
2211
|
-
//#endregion
|
|
2212
|
-
//#region src/internal/value/misc.ts
|
|
2213
|
-
function findKey(needle, haystack) {
|
|
2214
|
-
const keys = Object.keys(haystack);
|
|
2215
|
-
const index = keys.map((key) => key.toLowerCase()).indexOf(needle.toLowerCase());
|
|
2216
|
-
return index > -1 ? keys[index] : needle;
|
|
2217
|
-
}
|
|
2218
|
-
function getNestedValue(data, path, ignoreCase) {
|
|
2219
|
-
if (typeof data !== "object" || data === null || typeof path !== "string" || path.trim().length === 0) return error(void 0);
|
|
2220
|
-
const shouldIgnoreCase = ignoreCase === true;
|
|
2221
|
-
const paths = getPaths(path, shouldIgnoreCase);
|
|
2222
|
-
if (typeof paths === "string") return handleValue(data, paths, null, true, shouldIgnoreCase);
|
|
2223
|
-
const { length } = paths;
|
|
2224
|
-
let current = data;
|
|
2225
|
-
for (let index = 0; index < length; index += 1) {
|
|
2226
|
-
const part = paths[index];
|
|
2227
|
-
const handled = handleValue(current, part, null, true, shouldIgnoreCase);
|
|
2228
|
-
if (!handled.ok) return handled;
|
|
2229
|
-
current = handled.value;
|
|
2230
|
-
}
|
|
2231
|
-
return ok(current);
|
|
2232
|
-
}
|
|
2233
|
-
function getPaths(path, lowercase) {
|
|
2234
|
-
const normalized = lowercase ? path.toLowerCase() : path;
|
|
2235
|
-
if (!EXPRESSION_NESTED.test(normalized)) return normalized;
|
|
2236
|
-
return normalized.replace(EXPRESSION_BRACKET, ".$1").replace(EXPRESSION_DOTS, "").split(".");
|
|
2237
|
-
}
|
|
2238
|
-
function handleValue(data, path, value, get, ignoreCase) {
|
|
2239
|
-
if (typeof data === "object" && data !== null && !ignoreKey(path)) {
|
|
2240
|
-
const key = ignoreCase ? findKey(path, data) : path;
|
|
2241
|
-
if (get) return key in data ? ok(data[key]) : error(void 0);
|
|
2242
|
-
data[key] = typeof value === "function" ? value(data[key]) : value;
|
|
2243
|
-
}
|
|
2244
|
-
if (get) return error(void 0);
|
|
2245
|
-
}
|
|
2246
|
-
const EXPRESSION_BRACKET = /\[(\w+)\]/g;
|
|
2247
|
-
const EXPRESSION_DOTS = /^\.|\.$/g;
|
|
2248
|
-
const EXPRESSION_NESTED = /\.|\[\w+\]/;
|
|
2249
|
-
//#endregion
|
|
2250
2325
|
//#region src/internal/value/get.ts
|
|
2251
2326
|
function getValue(data, path, ignoreCase) {
|
|
2252
2327
|
return getNestedValue(data, path, ignoreCase === true).value;
|
|
2253
2328
|
}
|
|
2254
2329
|
//#endregion
|
|
2255
|
-
//#region src/internal/value/has.ts
|
|
2256
|
-
function hasValue(data, path, ignoreCase) {
|
|
2257
|
-
return getNestedValue(data, path, ignoreCase === true).ok;
|
|
2258
|
-
}
|
|
2259
|
-
hasValue.get = hasValueResult;
|
|
2260
|
-
function hasValueResult(data, path, ignoreCase) {
|
|
2261
|
-
return getNestedValue(data, path, ignoreCase === true);
|
|
2262
|
-
}
|
|
2263
|
-
//#endregion
|
|
2264
2330
|
//#region src/internal/value/set.ts
|
|
2265
2331
|
function setValue(data, path, value, ignoreCase) {
|
|
2266
2332
|
if (typeof data !== "object" || data === null || typeof path !== "string" || path.trim().length === 0) return data;
|
|
@@ -3481,7 +3547,8 @@ function unsmush(value) {
|
|
|
3481
3547
|
//#endregion
|
|
3482
3548
|
//#region src/value/merge.ts
|
|
3483
3549
|
/**
|
|
3484
|
-
* Assign values from
|
|
3550
|
+
* Assign values from one or more objects to the first one
|
|
3551
|
+
*
|
|
3485
3552
|
* @param to Value to assign to
|
|
3486
3553
|
* @param from Values to assign
|
|
3487
3554
|
* @param options Assigning options
|
|
@@ -3490,7 +3557,7 @@ function unsmush(value) {
|
|
|
3490
3557
|
function assign(to, from, options) {
|
|
3491
3558
|
const actual = getMergeOptions(options);
|
|
3492
3559
|
actual.assignValues = true;
|
|
3493
|
-
return mergeValues([to, ...from], actual
|
|
3560
|
+
return mergeValues([to, ...from], actual);
|
|
3494
3561
|
}
|
|
3495
3562
|
assign.initialize = initializeAssigner;
|
|
3496
3563
|
function getMergeOptions(options) {
|
|
@@ -3511,59 +3578,70 @@ function getReplaceableObjects(value) {
|
|
|
3511
3578
|
const items = (Array.isArray(value) ? value : [value]).filter((item) => typeof item === "string" || item instanceof RegExp);
|
|
3512
3579
|
if (items.length > 0) return (name) => items.some((item) => typeof item === "string" ? item === name : item.test(name));
|
|
3513
3580
|
}
|
|
3514
|
-
function handleMerge(values, options) {
|
|
3515
|
-
return !Array.isArray(values) || values.length === 0 ? {} : mergeValues(values, options, true);
|
|
3516
|
-
}
|
|
3517
3581
|
/**
|
|
3518
3582
|
* Create an assigner with predefined options
|
|
3519
3583
|
*
|
|
3520
3584
|
* Available as `initializeAssigner` and `assign.initialize`
|
|
3585
|
+
*
|
|
3521
3586
|
* @param options Assigning options
|
|
3522
3587
|
* @returns Assigner function
|
|
3523
3588
|
*/
|
|
3524
3589
|
function initializeAssigner(options) {
|
|
3525
3590
|
const actual = getMergeOptions(options);
|
|
3526
3591
|
actual.assignValues = true;
|
|
3527
|
-
return ((to, from) => mergeValues([to, ...from], actual
|
|
3592
|
+
return ((to, from) => mergeValues([to, ...from], actual));
|
|
3528
3593
|
}
|
|
3529
3594
|
/**
|
|
3530
3595
|
* Create a merger with predefined options
|
|
3531
3596
|
*
|
|
3532
3597
|
* Available as `initializeMerger` and `merge.initialize`
|
|
3598
|
+
*
|
|
3533
3599
|
* @param options Merging options
|
|
3534
3600
|
* @returns Merger function
|
|
3535
3601
|
*/
|
|
3536
3602
|
function initializeMerger(options) {
|
|
3537
3603
|
const actual = getMergeOptions(options);
|
|
3538
|
-
return (values) =>
|
|
3604
|
+
return ((values) => mergeValues(values, actual));
|
|
3539
3605
|
}
|
|
3606
|
+
/**
|
|
3607
|
+
* Merge multiple arrays or objects into a single one
|
|
3608
|
+
*
|
|
3609
|
+
* @param values Values to merge
|
|
3610
|
+
* @param options Merging options
|
|
3611
|
+
* @returns Merged value
|
|
3612
|
+
*/
|
|
3540
3613
|
function merge(values, options) {
|
|
3541
|
-
return
|
|
3614
|
+
return mergeValues(values, getMergeOptions(options));
|
|
3542
3615
|
}
|
|
3543
3616
|
merge.initialize = initializeMerger;
|
|
3544
|
-
function mergeObjects(values, options, prefix) {
|
|
3617
|
+
function mergeObjects(values, options, destination, prefix) {
|
|
3545
3618
|
const { length } = values;
|
|
3546
|
-
const isArray =
|
|
3547
|
-
const merged =
|
|
3548
|
-
|
|
3619
|
+
const isArray = Array.isArray(destination ?? values[0]);
|
|
3620
|
+
const merged = destination ?? (isArray ? [] : {});
|
|
3621
|
+
const offset = destination == null ? 0 : 1;
|
|
3622
|
+
for (let outerIndex = offset; outerIndex < length; outerIndex += 1) {
|
|
3549
3623
|
const item = values[outerIndex];
|
|
3550
3624
|
const keys = Object.keys(item);
|
|
3551
3625
|
const size = keys.length;
|
|
3552
3626
|
for (let innerIndex = 0; innerIndex < size; innerIndex += 1) {
|
|
3553
3627
|
const key = keys[innerIndex];
|
|
3554
|
-
const full = join([prefix, key], ".");
|
|
3555
3628
|
const next = item[key];
|
|
3556
3629
|
const previous = merged[key];
|
|
3557
3630
|
if (next == null && (options.skipNullableAny || isArray && options.skipNullableInArrays)) continue;
|
|
3558
|
-
|
|
3631
|
+
const full = options.replaceableObjects == null ? void 0 : prefix == null ? key : `${prefix}.${key}`;
|
|
3632
|
+
if (isArrayOrPlainObject(next) && isArrayOrPlainObject(previous) && !(options.replaceableObjects?.(full) ?? false)) merged[key] = mergeObjects([previous, next], options, destination == null ? void 0 : merged[key], full);
|
|
3559
3633
|
else merged[key] = next;
|
|
3560
3634
|
}
|
|
3561
3635
|
}
|
|
3562
3636
|
return merged;
|
|
3563
3637
|
}
|
|
3564
|
-
function mergeValues(values, options,
|
|
3565
|
-
|
|
3566
|
-
|
|
3638
|
+
function mergeValues(values, options, prefix) {
|
|
3639
|
+
if (!Array.isArray(values)) return {};
|
|
3640
|
+
const actual = values.filter(isArrayOrPlainObject);
|
|
3641
|
+
if (actual.length === 0) return {};
|
|
3642
|
+
if (options.assignValues && actual.length === 2 && !Array.isArray(actual[0]) && Object.keys(actual[0]).length === 0) return Object.assign(actual[0], actual[1]);
|
|
3643
|
+
if (actual.length > 1) return mergeObjects(actual, options, options.assignValues ? actual[0] : void 0, prefix);
|
|
3644
|
+
return options.assignValues ? actual[0] : Array.isArray(actual[0]) ? actual[0].slice() : { ...actual[0] };
|
|
3567
3645
|
}
|
|
3568
3646
|
//#endregion
|
|
3569
3647
|
//#region src/value/transform.ts
|
|
@@ -3603,6 +3681,9 @@ function transformValue(value, transformer) {
|
|
|
3603
3681
|
}
|
|
3604
3682
|
//#endregion
|
|
3605
3683
|
//#region src/beacon.ts
|
|
3684
|
+
/**
|
|
3685
|
+
* A beacon is a lighthouse, holding an observable value that can be subscribed to and emitted from
|
|
3686
|
+
*/
|
|
3606
3687
|
var Beacon = class {
|
|
3607
3688
|
#options;
|
|
3608
3689
|
#state;
|
|
@@ -3673,6 +3754,9 @@ var Beacon = class {
|
|
|
3673
3754
|
if (finish === true) finishBeacon(this.#state, true);
|
|
3674
3755
|
}
|
|
3675
3756
|
};
|
|
3757
|
+
/**
|
|
3758
|
+
* An observable holds a value and allows observers to subscribe to changes in that value
|
|
3759
|
+
*/
|
|
3676
3760
|
var Observable = class {
|
|
3677
3761
|
#state;
|
|
3678
3762
|
constructor(instance, observers) {
|
|
@@ -3697,6 +3781,9 @@ var Observable = class {
|
|
|
3697
3781
|
return instance;
|
|
3698
3782
|
}
|
|
3699
3783
|
};
|
|
3784
|
+
/**
|
|
3785
|
+
* A subscription represents an active subscription to an observable, holding its state and allowing it to be destroyed or unsubscribed from
|
|
3786
|
+
*/
|
|
3700
3787
|
var Subscription = class {
|
|
3701
3788
|
#state;
|
|
3702
3789
|
constructor(state) {
|
|
@@ -4317,6 +4404,9 @@ function setRGBColor(state, value, alpha) {
|
|
|
4317
4404
|
}
|
|
4318
4405
|
//#endregion
|
|
4319
4406
|
//#region src/color/instance.ts
|
|
4407
|
+
/**
|
|
4408
|
+
* A color that is represented in multiple color formats
|
|
4409
|
+
*/
|
|
4320
4410
|
var Color = class {
|
|
4321
4411
|
#state;
|
|
4322
4412
|
/**
|
|
@@ -4438,6 +4528,11 @@ function getColor(value) {
|
|
|
4438
4528
|
}
|
|
4439
4529
|
//#endregion
|
|
4440
4530
|
//#region src/logger.ts
|
|
4531
|
+
/**
|
|
4532
|
+
* A logger that can be used to log messages to the console
|
|
4533
|
+
*
|
|
4534
|
+
* _(Logging can be enabled or disabled by setting the `enabled` property)_
|
|
4535
|
+
*/
|
|
4441
4536
|
var Logger = class {
|
|
4442
4537
|
/**
|
|
4443
4538
|
* Log any number of values at the "debug" log level
|
|
@@ -4508,10 +4603,16 @@ var Logger = class {
|
|
|
4508
4603
|
return new Time(label);
|
|
4509
4604
|
}
|
|
4510
4605
|
};
|
|
4606
|
+
/**
|
|
4607
|
+
* A named timer that can be used to log durations to the console
|
|
4608
|
+
*/
|
|
4511
4609
|
var Time = class {
|
|
4512
4610
|
#logger;
|
|
4513
4611
|
#stopper;
|
|
4514
4612
|
#state;
|
|
4613
|
+
/**
|
|
4614
|
+
* Is the timer active? _(i.e. has it been started and not stopped, and is logging enabled?)_
|
|
4615
|
+
*/
|
|
4515
4616
|
get active() {
|
|
4516
4617
|
return this.#state.started && !this.#state.stopped && enabled;
|
|
4517
4618
|
}
|
|
@@ -4624,6 +4725,9 @@ function sum(array, key) {
|
|
|
4624
4725
|
}
|
|
4625
4726
|
//#endregion
|
|
4626
4727
|
//#region src/promise/models.ts
|
|
4728
|
+
/**
|
|
4729
|
+
* A promise that can be canceled
|
|
4730
|
+
*/
|
|
4627
4731
|
var CancelablePromise = class extends Promise {
|
|
4628
4732
|
#rejector;
|
|
4629
4733
|
constructor(executor) {
|
|
@@ -4642,6 +4746,9 @@ var CancelablePromise = class extends Promise {
|
|
|
4642
4746
|
this.#rejector(reason);
|
|
4643
4747
|
}
|
|
4644
4748
|
};
|
|
4749
|
+
/**
|
|
4750
|
+
* An error thrown when a promise times out
|
|
4751
|
+
*/
|
|
4645
4752
|
var PromiseTimeoutError = class extends Error {
|
|
4646
4753
|
constructor() {
|
|
4647
4754
|
super(PROMISE_MESSAGE_TIMEOUT);
|
|
@@ -4941,6 +5048,9 @@ const TYPES = new Set([
|
|
|
4941
5048
|
]);
|
|
4942
5049
|
//#endregion
|
|
4943
5050
|
//#region src/queue.ts
|
|
5051
|
+
/**
|
|
5052
|
+
* A queue that can be used to manage (a)synchronous tasks with a specific key
|
|
5053
|
+
*/
|
|
4944
5054
|
var KeyedQueue = class {
|
|
4945
5055
|
#callback;
|
|
4946
5056
|
#options;
|
|
@@ -5090,6 +5200,9 @@ var KeyedQueue = class {
|
|
|
5090
5200
|
for (const queue of queues) queue[type]();
|
|
5091
5201
|
}
|
|
5092
5202
|
};
|
|
5203
|
+
/**
|
|
5204
|
+
* A queue that can be used to manage (a)synchronous tasks
|
|
5205
|
+
*/
|
|
5093
5206
|
var Queue = class {
|
|
5094
5207
|
#callback;
|
|
5095
5208
|
#handled = [];
|
|
@@ -5267,6 +5380,9 @@ var Queue = class {
|
|
|
5267
5380
|
this.#runners -= 1;
|
|
5268
5381
|
}
|
|
5269
5382
|
};
|
|
5383
|
+
/**
|
|
5384
|
+
* An error thrown by the Queue when an operation fails
|
|
5385
|
+
*/
|
|
5270
5386
|
var QueueError = class extends Error {
|
|
5271
5387
|
constructor(message) {
|
|
5272
5388
|
super(message);
|
|
@@ -5374,6 +5490,25 @@ const BOOLEAN_MODIFIER = .5;
|
|
|
5374
5490
|
const HEX_CHARACTERS = "0123456789ABCDEF";
|
|
5375
5491
|
const HEX_MAXIMUM = 15;
|
|
5376
5492
|
//#endregion
|
|
5493
|
+
//#region src/result/index.ts
|
|
5494
|
+
async function asyncAttempt(value, err) {
|
|
5495
|
+
try {
|
|
5496
|
+
let result = typeof value === "function" ? value() : await value;
|
|
5497
|
+
if (result instanceof Promise) result = await result;
|
|
5498
|
+
return ok(result);
|
|
5499
|
+
} catch (thrown) {
|
|
5500
|
+
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
5501
|
+
}
|
|
5502
|
+
}
|
|
5503
|
+
function attempt(callback, err) {
|
|
5504
|
+
try {
|
|
5505
|
+
return ok(callback());
|
|
5506
|
+
} catch (thrown) {
|
|
5507
|
+
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
5508
|
+
}
|
|
5509
|
+
}
|
|
5510
|
+
attempt.async = asyncAttempt;
|
|
5511
|
+
//#endregion
|
|
5377
5512
|
//#region src/result/match.ts
|
|
5378
5513
|
async function asyncMatchResult(result, first, error) {
|
|
5379
5514
|
let value;
|
|
@@ -5441,33 +5576,11 @@ function attemptPipe(initial, first, ...seconds) {
|
|
|
5441
5576
|
}
|
|
5442
5577
|
attemptPipe.async = attemptAsyncPipe;
|
|
5443
5578
|
//#endregion
|
|
5444
|
-
//#region src/result/index.ts
|
|
5445
|
-
async function asyncAttempt(value, err) {
|
|
5446
|
-
try {
|
|
5447
|
-
let result = typeof value === "function" ? value() : await value;
|
|
5448
|
-
if (result instanceof Promise) result = await result;
|
|
5449
|
-
return ok(result);
|
|
5450
|
-
} catch (thrown) {
|
|
5451
|
-
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
5452
|
-
}
|
|
5453
|
-
}
|
|
5454
|
-
function attempt(callback, err) {
|
|
5455
|
-
try {
|
|
5456
|
-
return ok(callback());
|
|
5457
|
-
} catch (thrown) {
|
|
5458
|
-
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
5459
|
-
}
|
|
5460
|
-
}
|
|
5461
|
-
attempt.async = asyncAttempt;
|
|
5462
|
-
attempt.flow = attemptFlow;
|
|
5463
|
-
attempt.match = matchResult;
|
|
5464
|
-
attempt.pipe = attemptPipe;
|
|
5465
|
-
attempt.promise = attemptPromise;
|
|
5466
|
-
//#endregion
|
|
5467
5579
|
//#region src/sized/set.ts
|
|
5468
5580
|
/**
|
|
5469
|
-
*
|
|
5470
|
-
*
|
|
5581
|
+
* A Set with a maximum size
|
|
5582
|
+
*
|
|
5583
|
+
* Behavior is similar to a _LRU_-cache, where the oldest values are removed
|
|
5471
5584
|
*/
|
|
5472
5585
|
var SizedSet = class extends Set {
|
|
5473
5586
|
/**
|
|
@@ -5518,4 +5631,4 @@ var SizedSet = class extends Set {
|
|
|
5518
5631
|
}
|
|
5519
5632
|
};
|
|
5520
5633
|
//#endregion
|
|
5521
|
-
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,
|
|
5634
|
+
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 };
|