@oscarpalmer/atoms 0.204.1 → 0.206.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.
Files changed (102) hide show
  1. package/dist/array/filter.d.mts +1 -1
  2. package/dist/array/find.d.mts +3 -3
  3. package/dist/array/first.d.mts +3 -4
  4. package/dist/array/first.mjs +1 -1
  5. package/dist/array/group-by.d.mts +3 -3
  6. package/dist/array/index.d.mts +2 -5
  7. package/dist/array/index.mjs +2 -5
  8. package/dist/array/last.d.mts +3 -4
  9. package/dist/array/last.mjs +1 -1
  10. package/dist/array/move.d.mts +4 -4
  11. package/dist/array/push.d.mts +2 -1
  12. package/dist/array/push.mjs +1 -1
  13. package/dist/array/reverse.mjs +2 -1
  14. package/dist/array/select.d.mts +95 -84
  15. package/dist/array/select.mjs +6 -6
  16. package/dist/array/single.d.mts +3 -3
  17. package/dist/array/sort.d.mts +6 -6
  18. package/dist/array/sort.mjs +3 -2
  19. package/dist/array/swap.d.mts +3 -3
  20. package/dist/array/swap.mjs +1 -1
  21. package/dist/array/to-map.d.mts +3 -3
  22. package/dist/array/to-record.d.mts +3 -3
  23. package/dist/beacon.mjs +2 -2
  24. package/dist/color/constants.d.mts +14 -41
  25. package/dist/color/instance.d.mts +0 -1
  26. package/dist/color/misc/alpha.mjs +1 -1
  27. package/dist/color/misc/get.mjs +1 -1
  28. package/dist/color/misc/state.d.mts +2 -29
  29. package/dist/color/models.d.mts +18 -4
  30. package/dist/color/space/hsl.mjs +7 -2
  31. package/dist/color/space/hwb.mjs +2 -1
  32. package/dist/color/space/rgb.mjs +22 -13
  33. package/dist/function/limit.d.mts +4 -4
  34. package/dist/function/once.d.mts +6 -8
  35. package/dist/function/retry.d.mts +2 -2
  36. package/dist/function/retry.mjs +12 -14
  37. package/dist/index.d.mts +1104 -1127
  38. package/dist/index.mjs +385 -383
  39. package/dist/internal/array/compact.d.mts +1 -1
  40. package/dist/internal/array/find.d.mts +4 -4
  41. package/dist/internal/array/index-of.d.mts +3 -3
  42. package/dist/internal/array/insert.d.mts +1 -1
  43. package/dist/internal/array/insert.mjs +2 -1
  44. package/dist/internal/array/match.d.mts +1 -1
  45. package/dist/internal/array/sets.d.mts +1 -1
  46. package/dist/internal/function/assert.d.mts +7 -7
  47. package/dist/internal/function/limit.d.mts +1 -1
  48. package/dist/internal/function/limit.mjs +9 -9
  49. package/dist/internal/function/work.d.mts +4 -4
  50. package/dist/internal/herald.d.mts +1 -1
  51. package/dist/internal/math/aggregate.d.mts +43 -2
  52. package/dist/internal/math/aggregate.mjs +4 -1
  53. package/dist/internal/math/misc.d.mts +8 -0
  54. package/dist/internal/math/misc.mjs +11 -1
  55. package/dist/internal/random.mjs +2 -1
  56. package/dist/internal/result/attempt.d.mts +59 -0
  57. package/dist/internal/result/attempt.mjs +24 -0
  58. package/dist/internal/result/misc.d.mts +6 -6
  59. package/dist/internal/sized/map.d.mts +2 -2
  60. package/dist/internal/string/misc.mjs +4 -5
  61. package/dist/internal/value/compare.d.mts +7 -19
  62. package/dist/internal/value/equal.d.mts +8 -31
  63. package/dist/internal/value/equal.mjs +2 -1
  64. package/dist/internal/value/handlers.d.mts +2 -5
  65. package/dist/internal/value/has.d.mts +3 -3
  66. package/dist/internal/value/misc.mjs +1 -1
  67. package/dist/is.d.mts +4 -4
  68. package/dist/math.d.mts +3 -52
  69. package/dist/math.mjs +3 -16
  70. package/dist/promise/constants.d.mts +0 -1
  71. package/dist/promise/constants.mjs +1 -2
  72. package/dist/promise/helpers.d.mts +2 -2
  73. package/dist/promise/helpers.mjs +1 -1
  74. package/dist/promise/index.d.mts +7 -7
  75. package/dist/promise/index.mjs +9 -9
  76. package/dist/promise/misc.mjs +1 -1
  77. package/dist/promise/models.d.mts +1 -1
  78. package/dist/promise/timed.d.mts +1 -1
  79. package/dist/queue.d.mts +1 -1
  80. package/dist/queue.mjs +11 -6
  81. package/dist/result/index.d.mts +2 -59
  82. package/dist/result/index.mjs +1 -21
  83. package/dist/result/match.d.mts +3 -3
  84. package/dist/result/work/flow.d.mts +1 -1
  85. package/dist/result/work/flow.mjs +2 -1
  86. package/dist/result/work/pipe.d.mts +1 -1
  87. package/dist/result/work/pipe.mjs +2 -1
  88. package/dist/sized/set.d.mts +1 -1
  89. package/dist/string/fuzzy.d.mts +4 -4
  90. package/dist/string/fuzzy.mjs +7 -5
  91. package/dist/string/index.mjs +2 -1
  92. package/dist/string/normalize.d.mts +1 -1
  93. package/dist/string/template.d.mts +1 -2
  94. package/dist/value/clone.d.mts +8 -20
  95. package/dist/value/clone.mjs +5 -8
  96. package/dist/value/diff.d.mts +1 -1
  97. package/dist/value/diff.mjs +3 -2
  98. package/dist/value/freeze.d.mts +4 -4
  99. package/dist/value/merge.d.mts +5 -5
  100. package/dist/value/transform.d.mts +1 -1
  101. package/package.json +25 -10
  102. package/plugin/index.js +1 -1
package/dist/index.mjs CHANGED
@@ -115,6 +115,15 @@ function filter(array, ...parameters) {
115
115
  }
116
116
  filter.remove = exclude;
117
117
  //#endregion
118
+ //#region src/array/find.ts
119
+ function find(array, ...parameters) {
120
+ return findValue(FIND_VALUE_ITEM, array, parameters, false);
121
+ }
122
+ function findLast(array, ...parameters) {
123
+ return findValue(FIND_VALUE_ITEM, array, parameters, true);
124
+ }
125
+ find.last = findLast;
126
+ //#endregion
118
127
  //#region src/array/first.ts
119
128
  function first(array, ...parameters) {
120
129
  return findAbsoluteValueOrDefault(array, parameters, void 0, false, false);
@@ -122,7 +131,7 @@ function first(array, ...parameters) {
122
131
  function firstOrDefault(array, defaultValue, ...parameters) {
123
132
  return findAbsoluteValueOrDefault(array, parameters, defaultValue, true, false);
124
133
  }
125
- first.default = firstOrDefault;
134
+ first.defaulted = firstOrDefault;
126
135
  //#endregion
127
136
  //#region src/internal/array/group.ts
128
137
  function groupValues(array, key, value, arrays) {
@@ -397,15 +406,6 @@ function getArray(value, indiced) {
397
406
  return array;
398
407
  }
399
408
  //#endregion
400
- //#region src/internal/array/index-of.ts
401
- function indexOf(array, ...parameters) {
402
- return findValue(FIND_VALUE_INDEX, array, parameters, false);
403
- }
404
- function lastIndexOf(array, ...parameters) {
405
- return findValue(FIND_VALUE_INDEX, array, parameters, true);
406
- }
407
- indexOf.last = lastIndexOf;
408
- //#endregion
409
409
  //#region src/internal/array/match.ts
410
410
  function endsWithArray(haystack, needle, key) {
411
411
  return endings.has(getPosition(haystack, needle, key)[1]);
@@ -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 Math.floor(getRandomFloatingNumberValue(true, minimum, maximum));
519
+ return floor(getRandomFloatingNumberValue(true, minimum, maximum));
492
520
  }
493
521
  //#endregion
494
522
  //#region src/internal/array/shuffle.ts
@@ -551,15 +579,6 @@ function exists(array, ...parameters) {
551
579
  return findValue(FIND_VALUE_INDEX, array, parameters, false) > -1;
552
580
  }
553
581
  //#endregion
554
- //#region src/array/find.ts
555
- function find(array, ...parameters) {
556
- return findValue(FIND_VALUE_ITEM, array, parameters, false);
557
- }
558
- function findLast(array, ...parameters) {
559
- return findValue(FIND_VALUE_ITEM, array, parameters, true);
560
- }
561
- find.last = findLast;
562
- //#endregion
563
582
  //#region src/array/flatten.ts
564
583
  /**
565
584
  * Flatten an array _(using native `flat` and maximum depth)_
@@ -595,10 +614,81 @@ function times(length, value) {
595
614
  return values;
596
615
  }
597
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
598
688
  //#region src/internal/array/insert.ts
599
689
  function insertChunkedValues(type, array, items, start, deleteCount) {
600
690
  const actualDeleteCount = deleteCount < 0 ? 0 : deleteCount;
601
- const actualStart = Math.min(Math.max(0, start), array.length);
691
+ const actualStart = min([max([0, start]), array.length]);
602
692
  const chunked = chunk(items);
603
693
  const lastIndex = chunked.length - 1;
604
694
  let index = chunked.length;
@@ -667,7 +757,7 @@ function reverse(array) {
667
757
  if (!Array.isArray(array)) return [];
668
758
  const { length } = array;
669
759
  if (length < 2) return array;
670
- const half = Math.floor(length / 2);
760
+ const half = floor(length / 2);
671
761
  for (let firstIndex = 0; firstIndex < half; firstIndex += 1) {
672
762
  const temporaryItem = array[firstIndex];
673
763
  const secondIndex = length - 1 - firstIndex;
@@ -677,24 +767,6 @@ function reverse(array) {
677
767
  return array;
678
768
  }
679
769
  //#endregion
680
- //#region src/array/select.ts
681
- function reverseSelect(array, ...parameters) {
682
- return findValues("all", array, parameters, {
683
- callback: parameters.shift(),
684
- reverse: true
685
- }).matched;
686
- }
687
- function select(array, ...parameters) {
688
- return selectValues(array, parameters);
689
- }
690
- function selectValues(array, parameters) {
691
- return findValues("all", array, parameters, {
692
- callback: parameters.pop(),
693
- reverse: false
694
- }).matched;
695
- }
696
- select.reverse = reverseSelect;
697
- //#endregion
698
770
  //#region src/array/single.ts
699
771
  function single(array, ...parameters) {
700
772
  const { matched } = findValues("all", array, parameters);
@@ -821,7 +893,7 @@ function last(array, ...parameters) {
821
893
  function lastOrDefault(array, defaultValue, ...parameters) {
822
894
  return findAbsoluteValueOrDefault(array, parameters, defaultValue, true, true);
823
895
  }
824
- last.default = lastOrDefault;
896
+ last.defaulted = lastOrDefault;
825
897
  //#endregion
826
898
  //#region src/internal/array/overlap.ts
827
899
  function arraysOverlap(first, second) {
@@ -916,73 +988,110 @@ function moveToIndex(array, value, index, key) {
916
988
  move.indices = moveIndices;
917
989
  move.toIndex = moveToIndex;
918
990
  //#endregion
919
- //#region src/internal/math/aggregate.ts
920
- function aggregate(type, array, key, first) {
921
- const length = Array.isArray(array) ? array.length : 0;
922
- const aggregation = {
923
- array: false,
924
- count: 0,
925
- first: first === true,
926
- value: NaN
991
+ //#region src/array/select.ts
992
+ function filterAndMap(array, ...parameters) {
993
+ return selectValues(array, parameters);
994
+ }
995
+ function mapAndFilter(array, ...parameters) {
996
+ return findValues("all", array, parameters, {
997
+ callback: parameters.shift(),
998
+ reverse: true
999
+ }).matched;
1000
+ }
1001
+ function selectValues(array, parameters) {
1002
+ return findValues("all", array, parameters, {
1003
+ callback: parameters.pop(),
1004
+ reverse: false
1005
+ }).matched;
1006
+ }
1007
+ filterAndMap.reverse = mapAndFilter;
1008
+ //#endregion
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
927
1017
  };
928
- if (length === 0) return aggregation;
929
- const aggregator = aggregators[type];
930
- const callback = getAggregateCallback(key);
931
- aggregation.array = callback != null && (type === "max" || type === "min");
932
- let notNumber = true;
933
- for (let index = 0; index < length; index += 1) {
934
- const item = array[index];
935
- const value = callback == null ? item : callback(item, index, array);
936
- if (isNonNumber(value)) continue;
937
- aggregation.value = aggregator(aggregation, value, notNumber, item);
938
- aggregation.count += 1;
939
- notNumber = false;
940
- }
941
- return aggregation;
1018
+ if (original instanceof Error) errorResult.original = original;
1019
+ return errorResult;
942
1020
  }
943
- function calculateSum(aggregation, value, notNumber) {
944
- return notNumber ? value : aggregation.value + value;
1021
+ function isError(value, extended) {
1022
+ return isResultValue(value, false) && (extended === true ? value.original instanceof Error : true);
945
1023
  }
946
- function getAbsoluteValue(condition, aggregation, value, notNumber, item) {
947
- if (notNumber || condition(aggregation, value)) {
948
- if (aggregation.array) {
949
- aggregation.items ??= {};
950
- aggregation.items[value] ??= [];
951
- aggregation.items[value].push(item);
952
- }
953
- return value;
954
- }
955
- return aggregation.value;
1024
+ function isOk(value) {
1025
+ return isResultValue(value, true);
956
1026
  }
957
- function getAggregateCallback(key) {
958
- if (key == null) return;
959
- return typeof key === "function" ? key : (item) => item[key];
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);
960
1035
  }
961
- function getAggregated(type, array, key, first) {
962
- const aggregation = aggregate(type, array, key, first);
963
- if (aggregation.count === 0) return aggregation.array ? aggregation.first ? void 0 : [] : NaN;
964
- if (aggregation.array) {
965
- const array = aggregation.items[aggregation.value];
966
- return aggregation.first ? array[0] : array;
967
- }
968
- return aggregation.value;
1036
+ function isResultValue(value, okValue) {
1037
+ return isPlainObject(value) && value.ok === okValue && (okValue ? RESULT_PROPERTY_VALUE : RESULT_PROPERTY_ERROR) in value;
969
1038
  }
970
- function isMaxValue(aggregation, value) {
971
- return aggregation.array ? value >= aggregation.value : value > aggregation.value;
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
+ };
972
1050
  }
973
- function isMinValue(aggregation, value) {
974
- return aggregation.array ? value <= aggregation.value : value < aggregation.value;
1051
+ function unwrap(value, defaultValue) {
1052
+ return isOk(value) ? value.value : defaultValue;
975
1053
  }
976
- function max(array, key, first) {
977
- return getAggregated("max", array, key, first);
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);
978
1072
  }
979
- const AGGREGATION_AVERAGE = "average";
980
- const aggregators = {
981
- average: calculateSum,
982
- max: getAbsoluteValue.bind(void 0, isMaxValue),
983
- min: getAbsoluteValue.bind(void 0, isMinValue),
984
- sum: calculateSum
985
- };
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;
986
1095
  //#endregion
987
1096
  //#region src/internal/string/misc.ts
988
1097
  /**
@@ -1043,11 +1152,7 @@ function join(array, delimiter) {
1043
1152
  return values.join(typeof delimiter === "string" ? delimiter : "");
1044
1153
  }
1045
1154
  function tryCallback(value, callback) {
1046
- try {
1047
- return callback(value);
1048
- } catch {
1049
- return value;
1050
- }
1155
+ return unwrap(attempt(() => callback(value)), value);
1051
1156
  }
1052
1157
  function tryDecode(value) {
1053
1158
  return tryCallback(value, decodeURIComponent);
@@ -1253,7 +1358,7 @@ function getSortedArrayIndex(array, item) {
1253
1358
  let low = 0;
1254
1359
  let high = length - 1;
1255
1360
  while (low <= high) {
1256
- const mid = Math.floor((low + high) / 2);
1361
+ const mid = floor((low + high) / 2);
1257
1362
  if (getComparisonValue(item, array[mid], sorters, sortersLength) < 0) high = mid - 1;
1258
1363
  else low = mid + 1;
1259
1364
  }
@@ -1308,7 +1413,7 @@ function isSortedArray(array) {
1308
1413
  const sortersLength = sorters.length;
1309
1414
  let offset = 0;
1310
1415
  if (length >= SORT_THRESHOLD) {
1311
- offset = Math.round(length / SORT_PEEK_PERCENTAGE);
1416
+ offset = round(length / SORT_PEEK_PERCENTAGE);
1312
1417
  offset = offset > SORT_THRESHOLD ? SORT_THRESHOLD : offset;
1313
1418
  for (let index = 0; index < offset; index += 1) {
1314
1419
  const [firstItem, firstOffset] = [array[index], array[index + 1]];
@@ -1347,6 +1452,15 @@ sort.getIndex = getSortedIndex;
1347
1452
  sort.initialize = initializeSorter;
1348
1453
  sort.is = isSorted;
1349
1454
  //#endregion
1455
+ //#region src/internal/array/index-of.ts
1456
+ function indexOf(array, ...parameters) {
1457
+ return findValue(FIND_VALUE_INDEX, array, parameters, false);
1458
+ }
1459
+ function lastIndexOf(array, ...parameters) {
1460
+ return findValue(FIND_VALUE_INDEX, array, parameters, true);
1461
+ }
1462
+ indexOf.last = lastIndexOf;
1463
+ //#endregion
1350
1464
  //#region src/array/swap.ts
1351
1465
  function swap(array, first, second, third) {
1352
1466
  if (!Array.isArray(array)) return [];
@@ -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
- try {
1509
- let result = state.callback(...item.parameters);
1510
- if (result instanceof Promise) result = await result;
1511
- item.resolve(result);
1512
- } catch (error) {
1513
- item.reject(error);
1514
- } finally {
1515
- item.running = false;
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) {
@@ -1577,91 +1690,41 @@ function asyncDebounce(callback, time) {
1577
1690
  * Throttle a function, ensuring it is only called once every `time` milliseconds
1578
1691
  *
1579
1692
  * - When called, successful _(finished)_ results will resolve and errors will reject
1580
- * - On subsequent calls, existing calls will be canceled _(rejected)_ and will wait until the next valid time to call the callback again _(and so on...)_
1581
- *
1582
- * _Available as `asyncThrottle` and `throttle.async`_
1583
- *
1584
- * @param callback Callback to throttle
1585
- * @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_
1586
- * @returns Throttled callback handler with a `cancel` method
1587
- */
1588
- function asyncThrottle(callback, time) {
1589
- return getAsyncLimiter(LIMITER_THROTTLE, callback, time);
1590
- }
1591
- /**
1592
- * Debounce a function, ensuring it is only called after `time` milliseconds have passed
1593
- *
1594
- * On subsequent calls, the timer is reset and will wait another `time` milliseconds _(and so on...)_
1595
- *
1596
- * @param callback Callback to debounce
1597
- * @param time Time in milliseconds to wait before calling the callback _(defaults to `0`; e.g., as soon as possible)_
1598
- * @returns Debounced callback handler with a `cancel` method
1599
- */
1600
- function debounce(callback, time) {
1601
- return getLimiter(LIMITER_DEBOUNCE, callback, time);
1602
- }
1603
- /**
1604
- * Throttle a function, ensuring it is only called once every `time` milliseconds
1605
- *
1606
- * @param callback Callback to throttle
1607
- * @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_
1608
- * @returns Throttled callback handler with a `cancel` method
1609
- */
1610
- function throttle(callback, time) {
1611
- return getLimiter(LIMITER_THROTTLE, callback, time);
1612
- }
1613
- debounce.async = asyncDebounce;
1614
- throttle.async = asyncThrottle;
1615
- //#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);
1693
+ * - On subsequent calls, existing calls will be canceled _(rejected)_ and will wait until the next valid time to call the callback again _(and so on...)_
1694
+ *
1695
+ * _Available as `asyncThrottle` and `throttle.async`_
1696
+ *
1697
+ * @param callback Callback to throttle
1698
+ * @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_
1699
+ * @returns Throttled callback handler with a `cancel` method
1700
+ */
1701
+ function asyncThrottle(callback, time) {
1702
+ return getAsyncLimiter(LIMITER_THROTTLE, callback, time);
1633
1703
  }
1634
1704
  /**
1635
- * Is the value a _Result_?
1705
+ * Debounce a function, ensuring it is only called after `time` milliseconds have passed
1636
1706
  *
1637
- * @param value Value to check
1638
- * @returns `true` if the value is a _Result_, otherwise `false`
1707
+ * On subsequent calls, the timer is reset and will wait another `time` milliseconds _(and so on...)_
1708
+ *
1709
+ * @param callback Callback to debounce
1710
+ * @param time Time in milliseconds to wait before calling the callback _(defaults to `0`; e.g., as soon as possible)_
1711
+ * @returns Debounced callback handler with a `cancel` method
1639
1712
  */
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;
1713
+ function debounce(callback, time) {
1714
+ return getLimiter(LIMITER_DEBOUNCE, callback, time);
1645
1715
  }
1646
1716
  /**
1647
- * Creates an ok result
1717
+ * Throttle a function, ensuring it is only called once every `time` milliseconds
1648
1718
  *
1649
- * @param value Value
1650
- * @returns Ok result
1719
+ * @param callback Callback to throttle
1720
+ * @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_
1721
+ * @returns Throttled callback handler with a `cancel` method
1651
1722
  */
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;
1723
+ function throttle(callback, time) {
1724
+ return getLimiter(LIMITER_THROTTLE, callback, time);
1660
1725
  }
1661
- const RESULT_PROPERTY_ERROR = "error";
1662
- const RESULT_PROPERTY_VALUE = "value";
1663
- error.is = isError;
1664
- ok.is = isOk;
1726
+ debounce.async = asyncDebounce;
1727
+ throttle.async = asyncThrottle;
1665
1728
  //#endregion
1666
1729
  //#region src/internal/value/misc.ts
1667
1730
  function findKey(needle, 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
- try {
2009
- const result = await callback();
2010
- resolver(result);
2011
- } catch (error) {
2012
- if (attempts >= times || !when(error)) rejector(new RetryError(RETRY_MESSAGE_FAILED, error));
2013
- else {
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) try {
2050
- return callback();
2051
- } catch (error) {
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
  }
@@ -2064,66 +2124,6 @@ const RETRY_MESSAGE_EXPECTATION = "Retry expected a function";
2064
2124
  const RETRY_MESSAGE_FAILED = "Retry failed";
2065
2125
  retry.async = asyncRetry;
2066
2126
  //#endregion
2067
- //#region src/internal/function/work.ts
2068
- function asyncFlow(...fns) {
2069
- assertFlowFunctions(fns);
2070
- return (...args) => asyncWork(args.map((value) => {
2071
- if (isError(value)) throw value.error;
2072
- return isOk(value) ? value.value : value;
2073
- }), fns, true);
2074
- }
2075
- function flow(...fns) {
2076
- assertFlowFunctions(fns);
2077
- return (...args) => work(args.map((value) => {
2078
- if (isError(value)) throw value.error;
2079
- return isOk(value) ? value.value : value;
2080
- }), fns, true);
2081
- }
2082
- async function asyncPipe(value, ...pipes) {
2083
- assertPipeFunctions(pipes);
2084
- return asyncWork(value, pipes, false);
2085
- }
2086
- function pipe(value, ...pipes) {
2087
- assertPipeFunctions(pipes);
2088
- return work(value, pipes, false);
2089
- }
2090
- async function asyncWork(initial, functions, flow) {
2091
- const { length } = functions;
2092
- let transformed = unwrapValue(initial);
2093
- for (let index = 0; index < length; index += 1) {
2094
- const fn = functions[index];
2095
- transformed = unwrapValue(flow && index === 0 && Array.isArray(initial) ? await fn(...initial) : await fn(transformed));
2096
- }
2097
- return transformed;
2098
- }
2099
- function unwrapValue(value, flow, nested) {
2100
- if (typeof value === "function") {
2101
- if (nested != null) throw new TypeError(WORK_MESSAGE_NESTING);
2102
- return unwrapValue(value(), flow, true);
2103
- }
2104
- if (flow != null && value instanceof Promise) throw new TypeError(flow ? WORK_MESSAGE_FLOW_PROMISE : WORK_MESSAGE_PIPE_PROMISE);
2105
- if (isError(value)) throw value.error;
2106
- return isOk(value) ? value.value : value;
2107
- }
2108
- function work(initial, functions, flow) {
2109
- const { length } = functions;
2110
- let transformed = unwrapValue(initial, flow);
2111
- for (let index = 0; index < length; index += 1) {
2112
- const fn = functions[index];
2113
- transformed = unwrapValue(flow && index === 0 && Array.isArray(initial) ? fn(...initial) : fn(transformed), flow);
2114
- }
2115
- return transformed;
2116
- }
2117
- const WORK_MESSAGE_FLOW_ARRAY = "Flow expected to receive an array of functions";
2118
- const WORK_MESSAGE_FLOW_PROMISE = "Synchronous Flow received a promise. Use `flow.async` instead.";
2119
- const WORK_MESSAGE_NESTING = "Return values are too deeply nested.";
2120
- const WORK_MESSAGE_PIPE_ARRAY = "Pipe expected to receive an array of functions";
2121
- const WORK_MESSAGE_PIPE_PROMISE = "Synchronous Pipe received a promise. Use `pipe.async` instead.";
2122
- const assertFlowFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), WORK_MESSAGE_FLOW_ARRAY, TypeError);
2123
- const assertPipeFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), WORK_MESSAGE_PIPE_ARRAY, TypeError);
2124
- flow.async = asyncFlow;
2125
- pipe.async = asyncPipe;
2126
- //#endregion
2127
2127
  //#region src/internal/number.ts
2128
2128
  /**
2129
2129
  * Is the number between a minimum and maximum value?
@@ -2336,6 +2336,66 @@ const MEMOIZED_CALLBACK = "Memoized requires a callback function";
2336
2336
  const MEMOIZED_KEY_SEPARATOR = "_";
2337
2337
  const MEMOIZED_SYMBOL = Symbol("memoized");
2338
2338
  //#endregion
2339
+ //#region src/internal/function/work.ts
2340
+ function asyncFlow(...fns) {
2341
+ assertFlowFunctions(fns);
2342
+ return (...args) => asyncWork(args.map((value) => {
2343
+ if (isError(value)) throw value.error;
2344
+ return isOk(value) ? value.value : value;
2345
+ }), fns, true);
2346
+ }
2347
+ function flow(...fns) {
2348
+ assertFlowFunctions(fns);
2349
+ return (...args) => work(args.map((value) => {
2350
+ if (isError(value)) throw value.error;
2351
+ return isOk(value) ? value.value : value;
2352
+ }), fns, true);
2353
+ }
2354
+ async function asyncPipe(value, ...pipes) {
2355
+ assertPipeFunctions(pipes);
2356
+ return asyncWork(value, pipes, false);
2357
+ }
2358
+ function pipe(value, ...pipes) {
2359
+ assertPipeFunctions(pipes);
2360
+ return work(value, pipes, false);
2361
+ }
2362
+ async function asyncWork(initial, functions, flow) {
2363
+ const { length } = functions;
2364
+ let transformed = unwrapValue(initial);
2365
+ for (let index = 0; index < length; index += 1) {
2366
+ const fn = functions[index];
2367
+ transformed = unwrapValue(flow && index === 0 && Array.isArray(initial) ? await fn(...initial) : await fn(transformed));
2368
+ }
2369
+ return transformed;
2370
+ }
2371
+ function unwrapValue(value, flow, nested) {
2372
+ if (typeof value === "function") {
2373
+ if (nested != null) throw new TypeError(WORK_MESSAGE_NESTING);
2374
+ return unwrapValue(value(), flow, true);
2375
+ }
2376
+ if (flow != null && value instanceof Promise) throw new TypeError(flow ? WORK_MESSAGE_FLOW_PROMISE : WORK_MESSAGE_PIPE_PROMISE);
2377
+ if (isError(value)) throw value.error;
2378
+ return isOk(value) ? value.value : value;
2379
+ }
2380
+ function work(initial, functions, flow) {
2381
+ const { length } = functions;
2382
+ let transformed = unwrapValue(initial, flow);
2383
+ for (let index = 0; index < length; index += 1) {
2384
+ const fn = functions[index];
2385
+ transformed = unwrapValue(flow && index === 0 && Array.isArray(initial) ? fn(...initial) : fn(transformed), flow);
2386
+ }
2387
+ return transformed;
2388
+ }
2389
+ const WORK_MESSAGE_FLOW_ARRAY = "Flow expected to receive an array of functions";
2390
+ const WORK_MESSAGE_FLOW_PROMISE = "Synchronous Flow received a promise. Use `flow.async` instead.";
2391
+ const WORK_MESSAGE_NESTING = "Return values are too deeply nested.";
2392
+ const WORK_MESSAGE_PIPE_ARRAY = "Pipe expected to receive an array of functions";
2393
+ const WORK_MESSAGE_PIPE_PROMISE = "Synchronous Pipe received a promise. Use `pipe.async` instead.";
2394
+ const assertFlowFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), WORK_MESSAGE_FLOW_ARRAY, TypeError);
2395
+ const assertPipeFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), WORK_MESSAGE_PIPE_ARRAY, TypeError);
2396
+ flow.async = asyncFlow;
2397
+ pipe.async = asyncPipe;
2398
+ //#endregion
2339
2399
  //#region src/internal/string/case.ts
2340
2400
  /**
2341
2401
  * Convert a string to camel case _(thisIsCamelCase)_
@@ -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 = Math.round(length / EQUAL_ARRAY_PEEK_PERCENTAGE);
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
  }
@@ -2703,7 +2763,6 @@ const ABORT_OPTIONS = { once: true };
2703
2763
  //#region src/promise/constants.ts
2704
2764
  const PROMISE_ERROR_NAME = "PromiseTimeoutError";
2705
2765
  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
2766
  const PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE = "promises expected an array or object holding promise-functions or promises";
2708
2767
  const PROMISE_MESSAGE_EXPECTATION_RESULT = "toResult expected a Promise";
2709
2768
  const PROMISE_MESSAGE_EXPECTATION_TIMED = "Timed function expected a Promise";
@@ -2808,22 +2867,6 @@ function isType(value, type) {
2808
2867
  return isPlainObject(value) && "status" in value && value.status === type;
2809
2868
  }
2810
2869
  //#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
2870
  //#region src/promise/misc.ts
2828
2871
  /**
2829
2872
  * Create a cancelable _Promise_
@@ -2914,13 +2957,13 @@ async function attemptPromise(value, options) {
2914
2957
  rejector(signal?.reason);
2915
2958
  });
2916
2959
  async function handler(resolve, reject) {
2917
- try {
2960
+ const result = await asyncAttempt(async () => {
2918
2961
  let result = isFunction ? value() : await value;
2919
2962
  if (result instanceof Promise) result = await result;
2920
- settlePromise(resolve, result, aborter);
2921
- } catch (error) {
2922
- settlePromise(reject, error, aborter);
2923
- }
2963
+ return result;
2964
+ });
2965
+ if (result.ok) settlePromise(resolve, result.value, aborter);
2966
+ else settlePromise(reject, result.error, aborter);
2924
2967
  }
2925
2968
  let rejector;
2926
2969
  const promise = new Promise((resolve, reject) => {
@@ -2935,12 +2978,11 @@ async function promises(items, options) {
2935
2978
  if (!isArrayOrPlainObject(items)) return Promise.reject(PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE);
2936
2979
  const isArray = Array.isArray(items);
2937
2980
  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
2981
  const aborter = createAborter(signal, () => {
2942
2982
  handlers.reject(signal?.reason);
2943
2983
  });
2984
+ const complete = strategy === PROMISE_STRATEGY_DEFAULT;
2985
+ const { length } = actual;
2944
2986
  const data = {
2945
2987
  last: length - 1,
2946
2988
  result: isArray ? [] : {}
@@ -2976,25 +3018,6 @@ async function resultPromises(items, signal) {
2976
3018
  }
2977
3019
  promises.result = resultPromises;
2978
3020
  //#endregion
2979
- //#region src/result/index.ts
2980
- async function asyncAttempt(value, err) {
2981
- try {
2982
- let result = typeof value === "function" ? value() : await value;
2983
- if (result instanceof Promise) result = await result;
2984
- return ok(result);
2985
- } catch (thrown) {
2986
- return getError(err ?? thrown, err == null ? void 0 : thrown);
2987
- }
2988
- }
2989
- function attempt(callback, err) {
2990
- try {
2991
- return ok(callback());
2992
- } catch (thrown) {
2993
- return getError(err ?? thrown, err == null ? void 0 : thrown);
2994
- }
2995
- }
2996
- attempt.async = asyncAttempt;
2997
- //#endregion
2998
3021
  //#region src/result/match.ts
2999
3022
  async function asyncMatchResult(result, first, error) {
3000
3023
  let value;
@@ -3134,7 +3157,7 @@ function createFuzzyItems(items) {
3134
3157
  function createFuzzyOptions(input, state) {
3135
3158
  const options = isPlainObject(input) ? input : {};
3136
3159
  const limit = typeof input === "number" ? input : options.limit;
3137
- if (typeof limit === "number" && !Number.isNaN(limit) && limit >= 1) options.limit = Math.floor(limit);
3160
+ if (typeof limit === "number" && !Number.isNaN(limit) && limit >= 1) options.limit = floor(limit);
3138
3161
  else options.limit = state?.limit;
3139
3162
  options.tolerance = getTolerance(options.tolerance, state);
3140
3163
  return options;
@@ -3199,18 +3222,18 @@ function getScore(haystack, needle) {
3199
3222
  if (haystackIndex === 0) score += 1;
3200
3223
  if (previousMatchIndex !== -1) {
3201
3224
  const gap = haystackIndex - previousMatchIndex - 1;
3202
- score += Math.max(0, FUZZY_PROXIMITY_THRESHOLD - gap);
3225
+ score += max([0, FUZZY_PROXIMITY_THRESHOLD - gap]);
3203
3226
  }
3204
3227
  previousMatchIndex = haystackIndex;
3205
3228
  needleIndex += 1;
3206
3229
  }
3207
3230
  if (needleIndex === needleLength) break;
3208
3231
  }
3209
- score -= Math.floor(lowerCaseHaystack.length / FUZZY_LENGTH_DIVISOR);
3210
- return Math.max(0, score);
3232
+ score -= floor(lowerCaseHaystack.length / FUZZY_LENGTH_DIVISOR);
3233
+ return max([0, score]);
3211
3234
  }
3212
3235
  function getTolerance(input, state) {
3213
- if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : Math.floor(input);
3236
+ if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : floor(input);
3214
3237
  return state?.tolerance ?? FUZZY_PROXIMITY_THRESHOLD;
3215
3238
  }
3216
3239
  /**
@@ -3315,7 +3338,7 @@ function dedent(value, ...values) {
3315
3338
  if (indentation != null) lengths.push(indentation.length);
3316
3339
  }
3317
3340
  if (lengths.length === 0) return actual.trim();
3318
- const minimum = Math.min(...lengths);
3341
+ const minimum = min(lengths);
3319
3342
  const pattern = new RegExp(`^\\s{0,${minimum}}`);
3320
3343
  let result = "";
3321
3344
  for (let index = 0; index < length; index += 1) {
@@ -3709,14 +3732,9 @@ function registerCloner(constructor, handler) {
3709
3732
  }
3710
3733
  function tryStructuredClone(value, parameters, depth) {
3711
3734
  if (depth >= CLONE_MAX_DEPTH) return value;
3712
- try {
3713
- const cloned = structuredClone(value);
3714
- parameters.references.set(value, cloned);
3715
- return cloned;
3716
- } catch {
3717
- parameters.references.set(value, value);
3718
- return value;
3719
- }
3735
+ const cloned = unwrap(attempt(() => structuredClone(value)), value);
3736
+ parameters.references.set(value, cloned);
3737
+ return cloned;
3720
3738
  }
3721
3739
  const CLONE_COPY_OPTIONS = {
3722
3740
  copyFunctions: true,
@@ -3839,8 +3857,8 @@ function getChanges(changes, first, second, options, prefix) {
3839
3857
  function getDiffs(first, second, options, prefix) {
3840
3858
  const changes = [];
3841
3859
  if (Array.isArray(first) && Array.isArray(second)) {
3842
- const maximumLength = Math.max(first.length, second.length);
3843
- const minimumLength = Math.min(first.length, second.length);
3860
+ const maximumLength = max([first.length, second.length]);
3861
+ const minimumLength = min([first.length, second.length]);
3844
3862
  for (let index = minimumLength; index < maximumLength; index += 1) {
3845
3863
  const key = join([prefix, index], ".");
3846
3864
  changes.push({
@@ -4492,7 +4510,7 @@ function Observable(beacon) {
4492
4510
  };
4493
4511
  }
4494
4512
  Observable.prototype[BEACON_PROPERTY] = BEACON_OBSERVABLE;
4495
- Observable.prototype.deactivate = deactiveateObservable;
4513
+ Observable.prototype.deactivate = deactivateObservable;
4496
4514
  Observable.prototype.subscribe = subscribeToObservable;
4497
4515
  Object.defineProperty(Observable.prototype, "active", {
4498
4516
  enumerable: true,
@@ -4541,7 +4559,7 @@ function createObserver(first, second, third) {
4541
4559
  function deactivateBeacon() {
4542
4560
  closeBeacon(this[BEACON_SYMBOL], false);
4543
4561
  }
4544
- function deactiveateObservable() {
4562
+ function deactivateObservable() {
4545
4563
  this[BEACON_SYMBOL].active = false;
4546
4564
  }
4547
4565
  function emitBeaconError(error, finish) {
@@ -4866,24 +4884,6 @@ const colorSubscription = {
4866
4884
  value: SUBSCRIPTION_NAME
4867
4885
  };
4868
4886
  //#endregion
4869
- //#region src/internal/math/misc.ts
4870
- /**
4871
- * Round a number
4872
- *
4873
- * @param value Number to round
4874
- * @param decimals Number of decimal places to round to _(defaults to `0`)_
4875
- * @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
4876
- */
4877
- function round(value, decimals) {
4878
- return roundNumber(Math.round, value, decimals);
4879
- }
4880
- function roundNumber(callback, value, decimals) {
4881
- if (typeof value !== "number") return NaN;
4882
- if (typeof decimals !== "number" || decimals < 1) return callback(value);
4883
- const mod = 10 ** decimals;
4884
- return callback((value + Number.EPSILON) * mod) / mod;
4885
- }
4886
- //#endregion
4887
4887
  //#region src/color/misc/alpha.ts
4888
4888
  function getAlpha(value, hex) {
4889
4889
  if (typeof value === "number") return getAlphaFromValue(value);
@@ -5209,12 +5209,12 @@ function convertRgbToHex(rgb, alpha) {
5209
5209
  }
5210
5210
  function convertRgbToHsla(value) {
5211
5211
  const values = getRgbCalculationValues(isRgbLike(value) ? getRgbValues(value) : { ...COLOR_DEFAULTS.rgb });
5212
- const { delta, max, min } = values;
5213
- const lightness = (min + max) / 2;
5212
+ const { delta, maximum, minimum } = values;
5213
+ const lightness = (minimum + maximum) / 2;
5214
5214
  let hue = 0;
5215
5215
  let saturation = 0;
5216
5216
  if (delta !== 0) {
5217
- saturation = (max - lightness) / Math.min(lightness, 1 - lightness);
5217
+ saturation = (maximum - lightness) / min([lightness, 1 - lightness]);
5218
5218
  hue = getRgbHue(values);
5219
5219
  hue *= 60;
5220
5220
  }
@@ -5227,7 +5227,7 @@ function convertRgbToHsla(value) {
5227
5227
  }
5228
5228
  function convertRgbToHwba(value) {
5229
5229
  const values = getRgbCalculationValues(isRgbLike(value) ? getRgbValues(value) : { ...COLOR_DEFAULTS.rgb });
5230
- const { delta, max, min } = values;
5230
+ const { delta, maximum, minimum } = values;
5231
5231
  let hue = 0;
5232
5232
  if (delta !== 0) {
5233
5233
  hue = getRgbHue(values);
@@ -5235,8 +5235,8 @@ function convertRgbToHwba(value) {
5235
5235
  }
5236
5236
  return {
5237
5237
  hue,
5238
- whiteness: min * COLOR_MAX.percent,
5239
- blackness: (1 - max) * COLOR_MAX.percent,
5238
+ whiteness: minimum * COLOR_MAX.percent,
5239
+ blackness: (1 - maximum) * COLOR_MAX.percent,
5240
5240
  alpha: getAlphaValue(value?.alpha ?? COLOR_MAX.percent)
5241
5241
  };
5242
5242
  }
@@ -5256,14 +5256,22 @@ function getRgbCalculationValues(rgb) {
5256
5256
  const blue = rgb.blue / COLOR_MAX.hex;
5257
5257
  const green = rgb.green / COLOR_MAX.hex;
5258
5258
  const red = rgb.red / COLOR_MAX.hex;
5259
- const max = Math.max(blue, green, red);
5260
- const min = Math.min(blue, green, red);
5259
+ const maximum = max([
5260
+ blue,
5261
+ green,
5262
+ red
5263
+ ]);
5264
+ const minimum = min([
5265
+ blue,
5266
+ green,
5267
+ red
5268
+ ]);
5261
5269
  return {
5262
5270
  blue,
5263
- delta: max - min,
5271
+ delta: maximum - minimum,
5264
5272
  green,
5265
- max,
5266
- min,
5273
+ maximum,
5274
+ minimum,
5267
5275
  red
5268
5276
  };
5269
5277
  }
@@ -5274,8 +5282,8 @@ function getRgbaColor$1() {
5274
5282
  return getStateValue(this, COLOR_TYPE.rgb, true);
5275
5283
  }
5276
5284
  function getRgbHue(values) {
5277
- const { blue, delta, green, max, red } = values;
5278
- switch (max) {
5285
+ const { blue, delta, green, maximum, red } = values;
5286
+ switch (maximum) {
5279
5287
  case blue: return (red - green) / delta + 4;
5280
5288
  case green: return (blue - red) / delta + 2;
5281
5289
  default: return (green - blue) / delta + (green < blue ? 6 : 0);
@@ -5524,7 +5532,7 @@ function convertHslToHwba(input) {
5524
5532
  let { hue, lightness, saturation } = isHslLike(input) ? getHslValues(input) : { ...COLOR_DEFAULTS.hsl };
5525
5533
  lightness /= COLOR_MAX.percent;
5526
5534
  saturation /= COLOR_MAX.percent;
5527
- const value = lightness + saturation * Math.min(lightness, 1 - lightness);
5535
+ const value = lightness + saturation * min([lightness, 1 - lightness]);
5528
5536
  if (value === 0) saturation = 0;
5529
5537
  else saturation = 2 * (1 - lightness / value);
5530
5538
  const blackness = 1 - value;
@@ -5561,7 +5569,11 @@ function getColorFromHsl(state, type) {
5561
5569
  }
5562
5570
  function getHexyValue(hue, lightness, saturation, value) {
5563
5571
  const part = (value + hue / 30) % 12;
5564
- return (lightness - saturation * Math.min(lightness, 1 - lightness) * Math.max(-1, Math.min(part - 3, 9 - part, 1))) * COLOR_MAX.hex;
5572
+ return (lightness - saturation * min([lightness, 1 - lightness]) * max([-1, min([
5573
+ part - 3,
5574
+ 9 - part,
5575
+ 1
5576
+ ])])) * COLOR_MAX.hex;
5565
5577
  }
5566
5578
  function getHslValue() {
5567
5579
  return getStateValue(this, COLOR_TYPE.hsl, false);
@@ -5694,7 +5706,7 @@ function getColorFromHwb(state, type) {
5694
5706
  function getHwbSaturation(blackness, whiteness, lightness) {
5695
5707
  const hue = 1 - blackness - whiteness;
5696
5708
  if (hue <= 0) return 0;
5697
- return hue / Math.min(2 * lightness, 2 - 2 * lightness);
5709
+ return hue / min([2 * lightness, 2 - 2 * lightness]);
5698
5710
  }
5699
5711
  function getHwbValue() {
5700
5712
  return getStateValue(this, COLOR_TYPE.hwb, false);
@@ -6233,16 +6245,6 @@ function count(array, key, value) {
6233
6245
  }
6234
6246
  return counted;
6235
6247
  }
6236
- /**
6237
- * Round a number down
6238
- *
6239
- * @param value Number to round down
6240
- * @param decimals Number of decimal places to round to _(defaults to `0`)_
6241
- * @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
6242
- */
6243
- function floor(value, decimals) {
6244
- return roundNumber(Math.floor, value, decimals);
6245
- }
6246
6248
  function median(array, key) {
6247
6249
  let length = Array.isArray(array) ? array.length : 0;
6248
6250
  if (!Array.isArray(array) || length === 0) return NaN;
@@ -6257,10 +6259,7 @@ function median(array, key) {
6257
6259
  const second = length / 2;
6258
6260
  return (numbers[first] + numbers[second]) / 2;
6259
6261
  }
6260
- return numbers[Math.floor(length / 2)];
6261
- }
6262
- function min(array, key, first) {
6263
- return getAggregated("min", array, key, first);
6262
+ return numbers[floor(length / 2)];
6264
6263
  }
6265
6264
  function sum(array, key) {
6266
6265
  return getAggregated("sum", array, key);
@@ -6681,7 +6680,7 @@ function resumeQueue() {
6681
6680
  for (let index = 0; index < length; index += 1) handled[index]();
6682
6681
  }
6683
6682
  state.paused = false;
6684
- const length = Math.min(state.options.concurrency, state.items.length);
6683
+ const length = min([state.options.concurrency, state.items.length]);
6685
6684
  for (let index = 0; index < length; index += 1) run(state);
6686
6685
  }
6687
6686
  function resumeQueues(key) {
@@ -6694,14 +6693,17 @@ async function run(state) {
6694
6693
  while (item != null) {
6695
6694
  let error = false;
6696
6695
  let result;
6697
- try {
6698
- if (!(item.aborter?.signal?.aborted ?? false)) {
6696
+ const attempted = await asyncAttempt(async () => {
6697
+ if (item != null && !(item.aborter?.signal?.aborted ?? false)) {
6699
6698
  const parameters = item.key == null ? item.parameters : [item.key, ...item.parameters];
6700
- result = await state.callback(...parameters);
6699
+ return await state.callback(...parameters);
6701
6700
  }
6702
- } catch (thrown) {
6701
+ throw new Error();
6702
+ });
6703
+ if (attempted.ok) result = attempted.value;
6704
+ else {
6703
6705
  error = true;
6704
- result = thrown;
6706
+ result = attempted.error;
6705
6707
  }
6706
6708
  if (state.paused) {
6707
6709
  const paused = item;
@@ -6845,4 +6847,4 @@ var SizedSet = class extends Set {
6845
6847
  }
6846
6848
  };
6847
6849
  //#endregion
6848
- export { CancelablePromise, Logger, PromiseTimeoutError, QueueError, 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, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, 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, 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, reverseSelect, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, select, 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 };
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 };