@oscarpalmer/atoms 0.166.3 → 0.168.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/index.d.mts +1 -2
- package/dist/array/index.mjs +1 -2
- package/dist/array/sort.d.mts +29 -5
- package/dist/array/sort.mjs +27 -14
- package/dist/index.d.mts +287 -231
- package/dist/index.mjs +196 -183
- 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/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/package.json +34 -2
- package/src/array/index.ts +0 -1
- package/src/array/sort.ts +100 -63
- package/src/index.ts +10 -0
- package/src/promise/index.ts +0 -22
- package/src/promise/misc.ts +7 -0
- package/src/result/index.ts +0 -9
- package/src/result/misc.ts +6 -0
package/dist/index.d.mts
CHANGED
|
@@ -853,97 +853,6 @@ declare function take<Item extends PlainObject>(array: Item[], callback: (item:
|
|
|
853
853
|
*/
|
|
854
854
|
declare function take(array: unknown[], count: number): unknown[];
|
|
855
855
|
//#endregion
|
|
856
|
-
//#region src/array/sort.d.ts
|
|
857
|
-
/**
|
|
858
|
-
* Sorting information for arrays _(using a comparison callback)_
|
|
859
|
-
*/
|
|
860
|
-
type ArrayComparisonSorter<Item> = {
|
|
861
|
-
/**
|
|
862
|
-
* Callback to use when comparing items and values
|
|
863
|
-
*/
|
|
864
|
-
comparison: ComparisonSorter<Item>;
|
|
865
|
-
/**
|
|
866
|
-
* Direction to sort by
|
|
867
|
-
*/
|
|
868
|
-
direction?: SortDirection;
|
|
869
|
-
};
|
|
870
|
-
/**
|
|
871
|
-
* Sorting information for arrays _(using a key)_
|
|
872
|
-
*/
|
|
873
|
-
type ArrayKeySorter<Item extends PlainObject, ItemKey extends keyof Item> = {
|
|
874
|
-
/**
|
|
875
|
-
* Comparator to use when comparing items and values
|
|
876
|
-
*/
|
|
877
|
-
compare?: CompareCallback<Item, Item[ItemKey]>;
|
|
878
|
-
/**
|
|
879
|
-
* Direction to sort by
|
|
880
|
-
*/
|
|
881
|
-
direction?: SortDirection;
|
|
882
|
-
/**
|
|
883
|
-
* Key to sort by
|
|
884
|
-
*/
|
|
885
|
-
key: ItemKey;
|
|
886
|
-
};
|
|
887
|
-
/**
|
|
888
|
-
* Sorters based on keys in an object
|
|
889
|
-
*/
|
|
890
|
-
type ArrayKeySorters<Item extends PlainObject> = { [ItemKey in keyof Item]: ArrayKeySorter<Item, ItemKey> }[keyof Item];
|
|
891
|
-
/**
|
|
892
|
-
* Sorting information for arrays _(using a value callback and built-in comparison)_
|
|
893
|
-
*/
|
|
894
|
-
type ArrayValueSorter<Item> = {
|
|
895
|
-
/**
|
|
896
|
-
* Direction to sort by
|
|
897
|
-
*/
|
|
898
|
-
direction?: SortDirection;
|
|
899
|
-
/**
|
|
900
|
-
* Value to sort by
|
|
901
|
-
*/
|
|
902
|
-
value: (item: Item) => unknown;
|
|
903
|
-
};
|
|
904
|
-
/**
|
|
905
|
-
* Comparator to use when comparing items and values
|
|
906
|
-
*/
|
|
907
|
-
type CompareCallback<Item, Value = CompareCallbackValue<Item>> = (first: Item, firstValue: Value, second: Item, secondValue: Value) => number;
|
|
908
|
-
type CompareCallbackValue<Item> = Item extends Primitive ? Item : unknown;
|
|
909
|
-
/**
|
|
910
|
-
* Callback to use when comparing items and values
|
|
911
|
-
*/
|
|
912
|
-
type ComparisonSorter<Item> = (first: Item, second: Item) => number;
|
|
913
|
-
/**
|
|
914
|
-
* Direction to sort by
|
|
915
|
-
*/
|
|
916
|
-
type SortDirection = 'ascending' | 'descending';
|
|
917
|
-
/**
|
|
918
|
-
* Sorter to use for sorting
|
|
919
|
-
*/
|
|
920
|
-
type Sorter<Item> = Item extends PlainObject ? keyof Item | ArrayComparisonSorter<Item> | ArrayKeySorters<Item> | ArrayValueSorter<Item> | ComparisonSorter<Item> : ArrayComparisonSorter<Item> | ArrayValueSorter<Item> | ComparisonSorter<Item>;
|
|
921
|
-
/**
|
|
922
|
-
* Sort an array of items, using multiple sorters to sort by specific values
|
|
923
|
-
* @param array Array to sort
|
|
924
|
-
* @param sorters Sorters to use for sorting
|
|
925
|
-
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
926
|
-
* @returns Sorted array
|
|
927
|
-
*/
|
|
928
|
-
declare function sort<Item>(array: Item[], sorters: Array<Sorter<Item>>, descending?: boolean): Item[];
|
|
929
|
-
/**
|
|
930
|
-
* Sort an array of items, using multiple sorters to sort by specific values
|
|
931
|
-
* @param array Array to sort
|
|
932
|
-
* @param sorter Sorter to use for sorting
|
|
933
|
-
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
934
|
-
* @returns Sorted array
|
|
935
|
-
*/
|
|
936
|
-
declare function sort<Item>(array: Item[], sorter: Sorter<Item>, descending?: boolean): Item[];
|
|
937
|
-
/**
|
|
938
|
-
* Sort an array of items
|
|
939
|
-
* @param array Array to sort
|
|
940
|
-
* @param descending Sort in descending order? _(defaults to `false`)_
|
|
941
|
-
* @returns Sorted array
|
|
942
|
-
*/
|
|
943
|
-
declare function sort<Item>(array: Item[], descending?: boolean): Item[];
|
|
944
|
-
declare const SORT_DIRECTION_ASCENDING: SortDirection;
|
|
945
|
-
declare const SORT_DIRECTION_DESCENDING: SortDirection;
|
|
946
|
-
//#endregion
|
|
947
856
|
//#region src/array/splice.d.ts
|
|
948
857
|
/**
|
|
949
858
|
* Adds items into an array at a specific index and removes a specific amount of items
|
|
@@ -1183,6 +1092,121 @@ declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: n
|
|
|
1183
1092
|
*/
|
|
1184
1093
|
declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: number): Item[];
|
|
1185
1094
|
//#endregion
|
|
1095
|
+
//#region src/array/sort.d.ts
|
|
1096
|
+
/**
|
|
1097
|
+
* Sorting information for arrays _(using a comparison callback)_
|
|
1098
|
+
*/
|
|
1099
|
+
type ArrayComparisonSorter<Item> = {
|
|
1100
|
+
/**
|
|
1101
|
+
* Callback to use when comparing items and values
|
|
1102
|
+
*/
|
|
1103
|
+
comparison: ComparisonSorter<Item>;
|
|
1104
|
+
/**
|
|
1105
|
+
* Direction to sort by
|
|
1106
|
+
*/
|
|
1107
|
+
direction?: SortDirection;
|
|
1108
|
+
};
|
|
1109
|
+
/**
|
|
1110
|
+
* Sorting information for arrays _(using a key)_
|
|
1111
|
+
*/
|
|
1112
|
+
type ArrayKeySorter<Item extends PlainObject, ItemKey extends keyof Item> = {
|
|
1113
|
+
/**
|
|
1114
|
+
* Comparator to use when comparing items and values
|
|
1115
|
+
*/
|
|
1116
|
+
compare?: CompareCallback<Item, Item[ItemKey]>;
|
|
1117
|
+
/**
|
|
1118
|
+
* Direction to sort by
|
|
1119
|
+
*/
|
|
1120
|
+
direction?: SortDirection;
|
|
1121
|
+
/**
|
|
1122
|
+
* Key to sort by
|
|
1123
|
+
*/
|
|
1124
|
+
key: ItemKey;
|
|
1125
|
+
};
|
|
1126
|
+
/**
|
|
1127
|
+
* Sorters based on keys in an object
|
|
1128
|
+
*/
|
|
1129
|
+
type ArrayKeySorters<Item extends PlainObject> = { [ItemKey in keyof Item]: ArrayKeySorter<Item, ItemKey> }[keyof Item];
|
|
1130
|
+
/**
|
|
1131
|
+
* Sorter to use for sorting
|
|
1132
|
+
*/
|
|
1133
|
+
type ArraySorter<Item> = Item extends PlainObject ? keyof Item | ArrayComparisonSorter<Item> | ArrayKeySorters<Item> | ArrayValueSorter<Item> | ComparisonSorter<Item> : ArrayComparisonSorter<Item> | ArrayValueSorter<Item> | ComparisonSorter<Item>;
|
|
1134
|
+
/**
|
|
1135
|
+
* Sorting information for arrays _(using a value callback and built-in comparison)_
|
|
1136
|
+
*/
|
|
1137
|
+
type ArrayValueSorter<Item> = {
|
|
1138
|
+
/**
|
|
1139
|
+
* Direction to sort by
|
|
1140
|
+
*/
|
|
1141
|
+
direction?: SortDirection;
|
|
1142
|
+
/**
|
|
1143
|
+
* Value to sort by
|
|
1144
|
+
*/
|
|
1145
|
+
value: (item: Item) => unknown;
|
|
1146
|
+
};
|
|
1147
|
+
/**
|
|
1148
|
+
* Comparator to use when comparing items and values
|
|
1149
|
+
*/
|
|
1150
|
+
type CompareCallback<Item, Value = CompareCallbackValue<Item>> = (first: Item, firstValue: Value, second: Item, secondValue: Value) => number;
|
|
1151
|
+
type CompareCallbackValue<Item> = Item extends Primitive ? Item : unknown;
|
|
1152
|
+
/**
|
|
1153
|
+
* Callback to use when comparing items and values
|
|
1154
|
+
*/
|
|
1155
|
+
type ComparisonSorter<Item> = (first: Item, second: Item) => number;
|
|
1156
|
+
/**
|
|
1157
|
+
* Direction to sort by
|
|
1158
|
+
*/
|
|
1159
|
+
type SortDirection = 'ascending' | 'descending';
|
|
1160
|
+
type Sorter<Item> = (array: Item[]) => Item[];
|
|
1161
|
+
/**
|
|
1162
|
+
* Initialize a sort handler with sorters _(and an optional default direction)_
|
|
1163
|
+
* @param sorters Sorters to use for sorting
|
|
1164
|
+
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
1165
|
+
* @returns Sort handler
|
|
1166
|
+
*/
|
|
1167
|
+
declare function initializeSort<Item>(sorters: Array<ArraySorter<Item>>, descending?: boolean): Sorter<Item>;
|
|
1168
|
+
/**
|
|
1169
|
+
* Initialize a sort handler with a sorter _(and an optional default direction)_
|
|
1170
|
+
* @param sorter Sorter to use for sorting
|
|
1171
|
+
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
1172
|
+
* @returns Sort handler
|
|
1173
|
+
*/
|
|
1174
|
+
declare function initializeSort<Item>(sorter: ArraySorter<Item>, descending?: boolean): Sorter<Item>;
|
|
1175
|
+
/**
|
|
1176
|
+
* Initialize a sort handler _(with an optional default direction)_
|
|
1177
|
+
* @param descending Sort in descending order? _(defaults to `false`)_
|
|
1178
|
+
* @returns Sort handler
|
|
1179
|
+
*/
|
|
1180
|
+
declare function initializeSort<Item>(descending?: boolean): Sorter<Item>;
|
|
1181
|
+
/**
|
|
1182
|
+
* Sort an array of items, using multiple sorters to sort by specific values
|
|
1183
|
+
* @param array Array to sort
|
|
1184
|
+
* @param sorters Sorters to use for sorting
|
|
1185
|
+
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
1186
|
+
* @returns Sorted array
|
|
1187
|
+
*/
|
|
1188
|
+
declare function sort<Item>(array: Item[], sorters: Array<ArraySorter<Item>>, descending?: boolean): Item[];
|
|
1189
|
+
/**
|
|
1190
|
+
* Sort an array of items, using multiple sorters to sort by specific values
|
|
1191
|
+
* @param array Array to sort
|
|
1192
|
+
* @param sorter Sorter to use for sorting
|
|
1193
|
+
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
1194
|
+
* @returns Sorted array
|
|
1195
|
+
*/
|
|
1196
|
+
declare function sort<Item>(array: Item[], sorter: ArraySorter<Item>, descending?: boolean): Item[];
|
|
1197
|
+
/**
|
|
1198
|
+
* Sort an array of items
|
|
1199
|
+
* @param array Array to sort
|
|
1200
|
+
* @param descending Sort in descending order? _(defaults to `false`)_
|
|
1201
|
+
* @returns Sorted array
|
|
1202
|
+
*/
|
|
1203
|
+
declare function sort<Item>(array: Item[], descending?: boolean): Item[];
|
|
1204
|
+
declare namespace sort {
|
|
1205
|
+
var initialize: typeof initializeSort;
|
|
1206
|
+
}
|
|
1207
|
+
declare const SORT_DIRECTION_ASCENDING: SortDirection;
|
|
1208
|
+
declare const SORT_DIRECTION_DESCENDING: SortDirection;
|
|
1209
|
+
//#endregion
|
|
1186
1210
|
//#region src/array/swap.d.ts
|
|
1187
1211
|
/**
|
|
1188
1212
|
* Swap two smaller arrays within a larger array
|
|
@@ -3265,6 +3289,14 @@ type FulfilledPromise<Value> = {
|
|
|
3265
3289
|
status: typeof PROMISE_TYPE_FULFILLED;
|
|
3266
3290
|
value: Awaited<Value>;
|
|
3267
3291
|
};
|
|
3292
|
+
type PromiseData = {
|
|
3293
|
+
last: number;
|
|
3294
|
+
result: unknown[];
|
|
3295
|
+
};
|
|
3296
|
+
type PromiseHandlers = {
|
|
3297
|
+
resolve: (value: unknown[]) => void;
|
|
3298
|
+
reject: (reason: unknown) => void;
|
|
3299
|
+
};
|
|
3268
3300
|
type PromiseOptions = {
|
|
3269
3301
|
/**
|
|
3270
3302
|
* AbortSignal for aborting the promise; when aborted, the promise will reject with the reason of the signal
|
|
@@ -3275,6 +3307,15 @@ type PromiseOptions = {
|
|
|
3275
3307
|
*/
|
|
3276
3308
|
time?: number;
|
|
3277
3309
|
};
|
|
3310
|
+
type PromiseParameters = {
|
|
3311
|
+
abort: () => void;
|
|
3312
|
+
complete: boolean;
|
|
3313
|
+
data: PromiseData;
|
|
3314
|
+
handlers: PromiseHandlers;
|
|
3315
|
+
index: number;
|
|
3316
|
+
signal?: AbortSignal;
|
|
3317
|
+
value?: unknown;
|
|
3318
|
+
};
|
|
3278
3319
|
/**
|
|
3279
3320
|
* Promise handling strategy
|
|
3280
3321
|
*
|
|
@@ -3300,60 +3341,20 @@ type RejectedPromise = {
|
|
|
3300
3341
|
status: typeof PROMISE_TYPE_REJECTED;
|
|
3301
3342
|
reason: unknown;
|
|
3302
3343
|
};
|
|
3344
|
+
declare const PROMISE_ABORT_EVENT = "abort";
|
|
3345
|
+
declare const PROMISE_ABORT_OPTIONS: {
|
|
3346
|
+
once: boolean;
|
|
3347
|
+
};
|
|
3348
|
+
declare const PROMISE_ERROR_NAME = "PromiseTimeoutError";
|
|
3349
|
+
declare const PROMISE_MESSAGE_EXPECTATION_ATTEMPT = "Attempt expected a function or a promise";
|
|
3350
|
+
declare const PROMISE_MESSAGE_EXPECTATION_RESULT = "toResult expected a Promise";
|
|
3351
|
+
declare const PROMISE_MESSAGE_EXPECTATION_TIMED = "Timed function expected a Promise";
|
|
3352
|
+
declare const PROMISE_MESSAGE_TIMEOUT = "Promise timed out";
|
|
3353
|
+
declare const PROMISE_STRATEGY_ALL: Set<PromiseStrategy>;
|
|
3354
|
+
declare const PROMISE_STRATEGY_DEFAULT: PromiseStrategy;
|
|
3303
3355
|
declare const PROMISE_TYPE_FULFILLED = "fulfilled";
|
|
3304
3356
|
declare const PROMISE_TYPE_REJECTED = "rejected";
|
|
3305
3357
|
//#endregion
|
|
3306
|
-
//#region src/result/misc.d.ts
|
|
3307
|
-
/**
|
|
3308
|
-
* Creates an extended error result
|
|
3309
|
-
* @param error Error value
|
|
3310
|
-
* @param original Original error
|
|
3311
|
-
* @returns Error result
|
|
3312
|
-
*/
|
|
3313
|
-
declare function error<E>(value: E, original: Error): ExtendedErr<E>;
|
|
3314
|
-
/**
|
|
3315
|
-
* Creates an error result
|
|
3316
|
-
* @param error Error value
|
|
3317
|
-
* @returns Error result
|
|
3318
|
-
*/
|
|
3319
|
-
declare function error<E>(value: E): Err<E>;
|
|
3320
|
-
/**
|
|
3321
|
-
* Creates an ok result
|
|
3322
|
-
* @param value Value
|
|
3323
|
-
* @returns Ok result
|
|
3324
|
-
*/
|
|
3325
|
-
declare function ok<Value>(value: Value): Ok<Value>;
|
|
3326
|
-
/**
|
|
3327
|
-
* Converts a result to a promise
|
|
3328
|
-
*
|
|
3329
|
-
* Resolves if ok, rejects for error
|
|
3330
|
-
* @param result Result to convert
|
|
3331
|
-
* @returns Promised result
|
|
3332
|
-
*/
|
|
3333
|
-
declare function toPromise<Value, E = Error>(callback: () => AnyResult<Value, E>): Promise<Value>;
|
|
3334
|
-
/**
|
|
3335
|
-
* Converts a result to a promise
|
|
3336
|
-
*
|
|
3337
|
-
* Resolves if ok, rejects for error
|
|
3338
|
-
* @param result Result to convert
|
|
3339
|
-
* @returns Promised result
|
|
3340
|
-
*/
|
|
3341
|
-
declare function toPromise<Value, E = Error>(result: AnyResult<Value, E>): Promise<Value>;
|
|
3342
|
-
/**
|
|
3343
|
-
* Gets the value of an ok result _(or a default value)_
|
|
3344
|
-
* @param value Result to unwrap
|
|
3345
|
-
* @param defaultValue Default value
|
|
3346
|
-
* @returns Value of the result _(or the default value)_
|
|
3347
|
-
*/
|
|
3348
|
-
declare function unwrap<Value, E = Error>(value: Result<Value, E>, defaultValue: Value): Value;
|
|
3349
|
-
/**
|
|
3350
|
-
* Gets the value of an ok result _(or a default value)_
|
|
3351
|
-
* @param value Result to unwrap
|
|
3352
|
-
* @param defaultValue Default value
|
|
3353
|
-
* @returns Value of the result _(or the default value)_
|
|
3354
|
-
*/
|
|
3355
|
-
declare function unwrap(value: unknown, defaultValue: unknown): unknown;
|
|
3356
|
-
//#endregion
|
|
3357
3358
|
//#region src/promise/delay.d.ts
|
|
3358
3359
|
/**
|
|
3359
3360
|
* Create a delayed promise that resolves after a certain amount of time, or rejects if aborted
|
|
@@ -3368,56 +3369,6 @@ declare function delay(options?: PromiseOptions): Promise<void>;
|
|
|
3368
3369
|
*/
|
|
3369
3370
|
declare function delay(time?: number): Promise<void>;
|
|
3370
3371
|
//#endregion
|
|
3371
|
-
//#region src/promise/helpers.d.ts
|
|
3372
|
-
/**
|
|
3373
|
-
* Is the value a fulfilled promise result?
|
|
3374
|
-
* @param value Value to check
|
|
3375
|
-
* @returns `true` if the value is a fulfilled promise result, `false` otherwise
|
|
3376
|
-
*/
|
|
3377
|
-
declare function isFulfilled<Value>(value: unknown): value is FulfilledPromise<Value>;
|
|
3378
|
-
/**
|
|
3379
|
-
* Is the value a rejected promise result?
|
|
3380
|
-
* @param value Value to check
|
|
3381
|
-
* @returns `true` if the value is a rejected promise result, `false` otherwise
|
|
3382
|
-
*/
|
|
3383
|
-
declare function isRejected(value: unknown): value is RejectedPromise;
|
|
3384
|
-
//#endregion
|
|
3385
|
-
//#region src/promise/misc.d.ts
|
|
3386
|
-
/**
|
|
3387
|
-
* Create a cancelable promise
|
|
3388
|
-
* @param executor Executor function for the promise
|
|
3389
|
-
* @returns Cancelable promise
|
|
3390
|
-
*/
|
|
3391
|
-
declare function cancelable<Value>(executor: (resolve: (value: Value) => void, reject: (reason: unknown) => void) => void): CancelablePromise<Value>;
|
|
3392
|
-
/**
|
|
3393
|
-
* Converts a promise to a promised result
|
|
3394
|
-
* @param callback Promise callback
|
|
3395
|
-
* @returns Promised result
|
|
3396
|
-
*/
|
|
3397
|
-
declare function toResult<Value>(callback: () => Promise<Value>): Promise<Result<Value>>;
|
|
3398
|
-
/**
|
|
3399
|
-
* Converts a promise to a promised result
|
|
3400
|
-
* @param promise Promise to convert
|
|
3401
|
-
* @returns Promised result
|
|
3402
|
-
*/
|
|
3403
|
-
declare function toResult<Value>(promise: Promise<Value>): Promise<Result<Value>>;
|
|
3404
|
-
//#endregion
|
|
3405
|
-
//#region src/promise/timed.d.ts
|
|
3406
|
-
/**
|
|
3407
|
-
* Create a promise that should be settled within a certain amount of time
|
|
3408
|
-
* @param promise Promise to settle
|
|
3409
|
-
* @param options Timed options
|
|
3410
|
-
* @returns Timed promise
|
|
3411
|
-
*/
|
|
3412
|
-
declare function timed<Value>(promise: Promise<Value>, options: RequiredKeys<PromiseOptions, 'time'>): Promise<Value>;
|
|
3413
|
-
/**
|
|
3414
|
-
* Create a promise that should be settled within a certain amount of time
|
|
3415
|
-
* @param promise Promise to settle
|
|
3416
|
-
* @param time How long to wait for _(in milliseconds; defaults to `0`)_
|
|
3417
|
-
* @returns Timed promise
|
|
3418
|
-
*/
|
|
3419
|
-
declare function timed<Value>(promise: Promise<Value>, time: number): Promise<Value>;
|
|
3420
|
-
//#endregion
|
|
3421
3372
|
//#region src/promise/index.d.ts
|
|
3422
3373
|
/**
|
|
3423
3374
|
* Wrap a promise with safety handlers, with optional abort capabilities and timeout
|
|
@@ -3512,6 +3463,149 @@ declare function resultPromises<Items extends unknown[]>(items: [...Items], sign
|
|
|
3512
3463
|
*/
|
|
3513
3464
|
declare function resultPromises<Value>(items: Promise<Value>[], signal?: AbortSignal): Promise<Result<Awaited<Value>>[]>;
|
|
3514
3465
|
//#endregion
|
|
3466
|
+
//#region src/internal/result.d.ts
|
|
3467
|
+
/**
|
|
3468
|
+
* Is the result an extended error?
|
|
3469
|
+
* @param result Result to check
|
|
3470
|
+
* @returns `true` if the result is an extended error, `false` otherwise
|
|
3471
|
+
*/
|
|
3472
|
+
declare function isError<Value, E = Error>(value: ExtendedErr<E> | Result<Value, E>, extended: true): value is ExtendedErr<E>;
|
|
3473
|
+
/**
|
|
3474
|
+
* Is the result an error?
|
|
3475
|
+
* @param result Result to check
|
|
3476
|
+
* @returns `true` if the result is an error, `false` otherwise
|
|
3477
|
+
*/
|
|
3478
|
+
declare function isError<Value, E = Error>(value: Result<Value, E>): value is Err<E>;
|
|
3479
|
+
/**
|
|
3480
|
+
* Is the value an error?
|
|
3481
|
+
* @param value Value to check
|
|
3482
|
+
* @returns `true` if the value is an error, `false` otherwise
|
|
3483
|
+
*/
|
|
3484
|
+
declare function isError(value: unknown): value is Err<unknown> | ExtendedErr<unknown>;
|
|
3485
|
+
/**
|
|
3486
|
+
* Is the result ok?
|
|
3487
|
+
* @param value Result to check
|
|
3488
|
+
* @returns `true` if the result is ok, `false` otherwise
|
|
3489
|
+
*/
|
|
3490
|
+
declare function isOk<Value, E = Error>(value: Result<Value, E>): value is Ok<Value>;
|
|
3491
|
+
/**
|
|
3492
|
+
* Is the value ok?
|
|
3493
|
+
* @param value Value to check
|
|
3494
|
+
* @returns `true` if the value is ok, `false` otherwise
|
|
3495
|
+
*/
|
|
3496
|
+
declare function isOk(value: unknown): value is Ok<unknown>;
|
|
3497
|
+
/**
|
|
3498
|
+
* Is the value a result?
|
|
3499
|
+
* @param value Value to check
|
|
3500
|
+
* @returns `true` if the value is a result, `false` otherwise
|
|
3501
|
+
*/
|
|
3502
|
+
declare function isResult(value: unknown): value is ExtendedErr<unknown> | Result<unknown, unknown>;
|
|
3503
|
+
//#endregion
|
|
3504
|
+
//#region src/result/misc.d.ts
|
|
3505
|
+
/**
|
|
3506
|
+
* Creates an extended error result
|
|
3507
|
+
* @param error Error value
|
|
3508
|
+
* @param original Original error
|
|
3509
|
+
* @returns Error result
|
|
3510
|
+
*/
|
|
3511
|
+
declare function error<E>(value: E, original: Error): ExtendedErr<E>;
|
|
3512
|
+
/**
|
|
3513
|
+
* Creates an error result
|
|
3514
|
+
* @param error Error value
|
|
3515
|
+
* @returns Error result
|
|
3516
|
+
*/
|
|
3517
|
+
declare function error<E>(value: E): Err<E>;
|
|
3518
|
+
declare function getError<E>(value: E, original?: Error): Err<E> | ExtendedErr<E>;
|
|
3519
|
+
/**
|
|
3520
|
+
* Creates an ok result
|
|
3521
|
+
* @param value Value
|
|
3522
|
+
* @returns Ok result
|
|
3523
|
+
*/
|
|
3524
|
+
declare function ok<Value>(value: Value): Ok<Value>;
|
|
3525
|
+
/**
|
|
3526
|
+
* Converts a result to a promise
|
|
3527
|
+
*
|
|
3528
|
+
* Resolves if ok, rejects for error
|
|
3529
|
+
* @param result Result to convert
|
|
3530
|
+
* @returns Promised result
|
|
3531
|
+
*/
|
|
3532
|
+
declare function toPromise<Value, E = Error>(callback: () => AnyResult<Value, E>): Promise<Value>;
|
|
3533
|
+
/**
|
|
3534
|
+
* Converts a result to a promise
|
|
3535
|
+
*
|
|
3536
|
+
* Resolves if ok, rejects for error
|
|
3537
|
+
* @param result Result to convert
|
|
3538
|
+
* @returns Promised result
|
|
3539
|
+
*/
|
|
3540
|
+
declare function toPromise<Value, E = Error>(result: AnyResult<Value, E>): Promise<Value>;
|
|
3541
|
+
/**
|
|
3542
|
+
* Gets the value of an ok result _(or a default value)_
|
|
3543
|
+
* @param value Result to unwrap
|
|
3544
|
+
* @param defaultValue Default value
|
|
3545
|
+
* @returns Value of the result _(or the default value)_
|
|
3546
|
+
*/
|
|
3547
|
+
declare function unwrap<Value, E = Error>(value: Result<Value, E>, defaultValue: Value): Value;
|
|
3548
|
+
/**
|
|
3549
|
+
* Gets the value of an ok result _(or a default value)_
|
|
3550
|
+
* @param value Result to unwrap
|
|
3551
|
+
* @param defaultValue Default value
|
|
3552
|
+
* @returns Value of the result _(or the default value)_
|
|
3553
|
+
*/
|
|
3554
|
+
declare function unwrap(value: unknown, defaultValue: unknown): unknown;
|
|
3555
|
+
//#endregion
|
|
3556
|
+
//#region src/promise/helpers.d.ts
|
|
3557
|
+
/**
|
|
3558
|
+
* Is the value a fulfilled promise result?
|
|
3559
|
+
* @param value Value to check
|
|
3560
|
+
* @returns `true` if the value is a fulfilled promise result, `false` otherwise
|
|
3561
|
+
*/
|
|
3562
|
+
declare function isFulfilled<Value>(value: unknown): value is FulfilledPromise<Value>;
|
|
3563
|
+
/**
|
|
3564
|
+
* Is the value a rejected promise result?
|
|
3565
|
+
* @param value Value to check
|
|
3566
|
+
* @returns `true` if the value is a rejected promise result, `false` otherwise
|
|
3567
|
+
*/
|
|
3568
|
+
declare function isRejected(value: unknown): value is RejectedPromise;
|
|
3569
|
+
//#endregion
|
|
3570
|
+
//#region src/promise/misc.d.ts
|
|
3571
|
+
/**
|
|
3572
|
+
* Create a cancelable promise
|
|
3573
|
+
* @param executor Executor function for the promise
|
|
3574
|
+
* @returns Cancelable promise
|
|
3575
|
+
*/
|
|
3576
|
+
declare function cancelable<Value>(executor: (resolve: (value: Value) => void, reject: (reason: unknown) => void) => void): CancelablePromise<Value>;
|
|
3577
|
+
declare function handleResult(status: string, parameters: PromiseParameters): void;
|
|
3578
|
+
declare function settlePromise(aborter: () => void, settler: (value: any) => void, value: unknown, signal?: AbortSignal): void;
|
|
3579
|
+
/**
|
|
3580
|
+
* Converts a promise to a promised result
|
|
3581
|
+
* @param callback Promise callback
|
|
3582
|
+
* @returns Promised result
|
|
3583
|
+
*/
|
|
3584
|
+
declare function toResult<Value>(callback: () => Promise<Value>): Promise<Result<Value>>;
|
|
3585
|
+
/**
|
|
3586
|
+
* Converts a promise to a promised result
|
|
3587
|
+
* @param promise Promise to convert
|
|
3588
|
+
* @returns Promised result
|
|
3589
|
+
*/
|
|
3590
|
+
declare function toResult<Value>(promise: Promise<Value>): Promise<Result<Value>>;
|
|
3591
|
+
//#endregion
|
|
3592
|
+
//#region src/promise/timed.d.ts
|
|
3593
|
+
declare function getTimedPromise<Value>(promise: Promise<Value>, time: number, signal?: AbortSignal): Promise<Value>;
|
|
3594
|
+
/**
|
|
3595
|
+
* Create a promise that should be settled within a certain amount of time
|
|
3596
|
+
* @param promise Promise to settle
|
|
3597
|
+
* @param options Timed options
|
|
3598
|
+
* @returns Timed promise
|
|
3599
|
+
*/
|
|
3600
|
+
declare function timed<Value>(promise: Promise<Value>, options: RequiredKeys<PromiseOptions, 'time'>): Promise<Value>;
|
|
3601
|
+
/**
|
|
3602
|
+
* Create a promise that should be settled within a certain amount of time
|
|
3603
|
+
* @param promise Promise to settle
|
|
3604
|
+
* @param time How long to wait for _(in milliseconds; defaults to `0`)_
|
|
3605
|
+
* @returns Timed promise
|
|
3606
|
+
*/
|
|
3607
|
+
declare function timed<Value>(promise: Promise<Value>, time: number): Promise<Value>;
|
|
3608
|
+
//#endregion
|
|
3515
3609
|
//#region src/query.d.ts
|
|
3516
3610
|
/**
|
|
3517
3611
|
* Convert a query string to a plain _(nested)_ object
|
|
@@ -4120,44 +4214,6 @@ declare namespace attemptPipe {
|
|
|
4120
4214
|
var async: typeof attemptAsyncPipe;
|
|
4121
4215
|
}
|
|
4122
4216
|
//#endregion
|
|
4123
|
-
//#region src/internal/result.d.ts
|
|
4124
|
-
/**
|
|
4125
|
-
* Is the result an extended error?
|
|
4126
|
-
* @param result Result to check
|
|
4127
|
-
* @returns `true` if the result is an extended error, `false` otherwise
|
|
4128
|
-
*/
|
|
4129
|
-
declare function isError<Value, E = Error>(value: ExtendedErr<E> | Result<Value, E>, extended: true): value is ExtendedErr<E>;
|
|
4130
|
-
/**
|
|
4131
|
-
* Is the result an error?
|
|
4132
|
-
* @param result Result to check
|
|
4133
|
-
* @returns `true` if the result is an error, `false` otherwise
|
|
4134
|
-
*/
|
|
4135
|
-
declare function isError<Value, E = Error>(value: Result<Value, E>): value is Err<E>;
|
|
4136
|
-
/**
|
|
4137
|
-
* Is the value an error?
|
|
4138
|
-
* @param value Value to check
|
|
4139
|
-
* @returns `true` if the value is an error, `false` otherwise
|
|
4140
|
-
*/
|
|
4141
|
-
declare function isError(value: unknown): value is Err<unknown> | ExtendedErr<unknown>;
|
|
4142
|
-
/**
|
|
4143
|
-
* Is the result ok?
|
|
4144
|
-
* @param value Result to check
|
|
4145
|
-
* @returns `true` if the result is ok, `false` otherwise
|
|
4146
|
-
*/
|
|
4147
|
-
declare function isOk<Value, E = Error>(value: Result<Value, E>): value is Ok<Value>;
|
|
4148
|
-
/**
|
|
4149
|
-
* Is the value ok?
|
|
4150
|
-
* @param value Value to check
|
|
4151
|
-
* @returns `true` if the value is ok, `false` otherwise
|
|
4152
|
-
*/
|
|
4153
|
-
declare function isOk(value: unknown): value is Ok<unknown>;
|
|
4154
|
-
/**
|
|
4155
|
-
* Is the value a result?
|
|
4156
|
-
* @param value Value to check
|
|
4157
|
-
* @returns `true` if the value is a result, `false` otherwise
|
|
4158
|
-
*/
|
|
4159
|
-
declare function isResult(value: unknown): value is ExtendedErr<unknown> | Result<unknown, unknown>;
|
|
4160
|
-
//#endregion
|
|
4161
4217
|
//#region src/result/index.d.ts
|
|
4162
4218
|
/**
|
|
4163
4219
|
* Executes a promise, catching any errors, and returns a result
|
|
@@ -4295,4 +4351,4 @@ declare class SizedSet<Value = unknown> extends Set<Value> {
|
|
|
4295
4351
|
get(value: Value, update?: boolean): Value | undefined;
|
|
4296
4352
|
}
|
|
4297
4353
|
//#endregion
|
|
4298
|
-
export { ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, ArrayPosition, ArrayValueSorter, Asserter, type Beacon, type BeaconOptions, BuiltIns, CancelableCallback, CancelablePromise, type Color, Constructor, DiffOptions, DiffResult, DiffValue, EqualOptions,
|
|
4354
|
+
export { AnyResult, ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, ArrayPosition, ArrayValueSorter, Asserter, AttemptFlow, AttemptFlowPromise, type Beacon, type BeaconOptions, BuiltIns, CancelableCallback, CancelablePromise, type Color, Constructor, DiffOptions, DiffResult, DiffValue, EqualOptions, Err, EventPosition, ExtendedErr, ExtendedResult, Flow, FlowPromise, FulfilledPromise, GenericAsyncCallback, GenericCallback, type HSLAColor, type HSLColor, HasValue, Key, KeyedValue, type Logger, type Memoized, type MemoizedOptions, MergeOptions, Merger, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NumericalKeys, NumericalValues, type Observable, type Observer, Ok, OnceAsyncCallback, OnceCallback, 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, PlainObject, Primitive, PromiseData, PromiseHandlers, PromiseOptions, PromiseParameters, PromiseStrategy, PromiseTimeoutError, PromisesItems, PromisesOptions, PromisesResult, PromisesUnwrapped, PromisesValue, PromisesValues, type Queue, QueueError, type QueueOptions, type Queued, type RGBAColor, type RGBColor, RejectedPromise, RequiredKeys, Result, ResultMatch, RetryError, RetryOptions, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, Simplify, SizedMap, SizedSet, Smushed, SortDirection, Sorter, type Subscription, TemplateOptions, type Time, ToString, TypedArray, Unsmushed, UnwrapValue, 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 };
|