@oscarpalmer/atoms 0.205.0 → 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 (40) hide show
  1. package/dist/array/reverse.mjs +2 -1
  2. package/dist/array/single.d.mts +3 -3
  3. package/dist/array/sort.mjs +3 -2
  4. package/dist/color/misc/alpha.mjs +1 -1
  5. package/dist/color/misc/get.mjs +1 -1
  6. package/dist/color/space/hsl.mjs +7 -2
  7. package/dist/color/space/hwb.mjs +2 -1
  8. package/dist/color/space/rgb.mjs +22 -13
  9. package/dist/function/retry.mjs +12 -14
  10. package/dist/index.d.mts +53 -53
  11. package/dist/index.mjs +258 -258
  12. package/dist/internal/array/insert.mjs +2 -1
  13. package/dist/internal/function/limit.mjs +9 -9
  14. package/dist/internal/math/aggregate.d.mts +41 -0
  15. package/dist/internal/math/aggregate.mjs +4 -1
  16. package/dist/internal/math/misc.d.mts +8 -0
  17. package/dist/internal/math/misc.mjs +11 -1
  18. package/dist/internal/random.mjs +2 -1
  19. package/dist/internal/result/attempt.d.mts +59 -0
  20. package/dist/internal/result/attempt.mjs +24 -0
  21. package/dist/internal/string/misc.mjs +4 -5
  22. package/dist/internal/value/equal.mjs +2 -1
  23. package/dist/internal/value/misc.mjs +1 -1
  24. package/dist/math.d.mts +3 -52
  25. package/dist/math.mjs +3 -16
  26. package/dist/promise/constants.d.mts +0 -1
  27. package/dist/promise/constants.mjs +1 -2
  28. package/dist/promise/helpers.mjs +1 -1
  29. package/dist/promise/index.mjs +9 -9
  30. package/dist/promise/misc.mjs +1 -1
  31. package/dist/queue.mjs +11 -6
  32. package/dist/result/index.d.mts +2 -59
  33. package/dist/result/index.mjs +1 -23
  34. package/dist/result/work/flow.mjs +2 -1
  35. package/dist/result/work/pipe.mjs +2 -1
  36. package/dist/string/fuzzy.mjs +7 -5
  37. package/dist/string/index.mjs +2 -1
  38. package/dist/value/clone.mjs +5 -8
  39. package/dist/value/diff.mjs +3 -2
  40. package/package.json +1 -1
@@ -1,4 +1,6 @@
1
1
  import { isPlainObject } from "../internal/is.mjs";
2
+ import { floor } from "../internal/math/misc.mjs";
3
+ import { max } from "../internal/math/aggregate.mjs";
2
4
  import { getString } from "../internal/string/misc.mjs";
3
5
  import { lowerCase } from "../internal/string/case.mjs";
4
6
  import { includes } from "./match.mjs";
@@ -27,7 +29,7 @@ function createFuzzyItems(items) {
27
29
  function createFuzzyOptions(input, state) {
28
30
  const options = isPlainObject(input) ? input : {};
29
31
  const limit = typeof input === "number" ? input : options.limit;
30
- if (typeof limit === "number" && !Number.isNaN(limit) && limit >= 1) options.limit = Math.floor(limit);
32
+ if (typeof limit === "number" && !Number.isNaN(limit) && limit >= 1) options.limit = floor(limit);
31
33
  else options.limit = state?.limit;
32
34
  options.tolerance = getTolerance(options.tolerance, state);
33
35
  return options;
@@ -92,18 +94,18 @@ function getScore(haystack, needle) {
92
94
  if (haystackIndex === 0) score += 1;
93
95
  if (previousMatchIndex !== -1) {
94
96
  const gap = haystackIndex - previousMatchIndex - 1;
95
- score += Math.max(0, FUZZY_PROXIMITY_THRESHOLD - gap);
97
+ score += max([0, FUZZY_PROXIMITY_THRESHOLD - gap]);
96
98
  }
97
99
  previousMatchIndex = haystackIndex;
98
100
  needleIndex += 1;
99
101
  }
100
102
  if (needleIndex === needleLength) break;
101
103
  }
102
- score -= Math.floor(lowerCaseHaystack.length / FUZZY_LENGTH_DIVISOR);
103
- return Math.max(0, score);
104
+ score -= floor(lowerCaseHaystack.length / FUZZY_LENGTH_DIVISOR);
105
+ return max([0, score]);
104
106
  }
105
107
  function getTolerance(input, state) {
106
- if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : Math.floor(input);
108
+ if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : floor(input);
107
109
  return state?.tolerance ?? FUZZY_PROXIMITY_THRESHOLD;
108
110
  }
109
111
  /**
@@ -1,4 +1,5 @@
1
1
  import { isTemplateStringsArray } from "../internal/is.mjs";
2
+ import { min } from "../internal/math/aggregate.mjs";
2
3
  import { getString, interpolate, join, words } from "../internal/string/misc.mjs";
3
4
  //#region src/string/index.ts
4
5
  function dedent(value, ...values) {
@@ -16,7 +17,7 @@ function dedent(value, ...values) {
16
17
  if (indentation != null) lengths.push(indentation.length);
17
18
  }
18
19
  if (lengths.length === 0) return actual.trim();
19
- const minimum = Math.min(...lengths);
20
+ const minimum = min(lengths);
20
21
  const pattern = new RegExp(`^\\s{0,${minimum}}`);
21
22
  let result = "";
22
23
  for (let index = 0; index < length; index += 1) {
@@ -1,4 +1,6 @@
1
1
  import { isArrayOrPlainObject, isTypedArray } from "../internal/is.mjs";
2
+ import { unwrap } from "../internal/result/misc.mjs";
3
+ import { attempt } from "../internal/result/attempt.mjs";
2
4
  import { createValueHandler } from "../internal/value/handlers.mjs";
3
5
  //#region src/value/clone.ts
4
6
  const CLONE_NAME = "clone";
@@ -154,14 +156,9 @@ function registerCloner(constructor, handler) {
154
156
  }
155
157
  function tryStructuredClone(value, parameters, depth) {
156
158
  if (depth >= CLONE_MAX_DEPTH) return value;
157
- try {
158
- const cloned = structuredClone(value);
159
- parameters.references.set(value, cloned);
160
- return cloned;
161
- } catch {
162
- parameters.references.set(value, value);
163
- return value;
164
- }
159
+ const cloned = unwrap(attempt(() => structuredClone(value)), value);
160
+ parameters.references.set(value, cloned);
161
+ return cloned;
165
162
  }
166
163
  const CLONE_COPY_OPTIONS = {
167
164
  copyFunctions: true,
@@ -1,4 +1,5 @@
1
1
  import { isArrayOrPlainObject } from "../internal/is.mjs";
2
+ import { max, min } from "../internal/math/aggregate.mjs";
2
3
  import { join } from "../internal/string/misc.mjs";
3
4
  import { equal } from "../internal/value/equal.mjs";
4
5
  //#region src/value/diff.ts
@@ -70,8 +71,8 @@ function getChanges(changes, first, second, options, prefix) {
70
71
  function getDiffs(first, second, options, prefix) {
71
72
  const changes = [];
72
73
  if (Array.isArray(first) && Array.isArray(second)) {
73
- const maximumLength = Math.max(first.length, second.length);
74
- const minimumLength = Math.min(first.length, second.length);
74
+ const maximumLength = max([first.length, second.length]);
75
+ const minimumLength = min([first.length, second.length]);
75
76
  for (let index = minimumLength; index < maximumLength; index += 1) {
76
77
  const key = join([prefix, index], ".");
77
78
  changes.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oscarpalmer/atoms",
3
- "version": "0.205.0",
3
+ "version": "0.206.0",
4
4
  "description": "Atomic utilities for making your JavaScript better.",
5
5
  "keywords": [
6
6
  "array",