@oscarpalmer/atoms 0.166.2 → 0.167.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/difference.d.mts +1 -1
- package/dist/array/exists.d.mts +1 -1
- package/dist/array/filter.d.mts +2 -2
- package/dist/array/find.d.mts +1 -1
- package/dist/array/intersection.d.mts +1 -1
- package/dist/array/move.d.mts +2 -2
- package/dist/array/partition.d.mts +1 -1
- package/dist/array/select.d.mts +1 -1
- package/dist/array/slice.d.mts +2 -2
- package/dist/array/sort.d.mts +4 -4
- package/dist/array/swap.d.mts +2 -2
- package/dist/array/to-set.d.mts +1 -1
- package/dist/array/toggle.d.mts +1 -1
- package/dist/array/union.d.mts +1 -1
- package/dist/array/update.d.mts +1 -1
- package/dist/index.d.mts +243 -211
- package/dist/index.mjs +29 -29
- package/dist/internal/array/index-of.d.mts +1 -1
- package/dist/internal/math/aggregate.d.mts +1 -1
- package/dist/internal/value/partial.d.mts +2 -2
- package/dist/math.d.mts +1 -1
- package/dist/models.d.mts +7 -7
- package/dist/promise/index.d.mts +2 -7
- package/dist/promise/index.mjs +5 -7
- package/dist/promise/misc.d.mts +3 -1
- package/dist/promise/misc.mjs +3 -2
- package/dist/promise/models.d.mts +4 -4
- package/dist/result/index.d.mts +2 -5
- package/dist/result/index.mjs +2 -4
- package/dist/result/misc.d.mts +2 -1
- package/dist/result/misc.mjs +2 -2
- package/dist/sized/map.d.mts +11 -11
- package/dist/value/omit.d.mts +1 -1
- package/dist/value/pick.d.mts +1 -1
- package/dist/value/smush.d.mts +1 -1
- package/dist/value/unsmush.d.mts +1 -1
- package/package.json +30 -2
- package/src/array/difference.ts +2 -2
- package/src/array/exists.ts +3 -3
- package/src/array/filter.ts +6 -6
- package/src/array/find.ts +3 -3
- package/src/array/intersection.ts +2 -2
- package/src/array/move.ts +4 -4
- package/src/array/partition.ts +3 -3
- package/src/array/select.ts +3 -3
- package/src/array/slice.ts +6 -6
- package/src/array/sort.ts +4 -4
- package/src/array/swap.ts +4 -4
- package/src/array/to-set.ts +3 -3
- package/src/array/toggle.ts +2 -2
- package/src/array/union.ts +2 -2
- package/src/array/update.ts +2 -2
- package/src/index.ts +9 -0
- package/src/internal/array/index-of.ts +3 -3
- package/src/internal/math/aggregate.ts +2 -2
- package/src/internal/value/partial.ts +9 -9
- package/src/math.ts +3 -3
- package/src/models.ts +30 -20
- package/src/promise/index.ts +0 -22
- package/src/promise/misc.ts +7 -0
- package/src/promise/models.ts +13 -11
- package/src/result/index.ts +0 -9
- package/src/result/misc.ts +6 -0
- package/src/sized/map.ts +14 -14
- package/src/value/omit.ts +3 -3
- package/src/value/pick.ts +3 -3
- package/src/value/smush.ts +1 -1
- package/src/value/unsmush.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3808,7 +3808,7 @@ function isType(value, type) {
|
|
|
3808
3808
|
function cancelable(executor) {
|
|
3809
3809
|
return new CancelablePromise(executor);
|
|
3810
3810
|
}
|
|
3811
|
-
function handleResult
|
|
3811
|
+
function handleResult(status, parameters) {
|
|
3812
3812
|
const { abort, complete, data, handlers, index, signal, value } = parameters;
|
|
3813
3813
|
if (signal?.aborted ?? false) return;
|
|
3814
3814
|
if (!complete && status === "rejected") {
|
|
@@ -3834,6 +3834,28 @@ async function toResult(value) {
|
|
|
3834
3834
|
return actual.then((result) => ok(result)).catch((reason) => error(reason));
|
|
3835
3835
|
}
|
|
3836
3836
|
//#endregion
|
|
3837
|
+
//#region src/promise/delay.ts
|
|
3838
|
+
function delay(options) {
|
|
3839
|
+
const { signal, time } = getPromiseOptions(options);
|
|
3840
|
+
if (signal?.aborted ?? false) return Promise.reject(signal.reason);
|
|
3841
|
+
function abort() {
|
|
3842
|
+
timer.cancel();
|
|
3843
|
+
rejector(signal.reason);
|
|
3844
|
+
}
|
|
3845
|
+
const timer = getTimer(TIMER_WAIT, () => {
|
|
3846
|
+
settlePromise(abort, resolver, void 0, signal);
|
|
3847
|
+
}, time);
|
|
3848
|
+
signal?.addEventListener(PROMISE_ABORT_EVENT, abort, PROMISE_ABORT_OPTIONS);
|
|
3849
|
+
let rejector;
|
|
3850
|
+
let resolver;
|
|
3851
|
+
return new Promise((resolve, reject) => {
|
|
3852
|
+
rejector = reject;
|
|
3853
|
+
resolver = resolve;
|
|
3854
|
+
if (time === 0) settlePromise(abort, resolve, void 0, signal);
|
|
3855
|
+
else timer();
|
|
3856
|
+
});
|
|
3857
|
+
}
|
|
3858
|
+
//#endregion
|
|
3837
3859
|
//#region src/promise/timed.ts
|
|
3838
3860
|
async function getTimedPromise(promise, time, signal) {
|
|
3839
3861
|
function abort() {
|
|
@@ -3862,28 +3884,6 @@ async function timed(promise, options) {
|
|
|
3862
3884
|
return time > 0 ? getTimedPromise(promise, time, signal) : promise;
|
|
3863
3885
|
}
|
|
3864
3886
|
//#endregion
|
|
3865
|
-
//#region src/promise/delay.ts
|
|
3866
|
-
function delay(options) {
|
|
3867
|
-
const { signal, time } = getPromiseOptions(options);
|
|
3868
|
-
if (signal?.aborted ?? false) return Promise.reject(signal.reason);
|
|
3869
|
-
function abort() {
|
|
3870
|
-
timer.cancel();
|
|
3871
|
-
rejector(signal.reason);
|
|
3872
|
-
}
|
|
3873
|
-
const timer = getTimer(TIMER_WAIT, () => {
|
|
3874
|
-
settlePromise(abort, resolver, void 0, signal);
|
|
3875
|
-
}, time);
|
|
3876
|
-
signal?.addEventListener(PROMISE_ABORT_EVENT, abort, PROMISE_ABORT_OPTIONS);
|
|
3877
|
-
let rejector;
|
|
3878
|
-
let resolver;
|
|
3879
|
-
return new Promise((resolve, reject) => {
|
|
3880
|
-
rejector = reject;
|
|
3881
|
-
resolver = resolve;
|
|
3882
|
-
if (time === 0) settlePromise(abort, resolve, void 0, signal);
|
|
3883
|
-
else timer();
|
|
3884
|
-
});
|
|
3885
|
-
}
|
|
3886
|
-
//#endregion
|
|
3887
3887
|
//#region src/promise/index.ts
|
|
3888
3888
|
async function attemptPromise(value, options) {
|
|
3889
3889
|
const isFunction = typeof value === "function";
|
|
@@ -3932,7 +3932,7 @@ async function promises(items, options) {
|
|
|
3932
3932
|
reject,
|
|
3933
3933
|
resolve
|
|
3934
3934
|
};
|
|
3935
|
-
for (let index = 0; index < length; index += 1) actual[index].then((value) => handleResult
|
|
3935
|
+
for (let index = 0; index < length; index += 1) actual[index].then((value) => handleResult(PROMISE_TYPE_FULFILLED, {
|
|
3936
3936
|
abort,
|
|
3937
3937
|
complete,
|
|
3938
3938
|
data,
|
|
@@ -3940,7 +3940,7 @@ async function promises(items, options) {
|
|
|
3940
3940
|
index,
|
|
3941
3941
|
signal,
|
|
3942
3942
|
value
|
|
3943
|
-
})).catch((reason) => handleResult
|
|
3943
|
+
})).catch((reason) => handleResult(PROMISE_TYPE_REJECTED, {
|
|
3944
3944
|
abort,
|
|
3945
3945
|
complete,
|
|
3946
3946
|
data,
|
|
@@ -4187,11 +4187,11 @@ var Queue = class {
|
|
|
4187
4187
|
if (this.#paused) {
|
|
4188
4188
|
const paused = item;
|
|
4189
4189
|
this.#handled.push(() => {
|
|
4190
|
-
handleResult(paused, error, result);
|
|
4190
|
+
handleResult$1(paused, error, result);
|
|
4191
4191
|
});
|
|
4192
4192
|
break;
|
|
4193
4193
|
}
|
|
4194
|
-
handleResult(item, error, result);
|
|
4194
|
+
handleResult$1(item, error, result);
|
|
4195
4195
|
item = this.#items.shift();
|
|
4196
4196
|
}
|
|
4197
4197
|
this.#runners -= 1;
|
|
@@ -4217,7 +4217,7 @@ function getOptions(input) {
|
|
|
4217
4217
|
maximum: getNumberOrDefault(options.maximum, 0)
|
|
4218
4218
|
};
|
|
4219
4219
|
}
|
|
4220
|
-
function handleResult(item, error, result) {
|
|
4220
|
+
function handleResult$1(item, error, result) {
|
|
4221
4221
|
item.signal?.removeEventListener(EVENT_NAME, item.abort);
|
|
4222
4222
|
if (item.signal?.aborted ?? false) item.reject();
|
|
4223
4223
|
else if (error) item.reject(result);
|
|
@@ -4435,4 +4435,4 @@ var SizedSet = class extends Set {
|
|
|
4435
4435
|
}
|
|
4436
4436
|
};
|
|
4437
4437
|
//#endregion
|
|
4438
|
-
export { CancelablePromise, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, difference, drop, endsWith, endsWithArray, equal, error, exists, filter, find, flatten, floor, flow,
|
|
4438
|
+
export { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, attempt, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, difference, drop, endsWith, endsWithArray, equal, error, exists, filter, find, flatten, floor, flow, fromQuery, toPromise as fromResult, toPromise, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getTimedPromise, getUuid, getValue, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, includesArray, indexOf, indexOfArray, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shuffle, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
|
@@ -16,7 +16,7 @@ declare function indexOf<Item, Callback extends (item: Item, index: number, arra
|
|
|
16
16
|
* @param value Value to match against
|
|
17
17
|
* @returns Index of the first matching item, or `-1` if no match is found
|
|
18
18
|
*/
|
|
19
|
-
declare function indexOf<Item extends PlainObject,
|
|
19
|
+
declare function indexOf<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
20
20
|
/**
|
|
21
21
|
* Get the index of the first item matching the filter
|
|
22
22
|
* @param array Array to search in
|
|
@@ -22,7 +22,7 @@ declare function max<Item>(items: Item[], callback: (item: Item, index: number,
|
|
|
22
22
|
* @param key Key to use for value
|
|
23
23
|
* @returns Maximum value, or `NaN` if no maximum can be found
|
|
24
24
|
*/
|
|
25
|
-
declare function max<Item extends PlainObject,
|
|
25
|
+
declare function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(items: Item[], key: ItemKey): number;
|
|
26
26
|
/**
|
|
27
27
|
* Get the maximum value from a list of numbers
|
|
28
28
|
* @param values List of numbers
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/internal/value/partial.d.ts
|
|
2
|
-
declare function partial<Value extends object,
|
|
3
|
-
declare function partial<Value extends object,
|
|
2
|
+
declare function partial<Value extends object, ValueKey extends keyof Value>(value: unknown, keys: ValueKey[], omit: true): Omit<Value, ValueKey>;
|
|
3
|
+
declare function partial<Value extends object, ValueKey extends keyof Value>(value: unknown, keys: ValueKey[], omit: false): Pick<Value, ValueKey>;
|
|
4
4
|
//#endregion
|
|
5
5
|
export { partial };
|
package/dist/math.d.mts
CHANGED
|
@@ -44,7 +44,7 @@ declare function count<Item>(array: Item[], callback: (item: Item, index: number
|
|
|
44
44
|
* @param value Value to match and count
|
|
45
45
|
* @returns Number of items with the specified key value, or `NaN` if no count can be calculated
|
|
46
46
|
*/
|
|
47
|
-
declare function count<Item extends PlainObject,
|
|
47
|
+
declare function count<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
48
48
|
/**
|
|
49
49
|
* Count the number of items in an array
|
|
50
50
|
* @param values Array to count for
|
package/dist/models.d.mts
CHANGED
|
@@ -41,7 +41,7 @@ type GenericCallback = (...args: any[]) => any;
|
|
|
41
41
|
* A generic key type
|
|
42
42
|
*/
|
|
43
43
|
type Key = number | string;
|
|
44
|
-
type KeyedValue<Item,
|
|
44
|
+
type KeyedValue<Item, ItemKey extends keyof Item> = Item[ItemKey] extends PropertyKey ? Item[ItemKey] : never;
|
|
45
45
|
/**
|
|
46
46
|
* A nested array
|
|
47
47
|
*/
|
|
@@ -50,16 +50,16 @@ type NestedArray<Value> = Value extends Array<infer NestedValue> ? NestedArray<N
|
|
|
50
50
|
* All nested keys of an object as dot notation strings _(up to 5 levels deep)_
|
|
51
51
|
*/
|
|
52
52
|
type NestedKeys<Value extends PlainObject> = _NestedKeys<Value>;
|
|
53
|
-
type _NestedKeys<Value, Depth extends number = 5> = Depth extends 0 ? never : Value extends readonly any[] ? Value extends readonly [any, ...any] ? { [
|
|
53
|
+
type _NestedKeys<Value, Depth extends number = 5> = Depth extends 0 ? never : Value extends readonly any[] ? Value extends readonly [any, ...any] ? { [ItemKey in keyof Value]-?: ItemKey extends `${number}` ? NonNullable<Value[ItemKey]> extends readonly any[] | PlainObject ? `${ItemKey}` | `${ItemKey}.${_NestedKeys<NonNullable<Value[ItemKey]>, SubtractDepth<Depth>>}` : `${ItemKey}` : never }[number] : never : Value extends PlainObject ? { [ItemKey in keyof Value]-?: ItemKey extends number | string ? NonNullable<Value[ItemKey]> extends readonly any[] | PlainObject ? `${ItemKey}` | `${ItemKey}.${_NestedKeys<NonNullable<Value[ItemKey]>, SubtractDepth<Depth>>}` : `${ItemKey}` : never }[keyof Value] : never;
|
|
54
54
|
/**
|
|
55
55
|
* An extended version of `Partial` that allows for nested properties to be optional
|
|
56
56
|
*/
|
|
57
|
-
type NestedPartial<Value> = { [
|
|
57
|
+
type NestedPartial<Value> = { [ItemKey in keyof Value]?: Value[ItemKey] extends object ? NestedPartial<Value[ItemKey]> : Value[ItemKey] };
|
|
58
58
|
/**
|
|
59
59
|
* The value for a nested key of an object
|
|
60
60
|
*/
|
|
61
61
|
type NestedValue<Value extends PlainObject, Path extends string> = _NestedValue<Value, Path>;
|
|
62
|
-
type _NestedValue<Value, Path extends string> = Path extends `${infer
|
|
62
|
+
type _NestedValue<Value, Path extends string> = Path extends `${infer ItemKey}.${infer Rest}` ? ItemKey extends keyof Value ? undefined extends Value[ItemKey] ? _NestedValue<Exclude<Value[ItemKey], undefined>, Rest> | undefined : _NestedValue<Value[ItemKey], Rest> : ItemKey extends `${number}` ? Value extends readonly any[] ? _NestedValue<Value[number], Rest> : never : never : Path extends `${number}` ? Value extends readonly any[] ? Value[number] : never : Path extends keyof Value ? Value[Path] : never;
|
|
63
63
|
/**
|
|
64
64
|
* The nested (keyed) values of an object _(up to 5 levels deep)_
|
|
65
65
|
*/
|
|
@@ -67,11 +67,11 @@ type NestedValues<Value extends PlainObject> = { [Path in NestedKeys<Value>]: Ne
|
|
|
67
67
|
/**
|
|
68
68
|
* The numerical keys of an object
|
|
69
69
|
*/
|
|
70
|
-
type NumericalKeys<Value> = { [
|
|
70
|
+
type NumericalKeys<Value> = { [ItemKey in keyof Value]: ItemKey extends number ? ItemKey : ItemKey extends `${number}` ? ItemKey : never }[keyof Value];
|
|
71
71
|
/**
|
|
72
72
|
* The numerical values of an object
|
|
73
73
|
*/
|
|
74
|
-
type NumericalValues<Item extends PlainObject> = { [
|
|
74
|
+
type NumericalValues<Item extends PlainObject> = { [ItemKey in keyof Item as Item[ItemKey] extends number ? ItemKey : never]: Item[ItemKey] };
|
|
75
75
|
/**
|
|
76
76
|
* An asynchronous function that can only be called once, returning the same value on subsequent calls
|
|
77
77
|
*/
|
|
@@ -122,7 +122,7 @@ type RequiredKeys<Model extends object, Keys extends keyof Model> = Required<Pic
|
|
|
122
122
|
*
|
|
123
123
|
* _(Thanks, type-fest!)_
|
|
124
124
|
*/
|
|
125
|
-
type Simplify<Value> = { [
|
|
125
|
+
type Simplify<Value> = { [ValueKey in keyof Value]: Value[ValueKey] } & {};
|
|
126
126
|
type SubtractDepth<Value extends number> = Value extends 5 ? 4 : Value extends 4 ? 3 : Value extends 3 ? 2 : Value extends 2 ? 1 : Value extends 1 ? 0 : never;
|
|
127
127
|
/**
|
|
128
128
|
* Get the value's type as a string
|
package/dist/promise/index.d.mts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { Result } from "../result/models.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { toPromise } from "../result/misc.mjs";
|
|
4
|
-
import { delay } from "./delay.mjs";
|
|
5
|
-
import { isFulfilled, isRejected } from "./helpers.mjs";
|
|
6
|
-
import { cancelable, toResult } from "./misc.mjs";
|
|
7
|
-
import { timed } from "./timed.mjs";
|
|
2
|
+
import { PromiseOptions, PromisesItems, PromisesOptions, PromisesResult, PromisesUnwrapped, PromisesValue, PromisesValues } from "./models.mjs";
|
|
8
3
|
|
|
9
4
|
//#region src/promise/index.d.ts
|
|
10
5
|
/**
|
|
@@ -100,4 +95,4 @@ declare function resultPromises<Items extends unknown[]>(items: [...Items], sign
|
|
|
100
95
|
*/
|
|
101
96
|
declare function resultPromises<Value>(items: Promise<Value>[], signal?: AbortSignal): Promise<Result<Awaited<Value>>[]>;
|
|
102
97
|
//#endregion
|
|
103
|
-
export {
|
|
98
|
+
export { attemptPromise, promises };
|
package/dist/promise/index.mjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { getTimedPromise, timed } from "./timed.mjs";
|
|
6
|
-
import { delay } from "./delay.mjs";
|
|
1
|
+
import { PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "./models.mjs";
|
|
2
|
+
import { getPromiseOptions, getPromisesOptions, getResultsFromPromises } from "./helpers.mjs";
|
|
3
|
+
import { handleResult, settlePromise } from "./misc.mjs";
|
|
4
|
+
import { getTimedPromise } from "./timed.mjs";
|
|
7
5
|
//#region src/promise/index.ts
|
|
8
6
|
async function attemptPromise(value, options) {
|
|
9
7
|
const isFunction = typeof value === "function";
|
|
@@ -76,4 +74,4 @@ async function resultPromises(items, signal) {
|
|
|
76
74
|
return promises(items, signal).then(getResultsFromPromises);
|
|
77
75
|
}
|
|
78
76
|
//#endregion
|
|
79
|
-
export {
|
|
77
|
+
export { attemptPromise, promises };
|
package/dist/promise/misc.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Result } from "../result/models.mjs";
|
|
2
2
|
import { CancelablePromise, PromiseParameters } from "./models.mjs";
|
|
3
|
+
import { toPromise } from "../result/misc.mjs";
|
|
4
|
+
import { isFulfilled, isRejected } from "./helpers.mjs";
|
|
3
5
|
|
|
4
6
|
//#region src/promise/misc.d.ts
|
|
5
7
|
/**
|
|
@@ -23,4 +25,4 @@ declare function toResult<Value>(callback: () => Promise<Value>): Promise<Result
|
|
|
23
25
|
*/
|
|
24
26
|
declare function toResult<Value>(promise: Promise<Value>): Promise<Result<Value>>;
|
|
25
27
|
//#endregion
|
|
26
|
-
export { cancelable, handleResult, settlePromise, toResult };
|
|
28
|
+
export { cancelable, toPromise as fromResult, handleResult, isFulfilled, isRejected, settlePromise, toResult };
|
package/dist/promise/misc.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { error, ok } from "../result/misc.mjs";
|
|
1
|
+
import { error, ok, toPromise } from "../result/misc.mjs";
|
|
2
2
|
import { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_MESSAGE_EXPECTATION_RESULT } from "./models.mjs";
|
|
3
|
+
import { isFulfilled, isRejected } from "./helpers.mjs";
|
|
3
4
|
//#region src/promise/misc.ts
|
|
4
5
|
/**
|
|
5
6
|
* Create a cancelable promise
|
|
@@ -35,4 +36,4 @@ async function toResult(value) {
|
|
|
35
36
|
return actual.then((result) => ok(result)).catch((reason) => error(reason));
|
|
36
37
|
}
|
|
37
38
|
//#endregion
|
|
38
|
-
export { cancelable, handleResult, settlePromise, toResult };
|
|
39
|
+
export { cancelable, toPromise as fromResult, handleResult, isFulfilled, isRejected, settlePromise, toResult };
|
|
@@ -54,15 +54,15 @@ type PromiseStrategy = 'complete' | 'first';
|
|
|
54
54
|
declare class PromiseTimeoutError extends Error {
|
|
55
55
|
constructor();
|
|
56
56
|
}
|
|
57
|
-
type PromisesItems<Items extends unknown[]> = { [
|
|
57
|
+
type PromisesItems<Items extends unknown[]> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? Promise<Value> : never : Items[ItemsKey] extends Promise<infer Value> ? Promise<Value> : Promise<Items[ItemsKey]> };
|
|
58
58
|
type PromisesOptions = {
|
|
59
59
|
signal?: AbortSignal;
|
|
60
60
|
strategy?: PromiseStrategy;
|
|
61
61
|
};
|
|
62
|
-
type PromisesResult<Items extends unknown[]> = { [
|
|
63
|
-
type PromisesUnwrapped<Items extends unknown[]> = { [
|
|
62
|
+
type PromisesResult<Items extends unknown[]> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends Promise<infer Value> ? Result<Awaited<Value>> : never };
|
|
63
|
+
type PromisesUnwrapped<Items extends unknown[]> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? Awaited<Value> : never : Items[ItemsKey] extends Promise<infer Value> ? Awaited<Value> : never };
|
|
64
64
|
type PromisesValue<Value> = FulfilledPromise<Value> | RejectedPromise;
|
|
65
|
-
type PromisesValues<Items extends unknown[]> = { [
|
|
65
|
+
type PromisesValues<Items extends unknown[]> = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType<Items[ItemsKey]> extends Promise<infer Value> ? PromisesValue<Awaited<Value>> : never : Items[ItemsKey] extends Promise<infer Value> ? PromisesValue<Awaited<Value>> : never };
|
|
66
66
|
type RejectedPromise = {
|
|
67
67
|
status: typeof PROMISE_TYPE_REJECTED;
|
|
68
68
|
reason: unknown;
|
package/dist/result/index.d.mts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { error, ok, toPromise, unwrap } from "./misc.mjs";
|
|
3
|
-
import { toResult } from "../promise/misc.mjs";
|
|
1
|
+
import { ExtendedResult, Result } from "./models.mjs";
|
|
4
2
|
import { attemptPromise } from "../promise/index.mjs";
|
|
5
3
|
import { matchResult } from "./match.mjs";
|
|
6
4
|
import { attemptFlow } from "./work/flow.mjs";
|
|
7
5
|
import { attemptPipe } from "./work/pipe.mjs";
|
|
8
|
-
import { isError, isOk, isResult } from "../internal/result.mjs";
|
|
9
6
|
|
|
10
7
|
//#region src/result/index.d.ts
|
|
11
8
|
/**
|
|
@@ -55,4 +52,4 @@ declare namespace attempt {
|
|
|
55
52
|
var promise: typeof attemptPromise;
|
|
56
53
|
}
|
|
57
54
|
//#endregion
|
|
58
|
-
export {
|
|
55
|
+
export { attempt };
|
package/dist/result/index.mjs
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { error, getError, ok, toPromise, unwrap } from "./misc.mjs";
|
|
3
|
-
import { toResult } from "../promise/misc.mjs";
|
|
1
|
+
import { getError, ok } from "./misc.mjs";
|
|
4
2
|
import { attemptPromise } from "../promise/index.mjs";
|
|
5
3
|
import { matchResult } from "./match.mjs";
|
|
6
4
|
import { attemptFlow } from "./work/flow.mjs";
|
|
@@ -28,4 +26,4 @@ attempt.match = matchResult;
|
|
|
28
26
|
attempt.pipe = attemptPipe;
|
|
29
27
|
attempt.promise = attemptPromise;
|
|
30
28
|
//#endregion
|
|
31
|
-
export { attempt
|
|
29
|
+
export { attempt };
|
package/dist/result/misc.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AnyResult, Err, ExtendedErr, Ok, Result } from "./models.mjs";
|
|
2
|
+
import { isError, isOk, isResult } from "../internal/result.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/result/misc.d.ts
|
|
4
5
|
/**
|
|
@@ -52,4 +53,4 @@ declare function unwrap<Value, E = Error>(value: Result<Value, E>, defaultValue:
|
|
|
52
53
|
*/
|
|
53
54
|
declare function unwrap(value: unknown, defaultValue: unknown): unknown;
|
|
54
55
|
//#endregion
|
|
55
|
-
export { error, getError, ok, toPromise, unwrap };
|
|
56
|
+
export { error, getError, isError, isOk, isResult, ok, toPromise, unwrap };
|
package/dist/result/misc.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isOk, isResult } from "../internal/result.mjs";
|
|
1
|
+
import { isError, isOk, isResult } from "../internal/result.mjs";
|
|
2
2
|
//#region src/result/misc.ts
|
|
3
3
|
function error(value, original) {
|
|
4
4
|
return getError(value, original);
|
|
@@ -39,4 +39,4 @@ function unwrap(value, defaultValue) {
|
|
|
39
39
|
}
|
|
40
40
|
const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
|
|
41
41
|
//#endregion
|
|
42
|
-
export { error, getError, ok, toPromise, unwrap };
|
|
42
|
+
export { error, getError, isError, isOk, isResult, ok, toPromise, unwrap };
|
package/dist/sized/map.d.mts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Behavior is similar to a _LRU_-cache, where the least recently used entries are removed
|
|
6
6
|
*/
|
|
7
|
-
declare class SizedMap<
|
|
7
|
+
declare class SizedMap<SizedKey = unknown, SizedValue = unknown> extends Map<SizedKey, SizedValue> {
|
|
8
8
|
#private;
|
|
9
9
|
/**
|
|
10
10
|
* Is the Map full?
|
|
@@ -14,33 +14,33 @@ declare class SizedMap<Key = unknown, Value = unknown> extends Map<Key, Value> {
|
|
|
14
14
|
/**
|
|
15
15
|
* Create a new SizedMap with entries and a maximum size _(2^20)_
|
|
16
16
|
* @param entries Array of key-value pairs to initialize the SizedMap with
|
|
17
|
-
* @template
|
|
18
|
-
* @template
|
|
17
|
+
* @template SizedKey Type of the keys in the SizedMap
|
|
18
|
+
* @template SizedValue Type of the values in the SizedMap
|
|
19
19
|
*/
|
|
20
|
-
constructor(entries: [
|
|
20
|
+
constructor(entries: [SizedKey, SizedValue][]);
|
|
21
21
|
/**
|
|
22
22
|
* Create a new SizedMap with a maximum size _(but clamped at 2^24)_
|
|
23
23
|
* @param maximum Maximum size of the SizedMap
|
|
24
|
-
* @template
|
|
25
|
-
* @template
|
|
24
|
+
* @template SizedKey Type of the keys in the SizedMap
|
|
25
|
+
* @template SizedValue Type of the values in the SizedMap
|
|
26
26
|
*/
|
|
27
27
|
constructor(maximum: number);
|
|
28
28
|
/**
|
|
29
29
|
* Create a new SizedMap with _(optional)_ entries and a maximum size _(defaults to 2^20; clamped at 2^24)_
|
|
30
30
|
* @param entries Array of key-value pairs to initialize the SizedMap with
|
|
31
31
|
* @param maximum Maximum size of the SizedMap
|
|
32
|
-
* @template
|
|
33
|
-
* @template
|
|
32
|
+
* @template SizedKey Type of the keys in the SizedMap
|
|
33
|
+
* @template SizedValue Type of the values in the SizedMap
|
|
34
34
|
*/
|
|
35
|
-
constructor(entries?: [
|
|
35
|
+
constructor(entries?: [SizedKey, SizedValue][], maximum?: number);
|
|
36
36
|
/**
|
|
37
37
|
* @inheritdoc
|
|
38
38
|
*/
|
|
39
|
-
get(key:
|
|
39
|
+
get(key: SizedKey): SizedValue | undefined;
|
|
40
40
|
/**
|
|
41
41
|
* @inheritdoc
|
|
42
42
|
*/
|
|
43
|
-
set(key:
|
|
43
|
+
set(key: SizedKey, value: SizedValue): this;
|
|
44
44
|
}
|
|
45
45
|
//#endregion
|
|
46
46
|
export { SizedMap };
|
package/dist/value/omit.d.mts
CHANGED
|
@@ -7,6 +7,6 @@ import { PlainObject } from "../models.mjs";
|
|
|
7
7
|
* @param keys Keys to omit
|
|
8
8
|
* @returns Partial object without the specified keys
|
|
9
9
|
*/
|
|
10
|
-
declare function omit<Value extends PlainObject,
|
|
10
|
+
declare function omit<Value extends PlainObject, ValueKey extends keyof Value>(value: Value, keys: ValueKey[]): Omit<Value, ValueKey>;
|
|
11
11
|
//#endregion
|
|
12
12
|
export { omit };
|
package/dist/value/pick.d.mts
CHANGED
|
@@ -7,6 +7,6 @@ import { PlainObject } from "../models.mjs";
|
|
|
7
7
|
* @param keys Keys to use
|
|
8
8
|
* @returns Partial object with only the specified keys
|
|
9
9
|
*/
|
|
10
|
-
declare function pick<Value extends PlainObject,
|
|
10
|
+
declare function pick<Value extends PlainObject, ValueKey extends keyof Value>(value: Value, keys: ValueKey[]): Pick<Value, ValueKey>;
|
|
11
11
|
//#endregion
|
|
12
12
|
export { pick };
|
package/dist/value/smush.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NestedKeys, NestedValue, PlainObject, Simplify, ToString } from "../models.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/value/smush.d.ts
|
|
4
|
-
type Smushed<Value extends PlainObject> = Simplify<{ [
|
|
4
|
+
type Smushed<Value extends PlainObject> = Simplify<{ [NestedKey in NestedKeys<Value>]: NestedValue<Value, ToString<NestedKey>> }>;
|
|
5
5
|
/**
|
|
6
6
|
* Smush an object into a flat object that uses dot notation keys
|
|
7
7
|
* @param value Object to smush
|
package/dist/value/unsmush.d.mts
CHANGED
|
@@ -9,7 +9,7 @@ type KeysOfUnion<ObjectType> = keyof UnionToIntersection<ObjectType extends unkn
|
|
|
9
9
|
* Thanks, type-fest!
|
|
10
10
|
*/
|
|
11
11
|
type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
|
|
12
|
-
type Unsmushed<Value extends PlainObject> = Simplify<Omit<{ [
|
|
12
|
+
type Unsmushed<Value extends PlainObject> = Simplify<Omit<{ [UnionKey in KeysOfUnion<Value>]: Value[UnionKey] }, `${string}.${string}`>>;
|
|
13
13
|
/**
|
|
14
14
|
* Unsmush a smushed object _(turning dot notation keys into nested keys)_
|
|
15
15
|
* @param value Object to unsmush
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oscarpalmer/atoms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.167.0",
|
|
4
4
|
"description": "Atomic utilities for making your JavaScript better.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"helper",
|
|
@@ -111,10 +111,18 @@
|
|
|
111
111
|
"types": "./dist/promise/delay.d.mts",
|
|
112
112
|
"default": "./dist/promise/delay.mjs"
|
|
113
113
|
},
|
|
114
|
+
"./promise/misc": {
|
|
115
|
+
"types": "./dist/promise/misc.d.mts",
|
|
116
|
+
"default": "./dist/promise/misc.mjs"
|
|
117
|
+
},
|
|
114
118
|
"./promise/models": {
|
|
115
119
|
"types": "./dist/promise/models.d.mts",
|
|
116
120
|
"default": "./dist/promise/models.mjs"
|
|
117
121
|
},
|
|
122
|
+
"./promise/timed": {
|
|
123
|
+
"types": "./dist/promise/timed.d.mts",
|
|
124
|
+
"default": "./dist/promise/timed.mjs"
|
|
125
|
+
},
|
|
118
126
|
"./query": {
|
|
119
127
|
"types": "./dist/query.d.mts",
|
|
120
128
|
"default": "./dist/query.mjs"
|
|
@@ -131,6 +139,26 @@
|
|
|
131
139
|
"types": "./dist/result/index.d.mts",
|
|
132
140
|
"default": "./dist/result/index.mjs"
|
|
133
141
|
},
|
|
142
|
+
"./result/flow": {
|
|
143
|
+
"types": "./dist/result/work/flow.d.mts",
|
|
144
|
+
"default": "./dist/result/work/flow.mjs"
|
|
145
|
+
},
|
|
146
|
+
"./result/match": {
|
|
147
|
+
"types": "./dist/result/match.d.mts",
|
|
148
|
+
"default": "./dist/result/match.mjs"
|
|
149
|
+
},
|
|
150
|
+
"./result/misc": {
|
|
151
|
+
"types": "./dist/result/misc.d.mts",
|
|
152
|
+
"default": "./dist/result/misc.mjs"
|
|
153
|
+
},
|
|
154
|
+
"./result/models": {
|
|
155
|
+
"types": "./dist/result/models.d.mts",
|
|
156
|
+
"default": "./dist/result/models.mjs"
|
|
157
|
+
},
|
|
158
|
+
"./result/pipe": {
|
|
159
|
+
"types": "./dist/result/work/pipe.d.mts",
|
|
160
|
+
"default": "./dist/result/work/pipe.mjs"
|
|
161
|
+
},
|
|
134
162
|
"./sized/map": {
|
|
135
163
|
"types": "./dist/sized/map.d.mts",
|
|
136
164
|
"default": "./dist/sized/map.mjs"
|
|
@@ -203,4 +231,4 @@
|
|
|
203
231
|
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
|
|
204
232
|
},
|
|
205
233
|
"packageManager": "npm@11.11.1"
|
|
206
|
-
}
|
|
234
|
+
}
|
package/src/array/difference.ts
CHANGED
|
@@ -24,8 +24,8 @@ export function difference<First, Second>(
|
|
|
24
24
|
export function difference<
|
|
25
25
|
First extends PlainObject,
|
|
26
26
|
Second extends PlainObject,
|
|
27
|
-
|
|
28
|
-
>(first: First[], second: Second[], key:
|
|
27
|
+
SharedKey extends keyof First & keyof Second,
|
|
28
|
+
>(first: First[], second: Second[], key: SharedKey): First[];
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Get the items from the first array that are not in the second array
|
package/src/array/exists.ts
CHANGED
|
@@ -22,10 +22,10 @@ export function exists<
|
|
|
22
22
|
* @param value Value to match against
|
|
23
23
|
* @returns `true` if the item exists in the array, otherwise `false`
|
|
24
24
|
*/
|
|
25
|
-
export function exists<Item extends PlainObject,
|
|
25
|
+
export function exists<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
26
26
|
array: Item[],
|
|
27
|
-
key:
|
|
28
|
-
value: Item[
|
|
27
|
+
key: ItemKey,
|
|
28
|
+
value: Item[ItemKey],
|
|
29
29
|
): boolean;
|
|
30
30
|
|
|
31
31
|
/**
|
package/src/array/filter.ts
CHANGED
|
@@ -22,10 +22,10 @@ export function filter<
|
|
|
22
22
|
* @param value Value to match against
|
|
23
23
|
* @returns Filtered array of items
|
|
24
24
|
*/
|
|
25
|
-
export function filter<Item extends PlainObject,
|
|
25
|
+
export function filter<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
26
26
|
array: Item[],
|
|
27
|
-
key:
|
|
28
|
-
value: Item[
|
|
27
|
+
key: ItemKey,
|
|
28
|
+
value: Item[ItemKey],
|
|
29
29
|
): Item[];
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -58,10 +58,10 @@ function removeFiltered<
|
|
|
58
58
|
Callback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
59
59
|
>(array: Item[], callback: Callback, value: ReturnType<Callback>): unknown[];
|
|
60
60
|
|
|
61
|
-
function removeFiltered<Item extends PlainObject,
|
|
61
|
+
function removeFiltered<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
62
62
|
array: Item[],
|
|
63
|
-
key:
|
|
64
|
-
value: Item[
|
|
63
|
+
key: ItemKey,
|
|
64
|
+
value: Item[ItemKey],
|
|
65
65
|
): unknown[];
|
|
66
66
|
|
|
67
67
|
function removeFiltered<Item>(
|
package/src/array/find.ts
CHANGED
|
@@ -23,10 +23,10 @@ export function find<Item, Callback extends (item: Item, index: number, array: I
|
|
|
23
23
|
* @param value Value to match against
|
|
24
24
|
* @returns First item that matches the value, or `undefined` if no match is found
|
|
25
25
|
*/
|
|
26
|
-
export function find<Item extends PlainObject,
|
|
26
|
+
export function find<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
27
27
|
array: Item[],
|
|
28
|
-
key:
|
|
29
|
-
value: Item[
|
|
28
|
+
key: ItemKey,
|
|
29
|
+
value: Item[ItemKey],
|
|
30
30
|
): Item | undefined;
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -23,8 +23,8 @@ export function intersection<First, Second>(
|
|
|
23
23
|
export function intersection<
|
|
24
24
|
First extends Record<string, unknown>,
|
|
25
25
|
Second extends Record<string, unknown>,
|
|
26
|
-
|
|
27
|
-
>(first: First[], second: Second[], key:
|
|
26
|
+
SharedKey extends keyof First & keyof Second,
|
|
27
|
+
>(first: First[], second: Second[], key: SharedKey): First[];
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Get the common values between two arrays
|
package/src/array/move.ts
CHANGED
|
@@ -14,11 +14,11 @@ import {indexOfArray} from './position';
|
|
|
14
14
|
* @param key Key to get an item's value for matching
|
|
15
15
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
16
16
|
*/
|
|
17
|
-
export function move<Item extends PlainObject,
|
|
17
|
+
export function move<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
18
18
|
array: Item[],
|
|
19
19
|
from: Item | Item[],
|
|
20
20
|
to: Item | Item[],
|
|
21
|
-
key:
|
|
21
|
+
key: ItemKey,
|
|
22
22
|
): Item[];
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -156,11 +156,11 @@ function moveIndices<Item>(array: Item[], from: number, to: number): Item[] {
|
|
|
156
156
|
* @param key Key to get an item's value for matching
|
|
157
157
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
158
158
|
*/
|
|
159
|
-
function moveToIndex<Item extends PlainObject,
|
|
159
|
+
function moveToIndex<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
160
160
|
array: Item[],
|
|
161
161
|
value: Item | Item[],
|
|
162
162
|
index: number,
|
|
163
|
-
key:
|
|
163
|
+
key: ItemKey,
|
|
164
164
|
): Item[];
|
|
165
165
|
|
|
166
166
|
/**
|