@oscarpalmer/atoms 0.217.0 → 0.219.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 (85) hide show
  1. package/dist/array/filter.d.mts +38 -4
  2. package/dist/array/find.d.mts +34 -0
  3. package/dist/array/first.d.mts +40 -4
  4. package/dist/array/insert.mjs +1 -1
  5. package/dist/array/last.d.mts +46 -10
  6. package/dist/array/partition.d.mts +24 -8
  7. package/dist/array/reverse.d.mts +6 -0
  8. package/dist/array/reverse.mjs +6 -0
  9. package/dist/array/select.d.mts +97 -116
  10. package/dist/array/select.mjs +19 -15
  11. package/dist/array/single.d.mts +22 -0
  12. package/dist/array/single.mjs +1 -1
  13. package/dist/array/slice.mjs +27 -14
  14. package/dist/array/sort.d.mts +54 -0
  15. package/dist/array/sort.mjs +2 -1
  16. package/dist/color/misc/get.mjs +3 -1
  17. package/dist/color/space/hex.d.mts +8 -0
  18. package/dist/color/space/hex.mjs +9 -1
  19. package/dist/function/retry.d.mts +1 -1
  20. package/dist/function/retry.mjs +5 -2
  21. package/dist/index.d.mts +879 -324
  22. package/dist/index.mjs +480 -173
  23. package/dist/internal/array/callbacks.mjs +1 -1
  24. package/dist/internal/array/find.d.mts +3 -3
  25. package/dist/internal/array/find.mjs +90 -48
  26. package/dist/internal/array/insert.mjs +1 -1
  27. package/dist/internal/array/match.mjs +21 -17
  28. package/dist/internal/array/sets.mjs +7 -1
  29. package/dist/internal/array/shuffle.d.mts +5 -0
  30. package/dist/internal/array/shuffle.mjs +5 -0
  31. package/dist/internal/math/aggregate.d.mts +69 -21
  32. package/dist/internal/math/aggregate.mjs +4 -1
  33. package/dist/internal/math/misc.d.mts +14 -0
  34. package/dist/internal/math/misc.mjs +14 -0
  35. package/dist/internal/number.d.mts +19 -1
  36. package/dist/internal/number.mjs +22 -2
  37. package/dist/internal/plan/plan.generate.mjs +3 -3
  38. package/dist/internal/random.d.mts +6 -0
  39. package/dist/internal/random.mjs +13 -2
  40. package/dist/internal/result/attempt.mjs +4 -4
  41. package/dist/internal/string/case.d.mts +63 -0
  42. package/dist/internal/string/case.mjs +63 -0
  43. package/dist/internal/string/misc.d.mts +20 -0
  44. package/dist/internal/string/misc.mjs +22 -1
  45. package/dist/internal/subscription.mjs +1 -1
  46. package/dist/internal/value/equal.mjs +2 -1
  47. package/dist/internal/value/partial.mjs +3 -1
  48. package/dist/logger.d.mts +12 -0
  49. package/dist/logger.mjs +12 -0
  50. package/dist/math.d.mts +90 -0
  51. package/dist/math.mjs +7 -0
  52. package/dist/models/array/array.find.model.d.mts +26 -0
  53. package/dist/models/array/array.misc.model.d.mts +2 -4
  54. package/dist/models/index.d.mts +1 -1
  55. package/dist/models/plan.model.d.mts +2 -0
  56. package/dist/models/plan.model.mjs +3 -1
  57. package/dist/models/string/string.fuzzy.model.d.mts +1 -1
  58. package/dist/models/string/string.misc.model.mjs +1 -1
  59. package/dist/models/value/value.merge.model.d.mts +4 -4
  60. package/dist/plan/index.d.mts +1 -4
  61. package/dist/plan/index.mjs +2 -3
  62. package/dist/plan/use.mjs +4 -4
  63. package/dist/promise/index.d.mts +6 -4
  64. package/dist/promise/index.mjs +4 -4
  65. package/dist/promise/misc.d.mts +6 -0
  66. package/dist/promise/misc.mjs +11 -2
  67. package/dist/promise/timed.d.mts +3 -0
  68. package/dist/promise/timed.mjs +5 -2
  69. package/dist/queue.d.mts +0 -1
  70. package/dist/queue.mjs +5 -6
  71. package/dist/random.d.mts +2 -2
  72. package/dist/random.mjs +3 -3
  73. package/dist/result/match.mjs +2 -2
  74. package/dist/result/misc.mjs +3 -10
  75. package/dist/result/work/pipe.d.mts +24 -22
  76. package/dist/result/work/pipe.mjs +7 -3
  77. package/dist/string/fuzzy.mjs +1 -1
  78. package/dist/string/index.d.mts +15 -1
  79. package/dist/string/index.mjs +16 -2
  80. package/dist/string/match.d.mts +24 -0
  81. package/dist/string/match.mjs +24 -0
  82. package/dist/string/template.d.mts +4 -0
  83. package/dist/value/clone.mjs +1 -1
  84. package/dist/value/merge.mjs +17 -4
  85. package/package.json +1 -1
@@ -1,8 +1,34 @@
1
+ import { GenericCallback } from "../index.mjs";
1
2
  //#region src/models/array/array.find.model.d.ts
3
+ export type ArrayFindLimitOptions = {
4
+ limit?: number;
5
+ map?: never;
6
+ };
7
+ export type ArrayFindMapOptions = {
8
+ limit?: never;
9
+ map?: ArrayFindMapper;
10
+ };
2
11
  export type ArrayFindMapper = {
3
12
  callback: unknown;
13
+ flat: boolean;
4
14
  reverse: boolean;
5
15
  };
16
+ export type ArrayFindOptions = ArrayFindMapOptions | ArrayFindLimitOptions;
17
+ export type ArrayFindParameters = {
18
+ array: unknown[];
19
+ arrayLength: number;
20
+ callback?: GenericCallback;
21
+ flat: boolean;
22
+ limit: number;
23
+ map?: ArrayFindParametersMap;
24
+ result: ArrayFindValuesResult;
25
+ type: ArrayFindValuesType;
26
+ value: unknown;
27
+ };
28
+ export type ArrayFindParametersMap = {
29
+ after?: GenericCallback;
30
+ before?: GenericCallback;
31
+ };
6
32
  export type ArrayFindValueType = "index" | "item";
7
33
  export type ArrayFindValuesResult = {
8
34
  matched: unknown[];
@@ -1,4 +1,4 @@
1
- import { GenericCallback, PlainObject } from "../index.mjs";
1
+ import { GenericCallback } from "../index.mjs";
2
2
  //#region src/models/array/array.misc.model.d.ts
3
3
  export type ArrayCompareSetsType = "difference" | "intersection" | "union";
4
4
  /**
@@ -6,6 +6,7 @@ export type ArrayCompareSetsType = "difference" | "intersection" | "union";
6
6
  */
7
7
  export type ArrayComparison = "end" | "inside" | "invalid" | "outside" | "same" | "start";
8
8
  export type ArrayExtractType = "drop" | "take";
9
+ export type ArrayFlattened<Value> = Value extends ReadonlyArray<infer Inner> ? Inner : Value;
9
10
  export type ArrayGetCallbacks = {
10
11
  bool?: GenericCallback;
11
12
  keyed?: GenericCallback;
@@ -16,9 +17,6 @@ export type ArrayOverlapItem = {
16
17
  array: unknown[];
17
18
  index: number;
18
19
  };
19
- export type ArrayMapKeyOrCallback<Item> = ((item: Item, index: number, array: Item[]) => unknown) | (Item extends PlainObject ? keyof Item : never);
20
- export type ArrayMapped<Item, Map extends ArrayMapKeyOrCallback<Item>> = Map extends ((item: Item, index: number, array: Item[]) => unknown) ? ReturnType<Map> : Map extends keyof Item ? Item[Map] : never;
21
- export type ArrayObjectKeysOf<Item> = { [Key in keyof Item]: Item[Key] extends PlainObject ? Key : never; }[keyof Item];
22
20
  export type ArrayOverlapResult = {
23
21
  first: ArrayOverlapItem;
24
22
  second: ArrayOverlapItem;
@@ -49,7 +49,7 @@ export type KeyOrCallbackValue<Item, Arg extends KeyOrCallback<Item>> = Arg exte
49
49
  /**
50
50
  * A nested array
51
51
  */
52
- export type NestedArray<Value> = Value extends Array<infer NestedValue> ? NestedArray<NestedValue> : Value;
52
+ export type NestedArray<Value> = Value extends ReadonlyArray<infer NestedValue> ? NestedArray<NestedValue> : Value;
53
53
  /**
54
54
  * All nested keys of an object as dot notation strings _(up to 5 levels deep)_
55
55
  */
@@ -233,6 +233,8 @@ export declare const PLAN_FAILURE_ASYNC: "asyncFailure";
233
233
  export declare const PLAN_FAILURE_SYNC: "failure";
234
234
  export declare const PLAN_MESSAGE_PLAN_INPUT = "plan requires a generator function";
235
235
  export declare const PLAN_MESSAGE_RUN_INPUT = "run requires a plan or a generator function";
236
+ export declare const PLAN_MESSAGE_USE_NESTED_FN = "Cannot use nested functions with 'use'";
237
+ export declare const PLAN_MESSAGE_USE_SYNC_ASYNC = "Cannot use asynchronous values with 'use'";
236
238
  export declare const PLAN_STEP_ASYNC: "asyncStep";
237
239
  export declare const PLAN_STEP_SYNC: "step";
238
240
  export declare const PLAN_SUCCESS_ASYNC: "asyncSuccess";
@@ -7,6 +7,8 @@ const PLAN_FAILURE_ASYNC = "asyncFailure";
7
7
  const PLAN_FAILURE_SYNC = "failure";
8
8
  const PLAN_MESSAGE_PLAN_INPUT = "plan requires a generator function";
9
9
  const PLAN_MESSAGE_RUN_INPUT = "run requires a plan or a generator function";
10
+ const PLAN_MESSAGE_USE_NESTED_FN = "Cannot use nested functions with 'use'";
11
+ const PLAN_MESSAGE_USE_SYNC_ASYNC = "Cannot use asynchronous values with 'use'";
10
12
  const PLAN_STEP_ASYNC = "asyncStep";
11
13
  const PLAN_STEP_SYNC = "step";
12
14
  const PLAN_SUCCESS_ASYNC = "asyncSuccess";
@@ -15,4 +17,4 @@ const PLAN_SYMBOL = Symbol("plan");
15
17
  const PLAN_TYPE_ASYNC = "asyncPlan";
16
18
  const PLAN_TYPE_SYNC = "plan";
17
19
  //#endregion
18
- export { GENERATOR_FUNCTION_TYPE_ASYNC, GENERATOR_FUNCTION_TYPE_SYNC, GENERATOR_TYPE_ASYNC, GENERATOR_TYPE_SYNC, PLAN_FAILURE_ASYNC, PLAN_FAILURE_SYNC, PLAN_MESSAGE_PLAN_INPUT, PLAN_MESSAGE_RUN_INPUT, PLAN_STEP_ASYNC, PLAN_STEP_SYNC, PLAN_SUCCESS_ASYNC, PLAN_SUCCESS_SYNC, PLAN_SYMBOL, PLAN_TYPE_ASYNC, PLAN_TYPE_SYNC };
20
+ export { GENERATOR_FUNCTION_TYPE_ASYNC, GENERATOR_FUNCTION_TYPE_SYNC, GENERATOR_TYPE_ASYNC, GENERATOR_TYPE_SYNC, PLAN_FAILURE_ASYNC, PLAN_FAILURE_SYNC, PLAN_MESSAGE_PLAN_INPUT, PLAN_MESSAGE_RUN_INPUT, PLAN_MESSAGE_USE_NESTED_FN, PLAN_MESSAGE_USE_SYNC_ASYNC, PLAN_STEP_ASYNC, PLAN_STEP_SYNC, PLAN_SUCCESS_ASYNC, PLAN_SUCCESS_SYNC, PLAN_SYMBOL, PLAN_TYPE_ASYNC, PLAN_TYPE_SYNC };
@@ -88,7 +88,7 @@ export type FuzzyResult<Item> = {
88
88
  /**
89
89
  * Options for fuzzy searching
90
90
  */
91
- export type FuzzySearchOptions = FuzzyOptions;
91
+ export type FuzzySearchOptions = { [Key in keyof FuzzyOptions]: FuzzyOptions[Key]; };
92
92
  export type FuzzyState<Item> = {
93
93
  handler(item: Item): string;
94
94
  items: Item[];
@@ -2,7 +2,7 @@
2
2
  const STRING_DELIMITER_UUID_DEFAULT = "-";
3
3
  const STRING_DELIMITER_UUID_HTML = "_";
4
4
  const STRING_EXPRESSION_IGNORED = /(^|\.)(__proto__|constructor|prototype)(\.|$)/i;
5
- const STRING_EXPRESSION_WORDS = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
5
+ const STRING_EXPRESSION_WORDS = /([^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+)/g;
6
6
  const STRING_EXPRESSION_WHITESPACE_PREFIX = /^(\s+)/;
7
7
  const STRING_MATCH_ENDS_WITH = "endsWith";
8
8
  const STRING_MATCH_INCLUDES = "includes";
@@ -3,12 +3,12 @@ import { ArrayOrPlainObject, NestedPartial, PlainObject, UnionToIntersection } f
3
3
  /**
4
4
  * Options for assigning values
5
5
  */
6
- export type AssignOptions = BaseOptions;
6
+ export type AssignOptions = { [Key in keyof BaseOptions]: BaseOptions[Key]; };
7
7
  type BaseOptions = {
8
8
  /**
9
9
  * Key _(or key epxressions)_ for values that should be replaced
10
10
  *
11
- * ```ts
11
+ * ```typescript
12
12
  * merge([{items: [1, 2, 3]}, {items: [99]}]); // => {items: [99]}
13
13
  * ```
14
14
  */
@@ -16,7 +16,7 @@ type BaseOptions = {
16
16
  /**
17
17
  * Skip nullable values when merging objects?
18
18
  *
19
- * ```ts
19
+ * ```typescript
20
20
  * merge({a: 1, b: 2}, {b: null, c: 3}, {d: null}); // => {a: 1, b: 2, c: 3}
21
21
  * ```
22
22
  */
@@ -24,7 +24,7 @@ type BaseOptions = {
24
24
  /**
25
25
  * Skip nullable values when merging arrays?
26
26
  *
27
- * ```ts
27
+ * ```typescript
28
28
  * merge([1, 2, 3], [null, null, 99]); // => [1, 2, 99]
29
29
  * ```
30
30
  */
@@ -1,6 +1,4 @@
1
1
  import { AsyncPlan, Plan } from "../models/plan.model.mjs";
2
- import { asyncAttemptRun, attemptRun } from "./result.mjs";
3
- import { asyncRun, run } from "./run.mjs";
4
2
  //#region src/plan/index.d.ts
5
3
  /**
6
4
  * Create a plan for an asynchronous generator function
@@ -16,5 +14,4 @@ export declare function plan<Yielded, Returned, Parameters extends unknown[]>(ge
16
14
  * @returns Generator plan
17
15
  */
18
16
  export declare function plan<Yielded, Returned, Parameters extends unknown[]>(generator: (...parameters: Parameters) => Generator<Yielded, Returned>): Plan<Yielded, Returned, Parameters>;
19
- //#endregion
20
- export { asyncAttemptRun, asyncRun, attemptRun, run };
17
+ //#endregion
@@ -1,8 +1,7 @@
1
1
  import { PLAN_MESSAGE_PLAN_INPUT, PLAN_SYMBOL, PLAN_TYPE_ASYNC, PLAN_TYPE_SYNC } from "../models/plan.model.mjs";
2
2
  import { attemptRunPlan, getGenerator, runAsyncPlan, runPlan } from "../internal/plan/index.mjs";
3
3
  import { isAsyncGeneratorFunction, isGeneratorFunction } from "./is.mjs";
4
- import { asyncAttemptRun, attemptRun } from "./result.mjs";
5
- import { asyncRun, run } from "./run.mjs";
4
+ import { asyncAttemptRun } from "./result.mjs";
6
5
  //#region src/plan/index.ts
7
6
  function AsyncPlan(generator) {
8
7
  this[PLAN_SYMBOL] = {
@@ -31,4 +30,4 @@ function plan(generator) {
31
30
  throw new Error(PLAN_MESSAGE_PLAN_INPUT);
32
31
  }
33
32
  //#endregion
34
- export { asyncAttemptRun, asyncRun, attemptRun, plan, run };
33
+ export { plan };
package/dist/plan/use.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { isError, isOk } from "../internal/result/misc.mjs";
2
- import { PLAN_STEP_ASYNC, PLAN_STEP_SYNC, PLAN_SYMBOL } from "../models/plan.model.mjs";
2
+ import { PLAN_MESSAGE_USE_NESTED_FN, PLAN_MESSAGE_USE_SYNC_ASYNC, PLAN_STEP_ASYNC, PLAN_STEP_SYNC, PLAN_SYMBOL } from "../models/plan.model.mjs";
3
3
  import { getGenerator } from "../internal/plan/index.mjs";
4
4
  import { isAsyncFailure, isAsyncGenerator, isAsyncGeneratorFunction, isAsyncPlan, isAsyncStep, isAsyncSuccess, isGenerator } from "./is.mjs";
5
5
  import { fail } from "./misc.mjs";
@@ -23,7 +23,7 @@ function asyncUse(value) {
23
23
  let actual = value;
24
24
  if (typeof actual === "function") actual = actual();
25
25
  actual = await actual;
26
- if (typeof actual === "function") throw new Error();
26
+ if (typeof actual === "function") throw new TypeError(PLAN_MESSAGE_USE_NESTED_FN);
27
27
  if (typeof actual === "object" && actual !== null && PLAN_SYMBOL in actual) return yield* actual;
28
28
  if (isAsyncGenerator(actual) || isGenerator(actual)) return yield* actual;
29
29
  if (isError(actual)) {
@@ -61,8 +61,8 @@ function use(value) {
61
61
  });
62
62
  }
63
63
  function validateUseInput(value, resolved) {
64
- if (value instanceof Promise || isAsyncFailure(value) || isAsyncGenerator(value) || isAsyncGeneratorFunction(value) || isAsyncPlan(value) || isAsyncStep(value) || isAsyncSuccess(value)) throw new Error();
65
- if (resolved && typeof value === "function") throw new Error();
64
+ if (value instanceof Promise || isAsyncFailure(value) || isAsyncGenerator(value) || isAsyncGeneratorFunction(value) || isAsyncPlan(value) || isAsyncStep(value) || isAsyncSuccess(value)) throw new Error(PLAN_MESSAGE_USE_SYNC_ASYNC);
65
+ if (resolved && typeof value === "function") throw new Error(PLAN_MESSAGE_USE_NESTED_FN);
66
66
  }
67
67
  use.async = asyncUse;
68
68
  //#endregion
@@ -1,6 +1,7 @@
1
1
  import { PlainObject } from "../models/index.mjs";
2
2
  import { PromiseOptions, PromiseStrategy, PromisesItems, PromisesOptions, PromisesResult, PromisesUnwrapped, PromisesValues } from "../models/promise.model.mjs";
3
3
  //#region src/promise/index.d.ts
4
+ type AttemptPromiseOptions = PromiseOptions | AbortSignal | number;
4
5
  /**
5
6
  * Wrap a _Promise_ with safety handlers
6
7
  *
@@ -8,7 +9,7 @@ import { PromiseOptions, PromiseStrategy, PromisesItems, PromisesOptions, Promis
8
9
  * @param options Options for the _Promise_
9
10
  * @returns Wrapped _Promise_
10
11
  */
11
- export declare function attemptPromise<Value>(promise: Promise<Value>, options?: PromiseOptions | AbortSignal | number): Promise<Value>;
12
+ export declare function attemptPromise<Value>(promise: Promise<Value>, options?: AttemptPromiseOptions): Promise<Value>;
12
13
  /**
13
14
  * Wrap a _Promise_-returning callback with safety handlers
14
15
  *
@@ -16,7 +17,7 @@ export declare function attemptPromise<Value>(promise: Promise<Value>, options?:
16
17
  * @param options Options for the _Promise_
17
18
  * @returns _Promise_-wrapped callback
18
19
  */
19
- export declare function attemptPromise<Value>(callback: () => Promise<Value>, options?: PromiseOptions | AbortSignal | number): Promise<Value>;
20
+ export declare function attemptPromise<Value>(callback: () => Promise<Value>, options?: AttemptPromiseOptions): Promise<Value>;
20
21
  /**
21
22
  * Wrap a callback with a _Promise_ and safety handlers
22
23
  *
@@ -24,7 +25,7 @@ export declare function attemptPromise<Value>(callback: () => Promise<Value>, op
24
25
  * @param options Options for the _Promise_
25
26
  * @returns _Promise_-wrapped callback
26
27
  */
27
- export declare function attemptPromise<Value>(callback: () => Value, options?: PromiseOptions | AbortSignal | number): Promise<Value>;
28
+ export declare function attemptPromise<Value>(callback: () => Value, options?: AttemptPromiseOptions): Promise<Value>;
28
29
  /**
29
30
  * Handle a list of _Promises_, returning their results in an ordered array
30
31
  *
@@ -106,4 +107,5 @@ export declare function resultPromises<Items extends PlainObject>(items: Items,
106
107
  export declare namespace promises {
107
108
  export var result: typeof resultPromises;
108
109
  }
109
- //#endregion
110
+ //#endregion
111
+ export {};
@@ -8,9 +8,9 @@ import { getTimedPromise } from "./timed.mjs";
8
8
  //#region src/promise/index.ts
9
9
  async function attemptPromise(value, options) {
10
10
  const isFunction = typeof value === "function";
11
- if (!isFunction && !(value instanceof Promise)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_ATTEMPT));
11
+ if (!isFunction && !(value instanceof Promise)) throw new TypeError(PROMISE_MESSAGE_EXPECTATION_ATTEMPT);
12
12
  const { signal, time } = createPromiseOptions(options);
13
- if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
13
+ if (signal?.aborted ?? false) throw signal?.reason;
14
14
  const aborter = createAborter(signal, () => {
15
15
  rejector(signal?.reason);
16
16
  });
@@ -32,8 +32,8 @@ async function attemptPromise(value, options) {
32
32
  }
33
33
  async function promises(items, options) {
34
34
  const { signal, strategy } = createPromisesOptions(options);
35
- if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
36
- if (!isArrayOrPlainObject(items)) return Promise.reject(PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE);
35
+ if (signal?.aborted ?? false) throw signal?.reason;
36
+ if (!isArrayOrPlainObject(items)) throw new TypeError(PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE);
37
37
  const isArray = Array.isArray(items);
38
38
  const actual = (isArray ? items.map((item, index) => [index, item]) : Object.entries(items)).map(([key, value]) => [key, typeof value === "function" ? value() : value]).filter(([, value]) => value instanceof Promise);
39
39
  const aborter = createAborter(signal, () => {
@@ -11,7 +11,13 @@ import { isFulfilled, isRejected } from "./helpers.mjs";
11
11
  * @returns Cancelable _Promise_
12
12
  */
13
13
  export declare function cancelable<Value>(executor: (resolve: (value: Value) => void, reject: (reason: unknown) => void) => void): CancelablePromise<Value>;
14
+ /**
15
+ * @internal
16
+ */
14
17
  export declare function handleResult(status: string, parameters: PromiseParameters): void;
18
+ /**
19
+ * @internal
20
+ */
15
21
  export declare function settlePromise(settler: (value: any) => void, value: unknown, aborter?: Aborter): void;
16
22
  /**
17
23
  * Converts a _Promise_ to a promised result
@@ -12,6 +12,9 @@ import { isFulfilled, isRejected } from "./helpers.mjs";
12
12
  function cancelable(executor) {
13
13
  return new CancelablePromise(executor);
14
14
  }
15
+ /**
16
+ * @internal
17
+ */
15
18
  function handleResult(status, parameters) {
16
19
  const { aborter, complete, data, handlers, index, key, value } = parameters;
17
20
  if (aborter?.signal.aborted ?? false) return;
@@ -20,25 +23,31 @@ function handleResult(status, parameters) {
20
23
  handlers.reject(value);
21
24
  return;
22
25
  }
23
- data.result[key] = !complete ? value : status === "fulfilled" ? {
26
+ let resultValue;
27
+ if (complete) resultValue = status === "fulfilled" ? {
24
28
  status,
25
29
  value
26
30
  } : {
27
31
  status,
28
32
  reason: value
29
33
  };
34
+ else resultValue = value;
35
+ data.result[key] = resultValue;
30
36
  if (index === data.last) {
31
37
  aborter?.cancel();
32
38
  handlers.resolve(data.result);
33
39
  }
34
40
  }
41
+ /**
42
+ * @internal
43
+ */
35
44
  function settlePromise(settler, value, aborter) {
36
45
  aborter?.cancel();
37
46
  settler(value);
38
47
  }
39
48
  async function toResult(value) {
40
49
  const actual = typeof value === "function" ? value() : value;
41
- if (!(actual instanceof Promise)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_RESULT));
50
+ if (!(actual instanceof Promise)) throw new TypeError(PROMISE_MESSAGE_EXPECTATION_RESULT);
42
51
  return actual.then((result) => ok(result)).catch((reason) => error(reason));
43
52
  }
44
53
  //#endregion
@@ -1,6 +1,9 @@
1
1
  import { RequiredKeys } from "../models/index.mjs";
2
2
  import { PromiseOptions } from "../models/promise.model.mjs";
3
3
  //#region src/promise/timed.d.ts
4
+ /**
5
+ * @internal
6
+ */
4
7
  export declare function getTimedPromise<Value>(promise: Promise<Value>, time: number, signal?: AbortSignal): Promise<Value>;
5
8
  /**
6
9
  * Create a _Promise_ that should be settled within a certain amount of time
@@ -5,6 +5,9 @@ import { PROMISE_MESSAGE_EXPECTATION_TIMED, PromiseTimeoutError } from "../model
5
5
  import { createPromiseOptions } from "./helpers.mjs";
6
6
  import { settlePromise } from "./misc.mjs";
7
7
  //#region src/promise/timed.ts
8
+ /**
9
+ * @internal
10
+ */
8
11
  async function getTimedPromise(promise, time, signal) {
9
12
  const aborter = createAborter(signal, () => {
10
13
  limiter.cancel();
@@ -23,9 +26,9 @@ async function getTimedPromise(promise, time, signal) {
23
26
  });
24
27
  }
25
28
  async function timed(promise, options) {
26
- if (!(promise instanceof Promise)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_TIMED));
29
+ if (!(promise instanceof Promise)) throw new TypeError(PROMISE_MESSAGE_EXPECTATION_TIMED);
27
30
  const { signal, time } = createPromiseOptions(options);
28
- if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
31
+ if (signal?.aborted ?? false) throw signal?.reason;
29
32
  return time > 0 ? getTimedPromise(promise, time, signal) : promise;
30
33
  }
31
34
  //#endregion
package/dist/queue.d.mts CHANGED
@@ -17,7 +17,6 @@ export declare function isKeyedQueue(value: unknown): value is KeyedQueue<Generi
17
17
  * @returns `true` if the value is a queue, otherwise `false`
18
18
  */
19
19
  export declare function isQueue(value: unknown): value is Queue<GenericCallback | GenericAsyncCallback>;
20
- export declare function isQueueInstance<Instance>(name: string, value: unknown): value is Instance;
21
20
  /**
22
21
  * Create a keyed queue for an asynchronous callback function, where each key has its own queue
23
22
  *
package/dist/queue.mjs CHANGED
@@ -335,14 +335,13 @@ async function run(state) {
335
335
  state.runners += 1;
336
336
  let item = state.items.shift();
337
337
  while (item != null) {
338
+ const next = item;
338
339
  let error = false;
339
340
  let result;
340
341
  const attempted = await asyncAttempt(async () => {
341
- if (item != null && !(item.aborter?.signal?.aborted ?? false)) {
342
- const parameters = item.key == null ? item.parameters : [item.key, ...item.parameters];
343
- return await state.callback(...parameters);
344
- }
345
- throw new Error();
342
+ if (next.aborter?.signal?.aborted) throw next.aborter.signal.reason;
343
+ const parameters = next.key == null ? next.parameters : [next.key, ...next.parameters];
344
+ return await state.callback(...parameters);
346
345
  });
347
346
  if (attempted.ok) result = attempted.value;
348
347
  else {
@@ -361,4 +360,4 @@ async function run(state) {
361
360
  }
362
361
  queue.keyed = keyedQueue;
363
362
  //#endregion
364
- export { isKeyedQueue, isQueue, isQueueInstance, keyedQueue, queue };
363
+ export { isKeyedQueue, isQueue, keyedQueue, queue };
package/dist/random.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { getRandomFloatingNumber, getRandomInteger } from "./internal/random.mjs";
1
+ import { getRandom, getRandomFloatingNumber, getRandomInteger } from "./internal/random.mjs";
2
2
  //#region src/random.d.ts
3
3
  /**
4
4
  * Get a random boolean
@@ -50,4 +50,4 @@ export declare function getRandomItems<Value>(array: Value[], amount: number): V
50
50
  */
51
51
  export declare function getRandomItems<Value>(array: Value[]): Value[];
52
52
  //#endregion
53
- export { getRandomFloatingNumber as getRandomFloat, getRandomInteger };
53
+ export { getRandom, getRandomFloatingNumber as getRandomFloat, getRandomInteger };
package/dist/random.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { getRandomFloatingNumber, getRandomInteger } from "./internal/random.mjs";
1
+ import { getRandom, getRandomFloatingNumber, getRandomInteger } from "./internal/random.mjs";
2
2
  import { shuffle } from "./internal/array/shuffle.mjs";
3
3
  import { join } from "./internal/string/misc.mjs";
4
4
  import { RANDOM_ALPHABET, RANDOM_BOOLEAN_MODIFIER, RANDOM_HEX_CHARACTERS } from "./models/random.model.mjs";
@@ -9,7 +9,7 @@ import { RANDOM_ALPHABET, RANDOM_BOOLEAN_MODIFIER, RANDOM_HEX_CHARACTERS } from
9
9
  * @returns Random boolean
10
10
  */
11
11
  function getRandomBoolean() {
12
- return Math.random() > RANDOM_BOOLEAN_MODIFIER;
12
+ return getRandom() > RANDOM_BOOLEAN_MODIFIER;
13
13
  }
14
14
  /**
15
15
  * Get a random string of characters with a specified length
@@ -59,4 +59,4 @@ function getRandomItems(array, amount) {
59
59
  return typeof amount !== "number" || amount <= 0 || amount >= array.length ? shuffle(array) : shuffle(array).slice(0, amount);
60
60
  }
61
61
  //#endregion
62
- export { getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems };
62
+ export { getRandom, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems };
@@ -20,10 +20,10 @@ function handleResult(result, first, second) {
20
20
  error = second;
21
21
  }
22
22
  if (isOk(result)) {
23
- if (typeof ok !== "function") throw new Error(MATCH_MESSAGE_OK);
23
+ if (typeof ok !== "function") throw new TypeError(MATCH_MESSAGE_OK);
24
24
  return ok(result.value);
25
25
  }
26
- if (typeof error !== "function") throw new Error(MATCH_MESSAGE_ERROR);
26
+ if (typeof error !== "function") throw new TypeError(MATCH_MESSAGE_ERROR);
27
27
  return error(result.error, result.original);
28
28
  }
29
29
  function matchResult(result, first, second) {
@@ -1,17 +1,10 @@
1
1
  import { error, isError, isOk, isResult, ok, unwrap } from "../internal/result/misc.mjs";
2
2
  //#region src/result/misc.ts
3
- /**
4
- * Converts a _Result_ to a _Promise_
5
- *
6
- * Resolves if ok, rejects for error
7
- *
8
- * @param result _Result_ to convert
9
- * @returns Promised result
10
- */
11
3
  async function toPromise(result) {
12
4
  const actual = typeof result === "function" ? result() : result;
13
- if (!isResult(actual)) return Promise.reject(new Error(RESULT_MESSAGE_PROMISE));
14
- return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
5
+ if (!isResult(actual)) throw new TypeError(RESULT_MESSAGE_PROMISE);
6
+ if (isOk(actual)) return actual.value;
7
+ throw actual.error;
15
8
  }
16
9
  const RESULT_MESSAGE_PROMISE = "toPromise expected to receive a Result";
17
10
  //#endregion