@oscarpalmer/atoms 0.205.0 → 0.207.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/reverse.mjs +2 -1
- package/dist/array/single.d.mts +3 -3
- package/dist/array/sort.mjs +3 -2
- package/dist/color/misc/alpha.mjs +1 -1
- package/dist/color/misc/get.mjs +1 -1
- package/dist/color/space/hsl.mjs +7 -2
- package/dist/color/space/hwb.mjs +2 -1
- package/dist/color/space/rgb.mjs +22 -13
- package/dist/function/retry.mjs +12 -14
- package/dist/index.d.mts +105 -55
- package/dist/index.mjs +323 -262
- package/dist/internal/array/insert.mjs +2 -1
- package/dist/internal/function/limit.mjs +9 -9
- package/dist/internal/function/work.d.mts +1 -1
- package/dist/internal/math/aggregate.d.mts +41 -0
- package/dist/internal/math/aggregate.mjs +4 -1
- package/dist/internal/math/misc.d.mts +8 -0
- package/dist/internal/math/misc.mjs +11 -1
- package/dist/internal/models/plan.model.d.mts +23 -0
- package/dist/internal/models/plan.model.mjs +7 -0
- package/dist/internal/{result/models.d.mts → models/result.model.d.mts} +1 -1
- package/dist/internal/random.mjs +2 -1
- package/dist/internal/result/attempt.d.mts +59 -0
- package/dist/internal/result/attempt.mjs +24 -0
- package/dist/internal/result/misc.d.mts +1 -1
- package/dist/internal/string/misc.mjs +4 -5
- package/dist/internal/value/equal.mjs +2 -1
- package/dist/internal/value/has.d.mts +1 -1
- package/dist/internal/value/misc.d.mts +1 -1
- package/dist/internal/value/misc.mjs +1 -1
- package/dist/math.d.mts +3 -52
- package/dist/math.mjs +3 -16
- package/dist/plan/index.d.mts +38 -0
- package/dist/plan/index.mjs +61 -0
- package/dist/plan/models.d.mts +2 -0
- package/dist/plan/models.mjs +1 -0
- package/dist/promise/constants.d.mts +0 -1
- package/dist/promise/constants.mjs +1 -2
- package/dist/promise/helpers.mjs +1 -1
- package/dist/promise/index.mjs +9 -9
- package/dist/promise/misc.d.mts +1 -1
- package/dist/promise/misc.mjs +1 -1
- package/dist/promise/models.d.mts +1 -1
- package/dist/queue.mjs +11 -6
- package/dist/result/index.d.mts +2 -59
- package/dist/result/index.mjs +1 -23
- package/dist/result/match.d.mts +1 -1
- package/dist/result/misc.d.mts +1 -1
- package/dist/result/work/flow.d.mts +1 -1
- package/dist/result/work/flow.mjs +2 -1
- package/dist/result/work/pipe.d.mts +1 -1
- package/dist/result/work/pipe.mjs +2 -1
- package/dist/string/fuzzy.mjs +7 -5
- package/dist/string/index.mjs +2 -1
- package/dist/value/clone.mjs +5 -8
- package/dist/value/diff.mjs +3 -2
- package/package.json +9 -4
- /package/dist/internal/{result/models.mjs → models/result.model.mjs} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -462,6 +462,34 @@ const outside = [-1, MATCH_COMPARISON_OUTSIDE];
|
|
|
462
462
|
const outsides = /* @__PURE__ */ new Set([MATCH_COMPARISON_INVALID, MATCH_COMPARISON_OUTSIDE]);
|
|
463
463
|
const starts = /* @__PURE__ */ new Set([MATCH_COMPARISON_START, MATCH_COMPARISON_SAME]);
|
|
464
464
|
//#endregion
|
|
465
|
+
//#region src/internal/math/misc.ts
|
|
466
|
+
/**
|
|
467
|
+
* Round a number down
|
|
468
|
+
*
|
|
469
|
+
* @param value Number to round down
|
|
470
|
+
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
471
|
+
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
472
|
+
*/
|
|
473
|
+
function floor(value, decimals) {
|
|
474
|
+
return roundNumber(Math.floor, value, decimals);
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Round a number
|
|
478
|
+
*
|
|
479
|
+
* @param value Number to round
|
|
480
|
+
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
481
|
+
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
482
|
+
*/
|
|
483
|
+
function round(value, decimals) {
|
|
484
|
+
return roundNumber(Math.round, value, decimals);
|
|
485
|
+
}
|
|
486
|
+
function roundNumber(callback, value, decimals) {
|
|
487
|
+
if (typeof value !== "number") return NaN;
|
|
488
|
+
if (typeof decimals !== "number" || decimals < 1) return callback(value);
|
|
489
|
+
const mod = 10 ** decimals;
|
|
490
|
+
return callback((value + Number.EPSILON) * mod) / mod;
|
|
491
|
+
}
|
|
492
|
+
//#endregion
|
|
465
493
|
//#region src/internal/random.ts
|
|
466
494
|
function getRandomFloatingNumberValue(inclusive, minimum, maximum) {
|
|
467
495
|
let maxFloat = isNumber(maximum) && maximum <= Number.MAX_SAFE_INTEGER ? maximum : Number.MAX_SAFE_INTEGER;
|
|
@@ -488,7 +516,7 @@ function getRandomFloatingNumber(minimum, maximum) {
|
|
|
488
516
|
* @returns Random integer
|
|
489
517
|
*/
|
|
490
518
|
function getRandomInteger(minimum, maximum) {
|
|
491
|
-
return
|
|
519
|
+
return floor(getRandomFloatingNumberValue(true, minimum, maximum));
|
|
492
520
|
}
|
|
493
521
|
//#endregion
|
|
494
522
|
//#region src/internal/array/shuffle.ts
|
|
@@ -586,10 +614,81 @@ function times(length, value) {
|
|
|
586
614
|
return values;
|
|
587
615
|
}
|
|
588
616
|
//#endregion
|
|
617
|
+
//#region src/internal/math/aggregate.ts
|
|
618
|
+
function aggregate(type, array, key, first) {
|
|
619
|
+
const length = Array.isArray(array) ? array.length : 0;
|
|
620
|
+
const aggregation = {
|
|
621
|
+
array: false,
|
|
622
|
+
count: 0,
|
|
623
|
+
first: first === true,
|
|
624
|
+
value: NaN
|
|
625
|
+
};
|
|
626
|
+
if (length === 0) return aggregation;
|
|
627
|
+
const aggregator = aggregators[type];
|
|
628
|
+
const callback = getAggregateCallback(key);
|
|
629
|
+
aggregation.array = callback != null && (type === "max" || type === "min");
|
|
630
|
+
let notNumber = true;
|
|
631
|
+
for (let index = 0; index < length; index += 1) {
|
|
632
|
+
const item = array[index];
|
|
633
|
+
const value = callback == null ? item : callback(item, index, array);
|
|
634
|
+
if (isNonNumber(value)) continue;
|
|
635
|
+
aggregation.value = aggregator(aggregation, value, notNumber, item);
|
|
636
|
+
aggregation.count += 1;
|
|
637
|
+
notNumber = false;
|
|
638
|
+
}
|
|
639
|
+
return aggregation;
|
|
640
|
+
}
|
|
641
|
+
function calculateSum(aggregation, value, notNumber) {
|
|
642
|
+
return notNumber ? value : aggregation.value + value;
|
|
643
|
+
}
|
|
644
|
+
function getAbsoluteValue(condition, aggregation, value, notNumber, item) {
|
|
645
|
+
if (notNumber || condition(aggregation, value)) {
|
|
646
|
+
if (aggregation.array) {
|
|
647
|
+
aggregation.items ??= {};
|
|
648
|
+
aggregation.items[value] ??= [];
|
|
649
|
+
aggregation.items[value].push(item);
|
|
650
|
+
}
|
|
651
|
+
return value;
|
|
652
|
+
}
|
|
653
|
+
return aggregation.value;
|
|
654
|
+
}
|
|
655
|
+
function getAggregateCallback(key) {
|
|
656
|
+
if (key == null) return;
|
|
657
|
+
return typeof key === "function" ? key : (item) => item[key];
|
|
658
|
+
}
|
|
659
|
+
function getAggregated(type, array, key, first) {
|
|
660
|
+
const aggregation = aggregate(type, array, key, first);
|
|
661
|
+
if (aggregation.count === 0) return aggregation.array ? aggregation.first ? void 0 : [] : NaN;
|
|
662
|
+
if (aggregation.array) {
|
|
663
|
+
const array = aggregation.items[aggregation.value];
|
|
664
|
+
return aggregation.first ? array[0] : array;
|
|
665
|
+
}
|
|
666
|
+
return aggregation.value;
|
|
667
|
+
}
|
|
668
|
+
function isMaxValue(aggregation, value) {
|
|
669
|
+
return aggregation.array ? value >= aggregation.value : value > aggregation.value;
|
|
670
|
+
}
|
|
671
|
+
function isMinValue(aggregation, value) {
|
|
672
|
+
return aggregation.array ? value <= aggregation.value : value < aggregation.value;
|
|
673
|
+
}
|
|
674
|
+
function max(array, key, first) {
|
|
675
|
+
return getAggregated("max", array, key, first);
|
|
676
|
+
}
|
|
677
|
+
function min(array, key, first) {
|
|
678
|
+
return getAggregated("min", array, key, first);
|
|
679
|
+
}
|
|
680
|
+
const AGGREGATION_AVERAGE = "average";
|
|
681
|
+
const aggregators = {
|
|
682
|
+
average: calculateSum,
|
|
683
|
+
max: getAbsoluteValue.bind(void 0, isMaxValue),
|
|
684
|
+
min: getAbsoluteValue.bind(void 0, isMinValue),
|
|
685
|
+
sum: calculateSum
|
|
686
|
+
};
|
|
687
|
+
//#endregion
|
|
589
688
|
//#region src/internal/array/insert.ts
|
|
590
689
|
function insertChunkedValues(type, array, items, start, deleteCount) {
|
|
591
690
|
const actualDeleteCount = deleteCount < 0 ? 0 : deleteCount;
|
|
592
|
-
const actualStart =
|
|
691
|
+
const actualStart = min([max([0, start]), array.length]);
|
|
593
692
|
const chunked = chunk(items);
|
|
594
693
|
const lastIndex = chunked.length - 1;
|
|
595
694
|
let index = chunked.length;
|
|
@@ -658,7 +757,7 @@ function reverse(array) {
|
|
|
658
757
|
if (!Array.isArray(array)) return [];
|
|
659
758
|
const { length } = array;
|
|
660
759
|
if (length < 2) return array;
|
|
661
|
-
const half =
|
|
760
|
+
const half = floor(length / 2);
|
|
662
761
|
for (let firstIndex = 0; firstIndex < half; firstIndex += 1) {
|
|
663
762
|
const temporaryItem = array[firstIndex];
|
|
664
763
|
const secondIndex = length - 1 - firstIndex;
|
|
@@ -907,73 +1006,92 @@ function selectValues(array, parameters) {
|
|
|
907
1006
|
}
|
|
908
1007
|
filterAndMap.reverse = mapAndFilter;
|
|
909
1008
|
//#endregion
|
|
910
|
-
//#region src/internal/
|
|
911
|
-
function
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
1009
|
+
//#region src/internal/result/misc.ts
|
|
1010
|
+
function error(value, original) {
|
|
1011
|
+
return getError(value, original);
|
|
1012
|
+
}
|
|
1013
|
+
function getError(value, original) {
|
|
1014
|
+
const errorResult = {
|
|
1015
|
+
error: value,
|
|
1016
|
+
ok: false
|
|
918
1017
|
};
|
|
919
|
-
if (
|
|
920
|
-
|
|
921
|
-
const callback = getAggregateCallback(key);
|
|
922
|
-
aggregation.array = callback != null && (type === "max" || type === "min");
|
|
923
|
-
let notNumber = true;
|
|
924
|
-
for (let index = 0; index < length; index += 1) {
|
|
925
|
-
const item = array[index];
|
|
926
|
-
const value = callback == null ? item : callback(item, index, array);
|
|
927
|
-
if (isNonNumber(value)) continue;
|
|
928
|
-
aggregation.value = aggregator(aggregation, value, notNumber, item);
|
|
929
|
-
aggregation.count += 1;
|
|
930
|
-
notNumber = false;
|
|
931
|
-
}
|
|
932
|
-
return aggregation;
|
|
1018
|
+
if (original instanceof Error) errorResult.original = original;
|
|
1019
|
+
return errorResult;
|
|
933
1020
|
}
|
|
934
|
-
function
|
|
935
|
-
return
|
|
1021
|
+
function isError(value, extended) {
|
|
1022
|
+
return isResultValue(value, false) && (extended === true ? value.original instanceof Error : true);
|
|
936
1023
|
}
|
|
937
|
-
function
|
|
938
|
-
|
|
939
|
-
if (aggregation.array) {
|
|
940
|
-
aggregation.items ??= {};
|
|
941
|
-
aggregation.items[value] ??= [];
|
|
942
|
-
aggregation.items[value].push(item);
|
|
943
|
-
}
|
|
944
|
-
return value;
|
|
945
|
-
}
|
|
946
|
-
return aggregation.value;
|
|
1024
|
+
function isOk(value) {
|
|
1025
|
+
return isResultValue(value, true);
|
|
947
1026
|
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
1027
|
+
/**
|
|
1028
|
+
* Is the value a _Result_?
|
|
1029
|
+
*
|
|
1030
|
+
* @param value Value to check
|
|
1031
|
+
* @returns `true` if the value is a _Result_, otherwise `false`
|
|
1032
|
+
*/
|
|
1033
|
+
function isResult(value) {
|
|
1034
|
+
return isResultValue(value, true) || isResultValue(value, false);
|
|
951
1035
|
}
|
|
952
|
-
function
|
|
953
|
-
|
|
954
|
-
if (aggregation.count === 0) return aggregation.array ? aggregation.first ? void 0 : [] : NaN;
|
|
955
|
-
if (aggregation.array) {
|
|
956
|
-
const array = aggregation.items[aggregation.value];
|
|
957
|
-
return aggregation.first ? array[0] : array;
|
|
958
|
-
}
|
|
959
|
-
return aggregation.value;
|
|
1036
|
+
function isResultValue(value, okValue) {
|
|
1037
|
+
return isPlainObject(value) && value.ok === okValue && (okValue ? RESULT_PROPERTY_VALUE : RESULT_PROPERTY_ERROR) in value;
|
|
960
1038
|
}
|
|
961
|
-
|
|
962
|
-
|
|
1039
|
+
/**
|
|
1040
|
+
* Creates an ok result
|
|
1041
|
+
*
|
|
1042
|
+
* @param value Value
|
|
1043
|
+
* @returns Ok result
|
|
1044
|
+
*/
|
|
1045
|
+
function ok(value) {
|
|
1046
|
+
return {
|
|
1047
|
+
ok: true,
|
|
1048
|
+
value
|
|
1049
|
+
};
|
|
963
1050
|
}
|
|
964
|
-
function
|
|
965
|
-
return
|
|
1051
|
+
function unwrap(value, defaultValue) {
|
|
1052
|
+
return isOk(value) ? value.value : defaultValue;
|
|
966
1053
|
}
|
|
967
|
-
|
|
968
|
-
|
|
1054
|
+
const RESULT_PROPERTY_ERROR = "error";
|
|
1055
|
+
const RESULT_PROPERTY_VALUE = "value";
|
|
1056
|
+
error.is = isError;
|
|
1057
|
+
ok.is = isOk;
|
|
1058
|
+
//#endregion
|
|
1059
|
+
//#region src/result/misc.ts
|
|
1060
|
+
/**
|
|
1061
|
+
* Converts a _Result_ to a _Promise_
|
|
1062
|
+
*
|
|
1063
|
+
* Resolves if ok, rejects for error
|
|
1064
|
+
*
|
|
1065
|
+
* @param result _Result_ to convert
|
|
1066
|
+
* @returns Promised result
|
|
1067
|
+
*/
|
|
1068
|
+
async function toPromise(result) {
|
|
1069
|
+
const actual = typeof result === "function" ? result() : result;
|
|
1070
|
+
if (!isResult(actual)) return Promise.reject(new Error(RESULT_MESSAGE_PROMISE));
|
|
1071
|
+
return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
|
|
969
1072
|
}
|
|
970
|
-
const
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
1073
|
+
const RESULT_MESSAGE_PROMISE = "toPromise expected to receive a Result";
|
|
1074
|
+
//#endregion
|
|
1075
|
+
//#region src/internal/result/attempt.ts
|
|
1076
|
+
async function asyncAttempt(value, err) {
|
|
1077
|
+
try {
|
|
1078
|
+
let result;
|
|
1079
|
+
if (typeof value === "function") result = value();
|
|
1080
|
+
else result = value;
|
|
1081
|
+
if (result instanceof Promise) result = await result;
|
|
1082
|
+
return ok(result);
|
|
1083
|
+
} catch (thrown) {
|
|
1084
|
+
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
function attempt(callback, err) {
|
|
1088
|
+
try {
|
|
1089
|
+
return ok(callback());
|
|
1090
|
+
} catch (thrown) {
|
|
1091
|
+
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
attempt.async = asyncAttempt;
|
|
977
1095
|
//#endregion
|
|
978
1096
|
//#region src/internal/string/misc.ts
|
|
979
1097
|
/**
|
|
@@ -1034,11 +1152,7 @@ function join(array, delimiter) {
|
|
|
1034
1152
|
return values.join(typeof delimiter === "string" ? delimiter : "");
|
|
1035
1153
|
}
|
|
1036
1154
|
function tryCallback(value, callback) {
|
|
1037
|
-
|
|
1038
|
-
return callback(value);
|
|
1039
|
-
} catch {
|
|
1040
|
-
return value;
|
|
1041
|
-
}
|
|
1155
|
+
return unwrap(attempt(() => callback(value)), value);
|
|
1042
1156
|
}
|
|
1043
1157
|
function tryDecode(value) {
|
|
1044
1158
|
return tryCallback(value, decodeURIComponent);
|
|
@@ -1244,7 +1358,7 @@ function getSortedArrayIndex(array, item) {
|
|
|
1244
1358
|
let low = 0;
|
|
1245
1359
|
let high = length - 1;
|
|
1246
1360
|
while (low <= high) {
|
|
1247
|
-
const mid =
|
|
1361
|
+
const mid = floor((low + high) / 2);
|
|
1248
1362
|
if (getComparisonValue(item, array[mid], sorters, sortersLength) < 0) high = mid - 1;
|
|
1249
1363
|
else low = mid + 1;
|
|
1250
1364
|
}
|
|
@@ -1299,7 +1413,7 @@ function isSortedArray(array) {
|
|
|
1299
1413
|
const sortersLength = sorters.length;
|
|
1300
1414
|
let offset = 0;
|
|
1301
1415
|
if (length >= SORT_THRESHOLD) {
|
|
1302
|
-
offset =
|
|
1416
|
+
offset = round(length / SORT_PEEK_PERCENTAGE);
|
|
1303
1417
|
offset = offset > SORT_THRESHOLD ? SORT_THRESHOLD : offset;
|
|
1304
1418
|
for (let index = 0; index < offset; index += 1) {
|
|
1305
1419
|
const [firstItem, firstOffset] = [array[index], array[index + 1]];
|
|
@@ -1505,15 +1619,14 @@ async function handleAsyncLimiter(state, item) {
|
|
|
1505
1619
|
if (state.interval === 0 || now - state.start >= state.interval - LIMITER_OFFSET) {
|
|
1506
1620
|
state.start = state.throttle ? now : void 0;
|
|
1507
1621
|
item.running = true;
|
|
1508
|
-
|
|
1509
|
-
let
|
|
1510
|
-
if (
|
|
1511
|
-
|
|
1512
|
-
}
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
}
|
|
1622
|
+
const result = await asyncAttempt(async () => {
|
|
1623
|
+
let value = state.callback(...item.parameters);
|
|
1624
|
+
if (value instanceof Promise) value = await value;
|
|
1625
|
+
return value;
|
|
1626
|
+
});
|
|
1627
|
+
if (result.ok) item.resolve(result.value);
|
|
1628
|
+
else item.reject(result.error);
|
|
1629
|
+
item.running = false;
|
|
1517
1630
|
} else state.timer = startTimer(() => handleAsyncLimiter(state, item));
|
|
1518
1631
|
}
|
|
1519
1632
|
function handleLimiter(state) {
|
|
@@ -1613,56 +1726,6 @@ function throttle(callback, time) {
|
|
|
1613
1726
|
debounce.async = asyncDebounce;
|
|
1614
1727
|
throttle.async = asyncThrottle;
|
|
1615
1728
|
//#endregion
|
|
1616
|
-
//#region src/internal/result/misc.ts
|
|
1617
|
-
function error(value, original) {
|
|
1618
|
-
return getError(value, original);
|
|
1619
|
-
}
|
|
1620
|
-
function getError(value, original) {
|
|
1621
|
-
const errorResult = {
|
|
1622
|
-
error: value,
|
|
1623
|
-
ok: false
|
|
1624
|
-
};
|
|
1625
|
-
if (original instanceof Error) errorResult.original = original;
|
|
1626
|
-
return errorResult;
|
|
1627
|
-
}
|
|
1628
|
-
function isError(value, extended) {
|
|
1629
|
-
return isResultValue(value, false) && (extended === true ? value.original instanceof Error : true);
|
|
1630
|
-
}
|
|
1631
|
-
function isOk(value) {
|
|
1632
|
-
return isResultValue(value, true);
|
|
1633
|
-
}
|
|
1634
|
-
/**
|
|
1635
|
-
* Is the value a _Result_?
|
|
1636
|
-
*
|
|
1637
|
-
* @param value Value to check
|
|
1638
|
-
* @returns `true` if the value is a _Result_, otherwise `false`
|
|
1639
|
-
*/
|
|
1640
|
-
function isResult(value) {
|
|
1641
|
-
return isResultValue(value, true) || isResultValue(value, false);
|
|
1642
|
-
}
|
|
1643
|
-
function isResultValue(value, okValue) {
|
|
1644
|
-
return isPlainObject(value) && value.ok === okValue && (okValue ? RESULT_PROPERTY_VALUE : RESULT_PROPERTY_ERROR) in value;
|
|
1645
|
-
}
|
|
1646
|
-
/**
|
|
1647
|
-
* Creates an ok result
|
|
1648
|
-
*
|
|
1649
|
-
* @param value Value
|
|
1650
|
-
* @returns Ok result
|
|
1651
|
-
*/
|
|
1652
|
-
function ok(value) {
|
|
1653
|
-
return {
|
|
1654
|
-
ok: true,
|
|
1655
|
-
value
|
|
1656
|
-
};
|
|
1657
|
-
}
|
|
1658
|
-
function unwrap(value, defaultValue) {
|
|
1659
|
-
return isOk(value) ? value.value : defaultValue;
|
|
1660
|
-
}
|
|
1661
|
-
const RESULT_PROPERTY_ERROR = "error";
|
|
1662
|
-
const RESULT_PROPERTY_VALUE = "value";
|
|
1663
|
-
error.is = isError;
|
|
1664
|
-
ok.is = isOk;
|
|
1665
|
-
//#endregion
|
|
1666
1729
|
//#region src/internal/value/misc.ts
|
|
1667
1730
|
function findKey(needle, haystack) {
|
|
1668
1731
|
const keys = Object.keys(haystack);
|
|
@@ -2005,15 +2068,12 @@ var RetryError = class extends Error {
|
|
|
2005
2068
|
async function asyncRetry(callback, options) {
|
|
2006
2069
|
if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
2007
2070
|
async function handle() {
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
attempts += 1;
|
|
2015
|
-
limiter.run();
|
|
2016
|
-
}
|
|
2071
|
+
const result = await asyncAttempt(async () => callback());
|
|
2072
|
+
if (result.ok) resolver(result.value);
|
|
2073
|
+
else if (attempts >= times || !when(result.error)) rejector(new RetryError(RETRY_MESSAGE_FAILED, result.error));
|
|
2074
|
+
else {
|
|
2075
|
+
attempts += 1;
|
|
2076
|
+
limiter.run();
|
|
2017
2077
|
}
|
|
2018
2078
|
}
|
|
2019
2079
|
const { delay, times, when } = createRetryOptions(options);
|
|
@@ -2046,11 +2106,11 @@ function retry(callback, options) {
|
|
|
2046
2106
|
if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
2047
2107
|
const { times, when } = createRetryOptions(options);
|
|
2048
2108
|
let last;
|
|
2049
|
-
for (let index = 0; index <= times; index += 1)
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
if (index >= times || !when(error)) {
|
|
2053
|
-
last = error;
|
|
2109
|
+
for (let index = 0; index <= times; index += 1) {
|
|
2110
|
+
const result = attempt(callback);
|
|
2111
|
+
if (result.ok) return result.value;
|
|
2112
|
+
if (index >= times || !when(result.error)) {
|
|
2113
|
+
last = result.error;
|
|
2054
2114
|
break;
|
|
2055
2115
|
}
|
|
2056
2116
|
}
|
|
@@ -2531,7 +2591,7 @@ function equalArray(first, second, options) {
|
|
|
2531
2591
|
if (length !== second.length) return false;
|
|
2532
2592
|
let offset = 0;
|
|
2533
2593
|
if (length >= EQUAL_ARRAY_THRESHOLD) {
|
|
2534
|
-
offset =
|
|
2594
|
+
offset = round(length / EQUAL_ARRAY_PEEK_PERCENTAGE);
|
|
2535
2595
|
offset = offset > EQUAL_ARRAY_THRESHOLD ? EQUAL_ARRAY_THRESHOLD : offset;
|
|
2536
2596
|
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;
|
|
2537
2597
|
}
|
|
@@ -2686,6 +2746,67 @@ function setValue(data, path, value, ignoreCase) {
|
|
|
2686
2746
|
return data;
|
|
2687
2747
|
}
|
|
2688
2748
|
const SET_EXPRESSION_INDEX = /^\d+$/;
|
|
2749
|
+
const PLAN_MESSAGE_PLAN_INPUT = "plan requires a generator function";
|
|
2750
|
+
const PLAN_MESSAGE_RUN_INPUT = "run requires a plan or a generator function";
|
|
2751
|
+
const PLAN_SYMBOL = Symbol("plan");
|
|
2752
|
+
//#endregion
|
|
2753
|
+
//#region src/plan/index.ts
|
|
2754
|
+
function Plan(generator) {
|
|
2755
|
+
this[PLAN_SYMBOL] = { generator };
|
|
2756
|
+
}
|
|
2757
|
+
Plan.prototype.run = runPlan;
|
|
2758
|
+
function execute(callback) {
|
|
2759
|
+
const result = attempt(() => {
|
|
2760
|
+
const generator = callback();
|
|
2761
|
+
let lastValue;
|
|
2762
|
+
while (true) {
|
|
2763
|
+
const next = generator.next();
|
|
2764
|
+
const { done } = next;
|
|
2765
|
+
let { value } = next;
|
|
2766
|
+
if (value instanceof Error) throw value;
|
|
2767
|
+
lastValue = value;
|
|
2768
|
+
if (done === true) break;
|
|
2769
|
+
}
|
|
2770
|
+
return lastValue;
|
|
2771
|
+
});
|
|
2772
|
+
return result.ok ? result.value : result.error;
|
|
2773
|
+
}
|
|
2774
|
+
/**
|
|
2775
|
+
* Is the value a generator function?
|
|
2776
|
+
*
|
|
2777
|
+
* @param value Value to check
|
|
2778
|
+
* @returns `true` if the value is a generator function, otherwise `false`
|
|
2779
|
+
*/
|
|
2780
|
+
function isGenerator(value) {
|
|
2781
|
+
return typeof value === "function" && value.constructor.name === "GeneratorFunction" && typeof value.prototype.next === "function" && typeof value.prototype.return === "function" && typeof value.prototype.throw === "function";
|
|
2782
|
+
}
|
|
2783
|
+
/**
|
|
2784
|
+
* Is the value a plan?
|
|
2785
|
+
*
|
|
2786
|
+
* @param value Value to check
|
|
2787
|
+
* @returns `true` if the value is a plan, otherwise `false`
|
|
2788
|
+
*/
|
|
2789
|
+
function isPlan(value) {
|
|
2790
|
+
return typeof value === "object" && value !== null && PLAN_SYMBOL in value;
|
|
2791
|
+
}
|
|
2792
|
+
/**
|
|
2793
|
+
* Create a plan for a generator function
|
|
2794
|
+
*
|
|
2795
|
+
* @param generator Generator to plan for
|
|
2796
|
+
* @returns Generator plan
|
|
2797
|
+
*/
|
|
2798
|
+
function plan(generator) {
|
|
2799
|
+
if (!isGenerator(generator)) throw new Error(PLAN_MESSAGE_PLAN_INPUT);
|
|
2800
|
+
return new Plan(generator);
|
|
2801
|
+
}
|
|
2802
|
+
function run(input) {
|
|
2803
|
+
if (isPlan(input)) return input.run();
|
|
2804
|
+
if (!isGenerator(input)) throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
2805
|
+
return execute(input);
|
|
2806
|
+
}
|
|
2807
|
+
function runPlan() {
|
|
2808
|
+
return execute(this[PLAN_SYMBOL].generator);
|
|
2809
|
+
}
|
|
2689
2810
|
//#endregion
|
|
2690
2811
|
//#region src/internal/aborter.ts
|
|
2691
2812
|
function createAborter(value, onAbort) {
|
|
@@ -2703,7 +2824,6 @@ const ABORT_OPTIONS = { once: true };
|
|
|
2703
2824
|
//#region src/promise/constants.ts
|
|
2704
2825
|
const PROMISE_ERROR_NAME = "PromiseTimeoutError";
|
|
2705
2826
|
const PROMISE_MESSAGE_EXPECTATION_ATTEMPT = "Attempt expected a function or a promise";
|
|
2706
|
-
const PROMISE_MESSAGE_EXPECTATION_ITEMS_EMPTY = "promises expected at least one promise-function or promise in the array or object";
|
|
2707
2827
|
const PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE = "promises expected an array or object holding promise-functions or promises";
|
|
2708
2828
|
const PROMISE_MESSAGE_EXPECTATION_RESULT = "toResult expected a Promise";
|
|
2709
2829
|
const PROMISE_MESSAGE_EXPECTATION_TIMED = "Timed function expected a Promise";
|
|
@@ -2808,22 +2928,6 @@ function isType(value, type) {
|
|
|
2808
2928
|
return isPlainObject(value) && "status" in value && value.status === type;
|
|
2809
2929
|
}
|
|
2810
2930
|
//#endregion
|
|
2811
|
-
//#region src/result/misc.ts
|
|
2812
|
-
/**
|
|
2813
|
-
* Converts a _Result_ to a _Promise_
|
|
2814
|
-
*
|
|
2815
|
-
* Resolves if ok, rejects for error
|
|
2816
|
-
*
|
|
2817
|
-
* @param result _Result_ to convert
|
|
2818
|
-
* @returns Promised result
|
|
2819
|
-
*/
|
|
2820
|
-
async function toPromise(result) {
|
|
2821
|
-
const actual = typeof result === "function" ? result() : result;
|
|
2822
|
-
if (!isResult(actual)) return Promise.reject(new Error(RESULT_MESSAGE_PROMISE));
|
|
2823
|
-
return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
|
|
2824
|
-
}
|
|
2825
|
-
const RESULT_MESSAGE_PROMISE = "toPromise expected to receive a Result";
|
|
2826
|
-
//#endregion
|
|
2827
2931
|
//#region src/promise/misc.ts
|
|
2828
2932
|
/**
|
|
2829
2933
|
* Create a cancelable _Promise_
|
|
@@ -2914,13 +3018,13 @@ async function attemptPromise(value, options) {
|
|
|
2914
3018
|
rejector(signal?.reason);
|
|
2915
3019
|
});
|
|
2916
3020
|
async function handler(resolve, reject) {
|
|
2917
|
-
|
|
3021
|
+
const result = await asyncAttempt(async () => {
|
|
2918
3022
|
let result = isFunction ? value() : await value;
|
|
2919
3023
|
if (result instanceof Promise) result = await result;
|
|
2920
|
-
|
|
2921
|
-
}
|
|
2922
|
-
|
|
2923
|
-
|
|
3024
|
+
return result;
|
|
3025
|
+
});
|
|
3026
|
+
if (result.ok) settlePromise(resolve, result.value, aborter);
|
|
3027
|
+
else settlePromise(reject, result.error, aborter);
|
|
2924
3028
|
}
|
|
2925
3029
|
let rejector;
|
|
2926
3030
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -2935,12 +3039,11 @@ async function promises(items, options) {
|
|
|
2935
3039
|
if (!isArrayOrPlainObject(items)) return Promise.reject(PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE);
|
|
2936
3040
|
const isArray = Array.isArray(items);
|
|
2937
3041
|
const actual = (isArray ? items.map((item, index) => [index, item]) : Object.entries(items)).map(([key, value]) => [key, typeof value === "function" ? value() : value]).filter(([, value]) => value instanceof Promise);
|
|
2938
|
-
const { length } = actual;
|
|
2939
|
-
if (length === 0) return Promise.reject(PROMISE_MESSAGE_EXPECTATION_ITEMS_EMPTY);
|
|
2940
|
-
const complete = strategy === PROMISE_STRATEGY_DEFAULT;
|
|
2941
3042
|
const aborter = createAborter(signal, () => {
|
|
2942
3043
|
handlers.reject(signal?.reason);
|
|
2943
3044
|
});
|
|
3045
|
+
const complete = strategy === PROMISE_STRATEGY_DEFAULT;
|
|
3046
|
+
const { length } = actual;
|
|
2944
3047
|
const data = {
|
|
2945
3048
|
last: length - 1,
|
|
2946
3049
|
result: isArray ? [] : {}
|
|
@@ -2976,27 +3079,6 @@ async function resultPromises(items, signal) {
|
|
|
2976
3079
|
}
|
|
2977
3080
|
promises.result = resultPromises;
|
|
2978
3081
|
//#endregion
|
|
2979
|
-
//#region src/result/index.ts
|
|
2980
|
-
async function asyncAttempt(value, err) {
|
|
2981
|
-
try {
|
|
2982
|
-
let result;
|
|
2983
|
-
if (typeof value === "function") result = value();
|
|
2984
|
-
else result = value;
|
|
2985
|
-
if (result instanceof Promise) result = await result;
|
|
2986
|
-
return ok(result);
|
|
2987
|
-
} catch (thrown) {
|
|
2988
|
-
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
2989
|
-
}
|
|
2990
|
-
}
|
|
2991
|
-
function attempt(callback, err) {
|
|
2992
|
-
try {
|
|
2993
|
-
return ok(callback());
|
|
2994
|
-
} catch (thrown) {
|
|
2995
|
-
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
2996
|
-
}
|
|
2997
|
-
}
|
|
2998
|
-
attempt.async = asyncAttempt;
|
|
2999
|
-
//#endregion
|
|
3000
3082
|
//#region src/result/match.ts
|
|
3001
3083
|
async function asyncMatchResult(result, first, error) {
|
|
3002
3084
|
let value;
|
|
@@ -3136,7 +3218,7 @@ function createFuzzyItems(items) {
|
|
|
3136
3218
|
function createFuzzyOptions(input, state) {
|
|
3137
3219
|
const options = isPlainObject(input) ? input : {};
|
|
3138
3220
|
const limit = typeof input === "number" ? input : options.limit;
|
|
3139
|
-
if (typeof limit === "number" && !Number.isNaN(limit) && limit >= 1) options.limit =
|
|
3221
|
+
if (typeof limit === "number" && !Number.isNaN(limit) && limit >= 1) options.limit = floor(limit);
|
|
3140
3222
|
else options.limit = state?.limit;
|
|
3141
3223
|
options.tolerance = getTolerance(options.tolerance, state);
|
|
3142
3224
|
return options;
|
|
@@ -3201,18 +3283,18 @@ function getScore(haystack, needle) {
|
|
|
3201
3283
|
if (haystackIndex === 0) score += 1;
|
|
3202
3284
|
if (previousMatchIndex !== -1) {
|
|
3203
3285
|
const gap = haystackIndex - previousMatchIndex - 1;
|
|
3204
|
-
score +=
|
|
3286
|
+
score += max([0, FUZZY_PROXIMITY_THRESHOLD - gap]);
|
|
3205
3287
|
}
|
|
3206
3288
|
previousMatchIndex = haystackIndex;
|
|
3207
3289
|
needleIndex += 1;
|
|
3208
3290
|
}
|
|
3209
3291
|
if (needleIndex === needleLength) break;
|
|
3210
3292
|
}
|
|
3211
|
-
score -=
|
|
3212
|
-
return
|
|
3293
|
+
score -= floor(lowerCaseHaystack.length / FUZZY_LENGTH_DIVISOR);
|
|
3294
|
+
return max([0, score]);
|
|
3213
3295
|
}
|
|
3214
3296
|
function getTolerance(input, state) {
|
|
3215
|
-
if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 :
|
|
3297
|
+
if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : floor(input);
|
|
3216
3298
|
return state?.tolerance ?? FUZZY_PROXIMITY_THRESHOLD;
|
|
3217
3299
|
}
|
|
3218
3300
|
/**
|
|
@@ -3317,7 +3399,7 @@ function dedent(value, ...values) {
|
|
|
3317
3399
|
if (indentation != null) lengths.push(indentation.length);
|
|
3318
3400
|
}
|
|
3319
3401
|
if (lengths.length === 0) return actual.trim();
|
|
3320
|
-
const minimum =
|
|
3402
|
+
const minimum = min(lengths);
|
|
3321
3403
|
const pattern = new RegExp(`^\\s{0,${minimum}}`);
|
|
3322
3404
|
let result = "";
|
|
3323
3405
|
for (let index = 0; index < length; index += 1) {
|
|
@@ -3711,14 +3793,9 @@ function registerCloner(constructor, handler) {
|
|
|
3711
3793
|
}
|
|
3712
3794
|
function tryStructuredClone(value, parameters, depth) {
|
|
3713
3795
|
if (depth >= CLONE_MAX_DEPTH) return value;
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
return cloned;
|
|
3718
|
-
} catch {
|
|
3719
|
-
parameters.references.set(value, value);
|
|
3720
|
-
return value;
|
|
3721
|
-
}
|
|
3796
|
+
const cloned = unwrap(attempt(() => structuredClone(value)), value);
|
|
3797
|
+
parameters.references.set(value, cloned);
|
|
3798
|
+
return cloned;
|
|
3722
3799
|
}
|
|
3723
3800
|
const CLONE_COPY_OPTIONS = {
|
|
3724
3801
|
copyFunctions: true,
|
|
@@ -3841,8 +3918,8 @@ function getChanges(changes, first, second, options, prefix) {
|
|
|
3841
3918
|
function getDiffs(first, second, options, prefix) {
|
|
3842
3919
|
const changes = [];
|
|
3843
3920
|
if (Array.isArray(first) && Array.isArray(second)) {
|
|
3844
|
-
const maximumLength =
|
|
3845
|
-
const minimumLength =
|
|
3921
|
+
const maximumLength = max([first.length, second.length]);
|
|
3922
|
+
const minimumLength = min([first.length, second.length]);
|
|
3846
3923
|
for (let index = minimumLength; index < maximumLength; index += 1) {
|
|
3847
3924
|
const key = join([prefix, index], ".");
|
|
3848
3925
|
changes.push({
|
|
@@ -4868,24 +4945,6 @@ const colorSubscription = {
|
|
|
4868
4945
|
value: SUBSCRIPTION_NAME
|
|
4869
4946
|
};
|
|
4870
4947
|
//#endregion
|
|
4871
|
-
//#region src/internal/math/misc.ts
|
|
4872
|
-
/**
|
|
4873
|
-
* Round a number
|
|
4874
|
-
*
|
|
4875
|
-
* @param value Number to round
|
|
4876
|
-
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
4877
|
-
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
4878
|
-
*/
|
|
4879
|
-
function round(value, decimals) {
|
|
4880
|
-
return roundNumber(Math.round, value, decimals);
|
|
4881
|
-
}
|
|
4882
|
-
function roundNumber(callback, value, decimals) {
|
|
4883
|
-
if (typeof value !== "number") return NaN;
|
|
4884
|
-
if (typeof decimals !== "number" || decimals < 1) return callback(value);
|
|
4885
|
-
const mod = 10 ** decimals;
|
|
4886
|
-
return callback((value + Number.EPSILON) * mod) / mod;
|
|
4887
|
-
}
|
|
4888
|
-
//#endregion
|
|
4889
4948
|
//#region src/color/misc/alpha.ts
|
|
4890
4949
|
function getAlpha(value, hex) {
|
|
4891
4950
|
if (typeof value === "number") return getAlphaFromValue(value);
|
|
@@ -5211,12 +5270,12 @@ function convertRgbToHex(rgb, alpha) {
|
|
|
5211
5270
|
}
|
|
5212
5271
|
function convertRgbToHsla(value) {
|
|
5213
5272
|
const values = getRgbCalculationValues(isRgbLike(value) ? getRgbValues(value) : { ...COLOR_DEFAULTS.rgb });
|
|
5214
|
-
const { delta,
|
|
5215
|
-
const lightness = (
|
|
5273
|
+
const { delta, maximum, minimum } = values;
|
|
5274
|
+
const lightness = (minimum + maximum) / 2;
|
|
5216
5275
|
let hue = 0;
|
|
5217
5276
|
let saturation = 0;
|
|
5218
5277
|
if (delta !== 0) {
|
|
5219
|
-
saturation = (
|
|
5278
|
+
saturation = (maximum - lightness) / min([lightness, 1 - lightness]);
|
|
5220
5279
|
hue = getRgbHue(values);
|
|
5221
5280
|
hue *= 60;
|
|
5222
5281
|
}
|
|
@@ -5229,7 +5288,7 @@ function convertRgbToHsla(value) {
|
|
|
5229
5288
|
}
|
|
5230
5289
|
function convertRgbToHwba(value) {
|
|
5231
5290
|
const values = getRgbCalculationValues(isRgbLike(value) ? getRgbValues(value) : { ...COLOR_DEFAULTS.rgb });
|
|
5232
|
-
const { delta,
|
|
5291
|
+
const { delta, maximum, minimum } = values;
|
|
5233
5292
|
let hue = 0;
|
|
5234
5293
|
if (delta !== 0) {
|
|
5235
5294
|
hue = getRgbHue(values);
|
|
@@ -5237,8 +5296,8 @@ function convertRgbToHwba(value) {
|
|
|
5237
5296
|
}
|
|
5238
5297
|
return {
|
|
5239
5298
|
hue,
|
|
5240
|
-
whiteness:
|
|
5241
|
-
blackness: (1 -
|
|
5299
|
+
whiteness: minimum * COLOR_MAX.percent,
|
|
5300
|
+
blackness: (1 - maximum) * COLOR_MAX.percent,
|
|
5242
5301
|
alpha: getAlphaValue(value?.alpha ?? COLOR_MAX.percent)
|
|
5243
5302
|
};
|
|
5244
5303
|
}
|
|
@@ -5258,14 +5317,22 @@ function getRgbCalculationValues(rgb) {
|
|
|
5258
5317
|
const blue = rgb.blue / COLOR_MAX.hex;
|
|
5259
5318
|
const green = rgb.green / COLOR_MAX.hex;
|
|
5260
5319
|
const red = rgb.red / COLOR_MAX.hex;
|
|
5261
|
-
const
|
|
5262
|
-
|
|
5320
|
+
const maximum = max([
|
|
5321
|
+
blue,
|
|
5322
|
+
green,
|
|
5323
|
+
red
|
|
5324
|
+
]);
|
|
5325
|
+
const minimum = min([
|
|
5326
|
+
blue,
|
|
5327
|
+
green,
|
|
5328
|
+
red
|
|
5329
|
+
]);
|
|
5263
5330
|
return {
|
|
5264
5331
|
blue,
|
|
5265
|
-
delta:
|
|
5332
|
+
delta: maximum - minimum,
|
|
5266
5333
|
green,
|
|
5267
|
-
|
|
5268
|
-
|
|
5334
|
+
maximum,
|
|
5335
|
+
minimum,
|
|
5269
5336
|
red
|
|
5270
5337
|
};
|
|
5271
5338
|
}
|
|
@@ -5276,8 +5343,8 @@ function getRgbaColor$1() {
|
|
|
5276
5343
|
return getStateValue(this, COLOR_TYPE.rgb, true);
|
|
5277
5344
|
}
|
|
5278
5345
|
function getRgbHue(values) {
|
|
5279
|
-
const { blue, delta, green,
|
|
5280
|
-
switch (
|
|
5346
|
+
const { blue, delta, green, maximum, red } = values;
|
|
5347
|
+
switch (maximum) {
|
|
5281
5348
|
case blue: return (red - green) / delta + 4;
|
|
5282
5349
|
case green: return (blue - red) / delta + 2;
|
|
5283
5350
|
default: return (green - blue) / delta + (green < blue ? 6 : 0);
|
|
@@ -5526,7 +5593,7 @@ function convertHslToHwba(input) {
|
|
|
5526
5593
|
let { hue, lightness, saturation } = isHslLike(input) ? getHslValues(input) : { ...COLOR_DEFAULTS.hsl };
|
|
5527
5594
|
lightness /= COLOR_MAX.percent;
|
|
5528
5595
|
saturation /= COLOR_MAX.percent;
|
|
5529
|
-
const value = lightness + saturation *
|
|
5596
|
+
const value = lightness + saturation * min([lightness, 1 - lightness]);
|
|
5530
5597
|
if (value === 0) saturation = 0;
|
|
5531
5598
|
else saturation = 2 * (1 - lightness / value);
|
|
5532
5599
|
const blackness = 1 - value;
|
|
@@ -5563,7 +5630,11 @@ function getColorFromHsl(state, type) {
|
|
|
5563
5630
|
}
|
|
5564
5631
|
function getHexyValue(hue, lightness, saturation, value) {
|
|
5565
5632
|
const part = (value + hue / 30) % 12;
|
|
5566
|
-
return (lightness - saturation *
|
|
5633
|
+
return (lightness - saturation * min([lightness, 1 - lightness]) * max([-1, min([
|
|
5634
|
+
part - 3,
|
|
5635
|
+
9 - part,
|
|
5636
|
+
1
|
|
5637
|
+
])])) * COLOR_MAX.hex;
|
|
5567
5638
|
}
|
|
5568
5639
|
function getHslValue() {
|
|
5569
5640
|
return getStateValue(this, COLOR_TYPE.hsl, false);
|
|
@@ -5696,7 +5767,7 @@ function getColorFromHwb(state, type) {
|
|
|
5696
5767
|
function getHwbSaturation(blackness, whiteness, lightness) {
|
|
5697
5768
|
const hue = 1 - blackness - whiteness;
|
|
5698
5769
|
if (hue <= 0) return 0;
|
|
5699
|
-
return hue /
|
|
5770
|
+
return hue / min([2 * lightness, 2 - 2 * lightness]);
|
|
5700
5771
|
}
|
|
5701
5772
|
function getHwbValue() {
|
|
5702
5773
|
return getStateValue(this, COLOR_TYPE.hwb, false);
|
|
@@ -6235,16 +6306,6 @@ function count(array, key, value) {
|
|
|
6235
6306
|
}
|
|
6236
6307
|
return counted;
|
|
6237
6308
|
}
|
|
6238
|
-
/**
|
|
6239
|
-
* Round a number down
|
|
6240
|
-
*
|
|
6241
|
-
* @param value Number to round down
|
|
6242
|
-
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
6243
|
-
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
6244
|
-
*/
|
|
6245
|
-
function floor(value, decimals) {
|
|
6246
|
-
return roundNumber(Math.floor, value, decimals);
|
|
6247
|
-
}
|
|
6248
6309
|
function median(array, key) {
|
|
6249
6310
|
let length = Array.isArray(array) ? array.length : 0;
|
|
6250
6311
|
if (!Array.isArray(array) || length === 0) return NaN;
|
|
@@ -6259,10 +6320,7 @@ function median(array, key) {
|
|
|
6259
6320
|
const second = length / 2;
|
|
6260
6321
|
return (numbers[first] + numbers[second]) / 2;
|
|
6261
6322
|
}
|
|
6262
|
-
return numbers[
|
|
6263
|
-
}
|
|
6264
|
-
function min(array, key, first) {
|
|
6265
|
-
return getAggregated("min", array, key, first);
|
|
6323
|
+
return numbers[floor(length / 2)];
|
|
6266
6324
|
}
|
|
6267
6325
|
function sum(array, key) {
|
|
6268
6326
|
return getAggregated("sum", array, key);
|
|
@@ -6496,7 +6554,7 @@ function addToQueue(parameters, signal) {
|
|
|
6496
6554
|
reject: rejector,
|
|
6497
6555
|
resolve: resolver
|
|
6498
6556
|
});
|
|
6499
|
-
if (state.options.autostart) run(state);
|
|
6557
|
+
if (state.options.autostart) run$1(state);
|
|
6500
6558
|
return {
|
|
6501
6559
|
id,
|
|
6502
6560
|
promise
|
|
@@ -6683,27 +6741,30 @@ function resumeQueue() {
|
|
|
6683
6741
|
for (let index = 0; index < length; index += 1) handled[index]();
|
|
6684
6742
|
}
|
|
6685
6743
|
state.paused = false;
|
|
6686
|
-
const length =
|
|
6687
|
-
for (let index = 0; index < length; index += 1) run(state);
|
|
6744
|
+
const length = min([state.options.concurrency, state.items.length]);
|
|
6745
|
+
for (let index = 0; index < length; index += 1) run$1(state);
|
|
6688
6746
|
}
|
|
6689
6747
|
function resumeQueues(key) {
|
|
6690
6748
|
handleQueues(this, QUEUE_HANDLE_RESUME, key);
|
|
6691
6749
|
}
|
|
6692
|
-
async function run(state) {
|
|
6750
|
+
async function run$1(state) {
|
|
6693
6751
|
if (state.paused || state.runners >= state.options.concurrency) return;
|
|
6694
6752
|
state.runners += 1;
|
|
6695
6753
|
let item = state.items.shift();
|
|
6696
6754
|
while (item != null) {
|
|
6697
6755
|
let error = false;
|
|
6698
6756
|
let result;
|
|
6699
|
-
|
|
6700
|
-
if (!(item.aborter?.signal?.aborted ?? false)) {
|
|
6757
|
+
const attempted = await asyncAttempt(async () => {
|
|
6758
|
+
if (item != null && !(item.aborter?.signal?.aborted ?? false)) {
|
|
6701
6759
|
const parameters = item.key == null ? item.parameters : [item.key, ...item.parameters];
|
|
6702
|
-
|
|
6760
|
+
return await state.callback(...parameters);
|
|
6703
6761
|
}
|
|
6704
|
-
|
|
6762
|
+
throw new Error();
|
|
6763
|
+
});
|
|
6764
|
+
if (attempted.ok) result = attempted.value;
|
|
6765
|
+
else {
|
|
6705
6766
|
error = true;
|
|
6706
|
-
result =
|
|
6767
|
+
result = attempted.error;
|
|
6707
6768
|
}
|
|
6708
6769
|
if (state.paused) {
|
|
6709
6770
|
const paused = item;
|
|
@@ -6847,4 +6908,4 @@ var SizedSet = class extends Set {
|
|
|
6847
6908
|
}
|
|
6848
6909
|
};
|
|
6849
6910
|
//#endregion
|
|
6850
|
-
export { CancelablePromise, Logger, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, push as append, push, 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, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, filterAndMap, filterAndMap as select, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeCloner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isAsyncOnce, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isFuzzy, isHerald, isHeraldEvents, isHeraldSubscription, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isInstanceOf, isKey, isKeyedQueue, isLogger, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTemplateStringsArray, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isObservable, isOk, isOnce, isPlainObject, isPrimitive, isQueue, isQueueInstance, isRejected, isResult, isRgbColor, isRgbaColor, isSorted, isSubscription, isSubscriptions, isTemplateStringsArray, isTimeLogger, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, mapAndFilter, mapAndFilter as reverseSelect, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, subscriptions, 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 };
|
|
6911
|
+
export { CancelablePromise, Logger, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, push as append, push, 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, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, filterAndMap, filterAndMap as select, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeCloner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isAsyncOnce, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isFuzzy, isGenerator, isHerald, isHeraldEvents, isHeraldSubscription, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isInstanceOf, isKey, isKeyedQueue, isLogger, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTemplateStringsArray, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isObservable, isOk, isOnce, isPlainObject, isPlan, isPrimitive, isQueue, isQueueInstance, isRejected, isResult, isRgbColor, isRgbaColor, isSorted, isSubscription, isSubscriptions, isTemplateStringsArray, isTimeLogger, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, mapAndFilter, mapAndFilter as reverseSelect, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, plan, promises, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, run, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, subscriptions, 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 };
|