@oscarpalmer/atoms 0.158.0 → 0.160.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 (120) hide show
  1. package/dist/array/difference.js +2 -0
  2. package/dist/array/exists.js +2 -0
  3. package/dist/array/filter.js +2 -0
  4. package/dist/array/find.js +2 -0
  5. package/dist/array/flatten.js +2 -0
  6. package/dist/array/from.js +2 -0
  7. package/dist/array/get.js +2 -0
  8. package/dist/array/group-by.js +2 -0
  9. package/dist/array/index-of.js +2 -0
  10. package/dist/array/index.js +2 -1
  11. package/dist/array/insert.js +2 -0
  12. package/dist/array/intersection.js +2 -0
  13. package/dist/array/partition.js +2 -0
  14. package/dist/array/position.js +58 -0
  15. package/dist/array/push.js +2 -0
  16. package/dist/array/select.js +2 -0
  17. package/dist/array/slice.js +2 -0
  18. package/dist/array/sort.js +2 -0
  19. package/dist/array/splice.js +2 -0
  20. package/dist/array/to-map.js +2 -0
  21. package/dist/array/to-record.js +2 -0
  22. package/dist/array/to-set.js +2 -0
  23. package/dist/array/toggle.js +2 -0
  24. package/dist/array/union.js +2 -0
  25. package/dist/array/unique.js +2 -0
  26. package/dist/array/update.js +2 -0
  27. package/dist/atoms.full.js +223 -162
  28. package/dist/beacon.js +2 -0
  29. package/dist/color/constants.js +35 -33
  30. package/dist/color/index.js +2 -0
  31. package/dist/color/instance.js +2 -0
  32. package/dist/color/misc/alpha.js +2 -0
  33. package/dist/color/misc/get.js +2 -0
  34. package/dist/color/misc/index.js +2 -0
  35. package/dist/color/misc/is.js +2 -0
  36. package/dist/color/misc/state.js +2 -0
  37. package/dist/color/space/hex.js +2 -0
  38. package/dist/color/space/hsl.js +2 -0
  39. package/dist/color/space/rgb.js +2 -0
  40. package/dist/function/assert.js +2 -0
  41. package/dist/function/index.js +2 -0
  42. package/dist/function/memoize.js +2 -0
  43. package/dist/function/once.js +2 -0
  44. package/dist/function/retry.js +2 -0
  45. package/dist/function/work.js +2 -0
  46. package/dist/index.js +5 -4
  47. package/dist/internal/array/callbacks.js +2 -0
  48. package/dist/internal/array/chunk.js +2 -0
  49. package/dist/internal/array/compact.js +2 -0
  50. package/dist/internal/array/find.js +6 -4
  51. package/dist/internal/array/group.js +2 -0
  52. package/dist/internal/array/insert.js +2 -0
  53. package/dist/internal/array/sets.js +8 -6
  54. package/dist/internal/array/shuffle.js +3 -1
  55. package/dist/internal/array/update.js +2 -0
  56. package/dist/internal/function/misc.js +2 -0
  57. package/dist/internal/function/timer.js +5 -3
  58. package/dist/internal/is.js +2 -0
  59. package/dist/internal/math/aggregate.js +2 -0
  60. package/dist/internal/number.js +2 -0
  61. package/dist/internal/random.js +2 -0
  62. package/dist/internal/result.js +2 -0
  63. package/dist/internal/sized.js +2 -0
  64. package/dist/internal/string.js +2 -0
  65. package/dist/internal/value/compare.js +2 -0
  66. package/dist/internal/value/equal.js +2 -0
  67. package/dist/internal/value/get.js +2 -0
  68. package/dist/internal/value/handlers.js +2 -0
  69. package/dist/internal/value/has.js +2 -0
  70. package/dist/internal/value/misc.js +2 -0
  71. package/dist/internal/value/partial.js +2 -0
  72. package/dist/internal/value/set.js +2 -0
  73. package/dist/is.js +2 -0
  74. package/dist/logger.js +2 -0
  75. package/dist/math.js +2 -0
  76. package/dist/promise/delay.js +3 -1
  77. package/dist/promise/helpers.js +8 -1
  78. package/dist/promise/index.js +9 -3
  79. package/dist/promise/misc.js +3 -1
  80. package/dist/promise/models.js +14 -12
  81. package/dist/promise/timed.js +3 -1
  82. package/dist/query.js +2 -0
  83. package/dist/queue.js +2 -0
  84. package/dist/random.js +2 -0
  85. package/dist/result/index.js +5 -3
  86. package/dist/result/match.js +2 -0
  87. package/dist/result/misc.js +2 -0
  88. package/dist/result/work/flow.js +2 -0
  89. package/dist/result/work/pipe.js +2 -0
  90. package/dist/sized/map.js +2 -0
  91. package/dist/sized/set.js +2 -0
  92. package/dist/string/case.js +2 -0
  93. package/dist/string/index.js +2 -0
  94. package/dist/string/match.js +2 -0
  95. package/dist/string/template.js +2 -0
  96. package/dist/value/clone.js +3 -1
  97. package/dist/value/diff.js +2 -0
  98. package/dist/value/merge.js +2 -0
  99. package/dist/value/omit.js +2 -0
  100. package/dist/value/pick.js +2 -0
  101. package/dist/value/smush.js +3 -1
  102. package/dist/value/unsmush.js +3 -1
  103. package/package.json +3 -3
  104. package/src/array/index.ts +1 -0
  105. package/src/array/position.ts +303 -0
  106. package/src/internal/array/sets.ts +3 -3
  107. package/src/internal/array/shuffle.ts +1 -1
  108. package/src/promise/helpers.ts +13 -3
  109. package/src/promise/index.ts +89 -19
  110. package/src/promise/misc.ts +1 -4
  111. package/src/promise/models.ts +18 -12
  112. package/src/value/clone.ts +1 -1
  113. package/src/value/smush.ts +1 -1
  114. package/src/value/unsmush.ts +1 -1
  115. package/types/array/index.d.ts +1 -0
  116. package/types/array/position.d.ts +117 -0
  117. package/types/promise/helpers.d.ts +3 -1
  118. package/types/promise/index.d.ts +52 -5
  119. package/types/promise/misc.d.ts +1 -1
  120. package/types/promise/models.d.ts +15 -11
@@ -0,0 +1,117 @@
1
+ import type { PlainObject } from '../models';
2
+ export type ArrayPosition = 'end' | 'inside' | 'invalid' | 'outside' | 'same' | 'start';
3
+ /**
4
+ * Does the needle array end the haystack array?
5
+ * @param haystack Haystack array
6
+ * @param needle Needle array
7
+ * @param key Key to get an item's value for matching
8
+ * @return `true` if the haystack ends with the needle, otherwise `false`
9
+ */
10
+ export declare function endsWithArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
11
+ /**
12
+ * Does the needle array end the haystack array?
13
+ * @param haystack Haystack array
14
+ * @param needle Needle array
15
+ * @param callback Callback to get an item's value for matching
16
+ * @return `true` if the haystack ends with the needle, otherwise `false`
17
+ */
18
+ export declare function endsWithArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
19
+ /**
20
+ * Does the needle array end the haystack array?
21
+ * @param haystack Haystack array
22
+ * @param needle Needle array
23
+ * @return `true` if the haystack ends with the needle, otherwise `false`
24
+ */
25
+ export declare function endsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
26
+ /**
27
+ * Get the position of an array within another array
28
+ * @param haystack Haystack array
29
+ * @param needle Needle array
30
+ * @param key Key to get an item's value for matching
31
+ * @returns Position of the needle within the haystack
32
+ */
33
+ export declare function getArrayPosition<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): ArrayPosition;
34
+ /**
35
+ * Get the position of an array within another array
36
+ * @param haystack Haystack array
37
+ * @param needle Needle array
38
+ * @param callback Callback to get an item's value for matching
39
+ * @returns Position of the needle within the haystack
40
+ */
41
+ export declare function getArrayPosition<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): ArrayPosition;
42
+ /**
43
+ * Get the position of an array within another array
44
+ * @param haystack Haystack array
45
+ * @param needle Needle array
46
+ * @returns Position of the needle within the haystack
47
+ */
48
+ export declare function getArrayPosition<Item>(haystack: Item[], needle: Item[]): ArrayPosition;
49
+ /**
50
+ * Does the needle array exist within the haystack array?
51
+ * @param haystack Haystack array
52
+ * @param needle Needle array
53
+ * @param key Key to get an item's value for matching
54
+ * @return `true` if the haystack includes the needle, otherwise `false`
55
+ */
56
+ export declare function includesArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
57
+ /**
58
+ * Does the needle array exist within the haystack array?
59
+ * @param haystack Haystack array
60
+ * @param needle Needle array
61
+ * @param callback Callback to get an item's value for matching
62
+ * @return `true` if the haystack includes the needle, otherwise `false`
63
+ */
64
+ export declare function includesArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
65
+ /**
66
+ * Does the needle array exist within the haystack array?
67
+ * @param haystack Haystack array
68
+ * @param needle Needle array
69
+ * @return `true` if the haystack includes the needle, otherwise `false`
70
+ */
71
+ export declare function includesArray<Item>(haystack: Item[], needle: Item[]): boolean;
72
+ /**
73
+ * Get the index of an array within another array
74
+ * @param haystack Haystack array
75
+ * @param needle Needle array
76
+ * @param key Key to get an item's value for matching
77
+ * @return Index of the needle's start within the haystack, or `-1` if it is not found
78
+ */
79
+ export declare function indexOfArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): number;
80
+ /**
81
+ * Get the index of an array within another array
82
+ * @param haystack Haystack array
83
+ * @param needle Needle array
84
+ * @param callback Callback to get an item's value for matching
85
+ * @return Index of the needle's start within the haystack, or `-1` if it is not found
86
+ */
87
+ export declare function indexOfArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): number;
88
+ /**
89
+ * Get the index of an array within another array
90
+ * @param haystack Haystack array
91
+ * @param needle Needle array
92
+ * @return Index of the needle's start within the haystack, or `-1` if it is not found
93
+ */
94
+ export declare function indexOfArray<Item>(haystack: Item[], needle: Item[]): number;
95
+ /**
96
+ * Does the needle array start the haystack array?
97
+ * @param haystack Haystack array
98
+ * @param needle Needle array
99
+ * @param key Key to get an item's value for matching
100
+ * @return `true` if the haystack starts with the needle, otherwise `false`
101
+ */
102
+ export declare function startsWithArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
103
+ /**
104
+ * Does the needle array start the haystack array?
105
+ * @param haystack Haystack array
106
+ * @param needle Needle array
107
+ * @param callback Callback to get an item's value for matching
108
+ * @return `true` if the haystack starts with the needle, otherwise `false`
109
+ */
110
+ export declare function startsWithArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
111
+ /**
112
+ * Does the needle array start the haystack array?
113
+ * @param haystack Haystack array
114
+ * @param needle Needle array
115
+ * @return `true` if the haystack starts with the needle, otherwise `false`
116
+ */
117
+ export declare function startsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
@@ -1,7 +1,9 @@
1
1
  import type { RequiredKeys } from '../models';
2
- import { type FulfilledPromise, type PromiseOptions, type PromisesOptions, type PromiseStrategy, type RejectedPromise } from './models';
2
+ import type { Result } from '../result/models';
3
+ import { type FulfilledPromise, type PromiseOptions, type PromisesOptions, type PromiseStrategy, type PromisesValue, type RejectedPromise } from './models';
3
4
  export declare function getPromiseOptions(input: unknown): RequiredKeys<PromiseOptions, 'time'>;
4
5
  export declare function getPromisesOptions(input: unknown): RequiredKeys<PromisesOptions, 'strategy'>;
6
+ export declare function getResultsFromPromises<Value>(promised: PromisesValue<Value>[]): Result<Value>[];
5
7
  export declare function getStrategyOrDefault(value: unknown): PromiseStrategy;
6
8
  /**
7
9
  * Is the value a fulfilled promise result?
@@ -1,4 +1,5 @@
1
- import { type PromiseOptions, type Promises, type PromisesOptions, type PromisesResult } from './models';
1
+ import type { Result } from '../result/models';
2
+ import { type PromiseOptions, type PromisesItems, type PromisesOptions, type PromisesResult, type PromisesValue, type PromisesValues } from './models';
2
3
  /**
3
4
  * Wrap a promise with safety handlers, with optional abort capabilities and timeout
4
5
  * @param promise Promise to wrap
@@ -28,7 +29,25 @@ export declare function attemptPromise<Value>(callback: () => Value, options?: P
28
29
  * @param options Options for handling the promises
29
30
  * @returns List of results
30
31
  */
31
- export declare function promises<Items extends unknown[], Options extends PromisesOptions>(items: Promises<Items>, options?: Options): Promise<Options['strategy'] extends 'first' ? Items : PromisesResult<Items>>;
32
+ export declare function promises<Items extends unknown[], Options extends PromisesOptions>(items: [...Items], options?: Options): Promise<Options['strategy'] extends 'first' ? Items : PromisesValues<PromisesItems<Items>>>;
33
+ /**
34
+ * Handle a list of promises, returning their results in an ordered array.
35
+ *
36
+ * Depending on the strategy, the function will either reject on the first error encountered or return an array of rejected and resolved results
37
+ * @param items List of promises
38
+ * @param options Options for handling the promises
39
+ * @returns List of results
40
+ */
41
+ export declare function promises<Value, Options extends PromisesOptions>(items: Promise<Value>[], options?: Options): Promise<Options['strategy'] extends 'first' ? Value[] : PromisesValue<Value>[]>;
42
+ /**
43
+ * Handle a list of promises, returning their results in an ordered array.
44
+ *
45
+ * If any promise in the list is rejected, the whole function will reject
46
+ * @param items List of promises
47
+ * @param strategy Strategy for handling the promises; rejects on the first error encountered
48
+ * @returns List of results
49
+ */
50
+ export declare function promises<Items extends unknown[]>(items: [...Items], strategy: 'first'): Promise<PromisesItems<Items>>;
32
51
  /**
33
52
  * Handle a list of promises, returning their results in an ordered array.
34
53
  *
@@ -37,17 +56,45 @@ export declare function promises<Items extends unknown[], Options extends Promis
37
56
  * @param strategy Strategy for handling the promises; rejects on the first error encountered
38
57
  * @returns List of results
39
58
  */
40
- export declare function promises<Items extends unknown[]>(items: Promises<Items>, strategy: 'first'): Promise<Items>;
59
+ export declare function promises<Value>(items: Promise<Value>[], strategy: 'first'): Promise<Value[]>;
60
+ /**
61
+ * Handle a list of promises, returning their results in an ordered array of rejected and resolved results
62
+ * @param items List of promises
63
+ * @param signal AbortSignal for aborting the operation _(when aborted, the promise will reject with the reason of the signal)_
64
+ * @returns List of results
65
+ */
66
+ export declare function promises<Items extends unknown[]>(items: [...Items], signal?: AbortSignal): Promise<PromisesValues<PromisesItems<Items>>>;
41
67
  /**
42
68
  * Handle a list of promises, returning their results in an ordered array of rejected and resolved results
43
69
  * @param items List of promises
44
70
  * @param signal AbortSignal for aborting the operation _(when aborted, the promise will reject with the reason of the signal)_
45
71
  * @returns List of results
46
72
  */
47
- export declare function promises<Items extends unknown[]>(items: Promises<Items>, signal?: AbortSignal): Promise<PromisesResult<Items>>;
73
+ export declare function promises<Value>(items: Promise<Value>[], signal?: AbortSignal): Promise<PromisesValue<Value>[]>;
74
+ export declare namespace promises {
75
+ var result: typeof resultPromises;
76
+ }
77
+ /**
78
+ * Handle a list of promises, returning their results in an ordered array of results _({@link Result})_.
79
+ *
80
+ * Depending on the strategy, the function will either reject on the first error encountered or return an array of rejected and resolved results
81
+ * @param items List of promises
82
+ * @param signal AbortSignal for aborting the operation _(when aborted, the promise will reject with the reason of the signal)_
83
+ * @returns List of results
84
+ */
85
+ declare function resultPromises<Items extends unknown[]>(items: [...Items], signal?: AbortSignal): Promise<PromisesResult<PromisesItems<Items>>>;
86
+ /**
87
+ * Handle a list of promises, returning their results in an ordered array of results _({@link Result})_.
88
+ *
89
+ * Depending on the strategy, the function will either reject on the first error encountered or return an array of rejected and resolved results
90
+ * @param items List of promises
91
+ * @param signal AbortSignal for aborting the operation _(when aborted, the promise will reject with the reason of the signal)_
92
+ * @returns List of results
93
+ */
94
+ declare function resultPromises<Value>(items: Promise<Value>[], signal?: AbortSignal): Promise<Result<Awaited<Value>>[]>;
48
95
  export { toPromise as fromResult } from '../result/misc';
49
96
  export { delay } from './delay';
50
97
  export { isFulfilled, isRejected } from './helpers';
51
98
  export { cancelable, toResult } from './misc';
52
- export { CancelablePromise, PromiseTimeoutError, type FulfilledPromise, type RejectedPromise, type PromiseOptions, type PromiseStrategy, type PromisesOptions, type PromisesResult, type PromisesResultItem, } from './models';
99
+ export { CancelablePromise, PromiseTimeoutError, type FulfilledPromise, type PromiseOptions, type PromisesOptions, type PromisesResult, type PromiseStrategy, type PromisesValues as PromisesValue, type PromisesValue as PromisesValueItem, type RejectedPromise, } from './models';
53
100
  export { timed } from './timed';
@@ -6,7 +6,7 @@ import { CancelablePromise, type PromiseParameters } from './models';
6
6
  * @returns Cancelable promise
7
7
  */
8
8
  export declare function cancelable<Value>(executor: (resolve: (value: Value) => void, reject: (reason: unknown) => void) => void): CancelablePromise<Value>;
9
- export declare function handleResult<Items extends unknown[]>(status: string, parameters: PromiseParameters<Items>): void;
9
+ export declare function handleResult(status: string, parameters: PromiseParameters): void;
10
10
  export declare function settlePromise(aborter: () => void, settler: (value: any) => void, value: unknown, signal?: AbortSignal): void;
11
11
  /**
12
12
  * Converts a promise to a promised result
@@ -1,3 +1,4 @@
1
+ import type { Result } from '../result/models';
1
2
  export declare class CancelablePromise<Value = void> extends Promise<Value> {
2
3
  #private;
3
4
  constructor(executor: (resolve: (value: Value) => void, reject: (reason: unknown) => void) => void);
@@ -9,14 +10,14 @@ export declare class CancelablePromise<Value = void> extends Promise<Value> {
9
10
  }
10
11
  export type FulfilledPromise<Value> = {
11
12
  status: typeof PROMISE_TYPE_FULFILLED;
12
- value: Value;
13
+ value: Awaited<Value>;
13
14
  };
14
- export type PromiseData<Items extends unknown[]> = {
15
+ export type PromiseData = {
15
16
  last: number;
16
- result: Items | PromisesResult<Items>;
17
+ result: unknown[];
17
18
  };
18
- export type PromiseHandlers<Items extends unknown[]> = {
19
- resolve: (value: Items | PromisesResult<Items>) => void;
19
+ export type PromiseHandlers = {
20
+ resolve: (value: unknown[]) => void;
20
21
  reject: (reason: unknown) => void;
21
22
  };
22
23
  export type PromiseOptions = {
@@ -29,11 +30,11 @@ export type PromiseOptions = {
29
30
  */
30
31
  time?: number;
31
32
  };
32
- export type PromiseParameters<Items extends unknown[]> = {
33
+ export type PromiseParameters = {
33
34
  abort: () => void;
34
35
  complete: boolean;
35
- data: PromiseData<Items>;
36
- handlers: PromiseHandlers<Items>;
36
+ data: PromiseData;
37
+ handlers: PromiseHandlers;
37
38
  index: number;
38
39
  signal?: AbortSignal;
39
40
  value?: unknown;
@@ -50,7 +51,7 @@ export type PromiseStrategy = 'complete' | 'first';
50
51
  export declare class PromiseTimeoutError extends Error {
51
52
  constructor();
52
53
  }
53
- export type Promises<Items extends unknown[]> = {
54
+ export type PromisesItems<Items extends unknown[]> = {
54
55
  [K in keyof Items]: Promise<Items[K]>;
55
56
  };
56
57
  export type PromisesOptions = {
@@ -58,9 +59,12 @@ export type PromisesOptions = {
58
59
  strategy?: PromiseStrategy;
59
60
  };
60
61
  export type PromisesResult<Items extends unknown[]> = {
61
- [K in keyof Items]: Items[K] extends Promise<infer Value> ? PromisesResultItem<Value> : never;
62
+ [K in keyof Items]: Items[K] extends Promise<infer Value> ? Result<Awaited<Value>> : never;
63
+ };
64
+ export type PromisesValue<Value> = FulfilledPromise<Value> | RejectedPromise;
65
+ export type PromisesValues<Items extends unknown[]> = {
66
+ [K in keyof Items]: Items[K] extends Promise<infer Value> ? PromisesValue<Awaited<Value>> : never;
62
67
  };
63
- export type PromisesResultItem<Value> = FulfilledPromise<Value> | RejectedPromise;
64
68
  export type RejectedPromise = {
65
69
  status: typeof PROMISE_TYPE_REJECTED;
66
70
  reason: unknown;