@oscarpalmer/atoms 0.179.0 → 0.180.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 (100) hide show
  1. package/dist/array/filter.d.mts +36 -28
  2. package/dist/array/filter.mjs +5 -5
  3. package/dist/array/first.d.mts +13 -5
  4. package/dist/array/first.mjs +1 -1
  5. package/dist/array/group-by.d.mts +13 -1
  6. package/dist/array/group-by.mjs +1 -1
  7. package/dist/array/last.d.mts +9 -1
  8. package/dist/array/last.mjs +1 -1
  9. package/dist/array/move.d.mts +9 -1
  10. package/dist/array/move.mjs +3 -1
  11. package/dist/array/reverse.d.mts +5 -0
  12. package/dist/array/reverse.mjs +5 -0
  13. package/dist/array/select.d.mts +2 -2
  14. package/dist/array/sort.d.mts +23 -9
  15. package/dist/array/sort.mjs +22 -22
  16. package/dist/array/swap.d.mts +2 -0
  17. package/dist/array/swap.mjs +2 -0
  18. package/dist/array/to-map.d.mts +13 -1
  19. package/dist/array/to-map.mjs +1 -1
  20. package/dist/array/to-record.d.mts +13 -1
  21. package/dist/array/to-record.mjs +1 -1
  22. package/dist/function/assert.d.mts +9 -1
  23. package/dist/function/assert.mjs +9 -1
  24. package/dist/function/limit.d.mts +5 -1
  25. package/dist/function/limit.mjs +5 -1
  26. package/dist/function/once.d.mts +3 -1
  27. package/dist/function/once.mjs +3 -1
  28. package/dist/function/retry.d.mts +4 -0
  29. package/dist/function/retry.mjs +2 -0
  30. package/dist/function/work.d.mts +49 -1
  31. package/dist/function/work.mjs +1 -1
  32. package/dist/index.d.mts +415 -242
  33. package/dist/index.mjs +224 -167
  34. package/dist/internal/array/index-of.mjs +1 -1
  35. package/dist/internal/function/timer.mjs +3 -1
  36. package/dist/internal/value/compare.d.mts +13 -9
  37. package/dist/internal/value/compare.mjs +13 -9
  38. package/dist/internal/value/equal.d.mts +29 -15
  39. package/dist/internal/value/equal.mjs +41 -35
  40. package/dist/internal/value/handlers.d.mts +4 -4
  41. package/dist/internal/value/handlers.mjs +19 -11
  42. package/dist/internal/value/has.d.mts +9 -8
  43. package/dist/internal/value/has.mjs +3 -3
  44. package/dist/internal/value/misc.d.mts +4 -8
  45. package/dist/internal/value/misc.mjs +6 -17
  46. package/dist/promise/index.d.mts +11 -1
  47. package/dist/promise/index.mjs +1 -1
  48. package/dist/result/index.d.mts +9 -1
  49. package/dist/result/index.mjs +1 -1
  50. package/dist/result/match.d.mts +5 -1
  51. package/dist/result/match.mjs +1 -1
  52. package/dist/result/misc.d.mts +3 -3
  53. package/dist/result/work/flow.d.mts +49 -1
  54. package/dist/result/work/flow.mjs +1 -1
  55. package/dist/result/work/pipe.d.mts +67 -155
  56. package/dist/result/work/pipe.mjs +3 -3
  57. package/dist/string/fuzzy.d.mts +11 -1
  58. package/dist/string/fuzzy.mjs +22 -6
  59. package/dist/string/template.d.mts +3 -1
  60. package/dist/string/template.mjs +3 -1
  61. package/dist/value/clone.d.mts +13 -9
  62. package/dist/value/clone.mjs +21 -17
  63. package/dist/value/merge.d.mts +9 -7
  64. package/dist/value/merge.mjs +7 -5
  65. package/package.json +3 -3
  66. package/plugin/helpers.js +2 -2
  67. package/src/array/filter.ts +44 -36
  68. package/src/array/first.ts +18 -9
  69. package/src/array/group-by.ts +22 -10
  70. package/src/array/last.ts +17 -5
  71. package/src/array/move.ts +18 -5
  72. package/src/array/reverse.ts +5 -0
  73. package/src/array/select.ts +2 -2
  74. package/src/array/sort.ts +110 -86
  75. package/src/array/swap.ts +2 -0
  76. package/src/array/to-map.ts +22 -10
  77. package/src/array/to-record.ts +22 -10
  78. package/src/function/assert.ts +12 -4
  79. package/src/function/limit.ts +6 -2
  80. package/src/function/once.ts +3 -1
  81. package/src/function/retry.ts +8 -2
  82. package/src/function/work.ts +92 -26
  83. package/src/internal/array/index-of.ts +1 -1
  84. package/src/internal/function/timer.ts +4 -2
  85. package/src/internal/string.ts +2 -0
  86. package/src/internal/value/compare.ts +14 -11
  87. package/src/internal/value/equal.ts +79 -67
  88. package/src/internal/value/handlers.ts +19 -11
  89. package/src/internal/value/has.ts +16 -16
  90. package/src/internal/value/misc.ts +10 -8
  91. package/src/promise/index.ts +14 -4
  92. package/src/result/index.ts +15 -5
  93. package/src/result/match.ts +7 -3
  94. package/src/result/misc.ts +3 -3
  95. package/src/result/work/flow.ts +68 -13
  96. package/src/result/work/pipe.ts +97 -392
  97. package/src/string/fuzzy.ts +34 -8
  98. package/src/string/template.ts +3 -1
  99. package/src/value/clone.ts +25 -22
  100. package/src/value/merge.ts +14 -12
package/dist/index.mjs CHANGED
@@ -92,13 +92,13 @@ const FIND_VALUES_UNIQUE = "unique";
92
92
  const UNIQUE_THRESHOLD = 100;
93
93
  //#endregion
94
94
  //#region src/array/filter.ts
95
+ function exclude(array, ...parameters) {
96
+ return findValues("all", array, parameters).notMatched;
97
+ }
95
98
  function filter(array, ...parameters) {
96
99
  return findValues("all", array, parameters).matched;
97
100
  }
98
- filter.remove = removeFiltered;
99
- function removeFiltered(array, ...parameters) {
100
- return findValues("all", array, parameters).notMatched;
101
- }
101
+ filter.remove = exclude;
102
102
  //#endregion
103
103
  //#region src/array/first.ts
104
104
  function first(array, ...parameters) {
@@ -175,7 +175,7 @@ function compact(array, strict) {
175
175
  //#endregion
176
176
  //#region src/internal/array/index-of.ts
177
177
  function indexOf(array, ...parameters) {
178
- return findValue(FIND_VALUE_INDEX, array, parameters);
178
+ return findValue(FIND_VALUE_INDEX, array, parameters, false);
179
179
  }
180
180
  //#endregion
181
181
  //#region src/internal/is.ts
@@ -582,6 +582,11 @@ function push(array, pushed) {
582
582
  }
583
583
  //#endregion
584
584
  //#region src/array/reverse.ts
585
+ /**
586
+ * Reverse the order of items in an array
587
+ * @param array Array to reverse
588
+ * @returns Reversed array
589
+ */
585
590
  function reverse(array) {
586
591
  if (!Array.isArray(array)) return [];
587
592
  const { length } = array;
@@ -777,6 +782,8 @@ move.toIndex = moveToIndex;
777
782
  * Move an item from one index to another within an array
778
783
  *
779
784
  * If the from index is out of bounds, the array will be returned unchanged
785
+ *
786
+ * Available as `moveIndices` and `move.indices`
780
787
  * @param array Array to move within
781
788
  * @param from Index to move from
782
789
  * @param to Index to move to
@@ -908,20 +915,27 @@ const EXPRESSION_WORDS = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
908
915
  //#endregion
909
916
  //#region src/internal/value/handlers.ts
910
917
  function getCompareHandlers(owner, options) {
911
- const { get, register, unregister } = getHandlers(owner, options);
918
+ const handlers = getHandlers(owner, options);
912
919
  return {
913
- register,
914
- unregister,
920
+ deregister(constructor) {
921
+ handlers.deregister(constructor);
922
+ },
915
923
  handle(first, second, ...parameters) {
916
- const handler = get(first, second);
924
+ const handler = handlers.get(first, second);
917
925
  if (handler == null) return options.callback(first, second, ...parameters);
918
926
  return typeof handler === "function" ? handler(first, second) : first[handler](second);
927
+ },
928
+ register(constructor, handler) {
929
+ handlers.register(constructor, handler);
919
930
  }
920
931
  };
921
932
  }
922
933
  function getHandlers(owner, options) {
923
934
  const handlers = /* @__PURE__ */ new WeakMap();
924
935
  return {
936
+ deregister(constructor) {
937
+ handlers.delete(constructor);
938
+ },
925
939
  get(first, second) {
926
940
  if (isConstructable(first) && isConstructable(second) && first.constructor === second.constructor) return handlers.get(first.constructor);
927
941
  },
@@ -931,21 +945,22 @@ function getHandlers(owner, options) {
931
945
  if (typeof actual !== "function" && typeof actual !== "string") return;
932
946
  if (typeof actual === "string") actual = typeof constructor.prototype[actual] === "function" ? actual : void 0;
933
947
  if (actual != null) handlers.set(constructor, actual);
934
- },
935
- unregister(constructor) {
936
- handlers.delete(constructor);
937
948
  }
938
949
  };
939
950
  }
940
951
  function getSelfHandlers(owner, options) {
941
- const { get, register, unregister } = getHandlers(owner, options);
952
+ const handlers = getHandlers(owner, options);
942
953
  return {
943
- register,
944
- unregister,
954
+ deregister(constructor) {
955
+ handlers.deregister(constructor);
956
+ },
945
957
  handle(value, ...parameters) {
946
- const handler = get(value, value);
958
+ const handler = handlers.get(value, value);
947
959
  if (handler == null) return options.callback(value, ...parameters);
948
960
  return typeof handler === "function" ? handler(value) : value[handler]();
961
+ },
962
+ register(constructor, handler) {
963
+ handlers.register(constructor, handler);
949
964
  }
950
965
  };
951
966
  }
@@ -989,8 +1004,8 @@ compare.handlers = getCompareHandlers(compare, {
989
1004
  },
990
1005
  method: COMPARE_NAME
991
1006
  });
1007
+ compare.deregister = deregisterComparator;
992
1008
  compare.register = registerComparator;
993
- compare.unregister = unregisterComparator;
994
1009
  function compareNumbers(first, second) {
995
1010
  if (Object.is(first, second)) return 0;
996
1011
  if (Number.isNaN(first)) return -1;
@@ -1006,25 +1021,29 @@ function compareValue(first, second, compareStrings) {
1006
1021
  if (first instanceof Date && second instanceof Date) return compareNumbers(first.getTime(), second.getTime());
1007
1022
  return compare.handlers.handle(first, second, compareStrings);
1008
1023
  }
1024
+ /**
1025
+ * Deregister a custom comparison handler for a class
1026
+ *
1027
+ * Available as `deregisterComparator` and `compare.deregister`
1028
+ * @param constructor Class constructor
1029
+ */
1030
+ function deregisterComparator(constructor) {
1031
+ compare.handlers.deregister(constructor);
1032
+ }
1009
1033
  function getComparisonParts(value) {
1010
1034
  if (Array.isArray(value)) return value;
1011
1035
  return typeof value === "object" ? [value] : words(getString(value));
1012
1036
  }
1013
1037
  /**
1014
1038
  * Register a custom comparison handler for a class
1039
+ *
1040
+ * Available as `registerComparator` and `compare.register`
1015
1041
  * @param constructor Class constructor
1016
1042
  * @param handler Method name or comparison function _(defaults to `compare`)_
1017
1043
  */
1018
1044
  function registerComparator(constructor, handler) {
1019
1045
  compare.handlers.register(constructor, handler);
1020
1046
  }
1021
- /**
1022
- * Unregister a custom comparison handler for a class
1023
- * @param constructor Class constructor
1024
- */
1025
- function unregisterComparator(constructor) {
1026
- compare.handlers.unregister(constructor);
1027
- }
1028
1047
  const comparators = {
1029
1048
  bigint: compareNumbers,
1030
1049
  boolean: (first, second) => compareNumbers(first ? 1 : 0, second ? 1 : 0),
@@ -1050,23 +1069,7 @@ function getComparisonValue(first, second, sorters, length) {
1050
1069
  }
1051
1070
  return 0;
1052
1071
  }
1053
- function getIndex(array, item, first, second) {
1054
- return getSortedIndex(array, item, getSorters(first, getModifier(first, second)));
1055
- }
1056
- function getModifier(first, second) {
1057
- return modifiers[first === true || second === true ? SORT_DIRECTION_DESCENDING : SORT_DIRECTION_ASCENDING];
1058
- }
1059
- function getObjectSorter(obj, modifier) {
1060
- let sorter;
1061
- if (typeof obj.comparison === "function") sorter = getComparisonSorter(obj.comparison, modifier);
1062
- else if (typeof obj.key === "string") {
1063
- sorter = getValueSorter(obj.key, modifier);
1064
- if (typeof obj.compare === "function") sorter.compare = { complex: obj.compare };
1065
- } else if (typeof obj.value === "function") sorter = getValueSorter(obj.value, modifier);
1066
- if (sorter != null && typeof obj.direction === "string") sorter.modifier = modifiers[obj.direction] ?? modifier;
1067
- return sorter;
1068
- }
1069
- function getSortedIndex(array, item, sorters) {
1072
+ function getIndex(array, item, sorters) {
1070
1073
  if (!Array.isArray(array)) return -1;
1071
1074
  const { length } = array;
1072
1075
  if (length === 0) return 0;
@@ -1082,6 +1085,22 @@ function getSortedIndex(array, item, sorters) {
1082
1085
  }
1083
1086
  return low;
1084
1087
  }
1088
+ function getModifier(first, second) {
1089
+ return modifiers[first === true || second === true ? SORT_DIRECTION_DESCENDING : SORT_DIRECTION_ASCENDING];
1090
+ }
1091
+ function getObjectSorter(obj, modifier) {
1092
+ let sorter;
1093
+ if (typeof obj.comparison === "function") sorter = getComparisonSorter(obj.comparison, modifier);
1094
+ else if (typeof obj.key === "string") {
1095
+ sorter = getValueSorter(obj.key, modifier);
1096
+ if (typeof obj.compare === "function") sorter.compare = { complex: obj.compare };
1097
+ } else if (typeof obj.value === "function") sorter = getValueSorter(obj.value, modifier);
1098
+ if (sorter != null && typeof obj.direction === "string") sorter.modifier = modifiers[obj.direction] ?? modifier;
1099
+ return sorter;
1100
+ }
1101
+ function getSortedIndex(array, item, first, second) {
1102
+ return getIndex(array, item, getSorters(first, getModifier(first, second)));
1103
+ }
1085
1104
  function getSorter(value, modifier) {
1086
1105
  switch (true) {
1087
1106
  case typeof value === "function": return getComparisonSorter(value, modifier);
@@ -1114,10 +1133,10 @@ function getValueSorter(value, modifier) {
1114
1133
  value: typeof value === "function" ? value : (item) => item[value]
1115
1134
  };
1116
1135
  }
1117
- function initializeSort(first, second) {
1136
+ function initializeSorter(first, second) {
1118
1137
  const sorters = getSorters(first, getModifier(first, second));
1119
1138
  const sorter = (array) => sortArray(array, sorters);
1120
- sorter.index = (array, item) => getSortedIndex(array, item, sorters);
1139
+ sorter.index = (array, item) => getIndex(array, item, sorters);
1121
1140
  sorter.is = (array) => isSortedArray(array, sorters);
1122
1141
  return sorter;
1123
1142
  }
@@ -1156,8 +1175,8 @@ function sortArray(array, sorters) {
1156
1175
  const { length } = sorters;
1157
1176
  return array.length > 1 ? array.sort((first, second) => getComparisonValue(first, second, sorters, length)) : array;
1158
1177
  }
1159
- sort.index = getIndex;
1160
- sort.initialize = initializeSort;
1178
+ sort.index = getSortedIndex;
1179
+ sort.initialize = initializeSorter;
1161
1180
  sort.is = isSorted;
1162
1181
  const ARRAY_PEEK_PERCENTAGE$1 = 10;
1163
1182
  const ARRAY_THRESHOLD$1 = 100;
@@ -1198,6 +1217,8 @@ function swapArrays(array, from, to, key) {
1198
1217
  * Swap two indiced items in an array
1199
1218
  *
1200
1219
  * If either index is out of bounds, the array will be returned unchanged
1220
+ *
1221
+ * Available as `swapIndices` and `swap.indices`
1201
1222
  * @param array Array of items to swap
1202
1223
  * @param first First index _(can be negative to count from the end)_
1203
1224
  * @param second Second index _(can be negative to count from the end)_
@@ -1273,6 +1294,8 @@ assert.instanceOf = assertInstanceOf;
1273
1294
  assert.is = assertIs;
1274
1295
  /**
1275
1296
  * Creates an asserter that asserts a condition is true, throwing an error if it is not
1297
+ *
1298
+ * Available as `assertCondition` and `assert.condition`
1276
1299
  * @param condition Condition to assert
1277
1300
  * @param message Error message
1278
1301
  * @param error Error constructor
@@ -1285,6 +1308,8 @@ function assertCondition(condition, message, error) {
1285
1308
  }
1286
1309
  /**
1287
1310
  * Asserts that a value is defined throwing an error if it is not
1311
+ *
1312
+ * Available as `assertDefined` and `assert.defined`
1288
1313
  * @param value Value to assert
1289
1314
  * @param message Error message
1290
1315
  */
@@ -1293,6 +1318,8 @@ function assertDefined(value, message) {
1293
1318
  }
1294
1319
  /**
1295
1320
  * Creates an asserter that asserts a value is an instance of a constructor, throwing an error if it is not
1321
+ *
1322
+ * Available as `assertInstanceOf` and `assert.instanceOf`
1296
1323
  * @param constructor Constructor to check against
1297
1324
  * @param message Error message
1298
1325
  * @param error Error constructor
@@ -1305,6 +1332,8 @@ function assertInstanceOf(constructor, message, error) {
1305
1332
  }
1306
1333
  /**
1307
1334
  * Creates an asserter that asserts a value is of a specific type, throwing an error if it is not
1335
+ *
1336
+ * Available as `assertIs` and `assert.is`
1308
1337
  * @param condition Type guard function to check the value
1309
1338
  * @param message Error message
1310
1339
  * @param error Error constructor
@@ -1578,7 +1607,9 @@ function getAsyncTimer(type, callback, time) {
1578
1607
  });
1579
1608
  last = next;
1580
1609
  if (throttle) run(next);
1581
- else id = startTimer(() => run(next));
1610
+ else id = startTimer(() => {
1611
+ run(next);
1612
+ });
1582
1613
  return next.promise;
1583
1614
  };
1584
1615
  timer.cancel = () => {
@@ -1631,6 +1662,8 @@ const startTimer = typeof requestAnimationFrame === "function" ? requestAnimatio
1631
1662
  * When called, successful _(finished)_ results will resolve and errors will reject.
1632
1663
  *
1633
1664
  * On subsequent calls, existing calls will be canceled _(rejected)_, the timer reset, and will wait another `time` milliseconds before the new call is made _(and so on...)_
1665
+ *
1666
+ * Available as `asyncDebounce` and `debounce.async`
1634
1667
  * @param callback Callback to debounce
1635
1668
  * @param time Time in milliseconds to wait before calling the callback _(defaults to `0`; e.g., as soon as possible)_
1636
1669
  * @returns Debounced callback handler with a `cancel` method
@@ -1644,6 +1677,8 @@ function asyncDebounce(callback, time) {
1644
1677
  * When called, successful _(finished)_ results will resolve and errors will reject.
1645
1678
  *
1646
1679
  * 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...)_
1680
+ *
1681
+ * Available as `asyncThrottle` and `throttle.async`
1647
1682
  * @param callback Callback to throttle
1648
1683
  * @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_
1649
1684
  * @returns Throttled callback handler with a `cancel` method
@@ -1677,6 +1712,8 @@ throttle.async = asyncThrottle;
1677
1712
  //#region src/function/once.ts
1678
1713
  /**
1679
1714
  * Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls
1715
+ *
1716
+ * Available as `asyncOnce` and `once.async`
1680
1717
  * @param callback Callback to use once
1681
1718
  * @returns Once callback
1682
1719
  */
@@ -1781,6 +1818,8 @@ var RetryError = class extends Error {
1781
1818
  };
1782
1819
  /**
1783
1820
  * Retry a callback a specified number of times, with a delay between attempts
1821
+ *
1822
+ * Available as `asyncRetry` and `retry.async`
1784
1823
  * @param callback Callback to retry
1785
1824
  * @param options Retry options
1786
1825
  * @returns Callback result
@@ -1937,13 +1976,28 @@ const assertFlowFunctions = assert.condition((value) => Array.isArray(value) &&
1937
1976
  const assertPipeFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), MESSAGE_PIPE_ARRAY, TypeError);
1938
1977
  //#endregion
1939
1978
  //#region src/internal/value/equal.ts
1979
+ /**
1980
+ * Deregister a equality comparison handler for a specific class
1981
+ *
1982
+ * Available as `deregisterEqualizer` and `equal.deregister`
1983
+ * @param constructor Class constructor
1984
+ */
1985
+ function deregisterEqualizer(constructor) {
1986
+ equal.handlers.deregister(constructor);
1987
+ }
1988
+ function filterKey(key, options) {
1989
+ if (typeof key !== "string") return true;
1990
+ if (options.ignoreExpressions.enabled && options.ignoreExpressions.values.some((expression) => expression.test(key))) return false;
1991
+ if (options.ignoreKeys.enabled && options.ignoreKeys.values.has(key)) return false;
1992
+ return true;
1993
+ }
1940
1994
  function equal(first, second, options) {
1941
1995
  return equalValue(first, second, getEqualOptions(options));
1942
1996
  }
1943
1997
  equal.handlers = getCompareHandlers(equal, { callback: Object.is });
1998
+ equal.deregister = deregisterEqualizer;
1944
1999
  equal.initialize = initializeEqualizer;
1945
2000
  equal.register = registerEqualizer;
1946
- equal.unregister = unregisterEqualizer;
1947
2001
  function equalArray(first, second, options) {
1948
2002
  const { length } = first;
1949
2003
  if (length !== second.length) return false;
@@ -2035,39 +2089,6 @@ function equalValue(first, second, options) {
2035
2089
  default: return equal.handlers.handle(first, second, options);
2036
2090
  }
2037
2091
  }
2038
- /**
2039
- * Create an equalizer with predefined options
2040
- * @param options Comparison options
2041
- * @returns Equalizer function
2042
- */
2043
- function initializeEqualizer(options) {
2044
- const actual = getEqualOptions(options);
2045
- const equalizer = (first, second) => equalValue(first, second, actual);
2046
- equalizer.register = registerEqualizer;
2047
- equalizer.unregister = unregisterEqualizer;
2048
- return equalizer;
2049
- }
2050
- /**
2051
- * Register a equality comparison function for a specific class
2052
- * @param constructor Class constructor
2053
- * @param fn Comparison function
2054
- */
2055
- function registerEqualizer(constructor, handler) {
2056
- equal.handlers.register(constructor, handler);
2057
- }
2058
- /**
2059
- * Unregister a equality comparison handler for a specific class
2060
- * @param constructor Class constructor
2061
- */
2062
- function unregisterEqualizer(constructor) {
2063
- equal.handlers.unregister(constructor);
2064
- }
2065
- function filterKey(key, options) {
2066
- if (typeof key !== "string") return true;
2067
- if (options.ignoreExpressions.enabled && options.ignoreExpressions.values.some((expression) => expression.test(key))) return false;
2068
- if (options.ignoreKeys.enabled && options.ignoreKeys.values.has(key)) return false;
2069
- return true;
2070
- }
2071
2092
  function getEqualOptions(input) {
2072
2093
  const options = {
2073
2094
  ignoreCase: false,
@@ -2094,12 +2115,76 @@ function getEqualOptions(input) {
2094
2115
  options.relaxedNullish = input.relaxedNullish === true;
2095
2116
  return options;
2096
2117
  }
2118
+ /**
2119
+ * Create an equalizer with predefined options
2120
+ *
2121
+ * Available as `initializeEqualizer` and `equal.initialize`
2122
+ * @param options Comparison options
2123
+ * @returns Equalizer function
2124
+ */
2125
+ function initializeEqualizer(options) {
2126
+ const actual = getEqualOptions(options);
2127
+ const equalizer = (first, second) => equalValue(first, second, actual);
2128
+ equalizer.deregister = deregisterEqualizer;
2129
+ equalizer.register = registerEqualizer;
2130
+ return equalizer;
2131
+ }
2132
+ /**
2133
+ * Register a equality comparison function for a specific class
2134
+ *
2135
+ * Available as `registerEqualizer` and `equal.register`
2136
+ * @param constructor Class constructor
2137
+ * @param handler Comparison function
2138
+ */
2139
+ function registerEqualizer(constructor, handler) {
2140
+ equal.handlers.register(constructor, handler);
2141
+ }
2097
2142
  const ARRAY_PEEK_PERCENTAGE = 10;
2098
2143
  const ARRAY_THRESHOLD = 100;
2099
2144
  const ERROR_PROPERTIES = ["name", "message"];
2100
2145
  const EXPRESSION_PROPERTIES = ["source", "flags"];
2101
2146
  const MINIMUM_LENGTH_FOR_SET = 16;
2102
2147
  //#endregion
2148
+ //#region src/result/misc.ts
2149
+ function error(value, original) {
2150
+ return getError(value, original);
2151
+ }
2152
+ function getError(value, original) {
2153
+ const errorResult = {
2154
+ error: value,
2155
+ ok: false
2156
+ };
2157
+ if (original instanceof Error) errorResult.original = original;
2158
+ return errorResult;
2159
+ }
2160
+ /**
2161
+ * Creates an ok result
2162
+ * @param value Value
2163
+ * @returns Ok result
2164
+ */
2165
+ function ok(value) {
2166
+ return {
2167
+ ok: true,
2168
+ value
2169
+ };
2170
+ }
2171
+ /**
2172
+ * Converts a result to a promise
2173
+ *
2174
+ * Resolves if ok, rejects for error
2175
+ * @param result Result to convert
2176
+ * @returns Promised result
2177
+ */
2178
+ async function toPromise(result) {
2179
+ const actual = typeof result === "function" ? result() : result;
2180
+ if (!isResult(actual)) return Promise.reject(new Error(MESSAGE_PROMISE_RESULT));
2181
+ return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
2182
+ }
2183
+ function unwrap(value, defaultValue) {
2184
+ return isOk(value) ? value.value : defaultValue;
2185
+ }
2186
+ const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
2187
+ //#endregion
2103
2188
  //#region src/internal/value/misc.ts
2104
2189
  function findKey(needle, haystack) {
2105
2190
  const keys = Object.keys(haystack);
@@ -2107,10 +2192,7 @@ function findKey(needle, haystack) {
2107
2192
  return index > -1 ? keys[index] : needle;
2108
2193
  }
2109
2194
  function getNestedValue(data, path, ignoreCase) {
2110
- if (typeof data !== "object" || data === null || typeof path !== "string" || path.trim().length === 0) return {
2111
- exists: false,
2112
- value: void 0
2113
- };
2195
+ if (typeof data !== "object" || data === null || typeof path !== "string" || path.trim().length === 0) return error(void 0);
2114
2196
  const shouldIgnoreCase = ignoreCase === true;
2115
2197
  const paths = getPaths(path, shouldIgnoreCase);
2116
2198
  if (typeof paths === "string") return handleValue(data, paths, null, true, shouldIgnoreCase);
@@ -2119,13 +2201,10 @@ function getNestedValue(data, path, ignoreCase) {
2119
2201
  for (let index = 0; index < length; index += 1) {
2120
2202
  const part = paths[index];
2121
2203
  const handled = handleValue(current, part, null, true, shouldIgnoreCase);
2122
- if (!handled.exists) return handled;
2204
+ if (!handled.ok) return handled;
2123
2205
  current = handled.value;
2124
2206
  }
2125
- return {
2126
- exists: true,
2127
- value: current
2128
- };
2207
+ return ok(current);
2129
2208
  }
2130
2209
  function getPaths(path, lowercase) {
2131
2210
  const normalized = lowercase ? path.toLowerCase() : path;
@@ -2135,16 +2214,10 @@ function getPaths(path, lowercase) {
2135
2214
  function handleValue(data, path, value, get, ignoreCase) {
2136
2215
  if (typeof data === "object" && data !== null && !ignoreKey(path)) {
2137
2216
  const key = ignoreCase ? findKey(path, data) : path;
2138
- if (get) return {
2139
- exists: key in data,
2140
- value: data[key]
2141
- };
2217
+ if (get) return key in data ? ok(data[key]) : error(void 0);
2142
2218
  data[key] = typeof value === "function" ? value(data[key]) : value;
2143
2219
  }
2144
- if (get) return {
2145
- exists: false,
2146
- value: void 0
2147
- };
2220
+ if (get) return error(void 0);
2148
2221
  }
2149
2222
  const EXPRESSION_BRACKET = /\[(\w+)\]/g;
2150
2223
  const EXPRESSION_DOTS = /^\.|\.$/g;
@@ -2157,10 +2230,10 @@ function getValue(data, path, ignoreCase) {
2157
2230
  //#endregion
2158
2231
  //#region src/internal/value/has.ts
2159
2232
  function hasValue(data, path, ignoreCase) {
2160
- return getNestedValue(data, path, ignoreCase === true).exists;
2233
+ return getNestedValue(data, path, ignoreCase === true).ok;
2161
2234
  }
2162
- hasValue.get = getWithHasValue;
2163
- function getWithHasValue(data, path, ignoreCase) {
2235
+ hasValue.get = hasValueResult;
2236
+ function hasValueResult(data, path, ignoreCase) {
2164
2237
  return getNestedValue(data, path, ignoreCase === true);
2165
2238
  }
2166
2239
  //#endregion
@@ -2495,7 +2568,7 @@ var Fuzzy = class {
2495
2568
  this.#state = state;
2496
2569
  }
2497
2570
  search(value, options) {
2498
- return search(this.#state.items, this.#state.strings, value, options == null ? this.#state : getOptions$1(options, this.#state));
2571
+ return search(this.#state.items, this.#state.strings, value, options == null ? this.#state : getFuzzyOptions(options, this.#state));
2499
2572
  }
2500
2573
  };
2501
2574
  function getHandler(input) {
@@ -2511,18 +2584,17 @@ function getHandler(input) {
2511
2584
  function getItems(items) {
2512
2585
  return items.sort((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
2513
2586
  }
2514
- function getOptions$1(input, state) {
2587
+ function getFuzzyOptions(input, state) {
2515
2588
  const options = isPlainObject(input) ? input : {};
2516
2589
  const limit = typeof input === "number" ? input : options.limit;
2517
2590
  if (typeof limit === "number" && !Number.isNaN(limit) && limit >= 1) options.limit = Math.floor(limit);
2518
2591
  else options.limit = state?.limit;
2519
- if (typeof options.tolerance === "number" && !Number.isNaN(options.tolerance)) options.tolerance = options.tolerance < 0 ? 0 : Math.floor(options.tolerance);
2520
- else options.tolerance = state?.tolerance ?? PROXIMITY_THRESHOLD;
2592
+ options.tolerance = getTolerance(options.tolerance, state);
2521
2593
  return options;
2522
2594
  }
2523
2595
  function getState$1(items, input) {
2524
2596
  const handler = getHandler(input);
2525
- const options = getOptions$1(input);
2597
+ const options = getFuzzyOptions(input);
2526
2598
  return {
2527
2599
  handler,
2528
2600
  items: items.slice(),
@@ -2531,10 +2603,27 @@ function getState$1(items, input) {
2531
2603
  tolerance: options.tolerance
2532
2604
  };
2533
2605
  }
2606
+ function getTolerance(input, state) {
2607
+ if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : Math.floor(input);
2608
+ return state?.tolerance ?? PROXIMITY_THRESHOLD;
2609
+ }
2534
2610
  function fuzzy(items, configuration) {
2535
2611
  if (!Array.isArray(items)) throw new TypeError(MESSAGE_ARRAY);
2536
2612
  return new Fuzzy(getState$1(items, configuration));
2537
2613
  }
2614
+ fuzzy.match = fuzzyMatch;
2615
+ /**
2616
+ * Does the needle match the haystack in a fuzzy way?
2617
+ * @param haystack Haystack to search through
2618
+ * @param needle Needle to search for
2619
+ * @returns `true` if the needle matches the haystack in a fuzzy way, `false` otherwise
2620
+ */
2621
+ function fuzzyMatch(haystack, needle) {
2622
+ if (typeof haystack !== "string" || typeof needle !== "string") return false;
2623
+ const trimmed = needle.trim();
2624
+ if (includes(haystack, trimmed, true)) return true;
2625
+ return getScore(haystack, trimmed) > -1;
2626
+ }
2538
2627
  function isSubsequence(haystack, needle) {
2539
2628
  const lowerCaseHaystack = lowerCase(haystack);
2540
2629
  const lowerCaseNeedle = lowerCase(needle);
@@ -2734,6 +2823,8 @@ function handleTemplate(value, pattern, ignoreCase, variables) {
2734
2823
  }
2735
2824
  /**
2736
2825
  * Create a templater with predefined options
2826
+ *
2827
+ * Available as `initializeTemplater` and `template.initialize`
2737
2828
  * @param options Templating options
2738
2829
  * @returns Templater function
2739
2830
  */
@@ -2766,23 +2857,8 @@ clone.handlers = getSelfHandlers(clone, {
2766
2857
  callback: tryStructuredClone,
2767
2858
  method: CLONE_NAME
2768
2859
  });
2860
+ clone.deregister = deregisterCloner;
2769
2861
  clone.register = registerCloner;
2770
- clone.unregister = unregisterCloner;
2771
- /**
2772
- * Register a clone handler for a specific class
2773
- * @param constructor Class constructor
2774
- * @param handler Method name or clone function _(defaults to `clone`)_
2775
- */
2776
- function registerCloner(constructor, handler) {
2777
- clone.handlers.register(constructor, handler);
2778
- }
2779
- /**
2780
- * Unregister a clone handler for a specific class
2781
- * @param constructor Class constructor
2782
- */
2783
- function unregisterCloner(constructor) {
2784
- clone.handlers.unregister(constructor);
2785
- }
2786
2862
  function cloneArrayBuffer(value, depth, references) {
2787
2863
  if (typeof depth === "number" && depth >= MAX_CLONE_DEPTH) return value;
2788
2864
  const cloned = new ArrayBuffer(value.byteLength);
@@ -2867,6 +2943,25 @@ function cloneValue(value, depth, references) {
2867
2943
  default: return clone.handlers.handle(value, depth, references);
2868
2944
  }
2869
2945
  }
2946
+ /**
2947
+ * Deregister a clone handler for a specific class
2948
+ *
2949
+ * Available as `deregisterCloner` and `template.deregister`
2950
+ * @param constructor Class constructor
2951
+ */
2952
+ function deregisterCloner(constructor) {
2953
+ clone.handlers.deregister(constructor);
2954
+ }
2955
+ /**
2956
+ * Register a clone handler for a specific class
2957
+ *
2958
+ * Available as `registerCloner` and `template.register`
2959
+ * @param constructor Class constructor
2960
+ * @param handler Method name or clone function _(defaults to `clone`)_
2961
+ */
2962
+ function registerCloner(constructor, handler) {
2963
+ clone.handlers.register(constructor, handler);
2964
+ }
2870
2965
  function tryStructuredClone(value, depth, references) {
2871
2966
  if (depth >= MAX_CLONE_DEPTH) return value;
2872
2967
  try {
@@ -3128,12 +3223,10 @@ function getReplaceableObjects(value) {
3128
3223
  function handleMerge(values, options) {
3129
3224
  return !Array.isArray(values) || values.length === 0 ? {} : mergeValues(values, options, true);
3130
3225
  }
3131
- function merge(values, options) {
3132
- return handleMerge(values, getMergeOptions(options));
3133
- }
3134
- merge.initialize = initializeMerger;
3135
3226
  /**
3136
3227
  * Create a merger with predefined options
3228
+ *
3229
+ * Available as `initializeMerger` and `merge.initialize`
3137
3230
  * @param options Merging options
3138
3231
  * @returns Merger function
3139
3232
  */
@@ -3141,6 +3234,10 @@ function initializeMerger(options) {
3141
3234
  const actual = getMergeOptions(options);
3142
3235
  return (values) => handleMerge(values, actual);
3143
3236
  }
3237
+ function merge(values, options) {
3238
+ return handleMerge(values, getMergeOptions(options));
3239
+ }
3240
+ merge.initialize = initializeMerger;
3144
3241
  function mergeObjects(values, options, prefix) {
3145
3242
  const { length } = values;
3146
3243
  const isArray = values.every(Array.isArray);
@@ -4187,46 +4284,6 @@ function sum(array, key) {
4187
4284
  return getAggregated("sum", array, key);
4188
4285
  }
4189
4286
  //#endregion
4190
- //#region src/result/misc.ts
4191
- function error(value, original) {
4192
- return getError(value, original);
4193
- }
4194
- function getError(value, original) {
4195
- const errorResult = {
4196
- error: value,
4197
- ok: false
4198
- };
4199
- if (original instanceof Error) errorResult.original = original;
4200
- return errorResult;
4201
- }
4202
- /**
4203
- * Creates an ok result
4204
- * @param value Value
4205
- * @returns Ok result
4206
- */
4207
- function ok(value) {
4208
- return {
4209
- ok: true,
4210
- value
4211
- };
4212
- }
4213
- /**
4214
- * Converts a result to a promise
4215
- *
4216
- * Resolves if ok, rejects for error
4217
- * @param result Result to convert
4218
- * @returns Promised result
4219
- */
4220
- async function toPromise(result) {
4221
- const actual = typeof result === "function" ? result() : result;
4222
- if (!isResult(actual)) return Promise.reject(new Error(MESSAGE_PROMISE_RESULT));
4223
- return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
4224
- }
4225
- function unwrap(value, defaultValue) {
4226
- return isOk(value) ? value.value : defaultValue;
4227
- }
4228
- const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
4229
- //#endregion
4230
4287
  //#region src/promise/models.ts
4231
4288
  var CancelablePromise = class extends Promise {
4232
4289
  #rejector;
@@ -4870,7 +4927,7 @@ async function attemptAsyncPipe(initial, first, ...seconds) {
4870
4927
  if (isError(initial)) throw initial.error;
4871
4928
  const value = typeof initial === "function" ? initial() : isOk(initial) ? initial.value : initial;
4872
4929
  if (first == null) return value;
4873
- return pipe.async(value, ...[first, ...seconds]);
4930
+ return asyncPipe(value, ...[first, ...seconds]);
4874
4931
  });
4875
4932
  }
4876
4933
  function attemptPipe(initial, first, ...seconds) {
@@ -4960,4 +5017,4 @@ var SizedSet = class extends Set {
4960
5017
  }
4961
5018
  };
4962
5019
  //#endregion
4963
- export { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, attempt, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, dedent, delay, diff, difference, drop, endsWith, endsWithArray, equal, error, exists, filter, find, first, flatten, floor, flow, fromQuery, toPromise as fromResult, toPromise, fuzzy, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getTimedPromise, getUuid, getValue, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, last, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
5020
+ export { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, first, firstOrDefault, flatten, floor, flow, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeEqualizer, initializeMerger, initializeSorter, initializeTemplater, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kebabCase, last, lastOrDefault, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };