@oscarpalmer/atoms 0.195.0 → 0.196.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/function/limit.d.mts +6 -0
- package/dist/function/limit.mjs +2 -0
- package/dist/function/once.d.mts +3 -0
- package/dist/function/once.mjs +1 -0
- package/dist/function/retry.d.mts +24 -1
- package/dist/function/retry.mjs +1 -0
- package/dist/index.d.mts +113 -20
- package/dist/index.mjs +50 -21
- package/dist/internal/math/aggregate.d.mts +51 -10
- package/dist/internal/math/aggregate.mjs +40 -19
- package/dist/math.d.mts +22 -4
- package/dist/math.mjs +2 -2
- package/dist/models.d.mts +1 -8
- package/dist/result/index.d.mts +3 -0
- package/dist/result/index.mjs +1 -0
- package/dist/result/match.d.mts +3 -0
- package/dist/result/match.mjs +1 -0
- package/dist/result/work/flow.d.mts +3 -0
- package/dist/result/work/flow.mjs +1 -0
- package/dist/result/work/pipe.d.mts +3 -0
- package/dist/result/work/pipe.mjs +1 -0
- package/package.json +1 -1
|
@@ -36,6 +36,9 @@ declare function asyncThrottle<Callback extends GenericAsyncCallback | GenericCa
|
|
|
36
36
|
* @returns Debounced callback handler with a `cancel` method
|
|
37
37
|
*/
|
|
38
38
|
declare function debounce<Callback extends GenericCallback>(callback: Callback, time?: number): CancelableCallback<Callback>;
|
|
39
|
+
declare namespace debounce {
|
|
40
|
+
var async: typeof asyncDebounce;
|
|
41
|
+
}
|
|
39
42
|
/**
|
|
40
43
|
* Throttle a function, ensuring it is only called once every `time` milliseconds
|
|
41
44
|
*
|
|
@@ -44,5 +47,8 @@ declare function debounce<Callback extends GenericCallback>(callback: Callback,
|
|
|
44
47
|
* @returns Throttled callback handler with a `cancel` method
|
|
45
48
|
*/
|
|
46
49
|
declare function throttle<Callback extends GenericCallback>(callback: Callback, time?: number): CancelableCallback<Callback>;
|
|
50
|
+
declare namespace throttle {
|
|
51
|
+
var async: typeof asyncThrottle;
|
|
52
|
+
}
|
|
47
53
|
//#endregion
|
|
48
54
|
export { asyncDebounce, asyncThrottle, debounce, throttle };
|
package/dist/function/limit.mjs
CHANGED
|
@@ -52,6 +52,8 @@ function debounce(callback, time) {
|
|
|
52
52
|
function throttle(callback, time) {
|
|
53
53
|
return getTimer(TIMER_THROTTLE, callback, time);
|
|
54
54
|
}
|
|
55
|
+
debounce.async = asyncDebounce;
|
|
56
|
+
throttle.async = asyncThrottle;
|
|
55
57
|
Object.defineProperty(debounce, "async", { value: asyncDebounce });
|
|
56
58
|
Object.defineProperty(throttle, "async", { value: asyncThrottle });
|
|
57
59
|
//#endregion
|
package/dist/function/once.d.mts
CHANGED
|
@@ -16,5 +16,8 @@ declare function asyncOnce<Callback extends GenericAsyncCallback>(callback: Call
|
|
|
16
16
|
* @returns _Once_ callback
|
|
17
17
|
*/
|
|
18
18
|
declare function once<Callback extends GenericCallback>(callback: Callback): OnceCallback<Callback>;
|
|
19
|
+
declare namespace once {
|
|
20
|
+
var async: typeof asyncOnce;
|
|
21
|
+
}
|
|
19
22
|
//#endregion
|
|
20
23
|
export { asyncOnce, once };
|
package/dist/function/once.mjs
CHANGED
|
@@ -113,6 +113,7 @@ function once(callback) {
|
|
|
113
113
|
}
|
|
114
114
|
const ONCE_MESSAGE_CLEARED = "Once has been cleared";
|
|
115
115
|
const ONCE_MESSAGE_EXPECTATION = "Once expected a function";
|
|
116
|
+
once.async = asyncOnce;
|
|
116
117
|
Object.defineProperty(once, "async", { value: asyncOnce });
|
|
117
118
|
//#endregion
|
|
118
119
|
export { asyncOnce, once };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GenericCallback } from "../models.mjs";
|
|
1
|
+
import { GenericAsyncCallback, GenericCallback } from "../models.mjs";
|
|
2
2
|
//#region src/function/retry.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* An error thrown when a retry fails
|
|
@@ -12,6 +12,26 @@ type RetryOptions = {
|
|
|
12
12
|
times?: number;
|
|
13
13
|
when?: (error: unknown) => boolean;
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Retry a callback a specified number of times, with a delay between attempts
|
|
17
|
+
*
|
|
18
|
+
* _Available as `asyncRetry` and `retry.async`_
|
|
19
|
+
*
|
|
20
|
+
* @param callback Callback to retry
|
|
21
|
+
* @param options Retry options
|
|
22
|
+
* @returns Callback result
|
|
23
|
+
*/
|
|
24
|
+
declare function asyncRetry<Callback extends GenericAsyncCallback>(callback: Callback, options?: RetryOptions): Promise<Awaited<ReturnType<Callback>>>;
|
|
25
|
+
/**
|
|
26
|
+
* Retry a callback a specified number of times, with a delay between attempts
|
|
27
|
+
*
|
|
28
|
+
* _Available as `asyncRetry` and `retry.async`_
|
|
29
|
+
*
|
|
30
|
+
* @param callback Callback to retry
|
|
31
|
+
* @param options Retry options
|
|
32
|
+
* @returns Callback result
|
|
33
|
+
*/
|
|
34
|
+
declare function asyncRetry<Callback extends GenericCallback>(callback: Callback, options?: RetryOptions): Promise<ReturnType<Callback>>;
|
|
15
35
|
/**
|
|
16
36
|
* Retry a callback a specified number of times
|
|
17
37
|
*
|
|
@@ -20,5 +40,8 @@ type RetryOptions = {
|
|
|
20
40
|
* @returns Callback result
|
|
21
41
|
*/
|
|
22
42
|
declare function retry<Callback extends GenericCallback>(callback: Callback, options?: Omit<RetryOptions, 'delay'>): ReturnType<Callback>;
|
|
43
|
+
declare namespace retry {
|
|
44
|
+
var async: typeof asyncRetry;
|
|
45
|
+
}
|
|
23
46
|
//#endregion
|
|
24
47
|
export { RetryError, RetryOptions, retry };
|
package/dist/function/retry.mjs
CHANGED
|
@@ -84,6 +84,7 @@ function shouldRetry() {
|
|
|
84
84
|
const RETRY_ERROR_NAME = "RetryError";
|
|
85
85
|
const RETRY_MESSAGE_EXPECTATION = "Retry expected a function";
|
|
86
86
|
const RETRY_MESSAGE_FAILED = "Retry failed";
|
|
87
|
+
retry.async = asyncRetry;
|
|
87
88
|
Object.defineProperty(retry, "async", { value: asyncRetry });
|
|
88
89
|
//#endregion
|
|
89
90
|
export { RetryError, retry };
|
package/dist/index.d.mts
CHANGED
|
@@ -31,13 +31,6 @@ type CancelableCallback<Callback extends GenericCallback> = Callback & {
|
|
|
31
31
|
* A generic class constructor
|
|
32
32
|
*/
|
|
33
33
|
type Constructor<Instance = unknown> = new (...args: any[]) => Instance;
|
|
34
|
-
/**
|
|
35
|
-
* Position of an event
|
|
36
|
-
*/
|
|
37
|
-
type EventPosition = {
|
|
38
|
-
x: number;
|
|
39
|
-
y: number;
|
|
40
|
-
};
|
|
41
34
|
/**
|
|
42
35
|
* A generic async callback function
|
|
43
36
|
*/
|
|
@@ -3829,6 +3822,9 @@ declare function asyncThrottle<Callback extends GenericAsyncCallback | GenericCa
|
|
|
3829
3822
|
* @returns Debounced callback handler with a `cancel` method
|
|
3830
3823
|
*/
|
|
3831
3824
|
declare function debounce<Callback extends GenericCallback>(callback: Callback, time?: number): CancelableCallback<Callback>;
|
|
3825
|
+
declare namespace debounce {
|
|
3826
|
+
var async: typeof asyncDebounce;
|
|
3827
|
+
}
|
|
3832
3828
|
/**
|
|
3833
3829
|
* Throttle a function, ensuring it is only called once every `time` milliseconds
|
|
3834
3830
|
*
|
|
@@ -3837,6 +3833,9 @@ declare function debounce<Callback extends GenericCallback>(callback: Callback,
|
|
|
3837
3833
|
* @returns Throttled callback handler with a `cancel` method
|
|
3838
3834
|
*/
|
|
3839
3835
|
declare function throttle<Callback extends GenericCallback>(callback: Callback, time?: number): CancelableCallback<Callback>;
|
|
3836
|
+
declare namespace throttle {
|
|
3837
|
+
var async: typeof asyncThrottle;
|
|
3838
|
+
}
|
|
3840
3839
|
//#endregion
|
|
3841
3840
|
//#region src/function/once.d.ts
|
|
3842
3841
|
/**
|
|
@@ -3855,6 +3854,9 @@ declare function asyncOnce<Callback extends GenericAsyncCallback>(callback: Call
|
|
|
3855
3854
|
* @returns _Once_ callback
|
|
3856
3855
|
*/
|
|
3857
3856
|
declare function once<Callback extends GenericCallback>(callback: Callback): OnceCallback<Callback>;
|
|
3857
|
+
declare namespace once {
|
|
3858
|
+
var async: typeof asyncOnce;
|
|
3859
|
+
}
|
|
3858
3860
|
//#endregion
|
|
3859
3861
|
//#region src/function/retry.d.ts
|
|
3860
3862
|
/**
|
|
@@ -3869,6 +3871,26 @@ type RetryOptions = {
|
|
|
3869
3871
|
times?: number;
|
|
3870
3872
|
when?: (error: unknown) => boolean;
|
|
3871
3873
|
};
|
|
3874
|
+
/**
|
|
3875
|
+
* Retry a callback a specified number of times, with a delay between attempts
|
|
3876
|
+
*
|
|
3877
|
+
* _Available as `asyncRetry` and `retry.async`_
|
|
3878
|
+
*
|
|
3879
|
+
* @param callback Callback to retry
|
|
3880
|
+
* @param options Retry options
|
|
3881
|
+
* @returns Callback result
|
|
3882
|
+
*/
|
|
3883
|
+
declare function asyncRetry<Callback extends GenericAsyncCallback>(callback: Callback, options?: RetryOptions): Promise<Awaited<ReturnType<Callback>>>;
|
|
3884
|
+
/**
|
|
3885
|
+
* Retry a callback a specified number of times, with a delay between attempts
|
|
3886
|
+
*
|
|
3887
|
+
* _Available as `asyncRetry` and `retry.async`_
|
|
3888
|
+
*
|
|
3889
|
+
* @param callback Callback to retry
|
|
3890
|
+
* @param options Retry options
|
|
3891
|
+
* @returns Callback result
|
|
3892
|
+
*/
|
|
3893
|
+
declare function asyncRetry<Callback extends GenericCallback>(callback: Callback, options?: RetryOptions): Promise<ReturnType<Callback>>;
|
|
3872
3894
|
/**
|
|
3873
3895
|
* Retry a callback a specified number of times
|
|
3874
3896
|
*
|
|
@@ -3877,6 +3899,9 @@ type RetryOptions = {
|
|
|
3877
3899
|
* @returns Callback result
|
|
3878
3900
|
*/
|
|
3879
3901
|
declare function retry<Callback extends GenericCallback>(callback: Callback, options?: Omit<RetryOptions, 'delay'>): ReturnType<Callback>;
|
|
3902
|
+
declare namespace retry {
|
|
3903
|
+
var async: typeof asyncRetry;
|
|
3904
|
+
}
|
|
3880
3905
|
//#endregion
|
|
3881
3906
|
//#region src/internal/result/models.d.ts
|
|
3882
3907
|
/**
|
|
@@ -5396,6 +5421,9 @@ declare function attempt<Value, E>(callback: () => Value, error: E): ExtendedRes
|
|
|
5396
5421
|
* @returns Callback result
|
|
5397
5422
|
*/
|
|
5398
5423
|
declare function attempt<Value>(callback: () => Value): Result<Value, Error>;
|
|
5424
|
+
declare namespace attempt {
|
|
5425
|
+
var async: typeof asyncAttempt;
|
|
5426
|
+
}
|
|
5399
5427
|
//#endregion
|
|
5400
5428
|
//#region src/result/match.d.ts
|
|
5401
5429
|
/**
|
|
@@ -5436,6 +5464,9 @@ declare function matchResult<Value, Returned, E = Error>(result: AnyResult<Value
|
|
|
5436
5464
|
* @returns Matched value
|
|
5437
5465
|
*/
|
|
5438
5466
|
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;
|
|
5467
|
+
declare namespace matchResult {
|
|
5468
|
+
var async: typeof asyncMatchResult;
|
|
5469
|
+
}
|
|
5439
5470
|
//#endregion
|
|
5440
5471
|
//#region src/result/work/flow.d.ts
|
|
5441
5472
|
/**
|
|
@@ -5614,6 +5645,9 @@ declare function attemptFlow<First extends GenericCallback>(first: First, ...fns
|
|
|
5614
5645
|
* @returns _Flow_ function
|
|
5615
5646
|
*/
|
|
5616
5647
|
declare function attemptFlow(...fns: GenericCallback[]): (...args: unknown[]) => Result<unknown>;
|
|
5648
|
+
declare namespace attemptFlow {
|
|
5649
|
+
var async: typeof attemptAsyncFlow;
|
|
5650
|
+
}
|
|
5617
5651
|
//#endregion
|
|
5618
5652
|
//#region src/result/work/pipe.d.ts
|
|
5619
5653
|
type WrapValue<Value> = Result<UnwrapValue<Value>>;
|
|
@@ -5793,6 +5827,9 @@ declare function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth
|
|
|
5793
5827
|
* @returns _Piped_ result
|
|
5794
5828
|
*/
|
|
5795
5829
|
declare function attemptPipe<Initial>(initial: GenericCallback | Initial | Result<Initial>, first?: (value: UnwrapValue<Initial>) => unknown, ...seconds: Array<(value: unknown) => unknown>): WrapValue<Initial>;
|
|
5830
|
+
declare namespace attemptPipe {
|
|
5831
|
+
var async: typeof attemptAsyncPipe;
|
|
5832
|
+
}
|
|
5796
5833
|
//#endregion
|
|
5797
5834
|
//#region src/string/fuzzy.d.ts
|
|
5798
5835
|
/**
|
|
@@ -7819,16 +7856,17 @@ declare const Logger: Logger;
|
|
|
7819
7856
|
* max(
|
|
7820
7857
|
* [{id: 1, value: 10}, {id: 2, value: 20}],
|
|
7821
7858
|
* item => item.value,
|
|
7822
|
-
* ); // => 20
|
|
7859
|
+
* ); // => [{id: 2, value: 20}]
|
|
7823
7860
|
*
|
|
7824
|
-
* max([], item => item.value); // =>
|
|
7861
|
+
* max([], item => item.value); // => []
|
|
7825
7862
|
* ```
|
|
7826
7863
|
*
|
|
7827
7864
|
* @param items List of items
|
|
7828
7865
|
* @param callback Callback to get an item's value
|
|
7829
|
-
* @
|
|
7866
|
+
* @param first Return only the first item with the maximum value
|
|
7867
|
+
* @returns Item with the maximum value, or `undefined` if no maximum can be found
|
|
7830
7868
|
*/
|
|
7831
|
-
declare function max<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number):
|
|
7869
|
+
declare function max<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number, first: true): Item | undefined;
|
|
7832
7870
|
/**
|
|
7833
7871
|
* Get the maximum value from a list of items
|
|
7834
7872
|
*
|
|
@@ -7837,16 +7875,53 @@ declare function max<Item>(items: Item[], callback: (item: Item, index: number,
|
|
|
7837
7875
|
* max(
|
|
7838
7876
|
* [{id: 1, value: 10}, {id: 2, value: 20}],
|
|
7839
7877
|
* 'value',
|
|
7840
|
-
* ); // => 20
|
|
7878
|
+
* ); // => [{id: 2, value: 20}]
|
|
7841
7879
|
*
|
|
7842
|
-
* max([], 'value'); // =>
|
|
7880
|
+
* max([], 'value'); // => []
|
|
7843
7881
|
* ```
|
|
7844
7882
|
*
|
|
7845
7883
|
* @param items List of items
|
|
7846
7884
|
* @param key Key to use for value
|
|
7847
|
-
* @
|
|
7885
|
+
* @param first Return only the first item with the maximum value
|
|
7886
|
+
* @returns Item with the maximum value, or `undefined` if no maximum can be found
|
|
7848
7887
|
*/
|
|
7849
|
-
declare function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(items: Item[], key: ItemKey):
|
|
7888
|
+
declare function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(items: Item[], key: ItemKey, first: true): Item | undefined;
|
|
7889
|
+
/**
|
|
7890
|
+
* Get the maximum value from a list of items
|
|
7891
|
+
*
|
|
7892
|
+
* @example
|
|
7893
|
+
* ```typescript
|
|
7894
|
+
* max(
|
|
7895
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}],
|
|
7896
|
+
* item => item.value,
|
|
7897
|
+
* ); // => [{id: 2, value: 20}]
|
|
7898
|
+
*
|
|
7899
|
+
* max([], item => item.value); // => []
|
|
7900
|
+
* ```
|
|
7901
|
+
*
|
|
7902
|
+
* @param items List of items
|
|
7903
|
+
* @param callback Callback to get an item's value
|
|
7904
|
+
* @returns Items with the maximum value
|
|
7905
|
+
*/
|
|
7906
|
+
declare function max<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): Item[];
|
|
7907
|
+
/**
|
|
7908
|
+
* Get the maximum value from a list of items
|
|
7909
|
+
*
|
|
7910
|
+
* @example
|
|
7911
|
+
* ```typescript
|
|
7912
|
+
* max(
|
|
7913
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}],
|
|
7914
|
+
* 'value',
|
|
7915
|
+
* ); // => [{id: 2, value: 20}]
|
|
7916
|
+
*
|
|
7917
|
+
* max([], 'value'); // => []
|
|
7918
|
+
* ```
|
|
7919
|
+
*
|
|
7920
|
+
* @param items List of items
|
|
7921
|
+
* @param key Key to use for value
|
|
7922
|
+
* @returns Items with the maximum value
|
|
7923
|
+
*/
|
|
7924
|
+
declare function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(items: Item[], key: ItemKey): Item[];
|
|
7850
7925
|
/**
|
|
7851
7926
|
* Get the maximum value from a list of numbers
|
|
7852
7927
|
*
|
|
@@ -7964,17 +8039,35 @@ declare function median(array: number[]): number;
|
|
|
7964
8039
|
*
|
|
7965
8040
|
* @param items List of items
|
|
7966
8041
|
* @param callback Callback to get an item's value
|
|
7967
|
-
* @
|
|
8042
|
+
* @param first Return only the first item with the minimum value
|
|
8043
|
+
* @returns Items with the minimum value
|
|
7968
8044
|
*/
|
|
7969
|
-
declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number):
|
|
8045
|
+
declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number, first: true): Item[];
|
|
7970
8046
|
/**
|
|
7971
8047
|
* Get the minimum value from a list of items
|
|
7972
8048
|
*
|
|
7973
8049
|
* @param items List of items
|
|
7974
8050
|
* @param key Key to use for value
|
|
7975
|
-
* @
|
|
8051
|
+
* @param first Return only the first item with the minimum value
|
|
8052
|
+
* @returns Items with the minimum value
|
|
8053
|
+
*/
|
|
8054
|
+
declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>, first: true): Item[];
|
|
8055
|
+
/**
|
|
8056
|
+
* Get the minimum value from a list of items
|
|
8057
|
+
*
|
|
8058
|
+
* @param items List of items
|
|
8059
|
+
* @param callback Callback to get an item's value
|
|
8060
|
+
* @returns Items with the minimum value
|
|
8061
|
+
*/
|
|
8062
|
+
declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): Item[];
|
|
8063
|
+
/**
|
|
8064
|
+
* Get the minimum value from a list of items
|
|
8065
|
+
*
|
|
8066
|
+
* @param items List of items
|
|
8067
|
+
* @param key Key to use for value
|
|
8068
|
+
* @returns Items with the minimum value
|
|
7976
8069
|
*/
|
|
7977
|
-
declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>):
|
|
8070
|
+
declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): Item[];
|
|
7978
8071
|
/**
|
|
7979
8072
|
* Get the minimum value from a list of numbers
|
|
7980
8073
|
*
|
|
@@ -8424,4 +8517,4 @@ declare class SizedSet<Value = unknown> extends Set<Value> {
|
|
|
8424
8517
|
get(value: Value, update?: boolean): Value | undefined;
|
|
8425
8518
|
}
|
|
8426
8519
|
//#endregion
|
|
8427
|
-
export { AnyResult, ArrayComparison, ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, ArraySorter, ArraySorters, ArrayValueSorter, AssertProperty, Asserter, AssignOptions, Assigner, AsyncCancelableCallback, AttemptFlow, AttemptFlowPromise, Beacon, BeaconOptions, BuiltIns, CancelableCallback, CancelablePromise, type Color, type ColorType, type ColorTypeExtended, type ColorValue, type ColorValueExtended, Constructor, DiffOptions, DiffResult, DiffValue, EqualOptions, Err,
|
|
8520
|
+
export { AnyResult, ArrayComparison, ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, ArraySorter, ArraySorters, ArrayValueSorter, AssertProperty, Asserter, AssignOptions, Assigner, AsyncCancelableCallback, AttemptFlow, AttemptFlowPromise, Beacon, BeaconOptions, BuiltIns, CancelableCallback, CancelablePromise, type Color, type ColorType, type ColorTypeExtended, type ColorValue, type ColorValueExtended, Constructor, DiffOptions, DiffResult, DiffValue, EqualOptions, Err, ExtendedErr, ExtendedResult, Flow, FlowPromise, Frozen, FulfilledPromise, Fuzzy, FuzzyConfiguration, FuzzyOptions, FuzzyResult, FuzzySearchOptions, GenericAsyncCallback, GenericCallback, type HSLAColor, type HSLColor, type HWBAColor, type HWBColor, Key$1 as Key, KeyedQueue, KeyedValue, Logger, Memoized, MemoizedOptions, MergeOptions, Merger, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NormalizeOptions, Normalizer, NumericalKeys, NumericalValues, Observable, Ok, OnceAsyncCallback, OnceCallback, PlainObject, Primitive, PromiseData, PromiseHandlers, PromiseOptions, PromiseParameters, PromiseStrategy, PromiseTimeoutError, PromisesItems, PromisesOptions, PromisesResult, PromisesUnwrapped, PromisesValue, PromisesValues, Queue, QueueError, QueueOptions, Queued, type RGBAColor, type RGBColor, RejectedPromise, RequiredKeys, Result, ResultMatch, RetryError, RetryOptions, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, type Shaken, Simplify, SizedMap, SizedSet, type Smushed, SortDirection, Sorter, type Subscription, TemplateOptions, type TimedLogger, ToString, Transformer, TypedArray, UnionToIntersection, type Unsmushed, Unsubscriber, UnwrapValue, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isHerald, isHeraldEvents, isHeraldSubscription, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isInstanceOf, isKey, isKeyedQueue, isLogger, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isObservable, isOk, isPlainObject, isPrimitive, isQueue, isQueueInstance, isRejected, isResult, isRgbColor, isRgbaColor, isSorted, isSubscription, isTimedLogger, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
package/dist/index.mjs
CHANGED
|
@@ -881,49 +881,70 @@ function moveToIndex(array, value, index, key) {
|
|
|
881
881
|
}
|
|
882
882
|
//#endregion
|
|
883
883
|
//#region src/internal/math/aggregate.ts
|
|
884
|
-
function aggregate(type, array, key) {
|
|
884
|
+
function aggregate(type, array, key, first) {
|
|
885
885
|
const length = Array.isArray(array) ? array.length : 0;
|
|
886
|
-
|
|
886
|
+
const aggregation = {
|
|
887
|
+
array: false,
|
|
887
888
|
count: 0,
|
|
889
|
+
first: first === true,
|
|
888
890
|
value: NaN
|
|
889
891
|
};
|
|
892
|
+
if (length === 0) return aggregation;
|
|
890
893
|
const aggregator = aggregators[type];
|
|
891
894
|
const callback = getAggregateCallback(key);
|
|
892
|
-
|
|
893
|
-
let aggregated = NaN;
|
|
895
|
+
aggregation.array = callback != null && (type === "max" || type === "min");
|
|
894
896
|
let notNumber = true;
|
|
895
897
|
for (let index = 0; index < length; index += 1) {
|
|
896
898
|
const item = array[index];
|
|
897
899
|
const value = callback == null ? item : callback(item, index, array);
|
|
898
900
|
if (isNonNumber(value)) continue;
|
|
899
|
-
|
|
900
|
-
|
|
901
|
+
aggregation.value = aggregator(aggregation, value, notNumber, item);
|
|
902
|
+
aggregation.count += 1;
|
|
901
903
|
notNumber = false;
|
|
902
904
|
}
|
|
903
|
-
return
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
905
|
+
return aggregation;
|
|
906
|
+
}
|
|
907
|
+
function calculateSum(aggregation, value, notNumber) {
|
|
908
|
+
return notNumber ? value : aggregation.value + value;
|
|
909
|
+
}
|
|
910
|
+
function getAbsoluteValue(condition, aggregation, value, notNumber, item) {
|
|
911
|
+
if (notNumber || condition(aggregation, value)) {
|
|
912
|
+
if (aggregation.array) {
|
|
913
|
+
aggregation.items ??= {};
|
|
914
|
+
aggregation.items[value] ??= [];
|
|
915
|
+
aggregation.items[value].push(item);
|
|
916
|
+
}
|
|
917
|
+
return value;
|
|
918
|
+
}
|
|
919
|
+
return aggregation.value;
|
|
907
920
|
}
|
|
908
921
|
function getAggregateCallback(key) {
|
|
909
922
|
if (key == null) return;
|
|
910
923
|
return typeof key === "function" ? key : (item) => item[key];
|
|
911
924
|
}
|
|
912
|
-
function
|
|
913
|
-
|
|
925
|
+
function getAggregated(type, array, key, first) {
|
|
926
|
+
const aggregation = aggregate(type, array, key, first);
|
|
927
|
+
if (aggregation.count === 0) return aggregation.array ? aggregation.first ? void 0 : [] : NaN;
|
|
928
|
+
if (aggregation.array) {
|
|
929
|
+
const array = aggregation.items[aggregation.value];
|
|
930
|
+
return aggregation.first ? array[0] : array;
|
|
931
|
+
}
|
|
932
|
+
return aggregation.value;
|
|
933
|
+
}
|
|
934
|
+
function isMaxValue(aggregation, value) {
|
|
935
|
+
return aggregation.array ? value >= aggregation.value : value > aggregation.value;
|
|
914
936
|
}
|
|
915
|
-
function
|
|
916
|
-
return
|
|
937
|
+
function isMinValue(aggregation, value) {
|
|
938
|
+
return aggregation.array ? value <= aggregation.value : value < aggregation.value;
|
|
917
939
|
}
|
|
918
|
-
function
|
|
919
|
-
|
|
920
|
-
return aggregated.count > 0 ? aggregated.value : NaN;
|
|
940
|
+
function max(array, key, first) {
|
|
941
|
+
return getAggregated("max", array, key, first);
|
|
921
942
|
}
|
|
922
943
|
const AGGREGATION_AVERAGE = "average";
|
|
923
944
|
const aggregators = {
|
|
924
945
|
average: calculateSum,
|
|
925
|
-
max: (
|
|
926
|
-
min: (
|
|
946
|
+
max: getAbsoluteValue.bind(void 0, isMaxValue),
|
|
947
|
+
min: getAbsoluteValue.bind(void 0, isMinValue),
|
|
927
948
|
sum: calculateSum
|
|
928
949
|
};
|
|
929
950
|
//#endregion
|
|
@@ -1528,6 +1549,8 @@ function debounce(callback, time) {
|
|
|
1528
1549
|
function throttle(callback, time) {
|
|
1529
1550
|
return getTimer(TIMER_THROTTLE, callback, time);
|
|
1530
1551
|
}
|
|
1552
|
+
debounce.async = asyncDebounce;
|
|
1553
|
+
throttle.async = asyncThrottle;
|
|
1531
1554
|
Object.defineProperty(debounce, "async", { value: asyncDebounce });
|
|
1532
1555
|
Object.defineProperty(throttle, "async", { value: asyncThrottle });
|
|
1533
1556
|
//#endregion
|
|
@@ -1841,6 +1864,7 @@ function once(callback) {
|
|
|
1841
1864
|
}
|
|
1842
1865
|
const ONCE_MESSAGE_CLEARED = "Once has been cleared";
|
|
1843
1866
|
const ONCE_MESSAGE_EXPECTATION = "Once expected a function";
|
|
1867
|
+
once.async = asyncOnce;
|
|
1844
1868
|
Object.defineProperty(once, "async", { value: asyncOnce });
|
|
1845
1869
|
//#endregion
|
|
1846
1870
|
//#region src/function/retry.ts
|
|
@@ -1927,6 +1951,7 @@ function shouldRetry() {
|
|
|
1927
1951
|
const RETRY_ERROR_NAME = "RetryError";
|
|
1928
1952
|
const RETRY_MESSAGE_EXPECTATION = "Retry expected a function";
|
|
1929
1953
|
const RETRY_MESSAGE_FAILED = "Retry failed";
|
|
1954
|
+
retry.async = asyncRetry;
|
|
1930
1955
|
Object.defineProperty(retry, "async", { value: asyncRetry });
|
|
1931
1956
|
//#endregion
|
|
1932
1957
|
//#region src/internal/function/work.ts
|
|
@@ -2822,6 +2847,7 @@ function attempt(callback, err) {
|
|
|
2822
2847
|
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
2823
2848
|
}
|
|
2824
2849
|
}
|
|
2850
|
+
attempt.async = asyncAttempt;
|
|
2825
2851
|
Object.defineProperty(attempt, "async", { value: asyncAttempt });
|
|
2826
2852
|
//#endregion
|
|
2827
2853
|
//#region src/result/match.ts
|
|
@@ -2847,6 +2873,7 @@ function matchResult(result, first, error) {
|
|
|
2847
2873
|
return errorHandler(value.error, value.original);
|
|
2848
2874
|
}
|
|
2849
2875
|
const MATCH_MESSAGE = "`result.match` expected a Result or a function that returns a Result";
|
|
2876
|
+
matchResult.async = asyncMatchResult;
|
|
2850
2877
|
Object.defineProperty(matchResult, "async", { value: asyncMatchResult });
|
|
2851
2878
|
//#endregion
|
|
2852
2879
|
//#region src/result/work/flow.ts
|
|
@@ -2870,6 +2897,7 @@ function attemptFlow(...fns) {
|
|
|
2870
2897
|
}));
|
|
2871
2898
|
});
|
|
2872
2899
|
}
|
|
2900
|
+
attemptFlow.async = attemptAsyncFlow;
|
|
2873
2901
|
Object.defineProperty(attemptFlow, "async", { value: attemptAsyncFlow });
|
|
2874
2902
|
//#endregion
|
|
2875
2903
|
//#region src/result/work/pipe.ts
|
|
@@ -2889,6 +2917,7 @@ function attemptPipe(initial, first, ...seconds) {
|
|
|
2889
2917
|
return pipe(value, ...[first, ...seconds]);
|
|
2890
2918
|
});
|
|
2891
2919
|
}
|
|
2920
|
+
attemptPipe.async = attemptAsyncPipe;
|
|
2892
2921
|
Object.defineProperty(attemptPipe, "async", { value: attemptAsyncPipe });
|
|
2893
2922
|
//#endregion
|
|
2894
2923
|
//#region src/string/match.ts
|
|
@@ -5745,8 +5774,8 @@ function median(array, key) {
|
|
|
5745
5774
|
}
|
|
5746
5775
|
return numbers[Math.floor(length / 2)];
|
|
5747
5776
|
}
|
|
5748
|
-
function min(array, key) {
|
|
5749
|
-
return getAggregated("min", array, key);
|
|
5777
|
+
function min(array, key, first) {
|
|
5778
|
+
return getAggregated("min", array, key, first);
|
|
5750
5779
|
}
|
|
5751
5780
|
function sum(array, key) {
|
|
5752
5781
|
return getAggregated("sum", array, key);
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { NumericalValues, PlainObject } from "../../models.mjs";
|
|
2
2
|
//#region src/internal/math/aggregate.d.ts
|
|
3
3
|
type Aggregation = {
|
|
4
|
+
array: boolean;
|
|
4
5
|
count: number;
|
|
6
|
+
first: boolean;
|
|
7
|
+
items?: Record<number, unknown[]>;
|
|
5
8
|
value: number;
|
|
6
9
|
};
|
|
7
10
|
type AggregationType = 'average' | 'max' | 'min' | 'sum';
|
|
8
11
|
type NonAverageAggregationType = 'max' | 'min' | 'sum';
|
|
9
|
-
declare function aggregate(type: AggregationType, array: unknown[], key: unknown): Aggregation;
|
|
12
|
+
declare function aggregate(type: AggregationType, array: unknown[], key: unknown, first?: unknown): Aggregation;
|
|
10
13
|
declare function getAggregateCallback(key: unknown): Function | undefined;
|
|
14
|
+
declare function getAggregated(type: NonAverageAggregationType, array: unknown[], key?: unknown, first?: unknown): unknown;
|
|
11
15
|
/**
|
|
12
16
|
* Get the maximum value from a list of items
|
|
13
17
|
*
|
|
@@ -16,16 +20,17 @@ declare function getAggregateCallback(key: unknown): Function | undefined;
|
|
|
16
20
|
* max(
|
|
17
21
|
* [{id: 1, value: 10}, {id: 2, value: 20}],
|
|
18
22
|
* item => item.value,
|
|
19
|
-
* ); // => 20
|
|
23
|
+
* ); // => [{id: 2, value: 20}]
|
|
20
24
|
*
|
|
21
|
-
* max([], item => item.value); // =>
|
|
25
|
+
* max([], item => item.value); // => []
|
|
22
26
|
* ```
|
|
23
27
|
*
|
|
24
28
|
* @param items List of items
|
|
25
29
|
* @param callback Callback to get an item's value
|
|
26
|
-
* @
|
|
30
|
+
* @param first Return only the first item with the maximum value
|
|
31
|
+
* @returns Item with the maximum value, or `undefined` if no maximum can be found
|
|
27
32
|
*/
|
|
28
|
-
declare function max<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number):
|
|
33
|
+
declare function max<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number, first: true): Item | undefined;
|
|
29
34
|
/**
|
|
30
35
|
* Get the maximum value from a list of items
|
|
31
36
|
*
|
|
@@ -34,16 +39,53 @@ declare function max<Item>(items: Item[], callback: (item: Item, index: number,
|
|
|
34
39
|
* max(
|
|
35
40
|
* [{id: 1, value: 10}, {id: 2, value: 20}],
|
|
36
41
|
* 'value',
|
|
37
|
-
* ); // => 20
|
|
42
|
+
* ); // => [{id: 2, value: 20}]
|
|
38
43
|
*
|
|
39
|
-
* max([], 'value'); // =>
|
|
44
|
+
* max([], 'value'); // => []
|
|
40
45
|
* ```
|
|
41
46
|
*
|
|
42
47
|
* @param items List of items
|
|
43
48
|
* @param key Key to use for value
|
|
44
|
-
* @
|
|
49
|
+
* @param first Return only the first item with the maximum value
|
|
50
|
+
* @returns Item with the maximum value, or `undefined` if no maximum can be found
|
|
51
|
+
*/
|
|
52
|
+
declare function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(items: Item[], key: ItemKey, first: true): Item | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Get the maximum value from a list of items
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* max(
|
|
59
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}],
|
|
60
|
+
* item => item.value,
|
|
61
|
+
* ); // => [{id: 2, value: 20}]
|
|
62
|
+
*
|
|
63
|
+
* max([], item => item.value); // => []
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @param items List of items
|
|
67
|
+
* @param callback Callback to get an item's value
|
|
68
|
+
* @returns Items with the maximum value
|
|
69
|
+
*/
|
|
70
|
+
declare function max<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): Item[];
|
|
71
|
+
/**
|
|
72
|
+
* Get the maximum value from a list of items
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* max(
|
|
77
|
+
* [{id: 1, value: 10}, {id: 2, value: 20}],
|
|
78
|
+
* 'value',
|
|
79
|
+
* ); // => [{id: 2, value: 20}]
|
|
80
|
+
*
|
|
81
|
+
* max([], 'value'); // => []
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @param items List of items
|
|
85
|
+
* @param key Key to use for value
|
|
86
|
+
* @returns Items with the maximum value
|
|
45
87
|
*/
|
|
46
|
-
declare function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(items: Item[], key: ItemKey):
|
|
88
|
+
declare function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(items: Item[], key: ItemKey): Item[];
|
|
47
89
|
/**
|
|
48
90
|
* Get the maximum value from a list of numbers
|
|
49
91
|
*
|
|
@@ -57,7 +99,6 @@ declare function max<Item extends PlainObject, ItemKey extends keyof NumericalVa
|
|
|
57
99
|
* @returns Maximum value, or `Number.NaN` if no maximum can be found
|
|
58
100
|
*/
|
|
59
101
|
declare function max(values: number[]): number;
|
|
60
|
-
declare function getAggregated(type: NonAverageAggregationType, array: unknown[], key?: unknown): number;
|
|
61
102
|
declare const AGGREGATION_AVERAGE: AggregationType;
|
|
62
103
|
declare const AGGREGATION_MAX = "max";
|
|
63
104
|
declare const AGGREGATION_MIN = "min";
|
|
@@ -1,42 +1,63 @@
|
|
|
1
1
|
import { isNonNumber } from "../is.mjs";
|
|
2
2
|
//#region src/internal/math/aggregate.ts
|
|
3
|
-
function aggregate(type, array, key) {
|
|
3
|
+
function aggregate(type, array, key, first) {
|
|
4
4
|
const length = Array.isArray(array) ? array.length : 0;
|
|
5
|
-
|
|
5
|
+
const aggregation = {
|
|
6
|
+
array: false,
|
|
6
7
|
count: 0,
|
|
8
|
+
first: first === true,
|
|
7
9
|
value: NaN
|
|
8
10
|
};
|
|
11
|
+
if (length === 0) return aggregation;
|
|
9
12
|
const aggregator = aggregators[type];
|
|
10
13
|
const callback = getAggregateCallback(key);
|
|
11
|
-
|
|
12
|
-
let aggregated = NaN;
|
|
14
|
+
aggregation.array = callback != null && (type === "max" || type === "min");
|
|
13
15
|
let notNumber = true;
|
|
14
16
|
for (let index = 0; index < length; index += 1) {
|
|
15
17
|
const item = array[index];
|
|
16
18
|
const value = callback == null ? item : callback(item, index, array);
|
|
17
19
|
if (isNonNumber(value)) continue;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
aggregation.value = aggregator(aggregation, value, notNumber, item);
|
|
21
|
+
aggregation.count += 1;
|
|
20
22
|
notNumber = false;
|
|
21
23
|
}
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
return aggregation;
|
|
25
|
+
}
|
|
26
|
+
function calculateSum(aggregation, value, notNumber) {
|
|
27
|
+
return notNumber ? value : aggregation.value + value;
|
|
28
|
+
}
|
|
29
|
+
function getAbsoluteValue(condition, aggregation, value, notNumber, item) {
|
|
30
|
+
if (notNumber || condition(aggregation, value)) {
|
|
31
|
+
if (aggregation.array) {
|
|
32
|
+
aggregation.items ??= {};
|
|
33
|
+
aggregation.items[value] ??= [];
|
|
34
|
+
aggregation.items[value].push(item);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
return aggregation.value;
|
|
26
39
|
}
|
|
27
40
|
function getAggregateCallback(key) {
|
|
28
41
|
if (key == null) return;
|
|
29
42
|
return typeof key === "function" ? key : (item) => item[key];
|
|
30
43
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
44
|
+
function getAggregated(type, array, key, first) {
|
|
45
|
+
const aggregation = aggregate(type, array, key, first);
|
|
46
|
+
if (aggregation.count === 0) return aggregation.array ? aggregation.first ? void 0 : [] : NaN;
|
|
47
|
+
if (aggregation.array) {
|
|
48
|
+
const array = aggregation.items[aggregation.value];
|
|
49
|
+
return aggregation.first ? array[0] : array;
|
|
50
|
+
}
|
|
51
|
+
return aggregation.value;
|
|
52
|
+
}
|
|
53
|
+
function isMaxValue(aggregation, value) {
|
|
54
|
+
return aggregation.array ? value >= aggregation.value : value > aggregation.value;
|
|
33
55
|
}
|
|
34
|
-
function
|
|
35
|
-
return
|
|
56
|
+
function isMinValue(aggregation, value) {
|
|
57
|
+
return aggregation.array ? value <= aggregation.value : value < aggregation.value;
|
|
36
58
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
return aggregated.count > 0 ? aggregated.value : NaN;
|
|
59
|
+
function max(array, key, first) {
|
|
60
|
+
return getAggregated("max", array, key, first);
|
|
40
61
|
}
|
|
41
62
|
const AGGREGATION_AVERAGE = "average";
|
|
42
63
|
const AGGREGATION_MAX = "max";
|
|
@@ -44,8 +65,8 @@ const AGGREGATION_MIN = "min";
|
|
|
44
65
|
const AGGREGATION_SUM = "sum";
|
|
45
66
|
const aggregators = {
|
|
46
67
|
average: calculateSum,
|
|
47
|
-
max: (
|
|
48
|
-
min: (
|
|
68
|
+
max: getAbsoluteValue.bind(void 0, isMaxValue),
|
|
69
|
+
min: getAbsoluteValue.bind(void 0, isMinValue),
|
|
49
70
|
sum: calculateSum
|
|
50
71
|
};
|
|
51
72
|
//#endregion
|
package/dist/math.d.mts
CHANGED
|
@@ -94,17 +94,35 @@ declare function median(array: number[]): number;
|
|
|
94
94
|
*
|
|
95
95
|
* @param items List of items
|
|
96
96
|
* @param callback Callback to get an item's value
|
|
97
|
-
* @
|
|
97
|
+
* @param first Return only the first item with the minimum value
|
|
98
|
+
* @returns Items with the minimum value
|
|
98
99
|
*/
|
|
99
|
-
declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number):
|
|
100
|
+
declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number, first: true): Item[];
|
|
100
101
|
/**
|
|
101
102
|
* Get the minimum value from a list of items
|
|
102
103
|
*
|
|
103
104
|
* @param items List of items
|
|
104
105
|
* @param key Key to use for value
|
|
105
|
-
* @
|
|
106
|
+
* @param first Return only the first item with the minimum value
|
|
107
|
+
* @returns Items with the minimum value
|
|
108
|
+
*/
|
|
109
|
+
declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>, first: true): Item[];
|
|
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
|
+
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
|
|
106
124
|
*/
|
|
107
|
-
declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>):
|
|
125
|
+
declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): Item[];
|
|
108
126
|
/**
|
|
109
127
|
* Get the minimum value from a list of numbers
|
|
110
128
|
*
|
package/dist/math.mjs
CHANGED
|
@@ -54,8 +54,8 @@ function median(array, key) {
|
|
|
54
54
|
}
|
|
55
55
|
return numbers[Math.floor(length / 2)];
|
|
56
56
|
}
|
|
57
|
-
function min(array, key) {
|
|
58
|
-
return getAggregated("min", array, key);
|
|
57
|
+
function min(array, key, first) {
|
|
58
|
+
return getAggregated("min", array, key, first);
|
|
59
59
|
}
|
|
60
60
|
function sum(array, key) {
|
|
61
61
|
return getAggregated("sum", array, key);
|
package/dist/models.d.mts
CHANGED
|
@@ -31,13 +31,6 @@ type CancelableCallback<Callback extends GenericCallback> = Callback & {
|
|
|
31
31
|
* A generic class constructor
|
|
32
32
|
*/
|
|
33
33
|
type Constructor<Instance = unknown> = new (...args: any[]) => Instance;
|
|
34
|
-
/**
|
|
35
|
-
* Position of an event
|
|
36
|
-
*/
|
|
37
|
-
type EventPosition = {
|
|
38
|
-
x: number;
|
|
39
|
-
y: number;
|
|
40
|
-
};
|
|
41
34
|
/**
|
|
42
35
|
* A generic async callback function
|
|
43
36
|
*/
|
|
@@ -161,4 +154,4 @@ type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Un
|
|
|
161
154
|
*/
|
|
162
155
|
type Unsubscriber = () => void;
|
|
163
156
|
//#endregion
|
|
164
|
-
export { ArrayOrPlainObject, AsyncCancelableCallback, BuiltIns, CancelableCallback, Constructor,
|
|
157
|
+
export { ArrayOrPlainObject, AsyncCancelableCallback, BuiltIns, CancelableCallback, Constructor, GenericAsyncCallback, GenericCallback, Key, KeyedValue, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NumericalKeys, NumericalValues, OnceAsyncCallback, OnceCallback, PlainObject, Primitive, RequiredKeys, Simplify, ToString, TypedArray, UnionToIntersection, Unsubscriber };
|
package/dist/result/index.d.mts
CHANGED
|
@@ -53,5 +53,8 @@ declare function attempt<Value, E>(callback: () => Value, error: E): ExtendedRes
|
|
|
53
53
|
* @returns Callback result
|
|
54
54
|
*/
|
|
55
55
|
declare function attempt<Value>(callback: () => Value): Result<Value, Error>;
|
|
56
|
+
declare namespace attempt {
|
|
57
|
+
var async: typeof asyncAttempt;
|
|
58
|
+
}
|
|
56
59
|
//#endregion
|
|
57
60
|
export { asyncAttempt, attempt };
|
package/dist/result/index.mjs
CHANGED
|
@@ -17,6 +17,7 @@ function attempt(callback, err) {
|
|
|
17
17
|
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
attempt.async = asyncAttempt;
|
|
20
21
|
Object.defineProperty(attempt, "async", { value: asyncAttempt });
|
|
21
22
|
//#endregion
|
|
22
23
|
export { asyncAttempt, attempt };
|
package/dist/result/match.d.mts
CHANGED
|
@@ -38,5 +38,8 @@ declare function matchResult<Value, Returned, E = Error>(result: AnyResult<Value
|
|
|
38
38
|
* @returns Matched value
|
|
39
39
|
*/
|
|
40
40
|
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
|
+
declare namespace matchResult {
|
|
42
|
+
var async: typeof asyncMatchResult;
|
|
43
|
+
}
|
|
41
44
|
//#endregion
|
|
42
45
|
export { asyncMatchResult, matchResult };
|
package/dist/result/match.mjs
CHANGED
|
@@ -22,6 +22,7 @@ function matchResult(result, first, error) {
|
|
|
22
22
|
return errorHandler(value.error, value.original);
|
|
23
23
|
}
|
|
24
24
|
const MATCH_MESSAGE = "`result.match` expected a Result or a function that returns a Result";
|
|
25
|
+
matchResult.async = asyncMatchResult;
|
|
25
26
|
Object.defineProperty(matchResult, "async", { value: asyncMatchResult });
|
|
26
27
|
//#endregion
|
|
27
28
|
export { asyncMatchResult, matchResult };
|
|
@@ -177,5 +177,8 @@ declare function attemptFlow<First extends GenericCallback>(first: First, ...fns
|
|
|
177
177
|
* @returns _Flow_ function
|
|
178
178
|
*/
|
|
179
179
|
declare function attemptFlow(...fns: GenericCallback[]): (...args: unknown[]) => Result<unknown>;
|
|
180
|
+
declare namespace attemptFlow {
|
|
181
|
+
var async: typeof attemptAsyncFlow;
|
|
182
|
+
}
|
|
180
183
|
//#endregion
|
|
181
184
|
export { AttemptFlow, AttemptFlowPromise, attemptAsyncFlow, attemptFlow };
|
|
@@ -178,5 +178,8 @@ declare function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth
|
|
|
178
178
|
* @returns _Piped_ result
|
|
179
179
|
*/
|
|
180
180
|
declare function attemptPipe<Initial>(initial: GenericCallback | Initial | Result<Initial>, first?: (value: UnwrapValue<Initial>) => unknown, ...seconds: Array<(value: unknown) => unknown>): WrapValue<Initial>;
|
|
181
|
+
declare namespace attemptPipe {
|
|
182
|
+
var async: typeof attemptAsyncPipe;
|
|
183
|
+
}
|
|
181
184
|
//#endregion
|
|
182
185
|
export { attemptAsyncPipe, attemptPipe };
|
|
@@ -18,6 +18,7 @@ function attemptPipe(initial, first, ...seconds) {
|
|
|
18
18
|
return pipe(value, ...[first, ...seconds]);
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
+
attemptPipe.async = attemptAsyncPipe;
|
|
21
22
|
Object.defineProperty(attemptPipe, "async", { value: attemptAsyncPipe });
|
|
22
23
|
//#endregion
|
|
23
24
|
export { attemptAsyncPipe, attemptPipe };
|