@oscarpalmer/atoms 0.204.1 → 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.
- package/dist/array/filter.d.mts +1 -1
- package/dist/array/find.d.mts +3 -3
- package/dist/array/first.d.mts +3 -4
- package/dist/array/first.mjs +1 -1
- package/dist/array/group-by.d.mts +3 -3
- package/dist/array/index.d.mts +2 -5
- package/dist/array/index.mjs +2 -5
- package/dist/array/last.d.mts +3 -4
- package/dist/array/last.mjs +1 -1
- package/dist/array/move.d.mts +4 -4
- package/dist/array/push.d.mts +2 -1
- package/dist/array/push.mjs +1 -1
- package/dist/array/reverse.mjs +2 -1
- package/dist/array/select.d.mts +95 -84
- package/dist/array/select.mjs +6 -6
- package/dist/array/single.d.mts +3 -3
- package/dist/array/sort.d.mts +6 -6
- package/dist/array/sort.mjs +3 -2
- package/dist/array/swap.d.mts +3 -3
- package/dist/array/swap.mjs +1 -1
- package/dist/array/to-map.d.mts +3 -3
- package/dist/array/to-record.d.mts +3 -3
- package/dist/beacon.mjs +2 -2
- package/dist/color/constants.d.mts +14 -41
- package/dist/color/instance.d.mts +0 -1
- package/dist/color/misc/alpha.mjs +1 -1
- package/dist/color/misc/get.mjs +1 -1
- package/dist/color/misc/state.d.mts +2 -29
- package/dist/color/models.d.mts +18 -4
- package/dist/color/space/hsl.mjs +7 -2
- package/dist/color/space/hwb.mjs +2 -1
- package/dist/color/space/rgb.mjs +22 -13
- package/dist/function/limit.d.mts +4 -4
- package/dist/function/once.d.mts +6 -8
- package/dist/function/retry.d.mts +2 -2
- package/dist/function/retry.mjs +12 -14
- package/dist/index.d.mts +1104 -1127
- package/dist/index.mjs +385 -383
- package/dist/internal/array/compact.d.mts +1 -1
- package/dist/internal/array/find.d.mts +4 -4
- package/dist/internal/array/index-of.d.mts +3 -3
- package/dist/internal/array/insert.d.mts +1 -1
- package/dist/internal/array/insert.mjs +2 -1
- package/dist/internal/array/match.d.mts +1 -1
- package/dist/internal/array/sets.d.mts +1 -1
- package/dist/internal/function/assert.d.mts +7 -7
- package/dist/internal/function/limit.d.mts +1 -1
- package/dist/internal/function/limit.mjs +9 -9
- package/dist/internal/function/work.d.mts +4 -4
- package/dist/internal/herald.d.mts +1 -1
- package/dist/internal/math/aggregate.d.mts +43 -2
- package/dist/internal/math/aggregate.mjs +4 -1
- package/dist/internal/math/misc.d.mts +8 -0
- package/dist/internal/math/misc.mjs +11 -1
- package/dist/internal/random.mjs +2 -1
- package/dist/internal/result/attempt.d.mts +59 -0
- package/dist/internal/result/attempt.mjs +24 -0
- package/dist/internal/result/misc.d.mts +6 -6
- package/dist/internal/sized/map.d.mts +2 -2
- package/dist/internal/string/misc.mjs +4 -5
- package/dist/internal/value/compare.d.mts +7 -19
- package/dist/internal/value/equal.d.mts +8 -31
- package/dist/internal/value/equal.mjs +2 -1
- package/dist/internal/value/handlers.d.mts +2 -5
- package/dist/internal/value/has.d.mts +3 -3
- package/dist/internal/value/misc.mjs +1 -1
- package/dist/is.d.mts +4 -4
- package/dist/math.d.mts +3 -52
- package/dist/math.mjs +3 -16
- package/dist/promise/constants.d.mts +0 -1
- package/dist/promise/constants.mjs +1 -2
- package/dist/promise/helpers.d.mts +2 -2
- package/dist/promise/helpers.mjs +1 -1
- package/dist/promise/index.d.mts +7 -7
- package/dist/promise/index.mjs +9 -9
- package/dist/promise/misc.mjs +1 -1
- package/dist/promise/models.d.mts +1 -1
- package/dist/promise/timed.d.mts +1 -1
- package/dist/queue.d.mts +1 -1
- package/dist/queue.mjs +11 -6
- package/dist/result/index.d.mts +2 -59
- package/dist/result/index.mjs +1 -21
- package/dist/result/match.d.mts +3 -3
- package/dist/result/work/flow.d.mts +1 -1
- package/dist/result/work/flow.mjs +2 -1
- package/dist/result/work/pipe.d.mts +1 -1
- package/dist/result/work/pipe.mjs +2 -1
- package/dist/sized/set.d.mts +1 -1
- package/dist/string/fuzzy.d.mts +4 -4
- package/dist/string/fuzzy.mjs +7 -5
- package/dist/string/index.mjs +2 -1
- package/dist/string/normalize.d.mts +1 -1
- package/dist/string/template.d.mts +1 -2
- package/dist/value/clone.d.mts +8 -20
- package/dist/value/clone.mjs +5 -8
- package/dist/value/diff.d.mts +1 -1
- package/dist/value/diff.mjs +3 -2
- package/dist/value/freeze.d.mts +4 -4
- package/dist/value/merge.d.mts +5 -5
- package/dist/value/transform.d.mts +1 -1
- package/package.json +25 -10
- package/plugin/index.js +1 -1
package/dist/is.d.mts
CHANGED
|
@@ -27,14 +27,14 @@ export declare function isNonNullable<Value>(value: Value): value is Exclude<Val
|
|
|
27
27
|
* @param value Value to check
|
|
28
28
|
* @returns `true` if the value is not `undefined`, `null`, or matches an empty string, otherwise `false`
|
|
29
29
|
*/
|
|
30
|
-
export declare function isNonNullableOrEmpty<Value>(value: Value): value is Exclude<Value, undefined | null |
|
|
30
|
+
export declare function isNonNullableOrEmpty<Value>(value: Value): value is Exclude<Value, undefined | null | "">;
|
|
31
31
|
/**
|
|
32
32
|
* Is the value not `undefined`, `null`, or stringified as a whitespace-only string?
|
|
33
33
|
*
|
|
34
34
|
* @param value Value to check
|
|
35
35
|
* @returns `true` if the value is not `undefined`, `null`, or matches a whitespace-only string, otherwise `false`
|
|
36
36
|
*/
|
|
37
|
-
export declare function isNonNullableOrWhitespace<Value>(value: Value): value is Exclude<Value, undefined | null |
|
|
37
|
+
export declare function isNonNullableOrWhitespace<Value>(value: Value): value is Exclude<Value, undefined | null | "">;
|
|
38
38
|
/**
|
|
39
39
|
* Is the value not a number or a number-like string?
|
|
40
40
|
*
|
|
@@ -62,14 +62,14 @@ export declare function isNullable(value: unknown): value is undefined | null;
|
|
|
62
62
|
* @param value Value to check
|
|
63
63
|
* @returns `true` if the value is nullable or matches an empty string, otherwise `false`
|
|
64
64
|
*/
|
|
65
|
-
export declare function isNullableOrEmpty(value: unknown): value is undefined | null |
|
|
65
|
+
export declare function isNullableOrEmpty(value: unknown): value is undefined | null | "";
|
|
66
66
|
/**
|
|
67
67
|
* Is the value `undefined`, `null`, or stringified as a whitespace-only string?
|
|
68
68
|
*
|
|
69
69
|
* @param value Value to check
|
|
70
70
|
* @returns `true` if the value is nullable or matches a whitespace-only string, otherwise `false`
|
|
71
71
|
*/
|
|
72
|
-
export declare function isNullableOrWhitespace(value: unknown): value is undefined | null |
|
|
72
|
+
export declare function isNullableOrWhitespace(value: unknown): value is undefined | null | "";
|
|
73
73
|
/**
|
|
74
74
|
* Is the value a number or a number-like string?
|
|
75
75
|
*
|
package/dist/math.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NumericalValues, PlainObject } from "./models.mjs";
|
|
2
|
-
import { max } from "./internal/math/aggregate.mjs";
|
|
3
|
-
import { round } from "./internal/math/misc.mjs";
|
|
2
|
+
import { max, min } from "./internal/math/aggregate.mjs";
|
|
3
|
+
import { floor, round } from "./internal/math/misc.mjs";
|
|
4
4
|
//#region src/math.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Get the average value from a list of items
|
|
@@ -58,14 +58,6 @@ export declare function count<Item extends PlainObject, ItemKey extends keyof It
|
|
|
58
58
|
* @returns Number of items, or `Number.NaN` if no count can be calculated
|
|
59
59
|
*/
|
|
60
60
|
export declare function count(values: unknown[]): number;
|
|
61
|
-
/**
|
|
62
|
-
* Round a number down
|
|
63
|
-
*
|
|
64
|
-
* @param value Number to round down
|
|
65
|
-
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
66
|
-
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
67
|
-
*/
|
|
68
|
-
export declare function floor(value: number, decimals?: number): number;
|
|
69
61
|
/**
|
|
70
62
|
* Get the median value from a list of items
|
|
71
63
|
*
|
|
@@ -89,47 +81,6 @@ export declare function median<Item extends PlainObject>(array: Item[], key: key
|
|
|
89
81
|
* @returns Median value, or `Number.NaN` if no median can be calculated
|
|
90
82
|
*/
|
|
91
83
|
export declare function median(array: number[]): number;
|
|
92
|
-
/**
|
|
93
|
-
* Get the minimum value from a list of items
|
|
94
|
-
*
|
|
95
|
-
* @param items List of items
|
|
96
|
-
* @param callback Callback to get an item's value
|
|
97
|
-
* @param first Return only the first item with the minimum value
|
|
98
|
-
* @returns First item with the minimum value, or `undefined` if no minimum can be found
|
|
99
|
-
*/
|
|
100
|
-
export declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number, first: true): Item | undefined;
|
|
101
|
-
/**
|
|
102
|
-
* Get the minimum value from a list of items
|
|
103
|
-
*
|
|
104
|
-
* @param items List of items
|
|
105
|
-
* @param key Key to use for value
|
|
106
|
-
* @param first Return only the first item with the minimum value
|
|
107
|
-
* @returns First item with the minimum value, or `undefined` if no minimum can be found
|
|
108
|
-
*/
|
|
109
|
-
export declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>, first: true): Item | undefined;
|
|
110
|
-
/**
|
|
111
|
-
* Get the minimum value from a list of items
|
|
112
|
-
*
|
|
113
|
-
* @param items List of items
|
|
114
|
-
* @param callback Callback to get an item's value
|
|
115
|
-
* @returns Items with the minimum value
|
|
116
|
-
*/
|
|
117
|
-
export declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): Item[];
|
|
118
|
-
/**
|
|
119
|
-
* Get the minimum value from a list of items
|
|
120
|
-
*
|
|
121
|
-
* @param items List of items
|
|
122
|
-
* @param key Key to use for value
|
|
123
|
-
* @returns Items with the minimum value
|
|
124
|
-
*/
|
|
125
|
-
export declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): Item[];
|
|
126
|
-
/**
|
|
127
|
-
* Get the minimum value from a list of numbers
|
|
128
|
-
*
|
|
129
|
-
* @param values List of numbers
|
|
130
|
-
* @returns Minimum value, or `Number.NaN` if no minimum can be found
|
|
131
|
-
*/
|
|
132
|
-
export declare function min(values: number[]): number;
|
|
133
84
|
/**
|
|
134
85
|
* Get the sum of a list of items
|
|
135
86
|
*
|
|
@@ -154,4 +105,4 @@ export declare function sum<Item extends PlainObject>(items: Item[], key: keyof
|
|
|
154
105
|
*/
|
|
155
106
|
export declare function sum(values: number[]): number;
|
|
156
107
|
//#endregion
|
|
157
|
-
export { max, round };
|
|
108
|
+
export { floor, max, min, round };
|
package/dist/math.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isNumber } from "./internal/is.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { floor, round, roundNumber } from "./internal/math/misc.mjs";
|
|
3
|
+
import { AGGREGATION_AVERAGE, aggregate, getAggregateCallback, getAggregated, max, min } from "./internal/math/aggregate.mjs";
|
|
4
4
|
//#region src/math.ts
|
|
5
5
|
function average(array, key) {
|
|
6
6
|
const aggregated = aggregate(AGGREGATION_AVERAGE, array, key);
|
|
@@ -28,16 +28,6 @@ function count(array, key, value) {
|
|
|
28
28
|
}
|
|
29
29
|
return counted;
|
|
30
30
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Round a number down
|
|
33
|
-
*
|
|
34
|
-
* @param value Number to round down
|
|
35
|
-
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
36
|
-
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
37
|
-
*/
|
|
38
|
-
function floor(value, decimals) {
|
|
39
|
-
return roundNumber(Math.floor, value, decimals);
|
|
40
|
-
}
|
|
41
31
|
function median(array, key) {
|
|
42
32
|
let length = Array.isArray(array) ? array.length : 0;
|
|
43
33
|
if (!Array.isArray(array) || length === 0) return NaN;
|
|
@@ -52,10 +42,7 @@ function median(array, key) {
|
|
|
52
42
|
const second = length / 2;
|
|
53
43
|
return (numbers[first] + numbers[second]) / 2;
|
|
54
44
|
}
|
|
55
|
-
return numbers[
|
|
56
|
-
}
|
|
57
|
-
function min(array, key, first) {
|
|
58
|
-
return getAggregated("min", array, key, first);
|
|
45
|
+
return numbers[floor(length / 2)];
|
|
59
46
|
}
|
|
60
47
|
function sum(array, key) {
|
|
61
48
|
return getAggregated("sum", array, key);
|
|
@@ -6,7 +6,6 @@ export declare const PROMISE_ABORT_OPTIONS: {
|
|
|
6
6
|
};
|
|
7
7
|
export declare const PROMISE_ERROR_NAME = "PromiseTimeoutError";
|
|
8
8
|
export declare const PROMISE_MESSAGE_EXPECTATION_ATTEMPT = "Attempt expected a function or a promise";
|
|
9
|
-
export declare const PROMISE_MESSAGE_EXPECTATION_ITEMS_EMPTY = "promises expected at least one promise-function or promise in the array or object";
|
|
10
9
|
export declare const PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE = "promises expected an array or object holding promise-functions or promises";
|
|
11
10
|
export declare const PROMISE_MESSAGE_EXPECTATION_RESULT = "toResult expected a Promise";
|
|
12
11
|
export declare const PROMISE_MESSAGE_EXPECTATION_TIMED = "Timed function expected a Promise";
|
|
@@ -3,7 +3,6 @@ const PROMISE_ABORT_EVENT = "abort";
|
|
|
3
3
|
const PROMISE_ABORT_OPTIONS = { once: true };
|
|
4
4
|
const PROMISE_ERROR_NAME = "PromiseTimeoutError";
|
|
5
5
|
const PROMISE_MESSAGE_EXPECTATION_ATTEMPT = "Attempt expected a function or a promise";
|
|
6
|
-
const PROMISE_MESSAGE_EXPECTATION_ITEMS_EMPTY = "promises expected at least one promise-function or promise in the array or object";
|
|
7
6
|
const PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE = "promises expected an array or object holding promise-functions or promises";
|
|
8
7
|
const PROMISE_MESSAGE_EXPECTATION_RESULT = "toResult expected a Promise";
|
|
9
8
|
const PROMISE_MESSAGE_EXPECTATION_TIMED = "Timed function expected a Promise";
|
|
@@ -13,4 +12,4 @@ const PROMISE_STRATEGY_DEFAULT = "complete";
|
|
|
13
12
|
const PROMISE_TYPE_FULFILLED = "fulfilled";
|
|
14
13
|
const PROMISE_TYPE_REJECTED = "rejected";
|
|
15
14
|
//#endregion
|
|
16
|
-
export { PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT,
|
|
15
|
+
export { PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { RequiredKeys } from "../models.mjs";
|
|
2
2
|
import { FulfilledPromise, PromiseOptions, PromiseStrategy, PromisesOptions, PromisesValue, RejectedPromise } from "./models.mjs";
|
|
3
3
|
//#region src/promise/helpers.d.ts
|
|
4
|
-
export declare function createPromiseOptions(input: unknown): RequiredKeys<PromiseOptions,
|
|
5
|
-
export declare function createPromisesOptions(input: unknown): RequiredKeys<PromisesOptions,
|
|
4
|
+
export declare function createPromiseOptions(input: unknown): RequiredKeys<PromiseOptions, "time">;
|
|
5
|
+
export declare function createPromisesOptions(input: unknown): RequiredKeys<PromisesOptions, "strategy">;
|
|
6
6
|
export declare function getResultsFromPromises(promised: Array<PromisesValue<unknown>> | Record<string, PromisesValue<unknown>>): unknown;
|
|
7
7
|
export declare function getStrategyOrDefault(value: unknown): PromiseStrategy;
|
|
8
8
|
/**
|
package/dist/promise/helpers.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isPlainObject } from "../internal/is.mjs";
|
|
2
|
-
import { getNumberOrDefault } from "../internal/defaults.mjs";
|
|
3
2
|
import { error, ok } from "../internal/result/misc.mjs";
|
|
3
|
+
import { getNumberOrDefault } from "../internal/defaults.mjs";
|
|
4
4
|
import { PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "./constants.mjs";
|
|
5
5
|
//#region src/promise/helpers.ts
|
|
6
6
|
function createPromiseOptions(input) {
|
package/dist/promise/index.d.mts
CHANGED
|
@@ -34,7 +34,7 @@ export declare function attemptPromise<Value>(callback: () => Value, options?: P
|
|
|
34
34
|
* @param options Options for handling the _Promises_
|
|
35
35
|
* @returns List of results
|
|
36
36
|
*/
|
|
37
|
-
export declare function promises<Items extends unknown[], Options extends PromisesOptions>(items: [...Items], options?: Options): Promise<Options[
|
|
37
|
+
export declare function promises<Items extends unknown[], Options extends PromisesOptions>(items: [...Items], options?: Options): Promise<Options["strategy"] extends "first" ? PromisesUnwrapped<Items> : PromisesValues<PromisesItems<Items>>>;
|
|
38
38
|
/**
|
|
39
39
|
* Handle keyed _Promises_, returning their results in a similarly keyed object
|
|
40
40
|
*
|
|
@@ -44,7 +44,7 @@ export declare function promises<Items extends unknown[], Options extends Promis
|
|
|
44
44
|
* @param options Options for handling the _Promises_
|
|
45
45
|
* @returns Keyed object of results
|
|
46
46
|
*/
|
|
47
|
-
export declare function promises<Items extends PlainObject, Options extends PromisesOptions>(items: Items, options?: Options): Promise<Options[
|
|
47
|
+
export declare function promises<Items extends PlainObject, Options extends PromisesOptions>(items: Items, options?: Options): Promise<Options["strategy"] extends "first" ? PromisesUnwrapped<Items> : PromisesValues<PromisesItems<Items>>>;
|
|
48
48
|
/**
|
|
49
49
|
* Handle a list of _Promises_, returning their results in an ordered array
|
|
50
50
|
*
|
|
@@ -54,7 +54,7 @@ export declare function promises<Items extends PlainObject, Options extends Prom
|
|
|
54
54
|
* @param strategy Strategy for handling the _Promises_
|
|
55
55
|
* @returns List of results
|
|
56
56
|
*/
|
|
57
|
-
export declare function promises<Items extends unknown[], Strategy extends PromiseStrategy>(items: [...Items], strategy: Strategy): Promise<Strategy extends
|
|
57
|
+
export declare function promises<Items extends unknown[], Strategy extends PromiseStrategy>(items: [...Items], strategy: Strategy): Promise<Strategy extends "first" ? PromisesUnwrapped<Items> : PromisesValues<PromisesItems<Items>>>;
|
|
58
58
|
/**
|
|
59
59
|
* Handle keyed _Promises_, returning their results in a similarly keyed object
|
|
60
60
|
*
|
|
@@ -64,7 +64,7 @@ export declare function promises<Items extends unknown[], Strategy extends Promi
|
|
|
64
64
|
* @param strategy Strategy for handling the _Promises_
|
|
65
65
|
* @returns Keyed object of results
|
|
66
66
|
*/
|
|
67
|
-
export declare function promises<Items extends PlainObject, Strategy extends PromiseStrategy>(items: Items, strategy: Strategy): Promise<Strategy extends
|
|
67
|
+
export declare function promises<Items extends PlainObject, Strategy extends PromiseStrategy>(items: Items, strategy: Strategy): Promise<Strategy extends "first" ? PromisesUnwrapped<Items> : PromisesValues<PromisesItems<Items>>>;
|
|
68
68
|
/**
|
|
69
69
|
* Handle a list of _Promises_, returning their results in an ordered array
|
|
70
70
|
*
|
|
@@ -81,9 +81,6 @@ export declare function promises<Items extends unknown[]>(items: [...Items], sig
|
|
|
81
81
|
* @returns Keyed object of results
|
|
82
82
|
*/
|
|
83
83
|
export declare function promises<Items extends PlainObject>(items: Items, signal?: AbortSignal): Promise<PromisesValues<PromisesItems<Items>>>;
|
|
84
|
-
export declare namespace promises {
|
|
85
|
-
var result: typeof resultPromises;
|
|
86
|
-
}
|
|
87
84
|
/**
|
|
88
85
|
* Handle a list of _Promises_, returning their results in an ordered array of results _({@link Result})_
|
|
89
86
|
*
|
|
@@ -106,4 +103,7 @@ export declare function resultPromises<Items extends unknown[]>(items: [...Items
|
|
|
106
103
|
* @returns Keyed object of results
|
|
107
104
|
*/
|
|
108
105
|
export declare function resultPromises<Items extends PlainObject>(items: Items, signal?: AbortSignal): Promise<PromisesResult<PromisesItems<Items>>>;
|
|
106
|
+
export declare namespace promises {
|
|
107
|
+
export var result: typeof resultPromises;
|
|
108
|
+
}
|
|
109
109
|
//#endregion
|
package/dist/promise/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isArrayOrPlainObject } from "../internal/is.mjs";
|
|
2
2
|
import { createAborter } from "../internal/aborter.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { asyncAttempt } from "../internal/result/attempt.mjs";
|
|
4
|
+
import { PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "./constants.mjs";
|
|
4
5
|
import { createPromiseOptions, createPromisesOptions, getResultsFromPromises } from "./helpers.mjs";
|
|
5
6
|
import { handleResult, settlePromise } from "./misc.mjs";
|
|
6
7
|
import { getTimedPromise } from "./timed.mjs";
|
|
@@ -14,13 +15,13 @@ async function attemptPromise(value, options) {
|
|
|
14
15
|
rejector(signal?.reason);
|
|
15
16
|
});
|
|
16
17
|
async function handler(resolve, reject) {
|
|
17
|
-
|
|
18
|
+
const result = await asyncAttempt(async () => {
|
|
18
19
|
let result = isFunction ? value() : await value;
|
|
19
20
|
if (result instanceof Promise) result = await result;
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
return result;
|
|
22
|
+
});
|
|
23
|
+
if (result.ok) settlePromise(resolve, result.value, aborter);
|
|
24
|
+
else settlePromise(reject, result.error, aborter);
|
|
24
25
|
}
|
|
25
26
|
let rejector;
|
|
26
27
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -35,12 +36,11 @@ async function promises(items, options) {
|
|
|
35
36
|
if (!isArrayOrPlainObject(items)) return Promise.reject(PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE);
|
|
36
37
|
const isArray = Array.isArray(items);
|
|
37
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);
|
|
38
|
-
const { length } = actual;
|
|
39
|
-
if (length === 0) return Promise.reject(PROMISE_MESSAGE_EXPECTATION_ITEMS_EMPTY);
|
|
40
|
-
const complete = strategy === PROMISE_STRATEGY_DEFAULT;
|
|
41
39
|
const aborter = createAborter(signal, () => {
|
|
42
40
|
handlers.reject(signal?.reason);
|
|
43
41
|
});
|
|
42
|
+
const complete = strategy === PROMISE_STRATEGY_DEFAULT;
|
|
43
|
+
const { length } = actual;
|
|
44
44
|
const data = {
|
|
45
45
|
last: length - 1,
|
|
46
46
|
result: isArray ? [] : {}
|
package/dist/promise/misc.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { error, ok } from "../internal/result/misc.mjs";
|
|
2
|
+
import { toPromise } from "../result/misc.mjs";
|
|
2
3
|
import { PROMISE_MESSAGE_EXPECTATION_RESULT } from "./constants.mjs";
|
|
3
4
|
import { CancelablePromise } from "./models.mjs";
|
|
4
5
|
import { isFulfilled, isRejected } from "./helpers.mjs";
|
|
5
|
-
import { toPromise } from "../result/misc.mjs";
|
|
6
6
|
//#region src/promise/misc.ts
|
|
7
7
|
/**
|
|
8
8
|
* Create a cancelable _Promise_
|
|
@@ -65,7 +65,7 @@ export type PromiseParameters = {
|
|
|
65
65
|
* - `complete`: wait for all _Promises_ to settle, then return the results, as an array of fulfilled and/or rejected results
|
|
66
66
|
* - `first`: rejects on the first rejected _Promise_, and returns an array of values
|
|
67
67
|
*/
|
|
68
|
-
export type PromiseStrategy =
|
|
68
|
+
export type PromiseStrategy = "complete" | "first";
|
|
69
69
|
/**
|
|
70
70
|
* An error thrown when a promise times out
|
|
71
71
|
*/
|
package/dist/promise/timed.d.mts
CHANGED
|
@@ -9,7 +9,7 @@ export declare function getTimedPromise<Value>(promise: Promise<Value>, time: nu
|
|
|
9
9
|
* @param options Timed options
|
|
10
10
|
* @returns Timed _Promise_
|
|
11
11
|
*/
|
|
12
|
-
export declare function timed<Value>(promise: Promise<Value>, options: RequiredKeys<PromiseOptions,
|
|
12
|
+
export declare function timed<Value>(promise: Promise<Value>, options: RequiredKeys<PromiseOptions, "time">): Promise<Value>;
|
|
13
13
|
/**
|
|
14
14
|
* Create a _Promise_ that should be settled within a certain amount of time
|
|
15
15
|
*
|
package/dist/queue.d.mts
CHANGED
|
@@ -248,6 +248,6 @@ export declare function queue<Callback extends GenericAsyncCallback>(callback: C
|
|
|
248
248
|
*/
|
|
249
249
|
export declare function queue<Callback extends GenericCallback>(callback: Callback, options?: QueueOptions): Queue<Callback, Parameters<Callback>>;
|
|
250
250
|
export declare namespace queue {
|
|
251
|
-
var keyed: typeof keyedQueue;
|
|
251
|
+
export var keyed: typeof keyedQueue;
|
|
252
252
|
}
|
|
253
253
|
//#endregion
|
package/dist/queue.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { createAborter } from "./internal/aborter.mjs";
|
|
2
|
+
import { min } from "./internal/math/aggregate.mjs";
|
|
3
|
+
import { asyncAttempt } from "./internal/result/attempt.mjs";
|
|
2
4
|
import { getBooleanOrDefault, getNumberOrDefault } from "./internal/defaults.mjs";
|
|
3
5
|
//#region src/queue.ts
|
|
4
6
|
const QUEUE_NAME_KEYED = "keyedQueue";
|
|
@@ -333,7 +335,7 @@ function resumeQueue() {
|
|
|
333
335
|
for (let index = 0; index < length; index += 1) handled[index]();
|
|
334
336
|
}
|
|
335
337
|
state.paused = false;
|
|
336
|
-
const length =
|
|
338
|
+
const length = min([state.options.concurrency, state.items.length]);
|
|
337
339
|
for (let index = 0; index < length; index += 1) run(state);
|
|
338
340
|
}
|
|
339
341
|
function resumeQueues(key) {
|
|
@@ -346,14 +348,17 @@ async function run(state) {
|
|
|
346
348
|
while (item != null) {
|
|
347
349
|
let error = false;
|
|
348
350
|
let result;
|
|
349
|
-
|
|
350
|
-
if (!(item.aborter?.signal?.aborted ?? false)) {
|
|
351
|
+
const attempted = await asyncAttempt(async () => {
|
|
352
|
+
if (item != null && !(item.aborter?.signal?.aborted ?? false)) {
|
|
351
353
|
const parameters = item.key == null ? item.parameters : [item.key, ...item.parameters];
|
|
352
|
-
|
|
354
|
+
return await state.callback(...parameters);
|
|
353
355
|
}
|
|
354
|
-
|
|
356
|
+
throw new Error();
|
|
357
|
+
});
|
|
358
|
+
if (attempted.ok) result = attempted.value;
|
|
359
|
+
else {
|
|
355
360
|
error = true;
|
|
356
|
-
result =
|
|
361
|
+
result = attempted.error;
|
|
357
362
|
}
|
|
358
363
|
if (state.paused) {
|
|
359
364
|
const paused = item;
|
package/dist/result/index.d.mts
CHANGED
|
@@ -1,59 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Executes a _Promise_, catching any errors, and returns a result
|
|
5
|
-
*
|
|
6
|
-
* _Available as `asyncAttempt` and `attempt.async`_
|
|
7
|
-
*
|
|
8
|
-
* @param promise _Promise_ to execute
|
|
9
|
-
* @param error Error value
|
|
10
|
-
* @returns Callback result
|
|
11
|
-
*/
|
|
12
|
-
export declare function asyncAttempt<Value, E>(promise: Promise<Value>, error: E): Promise<ExtendedResult<Awaited<Value>, E>>;
|
|
13
|
-
/**
|
|
14
|
-
* Executes a callback asynchronously, catching any errors, and returns a result
|
|
15
|
-
*
|
|
16
|
-
* _Available as `asyncAttempt` and `attempt.async`_
|
|
17
|
-
*
|
|
18
|
-
* @param callback Callback to execute
|
|
19
|
-
* @param error Error value
|
|
20
|
-
* @returns Callback result
|
|
21
|
-
*/
|
|
22
|
-
export declare function asyncAttempt<Value, E>(callback: () => Promise<Value>, error: E): Promise<ExtendedResult<Awaited<Value>, E>>;
|
|
23
|
-
/**
|
|
24
|
-
* Executes a _Promise_, catching any errors, and returns a result
|
|
25
|
-
*
|
|
26
|
-
* _Available as `asyncAttempt` and `attempt.async`_
|
|
27
|
-
*
|
|
28
|
-
* @param promise _Promise_ to execute
|
|
29
|
-
* @returns Callback result
|
|
30
|
-
*/
|
|
31
|
-
export declare function asyncAttempt<Value>(promise: Promise<Value>): Promise<Result<Awaited<Value>>>;
|
|
32
|
-
/**
|
|
33
|
-
* Executes a callback asynchronously, catching any errors, and returns a result
|
|
34
|
-
*
|
|
35
|
-
* _Available as `asyncAttempt` and `attempt.async`_
|
|
36
|
-
*
|
|
37
|
-
* @param callback Callback to execute
|
|
38
|
-
* @returns Callback result
|
|
39
|
-
*/
|
|
40
|
-
export declare function asyncAttempt<Value>(callback: () => Promise<Value>): Promise<Result<Awaited<Value>>>;
|
|
41
|
-
/**
|
|
42
|
-
* Executes a callback, catching any errors, and returns a result
|
|
43
|
-
*
|
|
44
|
-
* @param callback Callback to execute
|
|
45
|
-
* @param error Error value
|
|
46
|
-
* @returns Callback result
|
|
47
|
-
*/
|
|
48
|
-
export declare function attempt<Value, E>(callback: () => Value, error: E): ExtendedResult<Value, E>;
|
|
49
|
-
/**
|
|
50
|
-
* Executes a callback, catching any errors, and returns a result
|
|
51
|
-
*
|
|
52
|
-
* @param callback Callback to execute
|
|
53
|
-
* @returns Callback result
|
|
54
|
-
*/
|
|
55
|
-
export declare function attempt<Value>(callback: () => Value): Result<Value, Error>;
|
|
56
|
-
export declare namespace attempt {
|
|
57
|
-
var async: typeof asyncAttempt;
|
|
58
|
-
}
|
|
59
|
-
//#endregion
|
|
1
|
+
import { asyncAttempt, attempt } from "../internal/result/attempt.mjs";
|
|
2
|
+
export { asyncAttempt, attempt };
|
package/dist/result/index.mjs
CHANGED
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region src/result/index.ts
|
|
3
|
-
async function asyncAttempt(value, err) {
|
|
4
|
-
try {
|
|
5
|
-
let result = typeof value === "function" ? value() : await value;
|
|
6
|
-
if (result instanceof Promise) result = await result;
|
|
7
|
-
return ok(result);
|
|
8
|
-
} catch (thrown) {
|
|
9
|
-
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function attempt(callback, err) {
|
|
13
|
-
try {
|
|
14
|
-
const value = callback();
|
|
15
|
-
return ok(value);
|
|
16
|
-
} catch (thrown) {
|
|
17
|
-
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
attempt.async = asyncAttempt;
|
|
21
|
-
//#endregion
|
|
1
|
+
import { asyncAttempt, attempt } from "../internal/result/attempt.mjs";
|
|
22
2
|
export { asyncAttempt, attempt };
|
package/dist/result/match.d.mts
CHANGED
|
@@ -20,7 +20,7 @@ export declare function asyncMatchResult<Value, Returned, E = Error>(result: Any
|
|
|
20
20
|
* @param error Error callback
|
|
21
21
|
* @returns Matched value-_Promise_
|
|
22
22
|
*/
|
|
23
|
-
export declare function asyncMatchResult<Value, Returned, E = Error>(result: AnyResult<Value, E> | Promise<AnyResult<Value, E>> | (() => Promise<AnyResult<Value, E>>), ok: ResultMatch<Value, Returned, E>[
|
|
23
|
+
export declare function asyncMatchResult<Value, Returned, E = Error>(result: AnyResult<Value, E> | Promise<AnyResult<Value, E>> | (() => Promise<AnyResult<Value, E>>), ok: ResultMatch<Value, Returned, E>["ok"], error: ResultMatch<Value, Returned, E>["error"]): Promise<Returned>;
|
|
24
24
|
/**
|
|
25
25
|
* Handles a _Result_ with match callbacks
|
|
26
26
|
*
|
|
@@ -37,8 +37,8 @@ export declare function matchResult<Value, Returned, E = Error>(result: AnyResul
|
|
|
37
37
|
* @param error Error callback
|
|
38
38
|
* @returns Matched value
|
|
39
39
|
*/
|
|
40
|
-
export declare function matchResult<Value, Returned, E = Error>(result: AnyResult<Value, E> | (() => AnyResult<Value, E>), ok: ResultMatch<Value, Returned, E>[
|
|
40
|
+
export declare function matchResult<Value, Returned, E = Error>(result: AnyResult<Value, E> | (() => AnyResult<Value, E>), ok: ResultMatch<Value, Returned, E>["ok"], error: ResultMatch<Value, Returned, E>["error"]): Returned;
|
|
41
41
|
export declare namespace matchResult {
|
|
42
|
-
var async: typeof asyncMatchResult;
|
|
42
|
+
export var async: typeof asyncMatchResult;
|
|
43
43
|
}
|
|
44
44
|
//#endregion
|
|
@@ -178,6 +178,6 @@ export declare function attemptFlow<First extends GenericCallback>(first: First,
|
|
|
178
178
|
*/
|
|
179
179
|
export declare function attemptFlow(...fns: GenericCallback[]): (...args: unknown[]) => Result<unknown>;
|
|
180
180
|
export declare namespace attemptFlow {
|
|
181
|
-
var async: typeof attemptAsyncFlow;
|
|
181
|
+
export var async: typeof attemptAsyncFlow;
|
|
182
182
|
}
|
|
183
183
|
//#endregion
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isError, isOk } from "../../internal/result/misc.mjs";
|
|
2
|
+
import { asyncAttempt, attempt } from "../../internal/result/attempt.mjs";
|
|
2
3
|
import { asyncFlow, flow } from "../../internal/function/work.mjs";
|
|
3
|
-
import
|
|
4
|
+
import "../index.mjs";
|
|
4
5
|
//#region src/result/work/flow.ts
|
|
5
6
|
function attemptAsyncFlow(...fns) {
|
|
6
7
|
let Flow;
|
|
@@ -179,6 +179,6 @@ export declare function attemptPipe<Initial, First, Second, Third, Fourth, Fifth
|
|
|
179
179
|
*/
|
|
180
180
|
export declare function attemptPipe<Initial>(initial: GenericCallback | Initial | Result<Initial>, first?: (value: UnwrapValue<Initial>) => unknown, ...seconds: Array<(value: unknown) => unknown>): WrapValue<Initial>;
|
|
181
181
|
export declare namespace attemptPipe {
|
|
182
|
-
var async: typeof attemptAsyncPipe;
|
|
182
|
+
export var async: typeof attemptAsyncPipe;
|
|
183
183
|
}
|
|
184
184
|
//#endregion
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isError, isOk } from "../../internal/result/misc.mjs";
|
|
2
|
+
import { asyncAttempt, attempt } from "../../internal/result/attempt.mjs";
|
|
2
3
|
import { asyncPipe, pipe } from "../../internal/function/work.mjs";
|
|
3
|
-
import
|
|
4
|
+
import "../index.mjs";
|
|
4
5
|
//#region src/result/work/pipe.ts
|
|
5
6
|
async function attemptAsyncPipe(initial, first, ...seconds) {
|
|
6
7
|
return asyncAttempt(() => {
|
package/dist/sized/set.d.mts
CHANGED
|
@@ -36,7 +36,7 @@ export declare class SizedSet<Value = unknown> extends Set<Value> {
|
|
|
36
36
|
/**
|
|
37
37
|
* @inheritdoc
|
|
38
38
|
*/
|
|
39
|
-
add(value: Value): this;
|
|
39
|
+
override add(value: Value): this;
|
|
40
40
|
/**
|
|
41
41
|
* Get a value from the _SizedSet_, if it exists _(and optionally move it to the end)_
|
|
42
42
|
*
|
package/dist/string/fuzzy.d.mts
CHANGED
|
@@ -109,10 +109,6 @@ export declare function fuzzy<Item>(items: Item[], handler?: (item: Item) => str
|
|
|
109
109
|
* @returns Fuzzy searcher
|
|
110
110
|
*/
|
|
111
111
|
export declare function fuzzy<Item>(items: Item[], configuration?: FuzzyConfiguration<Item>): Fuzzy<Item>;
|
|
112
|
-
export declare namespace fuzzy {
|
|
113
|
-
var is: typeof isFuzzy;
|
|
114
|
-
var match: typeof fuzzyMatch;
|
|
115
|
-
}
|
|
116
112
|
/**
|
|
117
113
|
* Does the needle match the haystack in a fuzzy way?
|
|
118
114
|
*
|
|
@@ -132,4 +128,8 @@ export declare function fuzzyMatch(haystack: string, needle: string): boolean;
|
|
|
132
128
|
* @returns `true` if the value is a fuzzy searcher, otherwise `false`
|
|
133
129
|
*/
|
|
134
130
|
export declare function isFuzzy<Item = unknown>(value: unknown): value is Fuzzy<Item>;
|
|
131
|
+
export declare namespace fuzzy {
|
|
132
|
+
export var is: typeof isFuzzy;
|
|
133
|
+
export var match: typeof fuzzyMatch;
|
|
134
|
+
}
|
|
135
135
|
//#endregion
|
package/dist/string/fuzzy.mjs
CHANGED
|
@@ -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 =
|
|
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 +=
|
|
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 -=
|
|
103
|
-
return
|
|
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 :
|
|
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
|
/**
|
package/dist/string/index.mjs
CHANGED
|
@@ -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 =
|
|
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) {
|
|
@@ -65,6 +65,6 @@ export declare function initializeNormalizer(options?: NormalizeOptions): Normal
|
|
|
65
65
|
*/
|
|
66
66
|
export declare function normalize(value: string, options?: NormalizeOptions): string;
|
|
67
67
|
export declare namespace normalize {
|
|
68
|
-
var initialize: typeof initializeNormalizer;
|
|
68
|
+
export var initialize: typeof initializeNormalizer;
|
|
69
69
|
}
|
|
70
70
|
//#endregion
|
|
@@ -41,7 +41,6 @@ type Templater = {
|
|
|
41
41
|
* Render a template string with variables
|
|
42
42
|
*/
|
|
43
43
|
type TemplaterRenderer = (variables?: PlainObject) => string;
|
|
44
|
-
declare function Templater(this: any, options: Required<TemplateOptions>): void;
|
|
45
44
|
/**
|
|
46
45
|
* Create a _Templater_ with predefined options
|
|
47
46
|
*
|
|
@@ -67,6 +66,6 @@ export declare function template(strings: TemplateStringsArray, ...values: unkno
|
|
|
67
66
|
*/
|
|
68
67
|
export declare function template(value: string, variables?: PlainObject, options?: Partial<TemplateOptions>): string;
|
|
69
68
|
export declare namespace template {
|
|
70
|
-
var initialize: typeof initializeTemplater;
|
|
69
|
+
export var initialize: typeof initializeTemplater;
|
|
71
70
|
}
|
|
72
71
|
//#endregion
|