@oscarpalmer/atoms 0.216.0 → 0.218.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 (77) hide show
  1. package/dist/array/insert.mjs +1 -1
  2. package/dist/array/slice.mjs +27 -14
  3. package/dist/array/sort.mjs +2 -1
  4. package/dist/array/swap.d.mts +2 -1
  5. package/dist/color/constants.d.mts +2 -1
  6. package/dist/color/misc/get.mjs +3 -1
  7. package/dist/color/space/hex.mjs +1 -1
  8. package/dist/color/space/rgb.d.mts +1 -0
  9. package/dist/function/index.mjs +1 -2
  10. package/dist/function/retry.d.mts +1 -1
  11. package/dist/function/retry.mjs +5 -2
  12. package/dist/herald.mjs +1 -2
  13. package/dist/index.d.mts +335 -113
  14. package/dist/index.mjs +483 -241
  15. package/dist/internal/array/find.mjs +57 -34
  16. package/dist/internal/array/insert.mjs +1 -1
  17. package/dist/internal/array/match.mjs +21 -17
  18. package/dist/internal/array/sets.mjs +7 -1
  19. package/dist/internal/math/aggregate.mjs +4 -1
  20. package/dist/internal/number.d.mts +1 -1
  21. package/dist/internal/number.mjs +4 -2
  22. package/dist/internal/plan/index.d.mts +7 -0
  23. package/dist/internal/plan/index.mjs +18 -0
  24. package/dist/{plan/generate.d.mts → internal/plan/plan.generate.d.mts} +2 -2
  25. package/dist/{plan/generate.mjs → internal/plan/plan.generate.mjs} +7 -7
  26. package/dist/internal/random.d.mts +6 -0
  27. package/dist/internal/random.mjs +13 -2
  28. package/dist/internal/result/attempt.mjs +4 -4
  29. package/dist/internal/string/misc.mjs +2 -1
  30. package/dist/internal/subscription.mjs +1 -1
  31. package/dist/internal/value/equal.mjs +2 -1
  32. package/dist/internal/value/partial.mjs +3 -1
  33. package/dist/models/color.model.d.mts +2 -1
  34. package/dist/models/function/once.model.d.mts +2 -1
  35. package/dist/models/index.d.mts +2 -1
  36. package/dist/models/plan.model.d.mts +160 -29
  37. package/dist/models/plan.model.mjs +15 -5
  38. package/dist/models/queue.model.d.mts +2 -1
  39. package/dist/models/result.model.d.mts +2 -1
  40. package/dist/models/string/string.fuzzy.model.d.mts +1 -1
  41. package/dist/models/string/string.misc.model.mjs +1 -1
  42. package/dist/models/value/value.equal.model.d.mts +2 -1
  43. package/dist/models/value/value.merge.model.d.mts +3 -2
  44. package/dist/models/value/value.misc.model.d.mts +2 -1
  45. package/dist/number.mjs +1 -2
  46. package/dist/plan/index.d.mts +1 -4
  47. package/dist/plan/index.mjs +14 -15
  48. package/dist/plan/is.d.mts +59 -3
  49. package/dist/plan/is.mjs +82 -10
  50. package/dist/plan/misc.d.mts +51 -3
  51. package/dist/plan/misc.mjs +47 -30
  52. package/dist/plan/models.d.mts +2 -2
  53. package/dist/plan/result.d.mts +15 -3
  54. package/dist/plan/result.mjs +5 -11
  55. package/dist/plan/run.d.mts +1 -3
  56. package/dist/plan/run.mjs +5 -11
  57. package/dist/plan/use.d.mts +36 -0
  58. package/dist/plan/use.mjs +69 -0
  59. package/dist/promise/index.d.mts +6 -4
  60. package/dist/promise/index.mjs +4 -4
  61. package/dist/promise/misc.mjs +5 -2
  62. package/dist/promise/models.mjs +1 -2
  63. package/dist/promise/timed.mjs +2 -2
  64. package/dist/queue.mjs +4 -5
  65. package/dist/random.d.mts +2 -2
  66. package/dist/random.mjs +3 -3
  67. package/dist/result/index.mjs +1 -2
  68. package/dist/result/match.mjs +2 -2
  69. package/dist/result/misc.mjs +3 -10
  70. package/dist/result/work/pipe.d.mts +26 -23
  71. package/dist/result/work/pipe.mjs +7 -3
  72. package/dist/string/fuzzy.mjs +1 -1
  73. package/dist/string/index.mjs +1 -1
  74. package/dist/subscription.mjs +1 -2
  75. package/dist/value/clone.mjs +1 -1
  76. package/dist/value/merge.mjs +17 -4
  77. package/package.json +8 -10
@@ -2,7 +2,7 @@ import { ARRAY_INSERT_TYPE_INSERT } from "../models/array/array.misc.model.mjs";
2
2
  import { insertValues } from "../internal/array/insert.mjs";
3
3
  //#region src/array/insert.ts
4
4
  function insert(array, indexOrItems, items) {
5
- return insertValues(ARRAY_INSERT_TYPE_INSERT, array, items == null ? indexOrItems : items, typeof indexOrItems === "number" ? indexOrItems : array?.length, 0);
5
+ return insertValues(ARRAY_INSERT_TYPE_INSERT, array, items ?? indexOrItems, typeof indexOrItems === "number" ? indexOrItems : array?.length, 0);
6
6
  }
7
7
  //#endregion
8
8
  export { insert };
@@ -8,34 +8,47 @@ function extract(type, array, first, second) {
8
8
  if (!Array.isArray(array)) return [];
9
9
  const { length } = array;
10
10
  if (length === 0) return [];
11
- const isTake = type === ARRAY_SLICE_TAKE;
12
- if (typeof first === "number") {
13
- if (Math.abs(first) >= length) return isTake ? array.slice() : [];
14
- if (first === 0) return isTake ? [] : array.slice();
15
- if (isTake) return first >= 0 ? array.slice(0, first) : array.slice(array.length + first);
16
- return first >= 0 ? array.slice(first) : array.slice(0, array.length + first);
17
- }
18
- const callbacks = second == null ? getArrayCallbacks(first) : getArrayCallbacks(void 0, void 0, first);
11
+ const take = type === ARRAY_SLICE_TAKE;
12
+ return typeof first === "number" ? getSlice(array, length, first, take) : extractSlice(array, length, first, second, take);
13
+ }
14
+ function extractSlice(array, length, first, second, take) {
15
+ const callbacks = getCallbacks(first, second);
16
+ if (callbacks?.bool == null && callbacks?.value == null) return take ? array.slice() : [];
19
17
  const isBoolean = callbacks?.bool != null;
20
- if (callbacks?.bool == null && callbacks?.value == null) return isTake ? array.slice() : [];
21
18
  const extracted = [];
22
19
  let push = false;
23
20
  for (let index = 0; index < length; index += 1) {
24
21
  const item = array[index];
25
- const matches = isBoolean ? callbacks.bool(item, index, array) : Object.is(callbacks.value(item, index, array), second);
26
- if (isTake) {
27
- if (isBoolean ? !matches : matches) break;
22
+ const matches = isMatch(item, index, array, callbacks, second, isBoolean);
23
+ const reached = isBoolean ? !matches : matches;
24
+ if (take && reached) break;
25
+ if (push || take) {
28
26
  extracted.push(item);
29
27
  continue;
30
28
  }
31
- if (push) extracted.push(item);
32
- else if (isBoolean ? !matches : matches) {
29
+ if (reached) {
33
30
  push = true;
34
31
  if (isBoolean) extracted.push(item);
35
32
  }
36
33
  }
37
34
  return extracted;
38
35
  }
36
+ function getCallbacks(first, second) {
37
+ let callbacks;
38
+ if (second == null) callbacks = getArrayCallbacks(first);
39
+ else callbacks = getArrayCallbacks(void 0, void 0, first);
40
+ return callbacks;
41
+ }
42
+ function getSlice(array, length, amount, take) {
43
+ if (Math.abs(amount) >= length) return take ? array.slice() : [];
44
+ if (amount === 0) return take ? [] : array.slice();
45
+ if (take) return amount >= 0 ? array.slice(0, amount) : array.slice(length + amount);
46
+ return amount >= 0 ? array.slice(amount) : array.slice(0, length + amount);
47
+ }
48
+ function isMatch(item, index, array, callbacks, second, isBoolean) {
49
+ if (isBoolean) return callbacks.bool(item, index, array);
50
+ return Object.is(callbacks.value(item, index, array), second);
51
+ }
39
52
  function slice(array, first, second) {
40
53
  if (!Array.isArray(array) || array.length === 0) return [];
41
54
  const firstIsNumber = typeof first === "number";
@@ -1,5 +1,6 @@
1
1
  import { isPlainObject } from "../internal/is.mjs";
2
2
  import { floor, round } from "../internal/math/misc.mjs";
3
+ import { min } from "../internal/math/aggregate.mjs";
3
4
  import { compare } from "../internal/value/compare.mjs";
4
5
  import { SORTER_SYMBOL, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, arrayModifiers } from "../models/array/array.sort.model.mjs";
5
6
  //#region src/array/sort.ts
@@ -106,7 +107,7 @@ function isSortedArray(array) {
106
107
  let offset = 0;
107
108
  if (length >= 100) {
108
109
  offset = round(length / 10);
109
- offset = offset > 100 ? 100 : offset;
110
+ offset = min([offset, 100]);
110
111
  for (let index = 0; index < offset; index += 1) {
111
112
  const [firstItem, firstOffset] = [array[index], array[index + 1]];
112
113
  const [secondItem, secondOffset] = [array[length - index - 2], array[length - index - 1]];
@@ -182,4 +182,5 @@ declare function swapIndices<Item>(array: Item[], first: number, second: number)
182
182
  export declare namespace swap {
183
183
  export var indices: typeof swapIndices;
184
184
  }
185
- //#endregion
185
+ //#endregion
186
+ export {};
@@ -55,4 +55,5 @@ export declare const COLOR_SRGB: {
55
55
  luminanceThreshold: number;
56
56
  };
57
57
  export declare const colorSubscription: SubscriptionProperty;
58
- //#endregion
58
+ //#endregion
59
+ export {};
@@ -5,7 +5,9 @@ import { getColorFromState, getColorState } from "./state.mjs";
5
5
  import { color } from "../instance.mjs";
6
6
  //#region src/color/misc/get.ts
7
7
  function getClampedValue(value, minimum, maximum, rounding) {
8
- return typeof value === "number" && !Number.isNaN(value) ? clamp(rounding ?? false ? round(value) : value, minimum, maximum) : minimum;
8
+ if (typeof value !== "number" || Number.isNaN(value)) return minimum;
9
+ const actual = rounding ?? false ? round(value) : value;
10
+ return clamp(actual, minimum, maximum);
9
11
  }
10
12
  function getForegroundColor(value, hex) {
11
13
  const { blue, green, red } = getColorFromState(getColorState(value), COLOR_TYPE.rgb);
@@ -46,7 +46,7 @@ function getHexaColor() {
46
46
  * @returns Normalized hex color
47
47
  */
48
48
  function getNormalizedHex(value, alpha) {
49
- const includeAlpha = alpha ?? false;
49
+ const includeAlpha = alpha === true;
50
50
  if (!isHexColor(value)) return `${COLOR_DEFAULTS.hexBlack}${includeAlpha ? COLOR_ALPHA.fullHexLong : ""}`;
51
51
  const normalized = value.replace(COLOR_EXPRESSION.prefix, "");
52
52
  if (normalized.length < COLOR_LENGTHS.hexLong) {
@@ -52,6 +52,7 @@ export declare function rgbToHsla(rgb: RGBAColor | RGBColor): HSLAColor;
52
52
  export declare function rgbToHwb(rgb: RGBAColor | RGBColor): HWBColor;
53
53
  /**
54
54
  * Convert an _RGB(A)_ color to an _HWBA_ color
55
+
55
56
  * _If the value is unable to be converted, a black _HWBA_ color will be returned_
56
57
  *
57
58
  * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
@@ -1,2 +1 @@
1
- import { noop } from "../internal/function/misc.mjs";
2
- export { noop };
1
+ export { noop } from "../internal/function/misc.mjs";
@@ -20,7 +20,7 @@ declare function asyncRetry<Callback extends GenericAsyncCallback>(callback: Cal
20
20
  * @param options Retry options
21
21
  * @returns Callback result
22
22
  */
23
- declare function asyncRetry<Callback extends GenericCallback>(callback: Callback, options?: RetryOptions): Promise<ReturnType<Callback>>;
23
+ declare function asyncRetry<Callback extends GenericAsyncCallback>(callback: Callback, options?: RetryOptions): Promise<ReturnType<Callback>>;
24
24
  /**
25
25
  * Retry a callback a specified number of times
26
26
  *
@@ -18,8 +18,11 @@ async function asyncRetry(callback, options) {
18
18
  if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
19
19
  async function handle() {
20
20
  const result = await asyncAttempt(async () => callback());
21
- if (result.ok) resolver(result.value);
22
- else if (attempts >= times || !when(result.error)) rejector(new RetryError(RETRY_MESSAGE_FAILED, result.error));
21
+ if (result.ok) {
22
+ resolver(result.value);
23
+ return;
24
+ }
25
+ if (attempts >= times || !when(result.error)) rejector(new RetryError(RETRY_MESSAGE_FAILED, result.error));
23
26
  else {
24
27
  attempts += 1;
25
28
  limiter.run();
package/dist/herald.mjs CHANGED
@@ -1,2 +1 @@
1
- import { herald, isHerald, isHeraldEvents, isHeraldSubscription } from "./internal/herald.mjs";
2
- export { herald, isHerald, isHeraldEvents, isHeraldSubscription };
1
+ export { herald, isHerald, isHeraldEvents, isHeraldSubscription } from "./internal/herald.mjs";