@oscarpalmer/atoms 0.142.0 → 0.144.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 (98) hide show
  1. package/dist/array/filter.js +5 -1
  2. package/dist/array/partition.js +6 -0
  3. package/dist/array/range.js +6 -0
  4. package/dist/array/select.js +5 -0
  5. package/dist/array/toggle.js +5 -0
  6. package/dist/array/unique.js +1 -1
  7. package/dist/array/update.js +5 -0
  8. package/dist/atoms.full.js +201 -56
  9. package/dist/color/misc/is.js +6 -6
  10. package/dist/function/memoize.js +1 -1
  11. package/dist/index.js +12 -6
  12. package/dist/internal/array/callbacks.js +1 -1
  13. package/dist/internal/array/find.js +23 -11
  14. package/dist/internal/array/update.js +22 -0
  15. package/dist/internal/math/aggregate.js +12 -8
  16. package/dist/internal/number.js +1 -1
  17. package/dist/internal/value/partial.js +14 -0
  18. package/dist/is.js +11 -3
  19. package/dist/math.js +44 -7
  20. package/dist/promise.js +30 -4
  21. package/dist/result.js +7 -5
  22. package/dist/sized/map.js +1 -1
  23. package/dist/sized/set.js +2 -2
  24. package/dist/value/merge.js +3 -1
  25. package/dist/value/misc.js +3 -2
  26. package/dist/value/omit.js +11 -0
  27. package/dist/value/pick.js +11 -0
  28. package/package.json +21 -1
  29. package/src/array/exists.ts +7 -8
  30. package/src/array/filter.ts +32 -9
  31. package/src/array/find.ts +6 -6
  32. package/src/array/index-of.ts +7 -8
  33. package/src/array/partition.ts +56 -0
  34. package/src/array/range.ts +35 -0
  35. package/src/array/select.ts +92 -0
  36. package/src/array/toggle.ts +40 -0
  37. package/src/array/unique.ts +6 -6
  38. package/src/array/update.ts +40 -0
  39. package/src/color/misc/is.ts +6 -6
  40. package/src/function/debounce.ts +2 -2
  41. package/src/function/memoize.ts +1 -1
  42. package/src/function/throttle.ts +2 -2
  43. package/src/index.ts +7 -1
  44. package/src/internal/array/callbacks.ts +1 -1
  45. package/src/internal/array/find.ts +35 -29
  46. package/src/internal/array/update.ts +52 -0
  47. package/src/internal/function/limiter.ts +3 -3
  48. package/src/internal/math/aggregate.ts +21 -12
  49. package/src/internal/number.ts +1 -1
  50. package/src/internal/value/partial.ts +46 -0
  51. package/src/is.ts +11 -2
  52. package/src/math.ts +100 -14
  53. package/src/models.ts +2 -2
  54. package/src/promise.ts +52 -15
  55. package/src/random.ts +2 -2
  56. package/src/result.ts +31 -11
  57. package/src/sized/map.ts +1 -1
  58. package/src/sized/set.ts +2 -2
  59. package/src/value/merge.ts +10 -6
  60. package/src/value/misc.ts +2 -1
  61. package/src/value/omit.ts +19 -0
  62. package/src/value/pick.ts +19 -0
  63. package/types/array/exists.d.ts +2 -2
  64. package/types/array/filter.d.ts +10 -2
  65. package/types/array/find.d.ts +2 -2
  66. package/types/array/index-of.d.ts +2 -2
  67. package/types/array/partition.d.ts +31 -0
  68. package/types/array/range.d.ts +20 -0
  69. package/types/array/select.d.ts +43 -0
  70. package/types/array/toggle.d.ts +24 -0
  71. package/types/array/unique.d.ts +2 -2
  72. package/types/array/update.d.ts +24 -0
  73. package/types/color/misc/is.d.ts +6 -6
  74. package/types/function/debounce.d.ts +2 -2
  75. package/types/function/memoize.d.ts +1 -1
  76. package/types/function/throttle.d.ts +2 -2
  77. package/types/index.d.ts +7 -1
  78. package/types/internal/array/callbacks.d.ts +1 -0
  79. package/types/internal/array/find.d.ts +5 -2
  80. package/types/internal/array/update.d.ts +1 -0
  81. package/types/internal/function/limiter.d.ts +2 -2
  82. package/types/internal/math/aggregate.d.ts +2 -1
  83. package/types/internal/number.d.ts +1 -1
  84. package/types/internal/value/partial.d.ts +2 -0
  85. package/types/is.d.ts +8 -2
  86. package/types/math.d.ts +35 -1
  87. package/types/models.d.ts +2 -2
  88. package/types/promise.d.ts +26 -11
  89. package/types/random.d.ts +2 -2
  90. package/types/result.d.ts +21 -6
  91. package/types/sized/map.d.ts +1 -1
  92. package/types/sized/set.d.ts +2 -2
  93. package/types/value/merge.d.ts +5 -4
  94. package/types/value/misc.d.ts +2 -1
  95. package/types/value/omit.d.ts +8 -0
  96. package/types/value/{partial.d.ts → pick.d.ts} +1 -1
  97. package/dist/value/partial.js +0 -17
  98. package/src/value/partial.ts +0 -39
@@ -1,5 +1,9 @@
1
1
  import { findValues } from "../internal/array/find.js";
2
2
  function filter(array, ...parameters) {
3
- return findValues("all", array, parameters);
3
+ return findValues("all", array, parameters).matched;
4
+ }
5
+ filter.remove = removeFiltered;
6
+ function removeFiltered(array, ...parameters) {
7
+ return findValues("all", array, parameters).notMatched;
4
8
  }
5
9
  export { filter };
@@ -0,0 +1,6 @@
1
+ import { findValues } from "../internal/array/find.js";
2
+ function partition(array, ...parameters) {
3
+ const { matched, notMatched } = findValues("all", array, parameters);
4
+ return [matched, notMatched];
5
+ }
6
+ export { partition };
@@ -0,0 +1,6 @@
1
+ function range(length, value) {
2
+ if (typeof length !== "number" || length <= 0) return [];
3
+ const isFunction = typeof value === "function";
4
+ return Array.from({ length }, (_, index) => isFunction ? value(index) : value ?? index);
5
+ }
6
+ export { range };
@@ -0,0 +1,5 @@
1
+ import { findValues } from "../internal/array/find.js";
2
+ function select(array, ...parameters) {
3
+ return findValues("all", array, parameters, parameters.pop()).matched;
4
+ }
5
+ export { select };
@@ -0,0 +1,5 @@
1
+ import { updateInArray } from "../internal/array/update.js";
2
+ function toggle(array, values, key) {
3
+ return updateInArray(array, values, key, false);
4
+ }
5
+ export { toggle };
@@ -1,6 +1,6 @@
1
1
  import { findValues } from "../internal/array/find.js";
2
2
  function unique(array, key) {
3
3
  if (!Array.isArray(array)) return [];
4
- return array.length > 1 ? findValues("unique", array, [key, void 0]) : array;
4
+ return array.length > 1 ? findValues("unique", array, [key, void 0]).matched : array;
5
5
  }
6
6
  export { unique };
@@ -0,0 +1,5 @@
1
+ import { updateInArray } from "../internal/array/update.js";
2
+ function update(array, values, key) {
3
+ return updateInArray(array, values, key, true);
4
+ }
5
+ export { update };
@@ -57,27 +57,39 @@ function findValueInArray(array, callback, value, findIndex) {
57
57
  }
58
58
  return findIndex ? -1 : void 0;
59
59
  }
60
- function findValues(type, array, parameters) {
61
- if (!Array.isArray(array)) return [];
62
- if (array.length === 0) return [];
60
+ function findValues(type, array, parameters, mapper) {
61
+ const result = {
62
+ matched: [],
63
+ notMatched: []
64
+ };
65
+ if (!Array.isArray(array) || array.length === 0) return result;
63
66
  const { length } = array;
64
67
  const { bool, key, value } = getParameters(parameters);
65
68
  const callbacks = getArrayCallbacks(bool, key);
66
- if (type === "unique" && callbacks?.keyed == null && length >= UNIQUE_THRESHOLD) return [...new Set(array)];
67
- if (callbacks?.bool != null) return array.filter(callbacks.bool);
68
- if (type === "all" && key == null) return array.filter((item) => item === value);
69
+ if (type === "unique" && callbacks?.keyed == null && length >= UNIQUE_THRESHOLD) {
70
+ result.matched = [...new Set(array)];
71
+ return result;
72
+ }
73
+ const mapCallback = typeof mapper === "function" ? mapper : void 0;
74
+ if (callbacks?.bool != null || type === "all" && key == null) {
75
+ const callback = callbacks?.bool ?? ((item) => Object.is(item, value));
76
+ for (let index = 0; index < length; index += 1) {
77
+ const item = array[index];
78
+ if (callback(item, index, array)) result.matched.push(mapCallback?.(item, index, array) ?? item);
79
+ else result.notMatched.push(item);
80
+ }
81
+ return result;
82
+ }
69
83
  const keys = /* @__PURE__ */ new Set();
70
- const values = [];
71
84
  for (let index = 0; index < length; index += 1) {
72
85
  const item = array[index];
73
86
  const keyed = callbacks?.keyed?.(item, index, array) ?? item;
74
87
  if (type === "all" && Object.is(keyed, value) || type === "unique" && !keys.has(keyed)) {
75
88
  keys.add(keyed);
76
- values.push(item);
77
- }
89
+ result.matched.push(mapCallback?.(item, index, array) ?? item);
90
+ } else result.notMatched.push(item);
78
91
  }
79
- keys.clear();
80
- return values;
92
+ return result;
81
93
  }
82
94
  function getParameters(original) {
83
95
  const { length } = original;
@@ -93,7 +105,11 @@ function exists(array, ...parameters) {
93
105
  return findValue("index", array, parameters) > -1;
94
106
  }
95
107
  function filter(array, ...parameters) {
96
- return findValues("all", array, parameters);
108
+ return findValues("all", array, parameters).matched;
109
+ }
110
+ filter.remove = removeFiltered;
111
+ function removeFiltered(array, ...parameters) {
112
+ return findValues("all", array, parameters).notMatched;
97
113
  }
98
114
  function find(array, ...parameters) {
99
115
  return findValue("value", array, parameters);
@@ -257,6 +273,10 @@ function insertValues(type, array, items, start, deleteCount) {
257
273
  function insert(array, indexOrItems, items) {
258
274
  return insertValues("insert", array, items == null ? indexOrItems : items, typeof indexOrItems === "number" ? indexOrItems : array?.length, 0);
259
275
  }
276
+ function partition(array, ...parameters) {
277
+ const { matched, notMatched } = findValues("all", array, parameters);
278
+ return [matched, notMatched];
279
+ }
260
280
  /**
261
281
  * Push items into an array _(at the end)_
262
282
  * @param array Original array
@@ -266,6 +286,14 @@ function insert(array, indexOrItems, items) {
266
286
  function push(array, pushed) {
267
287
  return insertValues("push", array, pushed, array.length, 0);
268
288
  }
289
+ function range(length, value) {
290
+ if (typeof length !== "number" || length <= 0) return [];
291
+ const isFunction = typeof value === "function";
292
+ return Array.from({ length }, (_, index) => isFunction ? value(index) : value ?? index);
293
+ }
294
+ function select(array, ...parameters) {
295
+ return findValues("all", array, parameters, parameters.pop()).matched;
296
+ }
269
297
  function aggregate(type, array, key) {
270
298
  const length = Array.isArray(array) ? array.length : 0;
271
299
  if (length === 0) return {
@@ -273,24 +301,27 @@ function aggregate(type, array, key) {
273
301
  value: NaN
274
302
  };
275
303
  const aggregator = aggregators[type];
276
- const isCallback = typeof key === "function";
304
+ const callback = getAggregateCallback(key);
277
305
  let counted = 0;
278
306
  let aggregated = NaN;
279
307
  let notNumber = true;
280
308
  for (let index = 0; index < length; index += 1) {
281
309
  const item = array[index];
282
- const value = isCallback ? key(item, index, array) : item[key] ?? item;
283
- if (typeof value === "number" && !Number.isNaN(value)) {
284
- aggregated = aggregator(aggregated, value, notNumber);
285
- counted += 1;
286
- notNumber = false;
287
- }
310
+ const value = callback == null ? item : callback(item, index, array);
311
+ if (!isNumber(value)) continue;
312
+ aggregated = aggregator(aggregated, value, notNumber);
313
+ counted += 1;
314
+ notNumber = false;
288
315
  }
289
316
  return {
290
317
  count: counted,
291
318
  value: aggregated
292
319
  };
293
320
  }
321
+ function getAggregateCallback(key) {
322
+ if (key == null) return;
323
+ return typeof key === "function" ? key : (item) => item[key];
324
+ }
294
325
  function max(array, key) {
295
326
  return getAggregated("max", array, key);
296
327
  }
@@ -587,9 +618,35 @@ function toSet(array, value) {
587
618
  for (let index = 0; index < length; index += 1) set.add(callbacks.value(array[index], index, array));
588
619
  return set;
589
620
  }
621
+ function updateInArray(array, items, key, replace) {
622
+ if (!Array.isArray(array)) return [];
623
+ const itemsIsArray = Array.isArray(items);
624
+ if (array.length === 0 || !itemsIsArray) {
625
+ if (itemsIsArray) array.push(...items);
626
+ return array;
627
+ }
628
+ const { length } = items;
629
+ if (length === 0) return array;
630
+ const callback = getArrayCallback(key);
631
+ for (let valuesIndex = 0; valuesIndex < length; valuesIndex += 1) {
632
+ const item = items[valuesIndex];
633
+ const value = callback?.(item) ?? item;
634
+ const arrayIndex = callback == null ? array.indexOf(value) : array.findIndex((arrayItem, arrayIndex) => callback(arrayItem, arrayIndex, array) === value);
635
+ if (arrayIndex === -1) array.push(item);
636
+ else if (replace) array[arrayIndex] = item;
637
+ else array.splice(arrayIndex, 1);
638
+ }
639
+ return array;
640
+ }
641
+ function toggle(array, values, key) {
642
+ return updateInArray(array, values, key, false);
643
+ }
590
644
  function unique(array, key) {
591
645
  if (!Array.isArray(array)) return [];
592
- return array.length > 1 ? findValues("unique", array, [key, void 0]) : array;
646
+ return array.length > 1 ? findValues("unique", array, [key, void 0]).matched : array;
647
+ }
648
+ function update(array, values, key) {
649
+ return updateInArray(array, values, key, true);
593
650
  }
594
651
  function getLimiter(callback, throttler, time) {
595
652
  const interval = typeof time === "number" && time >= frame_rate_default ? time : frame_rate_default;
@@ -665,7 +722,7 @@ function clamp(value, minimum, maximum, loop) {
665
722
  /**
666
723
  * Get the number value from an unknown value _(based on Lodash)_
667
724
  * @param value Original value
668
- * @returns The value as a number, or `NaN` if the value is unable to be parsed
725
+ * @returns Original value as a number, or `NaN` if the value is unable to be parsed
669
726
  */
670
727
  function getNumber(value) {
671
728
  if (typeof value === "number") return value;
@@ -699,7 +756,7 @@ const MAXIMUM_DEFAULT = 1048576;
699
756
  /**
700
757
  * A Map with a maximum size
701
758
  *
702
- * Behaviour is similar to a _LRU_-cache, where the least recently used entries are removed
759
+ * Behavior is similar to a _LRU_-cache, where the least recently used entries are removed
703
760
  */
704
761
  var SizedMap = class extends Map {
705
762
  /**
@@ -795,7 +852,7 @@ var Memoized = class {
795
852
  /**
796
853
  * Get a result from the cache
797
854
  * @param key Key to get
798
- * @returns The cached result or `undefined` if it does not exist
855
+ * @returns Cached result or `undefined` if it does not exist
799
856
  */
800
857
  get(key) {
801
858
  return this.#state.cache?.get(key);
@@ -1580,10 +1637,12 @@ function setChanges(parameters) {
1580
1637
  function getMergeOptions(options) {
1581
1638
  const actual = {
1582
1639
  replaceableObjects: void 0,
1640
+ skipNullableAny: false,
1583
1641
  skipNullableInArrays: false
1584
1642
  };
1585
1643
  if (typeof options !== "object" || options == null) return actual;
1586
1644
  actual.replaceableObjects = getReplaceableObjects(options.replaceableObjects);
1645
+ actual.skipNullableAny = options.skipNullableAny === true;
1587
1646
  actual.skipNullableInArrays = options.skipNullableInArrays === true;
1588
1647
  return actual;
1589
1648
  }
@@ -1626,7 +1685,7 @@ function mergeObjects(values, options, prefix) {
1626
1685
  const full = join([prefix, key], ".");
1627
1686
  const next = item[key];
1628
1687
  const previous = merged[key];
1629
- if (isArray && options.skipNullableInArrays && next == null) continue;
1688
+ if (next == null && (options.skipNullableAny || isArray && options.skipNullableInArrays)) continue;
1630
1689
  if (isArrayOrPlainObject(next) && isArrayOrPlainObject(previous) && !(options.replaceableObjects?.(full) ?? false)) merged[key] = mergeValues([previous, next], options, false, full);
1631
1690
  else merged[key] = next;
1632
1691
  }
@@ -1637,22 +1696,37 @@ function mergeValues(values, options, validate, prefix) {
1637
1696
  const actual = validate ? values.filter(isArrayOrPlainObject) : values;
1638
1697
  return actual.length > 1 ? mergeObjects(actual, options, prefix) : actual[0] ?? {};
1639
1698
  }
1640
- /**
1641
- * Create a new object with only the specified keys
1642
- * @param value Original object
1643
- * @param keys Keys to use
1644
- * @returns Partial object with only the specified keys
1645
- */
1646
- function partial(value, keys) {
1647
- if (typeof value !== "object" || value === null || Object.keys(value).length === 0 || !Array.isArray(keys) || keys.length === 0) return {};
1699
+ function partial(value, providedKeys, omit) {
1700
+ if (typeof value !== "object" || value === null) return {};
1701
+ const keys = omit ? Object.keys(value) : Array.isArray(providedKeys) ? providedKeys : [];
1648
1702
  const { length } = keys;
1703
+ if (length === 0) return omit ? value : {};
1649
1704
  const partials = {};
1650
1705
  for (let index = 0; index < length; index += 1) {
1651
1706
  const key = keys[index];
1652
- if (key in value) partials[key] = value[key];
1707
+ if (!(key in value)) continue;
1708
+ if (omit ? !providedKeys.includes(key) : true) partials[key] = value[key];
1653
1709
  }
1654
1710
  return partials;
1655
1711
  }
1712
+ /**
1713
+ * Create a new object without the specified keys
1714
+ * @param value Original object
1715
+ * @param keys Keys to omit
1716
+ * @returns Partial object without the specified keys
1717
+ */
1718
+ function omit(value, keys) {
1719
+ return partial(value, keys, true);
1720
+ }
1721
+ /**
1722
+ * Create a new object with only the specified keys
1723
+ * @param value Original object
1724
+ * @param keys Keys to use
1725
+ * @returns Partial object with only the specified keys
1726
+ */
1727
+ function pick(value, keys) {
1728
+ return partial(value, keys, false);
1729
+ }
1656
1730
  function flattenObject(value, depth, smushed, prefix) {
1657
1731
  if (depth >= MAX_DEPTH) return {};
1658
1732
  if (smushed.has(value)) return smushed.get(value);
@@ -1983,7 +2057,7 @@ function isBytey(value) {
1983
2057
  }
1984
2058
  /**
1985
2059
  * Is the value a Color?
1986
- * @param value The value to check
2060
+ * @param value Value to check
1987
2061
  * @returns `true` if the value is a Color, otherwise `false`
1988
2062
  */
1989
2063
  function isColor(value) {
@@ -2005,7 +2079,7 @@ function isDegree(value) {
2005
2079
  }
2006
2080
  /**
2007
2081
  * Is the value a hex color?
2008
- * @param value The value to check
2082
+ * @param value Value to check
2009
2083
  * @param alpha Allow alpha channel? _(defaults to `true`)_
2010
2084
  * @returns `true` if the value is a hex color, otherwise `false`
2011
2085
  */
@@ -2017,7 +2091,7 @@ function isHexColor(value, alpha) {
2017
2091
  }
2018
2092
  /**
2019
2093
  * Is the value an HSLA color?
2020
- * @param value The value to check
2094
+ * @param value Value to check
2021
2095
  * @returns `true` if the value is an HSLA color, otherwise `false`
2022
2096
  */
2023
2097
  function isHslaColor(value) {
@@ -2025,7 +2099,7 @@ function isHslaColor(value) {
2025
2099
  }
2026
2100
  /**
2027
2101
  * Is the value an HSL color?
2028
- * @param value The value to check
2102
+ * @param value Value to check
2029
2103
  * @returns `true` if the value is an HSL color, otherwise `false`
2030
2104
  */
2031
2105
  function isHslColor(value) {
@@ -2036,7 +2110,7 @@ function isHslLike(value) {
2036
2110
  }
2037
2111
  /**
2038
2112
  * Is the value an RGBA color?
2039
- * @param value The value to check
2113
+ * @param value Value to check
2040
2114
  * @returns `true` if the value is an RGBA color, otherwise `false`
2041
2115
  */
2042
2116
  function isRgbaColor(value) {
@@ -2044,7 +2118,7 @@ function isRgbaColor(value) {
2044
2118
  }
2045
2119
  /**
2046
2120
  * Is the value an RGB color?
2047
- * @param value The value to check
2121
+ * @param value Value to check
2048
2122
  * @returns `true` if the value is an RGB color, otherwise `false`
2049
2123
  */
2050
2124
  function isRgbColor(value) {
@@ -2544,8 +2618,8 @@ function getColor(value) {
2544
2618
  }
2545
2619
  /**
2546
2620
  * Is the value empty, or only containing `null` or `undefined` values?
2547
- * @param value Object to check
2548
- * @returns `true` if the object is considered empty, otherwise `false`
2621
+ * @param value Value to check
2622
+ * @returns `true` if the value is considered empty, otherwise `false`
2549
2623
  */
2550
2624
  function isEmpty(value) {
2551
2625
  if (value == null) return true;
@@ -2556,6 +2630,14 @@ function isEmpty(value) {
2556
2630
  return true;
2557
2631
  }
2558
2632
  /**
2633
+ * Is the value not `undefined` or `null`?
2634
+ * @param value Value to check
2635
+ * @returns `true` if the value is not `undefined` or `null`, otherwise `false`
2636
+ */
2637
+ function isNonNullable(value) {
2638
+ return value != null;
2639
+ }
2640
+ /**
2559
2641
  * Is the value `undefined` or `null`?
2560
2642
  * @param value Value to check
2561
2643
  * @returns `true` if the value is `undefined` or `null`, otherwise `false`
@@ -2720,12 +2802,20 @@ function average(array, key) {
2720
2802
  const aggregated = aggregate("average", array, key);
2721
2803
  return aggregated.count > 0 ? aggregated.value / aggregated.count : NaN;
2722
2804
  }
2805
+ /**
2806
+ * Round a number up
2807
+ * @param value Number to round up
2808
+ * @param decimals Number of decimal places to round to _(defaults to `0`)_
2809
+ * @returns Rounded number, or `NaN` if the value if unable to be rounded
2810
+ */
2811
+ function ceil(value, decimals) {
2812
+ return roundNumber(Math.ceil, value, decimals);
2813
+ }
2723
2814
  function count(array, key, value) {
2724
2815
  if (!Array.isArray(array)) return NaN;
2725
2816
  const { length } = array;
2726
- if (key == null) return length;
2727
- if (typeof key !== "string" && typeof key !== "function") return NaN;
2728
- const callback = typeof key === "function" ? key : (item) => item[key];
2817
+ const callback = getAggregateCallback(key);
2818
+ if (callback == null) return length;
2729
2819
  let counted = 0;
2730
2820
  for (let index = 0; index < length; index += 1) {
2731
2821
  const item = array[index];
@@ -2733,6 +2823,31 @@ function count(array, key, value) {
2733
2823
  }
2734
2824
  return counted;
2735
2825
  }
2826
+ /**
2827
+ * Round a number down
2828
+ * @param value Number to round down
2829
+ * @param decimals Number of decimal places to round to _(defaults to `0`)_
2830
+ * @returns Rounded number, or `NaN` if the value if unable to be rounded
2831
+ */
2832
+ function floor(value, decimals) {
2833
+ return roundNumber(Math.floor, value, decimals);
2834
+ }
2835
+ function median(array, key) {
2836
+ let length = Array.isArray(array) ? array.length : 0;
2837
+ if (!Array.isArray(array) || length === 0) return NaN;
2838
+ if (length === 1) return isNumber(array[0]) ? array[0] : NaN;
2839
+ let values = array;
2840
+ const callback = getAggregateCallback(key);
2841
+ if (callback != null) values = array.map((item, index) => callback(item, index, array));
2842
+ const numbers = values.filter(isNumber).sort((first, second) => first - second);
2843
+ length = numbers.length;
2844
+ if (length % 2 === 0) {
2845
+ const first = length / 2 - 1;
2846
+ const second = length / 2;
2847
+ return (numbers[first] + numbers[second]) / 2;
2848
+ }
2849
+ return numbers[Math.floor(length / 2)];
2850
+ }
2736
2851
  function min(array, key) {
2737
2852
  return getAggregated("min", array, key);
2738
2853
  }
@@ -2743,20 +2858,49 @@ function min(array, key) {
2743
2858
  * @returns Rounded number, or `NaN` if the value if unable to be rounded
2744
2859
  */
2745
2860
  function round(value, decimals) {
2861
+ return roundNumber(Math.round, value, decimals);
2862
+ }
2863
+ function roundNumber(callback, value, decimals) {
2746
2864
  if (typeof value !== "number") return NaN;
2747
- if (typeof decimals !== "number" || decimals < 1) return Math.round(value);
2865
+ if (typeof decimals !== "number" || decimals < 1) return callback(value);
2748
2866
  const mod = 10 ** decimals;
2749
- return Math.round((value + Number.EPSILON) * mod) / mod;
2867
+ return callback((value + Number.EPSILON) * mod) / mod;
2750
2868
  }
2751
2869
  function sum(array, key) {
2752
2870
  return getAggregated("sum", array, key);
2753
2871
  }
2872
+ var CancelablePromise = class extends Promise {
2873
+ #rejector;
2874
+ constructor(executor) {
2875
+ let rejector;
2876
+ super((resolve, reject) => {
2877
+ rejector = reject;
2878
+ executor(resolve, reject);
2879
+ });
2880
+ this.#rejector = rejector;
2881
+ }
2882
+ /**
2883
+ * Cancel the promise, rejecting it with an optional reason
2884
+ * @param reason Optional reason for canceling the promise
2885
+ */
2886
+ cancel(reason) {
2887
+ this.#rejector(reason);
2888
+ }
2889
+ };
2754
2890
  var PromiseTimeoutError = class extends Error {
2755
2891
  constructor() {
2756
2892
  super(MESSAGE_TIMEOUT);
2757
2893
  this.name = ERROR_NAME$1;
2758
2894
  }
2759
2895
  };
2896
+ /**
2897
+ * Create a cancelable promise
2898
+ * @param executor Executor function for the promise
2899
+ * @returns Cancelable promise
2900
+ */
2901
+ function cancelable(executor) {
2902
+ return new CancelablePromise(executor);
2903
+ }
2760
2904
  function delay(options) {
2761
2905
  const { signal, time } = getPromiseOptions(options);
2762
2906
  if (signal?.aborted ?? false) return Promise.reject(signal.reason);
@@ -2909,9 +3053,9 @@ async function timed(promise, options) {
2909
3053
  if (signal?.aborted ?? false) return Promise.reject(signal.reason);
2910
3054
  return time > 0 ? getTimed(promise, time, signal) : promise;
2911
3055
  }
2912
- async function tryPromise(value, options) {
3056
+ async function attemptPromise(value, options) {
2913
3057
  const isFunction = typeof value === "function";
2914
- if (!isFunction && !(value instanceof Promise)) return Promise.reject(new TypeError(MESSAGE_EXPECTATION_TRY));
3058
+ if (!isFunction && !(value instanceof Promise)) return Promise.reject(new TypeError(MESSAGE_EXPECTATION_ATTEMPT));
2915
3059
  const { signal, time } = getPromiseOptions(options);
2916
3060
  if (signal?.aborted ?? false) return Promise.reject(signal.reason);
2917
3061
  function abort() {
@@ -2938,9 +3082,9 @@ const ABORT_OPTIONS = { once: true };
2938
3082
  const DEFAULT_STRATEGY = "complete";
2939
3083
  const ERROR_NAME$1 = "PromiseTimeoutError";
2940
3084
  const EVENT_NAME$1 = "abort";
3085
+ const MESSAGE_EXPECTATION_ATTEMPT = "Attempt expected a function or a promise";
2941
3086
  const MESSAGE_EXPECTATION_PROMISES = "Promises expected an array of promises";
2942
3087
  const MESSAGE_EXPECTATION_TIMED = "Timed function expected a Promise";
2943
- const MESSAGE_EXPECTATION_TRY = "TryPromise expected a function or a promise";
2944
3088
  const MESSAGE_TIMEOUT = "Promise timed out";
2945
3089
  const strategies = new Set(["complete", "first"]);
2946
3090
  const TYPE_FULFILLED = "fulfilled";
@@ -3317,17 +3461,18 @@ function ok(value) {
3317
3461
  value
3318
3462
  };
3319
3463
  }
3320
- function result(callback, err) {
3464
+ function attempt(callback, err) {
3321
3465
  try {
3322
3466
  return ok(callback());
3323
3467
  } catch (thrown) {
3324
3468
  return getError(err ?? thrown, err == null ? void 0 : thrown);
3325
3469
  }
3326
3470
  }
3327
- result.async = asyncResult;
3328
- async function asyncResult(callback, err) {
3471
+ attempt.async = asyncAttempt;
3472
+ attempt.promise = attemptPromise;
3473
+ async function asyncAttempt(value, err) {
3329
3474
  try {
3330
- return ok(await callback());
3475
+ return ok(await (typeof value === "function" ? value() : value));
3331
3476
  } catch (thrown) {
3332
3477
  return getError(err ?? thrown, err == null ? void 0 : thrown);
3333
3478
  }
@@ -3337,7 +3482,7 @@ function unwrap(value, defaultValue) {
3337
3482
  }
3338
3483
  /**
3339
3484
  * - A Set with a maximum size
3340
- * - Behaviour is similar to a _LRU_-cache, where the oldest values are removed
3485
+ * - Behavior is similar to a _LRU_-cache, where the oldest values are removed
3341
3486
  */
3342
3487
  var SizedSet = class extends Set {
3343
3488
  /**
@@ -3375,7 +3520,7 @@ var SizedSet = class extends Set {
3375
3520
  * Get a value from the SizedSet, if it exists _(and move it to the end)_
3376
3521
  * @param value Value to get from the SizedSet
3377
3522
  * @param update Update the value's position in the SizedSet? _(defaults to `false`)_
3378
- * @returns The value if it exists, otherwise `undefined`
3523
+ * @returns Found value if it exists, otherwise `undefined`
3379
3524
  */
3380
3525
  get(value, update) {
3381
3526
  if (this.has(value)) {
@@ -3387,4 +3532,4 @@ var SizedSet = class extends Set {
3387
3532
  }
3388
3533
  }
3389
3534
  };
3390
- export { frame_rate_default as FRAME_RATE_MS, PromiseTimeoutError, QueueError, SizedMap, SizedSet, average, beacon, between, camelCase, capitalize, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, fromQuery, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isKey, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, memoize, merge, min, noop, ok, parse, partial, pascalCase, promises, push, queue, result, rgbToHex, rgbToHsl, rgbToHsla, round, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, titleCase, toMap, toQuery, toRecord, toSet, trim, truncate, tryDecode, tryEncode, tryPromise, unique, unsmush, unwrap, upperCase, words };
3535
+ export { CancelablePromise, frame_rate_default as FRAME_RATE_MS, PromiseTimeoutError, QueueError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, floor, fromQuery, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, parse, partition, pascalCase, pick, promises, push, queue, range, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, titleCase, toMap, toQuery, toRecord, toSet, toggle, trim, truncate, tryDecode, tryEncode, unique, unsmush, unwrap, update, upperCase, words };
@@ -11,7 +11,7 @@ function isBytey(value) {
11
11
  }
12
12
  /**
13
13
  * Is the value a Color?
14
- * @param value The value to check
14
+ * @param value Value to check
15
15
  * @returns `true` if the value is a Color, otherwise `false`
16
16
  */
17
17
  function isColor(value) {
@@ -33,7 +33,7 @@ function isDegree(value) {
33
33
  }
34
34
  /**
35
35
  * Is the value a hex color?
36
- * @param value The value to check
36
+ * @param value Value to check
37
37
  * @param alpha Allow alpha channel? _(defaults to `true`)_
38
38
  * @returns `true` if the value is a hex color, otherwise `false`
39
39
  */
@@ -45,7 +45,7 @@ function isHexColor(value, alpha) {
45
45
  }
46
46
  /**
47
47
  * Is the value an HSLA color?
48
- * @param value The value to check
48
+ * @param value Value to check
49
49
  * @returns `true` if the value is an HSLA color, otherwise `false`
50
50
  */
51
51
  function isHslaColor(value) {
@@ -53,7 +53,7 @@ function isHslaColor(value) {
53
53
  }
54
54
  /**
55
55
  * Is the value an HSL color?
56
- * @param value The value to check
56
+ * @param value Value to check
57
57
  * @returns `true` if the value is an HSL color, otherwise `false`
58
58
  */
59
59
  function isHslColor(value) {
@@ -64,7 +64,7 @@ function isHslLike(value) {
64
64
  }
65
65
  /**
66
66
  * Is the value an RGBA color?
67
- * @param value The value to check
67
+ * @param value Value to check
68
68
  * @returns `true` if the value is an RGBA color, otherwise `false`
69
69
  */
70
70
  function isRgbaColor(value) {
@@ -72,7 +72,7 @@ function isRgbaColor(value) {
72
72
  }
73
73
  /**
74
74
  * Is the value an RGB color?
75
- * @param value The value to check
75
+ * @param value Value to check
76
76
  * @returns `true` if the value is an RGB color, otherwise `false`
77
77
  */
78
78
  function isRgbColor(value) {
@@ -54,7 +54,7 @@ var Memoized = class {
54
54
  /**
55
55
  * Get a result from the cache
56
56
  * @param key Key to get
57
- * @returns The cached result or `undefined` if it does not exist
57
+ * @returns Cached result or `undefined` if it does not exist
58
58
  */
59
59
  get(key) {
60
60
  return this.#state.cache?.get(key);