@oscarpalmer/atoms 0.192.0 → 0.193.1
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/index.d.mts +25 -23
- package/dist/index.mjs +30 -31
- package/dist/queue.d.mts +25 -23
- package/dist/queue.mjs +27 -28
- package/package.json +3 -4
- package/src/array/difference.ts +0 -73
- package/src/array/exists.ts +0 -93
- package/src/array/filter.ts +0 -182
- package/src/array/find.ts +0 -183
- package/src/array/first.ts +0 -196
- package/src/array/flatten.ts +0 -20
- package/src/array/from.ts +0 -129
- package/src/array/get.ts +0 -131
- package/src/array/group-by.ts +0 -369
- package/src/array/index.ts +0 -26
- package/src/array/insert.ts +0 -52
- package/src/array/intersection.ts +0 -72
- package/src/array/last.ts +0 -194
- package/src/array/match.ts +0 -436
- package/src/array/move.ts +0 -315
- package/src/array/partition.ts +0 -91
- package/src/array/push.ts +0 -23
- package/src/array/reverse.ts +0 -33
- package/src/array/select.ts +0 -260
- package/src/array/single.ts +0 -93
- package/src/array/slice.ts +0 -335
- package/src/array/sort.ts +0 -607
- package/src/array/splice.ts +0 -106
- package/src/array/swap.ts +0 -322
- package/src/array/to-map.ts +0 -371
- package/src/array/to-record.ts +0 -351
- package/src/array/to-set.ts +0 -80
- package/src/array/toggle.ts +0 -79
- package/src/array/union.ts +0 -72
- package/src/array/unique.ts +0 -67
- package/src/array/update.ts +0 -75
- package/src/beacon.ts +0 -378
- package/src/color/constants.ts +0 -137
- package/src/color/index.ts +0 -83
- package/src/color/instance.ts +0 -162
- package/src/color/misc/alpha.ts +0 -56
- package/src/color/misc/format.ts +0 -29
- package/src/color/misc/get.ts +0 -210
- package/src/color/misc/is.ts +0 -221
- package/src/color/misc/state.ts +0 -243
- package/src/color/models.ts +0 -389
- package/src/color/space/hex.ts +0 -184
- package/src/color/space/hsl.ts +0 -174
- package/src/color/space/hwb.ts +0 -153
- package/src/color/space/rgb.ts +0 -240
- package/src/function/assert.ts +0 -174
- package/src/function/index.ts +0 -2
- package/src/function/limit.ts +0 -83
- package/src/function/memoize.ts +0 -202
- package/src/function/once.ts +0 -200
- package/src/function/retry.ts +0 -175
- package/src/function/work.ts +0 -1007
- package/src/herald.ts +0 -216
- package/src/index.ts +0 -68
- package/src/internal/array/callbacks.ts +0 -46
- package/src/internal/array/chunk.ts +0 -51
- package/src/internal/array/compact.ts +0 -56
- package/src/internal/array/find.ts +0 -200
- package/src/internal/array/group.ts +0 -42
- package/src/internal/array/index-of.ts +0 -182
- package/src/internal/array/insert.ts +0 -80
- package/src/internal/array/overlap.ts +0 -35
- package/src/internal/array/sets.ts +0 -74
- package/src/internal/array/shuffle.ts +0 -33
- package/src/internal/array/update.ts +0 -52
- package/src/internal/function/misc.ts +0 -8
- package/src/internal/function/timer.ts +0 -168
- package/src/internal/is.ts +0 -244
- package/src/internal/math/aggregate.ts +0 -164
- package/src/internal/math/misc.ts +0 -28
- package/src/internal/number.ts +0 -129
- package/src/internal/random.ts +0 -49
- package/src/internal/result.ts +0 -92
- package/src/internal/sized.ts +0 -25
- package/src/internal/string.ts +0 -128
- package/src/internal/subscription.ts +0 -264
- package/src/internal/value/compare.ts +0 -170
- package/src/internal/value/equal.ts +0 -465
- package/src/internal/value/get.ts +0 -57
- package/src/internal/value/handlers.ts +0 -95
- package/src/internal/value/has.ts +0 -118
- package/src/internal/value/misc.ts +0 -125
- package/src/internal/value/partial.ts +0 -46
- package/src/internal/value/set.ts +0 -132
- package/src/is.ts +0 -182
- package/src/logger.ts +0 -230
- package/src/math.ts +0 -281
- package/src/models.ts +0 -286
- package/src/number.ts +0 -1
- package/src/promise/delay.ts +0 -62
- package/src/promise/helpers.ts +0 -96
- package/src/promise/index.ts +0 -300
- package/src/promise/misc.ts +0 -96
- package/src/promise/models.ts +0 -195
- package/src/promise/timed.ts +0 -91
- package/src/query.ts +0 -147
- package/src/queue.ts +0 -814
- package/src/random.ts +0 -125
- package/src/result/index.ts +0 -105
- package/src/result/match.ts +0 -124
- package/src/result/misc.ts +0 -129
- package/src/result/models.ts +0 -83
- package/src/result/work/flow.ts +0 -488
- package/src/result/work/pipe.ts +0 -496
- package/src/sized/map.ts +0 -110
- package/src/sized/set.ts +0 -107
- package/src/string/case.ts +0 -236
- package/src/string/fuzzy.ts +0 -444
- package/src/string/index.ts +0 -199
- package/src/string/match.ts +0 -80
- package/src/string/normalize.ts +0 -205
- package/src/string/template.ts +0 -161
- package/src/value/clone.ts +0 -319
- package/src/value/collection.ts +0 -63
- package/src/value/diff.ts +0 -232
- package/src/value/freeze.ts +0 -322
- package/src/value/handle.ts +0 -3
- package/src/value/index.ts +0 -5
- package/src/value/merge.ts +0 -278
- package/src/value/omit.ts +0 -20
- package/src/value/pick.ts +0 -20
- package/src/value/shake.ts +0 -45
- package/src/value/smush.ts +0 -89
- package/src/value/transform.ts +0 -153
- package/src/value/unsmush.ts +0 -84
package/dist/index.d.mts
CHANGED
|
@@ -7636,7 +7636,7 @@ declare function toQuery(parameters: PlainObject): string;
|
|
|
7636
7636
|
/**
|
|
7637
7637
|
* A queue that can be used to manage (a)synchronous tasks with a specific key
|
|
7638
7638
|
*/
|
|
7639
|
-
type KeyedQueue<CallbackParameters extends Parameters<
|
|
7639
|
+
type KeyedQueue<Callback extends GenericCallback | GenericAsyncCallback, CallbackParameters extends unknown[] = Parameters<Callback>> = {
|
|
7640
7640
|
/**
|
|
7641
7641
|
* Get keys of all active queues
|
|
7642
7642
|
*/
|
|
@@ -7685,7 +7685,7 @@ type KeyedQueue<CallbackParameters extends Parameters<GenericAsyncCallback>, Cal
|
|
|
7685
7685
|
* @param signal Optional signal to abort the item
|
|
7686
7686
|
* @returns Queued item
|
|
7687
7687
|
*/
|
|
7688
|
-
add(key: string, parameters: Tail<CallbackParameters>, signal?: AbortSignal): Queued<
|
|
7688
|
+
add(key: string, parameters: Tail<CallbackParameters>, signal?: AbortSignal): Queued<ReturnType<Callback>>;
|
|
7689
7689
|
/**
|
|
7690
7690
|
* Clear all items for a specific key _(or all items for all keys, if no key is provided)_
|
|
7691
7691
|
*
|
|
@@ -7698,7 +7698,7 @@ type KeyedQueue<CallbackParameters extends Parameters<GenericAsyncCallback>, Cal
|
|
|
7698
7698
|
* @param key Key to get the queue for
|
|
7699
7699
|
* @returns Queue for the key, or `undefined` if it doesn't exist
|
|
7700
7700
|
*/
|
|
7701
|
-
get(key: string): Queue<Tail<CallbackParameters
|
|
7701
|
+
get(key: string): Queue<Callback, Tail<CallbackParameters>> | undefined;
|
|
7702
7702
|
/**
|
|
7703
7703
|
* Pause the queue for a specific key _(or all queues, if no key is provided)_
|
|
7704
7704
|
*
|
|
@@ -7734,7 +7734,7 @@ type KeyedQueue<CallbackParameters extends Parameters<GenericAsyncCallback>, Cal
|
|
|
7734
7734
|
/**
|
|
7735
7735
|
* A queue that can be used to manage (a)synchronous tasks
|
|
7736
7736
|
*/
|
|
7737
|
-
type Queue<CallbackParameters extends Parameters<
|
|
7737
|
+
type Queue<Callback extends GenericCallback | GenericAsyncCallback, CallbackParameters extends unknown[] = Parameters<Callback>> = {
|
|
7738
7738
|
/**
|
|
7739
7739
|
* Is the queue active?
|
|
7740
7740
|
*/
|
|
@@ -7774,7 +7774,7 @@ type Queue<CallbackParameters extends Parameters<GenericAsyncCallback>, Callback
|
|
|
7774
7774
|
* @param signal Optional signal to abort the item
|
|
7775
7775
|
* @returns Queued item
|
|
7776
7776
|
*/
|
|
7777
|
-
add(parameters: CallbackParameters, signal?: AbortSignal): Queued<
|
|
7777
|
+
add(parameters: CallbackParameters, signal?: AbortSignal): Queued<ReturnType<Callback>>;
|
|
7778
7778
|
/**
|
|
7779
7779
|
* Remove and reject all items in the queue
|
|
7780
7780
|
*/
|
|
@@ -7828,17 +7828,7 @@ type Queued<Value> = {
|
|
|
7828
7828
|
/**
|
|
7829
7829
|
* Queued promise
|
|
7830
7830
|
*/
|
|
7831
|
-
readonly promise: Promise<
|
|
7832
|
-
};
|
|
7833
|
-
type QueuedResult<Value> = {
|
|
7834
|
-
/**
|
|
7835
|
-
* Has the queue finished processing all items?
|
|
7836
|
-
*/
|
|
7837
|
-
finished: boolean;
|
|
7838
|
-
/**
|
|
7839
|
-
* Result for the queued promise
|
|
7840
|
-
*/
|
|
7841
|
-
value: Value extends Promise<infer Result> ? Result : Value;
|
|
7831
|
+
readonly promise: Promise<Value extends Promise<infer Result> ? Result : Value>;
|
|
7842
7832
|
};
|
|
7843
7833
|
type Tail<Values extends any[]> = Values extends [infer _, ...infer Rest] ? Rest : never;
|
|
7844
7834
|
/**
|
|
@@ -7847,17 +7837,29 @@ type Tail<Values extends any[]> = Values extends [infer _, ...infer Rest] ? Rest
|
|
|
7847
7837
|
* @param value Value to check
|
|
7848
7838
|
* @returns `true` if the value is a keyed queue, otherwise `false`
|
|
7849
7839
|
*/
|
|
7850
|
-
declare function isKeyedQueue(value: unknown): value is KeyedQueue<
|
|
7840
|
+
declare function isKeyedQueue(value: unknown): value is KeyedQueue<GenericAsyncCallback>;
|
|
7851
7841
|
/**
|
|
7852
7842
|
* Is the value a queue?
|
|
7853
7843
|
*
|
|
7854
7844
|
* @param value Value to check
|
|
7855
7845
|
* @returns `true` if the value is a queue, otherwise `false`
|
|
7856
7846
|
*/
|
|
7857
|
-
declare function isQueue(value: unknown): value is Queue<
|
|
7847
|
+
declare function isQueue(value: unknown): value is Queue<GenericCallback | GenericAsyncCallback>;
|
|
7858
7848
|
declare function isQueueInstance<Instance>(name: string, value: unknown): value is Instance;
|
|
7859
|
-
|
|
7860
|
-
|
|
7849
|
+
/**
|
|
7850
|
+
* Create a keyed queue for an asynchronous callback function, where each key has its own queue
|
|
7851
|
+
*
|
|
7852
|
+
* @param callback Callback function for queued items
|
|
7853
|
+
* @param options Queue options
|
|
7854
|
+
*/
|
|
7855
|
+
declare function keyedQueue<Callback extends (key: string, ...parameters: any[]) => Promise<void>>(callback: Callback, options?: QueueOptions): KeyedQueue<Callback, Parameters<Callback>>;
|
|
7856
|
+
/**
|
|
7857
|
+
* Create a keyed queue for an asynchronous callback function, where each key has its own queue
|
|
7858
|
+
*
|
|
7859
|
+
* @param callback Callback function for queued items
|
|
7860
|
+
* @param options Queue options
|
|
7861
|
+
*/
|
|
7862
|
+
declare function keyedQueue<Callback extends (key: string, ...parameters: any[]) => void>(callback: Callback, options?: QueueOptions): KeyedQueue<Callback, Parameters<Callback>>;
|
|
7861
7863
|
/**
|
|
7862
7864
|
* Create a queue for an asynchronous callback function
|
|
7863
7865
|
*
|
|
@@ -7865,7 +7867,7 @@ declare function keyedQueue<Callback extends (key: string, ...parameters: any[])
|
|
|
7865
7867
|
* @param options Queue options
|
|
7866
7868
|
* @returns Queue instance
|
|
7867
7869
|
*/
|
|
7868
|
-
declare function queue<Callback extends GenericAsyncCallback>(callback: Callback, options?: QueueOptions): Queue<
|
|
7870
|
+
declare function queue<Callback extends GenericAsyncCallback>(callback: Callback, options?: QueueOptions): Queue<Callback, Parameters<Callback>>;
|
|
7869
7871
|
/**
|
|
7870
7872
|
* Create a queue for a synchronous callback function
|
|
7871
7873
|
*
|
|
@@ -7873,7 +7875,7 @@ declare function queue<Callback extends GenericAsyncCallback>(callback: Callback
|
|
|
7873
7875
|
* @param options Queue options
|
|
7874
7876
|
* @returns Queue instance
|
|
7875
7877
|
*/
|
|
7876
|
-
declare function queue<Callback extends GenericCallback>(callback: Callback, options?: QueueOptions): Queue<
|
|
7878
|
+
declare function queue<Callback extends GenericCallback>(callback: Callback, options?: QueueOptions): Queue<Callback, Parameters<Callback>>;
|
|
7877
7879
|
declare namespace queue {
|
|
7878
7880
|
var keyed: typeof keyedQueue;
|
|
7879
7881
|
}
|
|
@@ -8508,4 +8510,4 @@ declare class SizedSet<Value = unknown> extends Set<Value> {
|
|
|
8508
8510
|
get(value: Value, update?: boolean): Value | undefined;
|
|
8509
8511
|
}
|
|
8510
8512
|
//#endregion
|
|
8511
|
-
export { AnyResult, ArrayComparison, ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, 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, EventPosition, Events, ExtendedErr, ExtendedResult, Flow, FlowPromise, Frozen, FulfilledPromise, Fuzzy, FuzzyConfiguration, FuzzyOptions, FuzzyResult, FuzzySearchOptions, GenericAsyncCallback, GenericCallback, type HSLAColor, type HSLColor, type HWBAColor, type HWBColor, Herald, Key$1 as Key, KeyedQueue, KeyedValue, Logger, type Memoized, type MemoizedOptions, MergeOptions, Merger, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NormalizeOptions, Normalizer, NumericalKeys, NumericalValues, Observable, 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, Queue, QueueError, QueueOptions, Queued,
|
|
8513
|
+
export { AnyResult, ArrayComparison, ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, 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, EventPosition, Events, ExtendedErr, ExtendedResult, Flow, FlowPromise, Frozen, FulfilledPromise, Fuzzy, FuzzyConfiguration, FuzzyOptions, FuzzyResult, FuzzySearchOptions, GenericAsyncCallback, GenericCallback, type HSLAColor, type HSLColor, type HWBAColor, type HWBColor, Herald, Key$1 as Key, KeyedQueue, KeyedValue, Logger, type Memoized, type MemoizedOptions, MergeOptions, Merger, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NormalizeOptions, Normalizer, NumericalKeys, NumericalValues, Observable, 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, 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, getError, 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, isColor, isConstructor, isEmpty, isError, isEvents, isFrozen, isFulfilled, isHerald, 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
|
@@ -2816,7 +2816,7 @@ function getHandler(input) {
|
|
|
2816
2816
|
throw new TypeError(MESSAGE_HANDLER);
|
|
2817
2817
|
}
|
|
2818
2818
|
}
|
|
2819
|
-
function getItems(items) {
|
|
2819
|
+
function getItems$1(items) {
|
|
2820
2820
|
return items.sort((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
|
|
2821
2821
|
}
|
|
2822
2822
|
function getFuzzyOptions(input, state) {
|
|
@@ -2949,10 +2949,10 @@ function search(items, strings, input, options) {
|
|
|
2949
2949
|
for (let index = 0; index < length; index += 1) {
|
|
2950
2950
|
const key = keys[index];
|
|
2951
2951
|
if (maxScore - key > options.tolerance) break;
|
|
2952
|
-
similar.push(...getItems(scored[key]));
|
|
2952
|
+
similar.push(...getItems$1(scored[key]));
|
|
2953
2953
|
}
|
|
2954
2954
|
}
|
|
2955
|
-
result.exact = getItems(options.limit == null ? exact : exact.slice(0, options.limit));
|
|
2955
|
+
result.exact = getItems$1(options.limit == null ? exact : exact.slice(0, options.limit));
|
|
2956
2956
|
if (options.limit == null) result.similar = similar;
|
|
2957
2957
|
else result.similar = similar.slice(0, options.limit - result.exact.length);
|
|
2958
2958
|
return result;
|
|
@@ -5877,6 +5877,12 @@ function createQueue(callback, options, key) {
|
|
|
5877
5877
|
function getBooleanOrDefault(value, defaultValue) {
|
|
5878
5878
|
return typeof value === "boolean" ? value : defaultValue;
|
|
5879
5879
|
}
|
|
5880
|
+
function getItems(state) {
|
|
5881
|
+
const size = {};
|
|
5882
|
+
const queues = state.queues.entries();
|
|
5883
|
+
for (const [key, queue] of queues) size[key] = queue.size;
|
|
5884
|
+
return size;
|
|
5885
|
+
}
|
|
5880
5886
|
function getOptions(input) {
|
|
5881
5887
|
const options = typeof input === "object" && input != null ? input : {};
|
|
5882
5888
|
return {
|
|
@@ -5900,7 +5906,7 @@ function getStatus(state, status) {
|
|
|
5900
5906
|
for (const [key, queue] of queues) if (queue[status]) result.push(key);
|
|
5901
5907
|
return result;
|
|
5902
5908
|
}
|
|
5903
|
-
function handleQueuedResult(item, error, result
|
|
5909
|
+
function handleQueuedResult(item, error, result) {
|
|
5904
5910
|
item.signal?.removeEventListener(EVENT_NAME, item.abort);
|
|
5905
5911
|
if (item.signal?.aborted ?? false) {
|
|
5906
5912
|
item.reject();
|
|
@@ -5910,10 +5916,7 @@ function handleQueuedResult(item, error, result, finished) {
|
|
|
5910
5916
|
item.reject(result);
|
|
5911
5917
|
return;
|
|
5912
5918
|
}
|
|
5913
|
-
item.resolve(
|
|
5914
|
-
finished,
|
|
5915
|
-
value: result
|
|
5916
|
-
});
|
|
5919
|
+
item.resolve(result);
|
|
5917
5920
|
}
|
|
5918
5921
|
function handleQueues(state, type, key) {
|
|
5919
5922
|
if (typeof key === "string") {
|
|
@@ -5964,21 +5967,7 @@ function keyedQueue(callback, options) {
|
|
|
5964
5967
|
pause: (key) => {
|
|
5965
5968
|
handleQueues(state, HANDLE_PAUSE, key);
|
|
5966
5969
|
},
|
|
5967
|
-
remove: (key, id) =>
|
|
5968
|
-
if (key == null) {
|
|
5969
|
-
handleQueues(state, HANDLE_CLEAR);
|
|
5970
|
-
state.queues.clear();
|
|
5971
|
-
return;
|
|
5972
|
-
}
|
|
5973
|
-
const queue = getQueue(state, key);
|
|
5974
|
-
if (queue == null) return;
|
|
5975
|
-
if (typeof id === "number") {
|
|
5976
|
-
queue.remove(id);
|
|
5977
|
-
return;
|
|
5978
|
-
}
|
|
5979
|
-
queue.clear();
|
|
5980
|
-
state.queues.delete(key);
|
|
5981
|
-
},
|
|
5970
|
+
remove: (key, id) => removeQueue(state, key, id),
|
|
5982
5971
|
resume: (key) => {
|
|
5983
5972
|
handleQueues(state, HANDLE_RESUME, key);
|
|
5984
5973
|
}
|
|
@@ -6010,12 +5999,7 @@ function keyedQueue(callback, options) {
|
|
|
6010
5999
|
},
|
|
6011
6000
|
items: {
|
|
6012
6001
|
enumerable: true,
|
|
6013
|
-
get: () =>
|
|
6014
|
-
const size = {};
|
|
6015
|
-
const queues = state.queues.entries();
|
|
6016
|
-
for (const [key, queue] of queues) size[key] = queue.size;
|
|
6017
|
-
return size;
|
|
6018
|
-
}
|
|
6002
|
+
get: () => getItems(state)
|
|
6019
6003
|
},
|
|
6020
6004
|
keys: {
|
|
6021
6005
|
enumerable: true,
|
|
@@ -6040,6 +6024,21 @@ function queue(callback, options) {
|
|
|
6040
6024
|
return createQueue(callback, options);
|
|
6041
6025
|
}
|
|
6042
6026
|
queue.keyed = keyedQueue;
|
|
6027
|
+
function removeQueue(state, key, id) {
|
|
6028
|
+
if (key == null) {
|
|
6029
|
+
handleQueues(state, HANDLE_CLEAR);
|
|
6030
|
+
state.queues.clear();
|
|
6031
|
+
return;
|
|
6032
|
+
}
|
|
6033
|
+
const queue = getQueue(state, key);
|
|
6034
|
+
if (queue == null) return;
|
|
6035
|
+
if (typeof id === "number") {
|
|
6036
|
+
queue.remove(id);
|
|
6037
|
+
return;
|
|
6038
|
+
}
|
|
6039
|
+
queue.clear();
|
|
6040
|
+
state.queues.delete(key);
|
|
6041
|
+
}
|
|
6043
6042
|
async function run(state) {
|
|
6044
6043
|
if (state.paused || state.runners >= state.options.concurrency) return;
|
|
6045
6044
|
state.runners += 1;
|
|
@@ -6059,11 +6058,11 @@ async function run(state) {
|
|
|
6059
6058
|
if (state.paused) {
|
|
6060
6059
|
const paused = item;
|
|
6061
6060
|
state.handled.push(() => {
|
|
6062
|
-
handleQueuedResult(paused, error, result
|
|
6061
|
+
handleQueuedResult(paused, error, result);
|
|
6063
6062
|
});
|
|
6064
6063
|
break;
|
|
6065
6064
|
}
|
|
6066
|
-
handleQueuedResult(item, error, result
|
|
6065
|
+
handleQueuedResult(item, error, result);
|
|
6067
6066
|
item = state.items.shift();
|
|
6068
6067
|
}
|
|
6069
6068
|
state.runners -= 1;
|
package/dist/queue.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { GenericAsyncCallback, GenericCallback } from "./models.mjs";
|
|
|
3
3
|
/**
|
|
4
4
|
* A queue that can be used to manage (a)synchronous tasks with a specific key
|
|
5
5
|
*/
|
|
6
|
-
type KeyedQueue<CallbackParameters extends Parameters<
|
|
6
|
+
type KeyedQueue<Callback extends GenericCallback | GenericAsyncCallback, CallbackParameters extends unknown[] = Parameters<Callback>> = {
|
|
7
7
|
/**
|
|
8
8
|
* Get keys of all active queues
|
|
9
9
|
*/
|
|
@@ -52,7 +52,7 @@ type KeyedQueue<CallbackParameters extends Parameters<GenericAsyncCallback>, Cal
|
|
|
52
52
|
* @param signal Optional signal to abort the item
|
|
53
53
|
* @returns Queued item
|
|
54
54
|
*/
|
|
55
|
-
add(key: string, parameters: Tail<CallbackParameters>, signal?: AbortSignal): Queued<
|
|
55
|
+
add(key: string, parameters: Tail<CallbackParameters>, signal?: AbortSignal): Queued<ReturnType<Callback>>;
|
|
56
56
|
/**
|
|
57
57
|
* Clear all items for a specific key _(or all items for all keys, if no key is provided)_
|
|
58
58
|
*
|
|
@@ -65,7 +65,7 @@ type KeyedQueue<CallbackParameters extends Parameters<GenericAsyncCallback>, Cal
|
|
|
65
65
|
* @param key Key to get the queue for
|
|
66
66
|
* @returns Queue for the key, or `undefined` if it doesn't exist
|
|
67
67
|
*/
|
|
68
|
-
get(key: string): Queue<Tail<CallbackParameters
|
|
68
|
+
get(key: string): Queue<Callback, Tail<CallbackParameters>> | undefined;
|
|
69
69
|
/**
|
|
70
70
|
* Pause the queue for a specific key _(or all queues, if no key is provided)_
|
|
71
71
|
*
|
|
@@ -101,7 +101,7 @@ type KeyedQueue<CallbackParameters extends Parameters<GenericAsyncCallback>, Cal
|
|
|
101
101
|
/**
|
|
102
102
|
* A queue that can be used to manage (a)synchronous tasks
|
|
103
103
|
*/
|
|
104
|
-
type Queue<CallbackParameters extends Parameters<
|
|
104
|
+
type Queue<Callback extends GenericCallback | GenericAsyncCallback, CallbackParameters extends unknown[] = Parameters<Callback>> = {
|
|
105
105
|
/**
|
|
106
106
|
* Is the queue active?
|
|
107
107
|
*/
|
|
@@ -141,7 +141,7 @@ type Queue<CallbackParameters extends Parameters<GenericAsyncCallback>, Callback
|
|
|
141
141
|
* @param signal Optional signal to abort the item
|
|
142
142
|
* @returns Queued item
|
|
143
143
|
*/
|
|
144
|
-
add(parameters: CallbackParameters, signal?: AbortSignal): Queued<
|
|
144
|
+
add(parameters: CallbackParameters, signal?: AbortSignal): Queued<ReturnType<Callback>>;
|
|
145
145
|
/**
|
|
146
146
|
* Remove and reject all items in the queue
|
|
147
147
|
*/
|
|
@@ -195,17 +195,7 @@ type Queued<Value> = {
|
|
|
195
195
|
/**
|
|
196
196
|
* Queued promise
|
|
197
197
|
*/
|
|
198
|
-
readonly promise: Promise<
|
|
199
|
-
};
|
|
200
|
-
type QueuedResult<Value> = {
|
|
201
|
-
/**
|
|
202
|
-
* Has the queue finished processing all items?
|
|
203
|
-
*/
|
|
204
|
-
finished: boolean;
|
|
205
|
-
/**
|
|
206
|
-
* Result for the queued promise
|
|
207
|
-
*/
|
|
208
|
-
value: Value extends Promise<infer Result> ? Result : Value;
|
|
198
|
+
readonly promise: Promise<Value extends Promise<infer Result> ? Result : Value>;
|
|
209
199
|
};
|
|
210
200
|
type Tail<Values extends any[]> = Values extends [infer _, ...infer Rest] ? Rest : never;
|
|
211
201
|
/**
|
|
@@ -214,17 +204,29 @@ type Tail<Values extends any[]> = Values extends [infer _, ...infer Rest] ? Rest
|
|
|
214
204
|
* @param value Value to check
|
|
215
205
|
* @returns `true` if the value is a keyed queue, otherwise `false`
|
|
216
206
|
*/
|
|
217
|
-
declare function isKeyedQueue(value: unknown): value is KeyedQueue<
|
|
207
|
+
declare function isKeyedQueue(value: unknown): value is KeyedQueue<GenericAsyncCallback>;
|
|
218
208
|
/**
|
|
219
209
|
* Is the value a queue?
|
|
220
210
|
*
|
|
221
211
|
* @param value Value to check
|
|
222
212
|
* @returns `true` if the value is a queue, otherwise `false`
|
|
223
213
|
*/
|
|
224
|
-
declare function isQueue(value: unknown): value is Queue<
|
|
214
|
+
declare function isQueue(value: unknown): value is Queue<GenericCallback | GenericAsyncCallback>;
|
|
225
215
|
declare function isQueueInstance<Instance>(name: string, value: unknown): value is Instance;
|
|
226
|
-
|
|
227
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Create a keyed queue for an asynchronous callback function, where each key has its own queue
|
|
218
|
+
*
|
|
219
|
+
* @param callback Callback function for queued items
|
|
220
|
+
* @param options Queue options
|
|
221
|
+
*/
|
|
222
|
+
declare function keyedQueue<Callback extends (key: string, ...parameters: any[]) => Promise<void>>(callback: Callback, options?: QueueOptions): KeyedQueue<Callback, Parameters<Callback>>;
|
|
223
|
+
/**
|
|
224
|
+
* Create a keyed queue for an asynchronous callback function, where each key has its own queue
|
|
225
|
+
*
|
|
226
|
+
* @param callback Callback function for queued items
|
|
227
|
+
* @param options Queue options
|
|
228
|
+
*/
|
|
229
|
+
declare function keyedQueue<Callback extends (key: string, ...parameters: any[]) => void>(callback: Callback, options?: QueueOptions): KeyedQueue<Callback, Parameters<Callback>>;
|
|
228
230
|
/**
|
|
229
231
|
* Create a queue for an asynchronous callback function
|
|
230
232
|
*
|
|
@@ -232,7 +234,7 @@ declare function keyedQueue<Callback extends (key: string, ...parameters: any[])
|
|
|
232
234
|
* @param options Queue options
|
|
233
235
|
* @returns Queue instance
|
|
234
236
|
*/
|
|
235
|
-
declare function queue<Callback extends GenericAsyncCallback>(callback: Callback, options?: QueueOptions): Queue<
|
|
237
|
+
declare function queue<Callback extends GenericAsyncCallback>(callback: Callback, options?: QueueOptions): Queue<Callback, Parameters<Callback>>;
|
|
236
238
|
/**
|
|
237
239
|
* Create a queue for a synchronous callback function
|
|
238
240
|
*
|
|
@@ -240,9 +242,9 @@ declare function queue<Callback extends GenericAsyncCallback>(callback: Callback
|
|
|
240
242
|
* @param options Queue options
|
|
241
243
|
* @returns Queue instance
|
|
242
244
|
*/
|
|
243
|
-
declare function queue<Callback extends GenericCallback>(callback: Callback, options?: QueueOptions): Queue<
|
|
245
|
+
declare function queue<Callback extends GenericCallback>(callback: Callback, options?: QueueOptions): Queue<Callback, Parameters<Callback>>;
|
|
244
246
|
declare namespace queue {
|
|
245
247
|
var keyed: typeof keyedQueue;
|
|
246
248
|
}
|
|
247
249
|
//#endregion
|
|
248
|
-
export { KeyedQueue, Queue, QueueError, QueueOptions, Queued,
|
|
250
|
+
export { KeyedQueue, Queue, QueueError, QueueOptions, Queued, isKeyedQueue, isQueue, isQueueInstance, keyedQueue, queue };
|
package/dist/queue.mjs
CHANGED
|
@@ -125,6 +125,12 @@ function createQueue(callback, options, key) {
|
|
|
125
125
|
function getBooleanOrDefault(value, defaultValue) {
|
|
126
126
|
return typeof value === "boolean" ? value : defaultValue;
|
|
127
127
|
}
|
|
128
|
+
function getItems(state) {
|
|
129
|
+
const size = {};
|
|
130
|
+
const queues = state.queues.entries();
|
|
131
|
+
for (const [key, queue] of queues) size[key] = queue.size;
|
|
132
|
+
return size;
|
|
133
|
+
}
|
|
128
134
|
function getOptions(input) {
|
|
129
135
|
const options = typeof input === "object" && input != null ? input : {};
|
|
130
136
|
return {
|
|
@@ -148,7 +154,7 @@ function getStatus(state, status) {
|
|
|
148
154
|
for (const [key, queue] of queues) if (queue[status]) result.push(key);
|
|
149
155
|
return result;
|
|
150
156
|
}
|
|
151
|
-
function handleQueuedResult(item, error, result
|
|
157
|
+
function handleQueuedResult(item, error, result) {
|
|
152
158
|
item.signal?.removeEventListener(EVENT_NAME, item.abort);
|
|
153
159
|
if (item.signal?.aborted ?? false) {
|
|
154
160
|
item.reject();
|
|
@@ -158,10 +164,7 @@ function handleQueuedResult(item, error, result, finished) {
|
|
|
158
164
|
item.reject(result);
|
|
159
165
|
return;
|
|
160
166
|
}
|
|
161
|
-
item.resolve(
|
|
162
|
-
finished,
|
|
163
|
-
value: result
|
|
164
|
-
});
|
|
167
|
+
item.resolve(result);
|
|
165
168
|
}
|
|
166
169
|
function handleQueues(state, type, key) {
|
|
167
170
|
if (typeof key === "string") {
|
|
@@ -212,21 +215,7 @@ function keyedQueue(callback, options) {
|
|
|
212
215
|
pause: (key) => {
|
|
213
216
|
handleQueues(state, HANDLE_PAUSE, key);
|
|
214
217
|
},
|
|
215
|
-
remove: (key, id) =>
|
|
216
|
-
if (key == null) {
|
|
217
|
-
handleQueues(state, HANDLE_CLEAR);
|
|
218
|
-
state.queues.clear();
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
const queue = getQueue(state, key);
|
|
222
|
-
if (queue == null) return;
|
|
223
|
-
if (typeof id === "number") {
|
|
224
|
-
queue.remove(id);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
queue.clear();
|
|
228
|
-
state.queues.delete(key);
|
|
229
|
-
},
|
|
218
|
+
remove: (key, id) => removeQueue(state, key, id),
|
|
230
219
|
resume: (key) => {
|
|
231
220
|
handleQueues(state, HANDLE_RESUME, key);
|
|
232
221
|
}
|
|
@@ -258,12 +247,7 @@ function keyedQueue(callback, options) {
|
|
|
258
247
|
},
|
|
259
248
|
items: {
|
|
260
249
|
enumerable: true,
|
|
261
|
-
get: () =>
|
|
262
|
-
const size = {};
|
|
263
|
-
const queues = state.queues.entries();
|
|
264
|
-
for (const [key, queue] of queues) size[key] = queue.size;
|
|
265
|
-
return size;
|
|
266
|
-
}
|
|
250
|
+
get: () => getItems(state)
|
|
267
251
|
},
|
|
268
252
|
keys: {
|
|
269
253
|
enumerable: true,
|
|
@@ -288,6 +272,21 @@ function queue(callback, options) {
|
|
|
288
272
|
return createQueue(callback, options);
|
|
289
273
|
}
|
|
290
274
|
queue.keyed = keyedQueue;
|
|
275
|
+
function removeQueue(state, key, id) {
|
|
276
|
+
if (key == null) {
|
|
277
|
+
handleQueues(state, HANDLE_CLEAR);
|
|
278
|
+
state.queues.clear();
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const queue = getQueue(state, key);
|
|
282
|
+
if (queue == null) return;
|
|
283
|
+
if (typeof id === "number") {
|
|
284
|
+
queue.remove(id);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
queue.clear();
|
|
288
|
+
state.queues.delete(key);
|
|
289
|
+
}
|
|
291
290
|
async function run(state) {
|
|
292
291
|
if (state.paused || state.runners >= state.options.concurrency) return;
|
|
293
292
|
state.runners += 1;
|
|
@@ -307,11 +306,11 @@ async function run(state) {
|
|
|
307
306
|
if (state.paused) {
|
|
308
307
|
const paused = item;
|
|
309
308
|
state.handled.push(() => {
|
|
310
|
-
handleQueuedResult(paused, error, result
|
|
309
|
+
handleQueuedResult(paused, error, result);
|
|
311
310
|
});
|
|
312
311
|
break;
|
|
313
312
|
}
|
|
314
|
-
handleQueuedResult(item, error, result
|
|
313
|
+
handleQueuedResult(item, error, result);
|
|
315
314
|
item = state.items.shift();
|
|
316
315
|
}
|
|
317
316
|
state.runners -= 1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oscarpalmer/atoms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.193.1",
|
|
4
4
|
"description": "Atomic utilities for making your JavaScript better.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"helper",
|
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|
|
20
|
-
"plugin"
|
|
21
|
-
"src"
|
|
20
|
+
"plugin"
|
|
22
21
|
],
|
|
23
22
|
"type": "module",
|
|
24
23
|
"module": "./dist/index.mjs",
|
|
@@ -269,4 +268,4 @@
|
|
|
269
268
|
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
|
|
270
269
|
},
|
|
271
270
|
"packageManager": "npm@11.11.1"
|
|
272
|
-
}
|
|
271
|
+
}
|
package/src/array/difference.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import {COMPARE_SETS_DIFFERENCE, compareSets} from '../internal/array/sets';
|
|
2
|
-
import type {PlainObject} from '../models';
|
|
3
|
-
|
|
4
|
-
// #region Functions
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Get the items from the first array that are not in the second array
|
|
8
|
-
*
|
|
9
|
-
* @param first First array
|
|
10
|
-
* @param second Second array
|
|
11
|
-
* @param callback Callback to get an item's value for comparison
|
|
12
|
-
* @returns Unique values from the first array
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* difference(
|
|
17
|
-
* [{id: 1}, {id: 2}, {id: 3}],
|
|
18
|
-
* [{id: 2}, {id: 4}],
|
|
19
|
-
* item => item.id,
|
|
20
|
-
* ); // => [{id: 1}, {id: 3}]
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export function difference<First, Second>(
|
|
24
|
-
first: First[],
|
|
25
|
-
second: Second[],
|
|
26
|
-
callback: (item: First | Second) => unknown,
|
|
27
|
-
): First[];
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Get the items from the first array that are not in the second array
|
|
31
|
-
*
|
|
32
|
-
* @param first First array
|
|
33
|
-
* @param second Second array
|
|
34
|
-
* @param key Key to get an item's value for comparison
|
|
35
|
-
* @returns Unique values from the first array
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* difference(
|
|
40
|
-
* [{id: 1}, {id: 2}, {id: 3}],
|
|
41
|
-
* [{id: 2}, {id: 4}],
|
|
42
|
-
* 'id',
|
|
43
|
-
* ); // => [{id: 1}, {id: 3}]
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export function difference<
|
|
47
|
-
First extends PlainObject,
|
|
48
|
-
Second extends PlainObject,
|
|
49
|
-
SharedKey extends keyof First & keyof Second,
|
|
50
|
-
>(first: First[], second: Second[], key: SharedKey): First[];
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Get the items from the first array that are not in the second array
|
|
54
|
-
*
|
|
55
|
-
* @param first First array
|
|
56
|
-
* @param second Second array
|
|
57
|
-
* @returns Unique values from the first array
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* difference(
|
|
62
|
-
* [1, 2, 3],
|
|
63
|
-
* [2, 4],
|
|
64
|
-
* ); // => [1, 3]
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export function difference<First, Second>(first: First[], second: Second[]): First[];
|
|
68
|
-
|
|
69
|
-
export function difference(first: unknown[], second: unknown[], key?: unknown): unknown[] {
|
|
70
|
-
return compareSets(COMPARE_SETS_DIFFERENCE, first, second, key);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// #endregion
|
package/src/array/exists.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import {FIND_VALUE_INDEX, findValue} from '../internal/array/find';
|
|
2
|
-
import type {PlainObject} from '../models';
|
|
3
|
-
|
|
4
|
-
// #region Functions
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Does an item with a specific value exist in the array?
|
|
8
|
-
*
|
|
9
|
-
* @param array Array to search in
|
|
10
|
-
* @param callback Callback to get an item's value for matching
|
|
11
|
-
* @param value Value to match against
|
|
12
|
-
* @returns `true` if the item exists in the array, otherwise `false`
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* exists(
|
|
17
|
-
* [{id: 1}, {id: 2}, {id: 3}],
|
|
18
|
-
* item => item.id,
|
|
19
|
-
* 2,
|
|
20
|
-
* ); // => true
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export function exists<
|
|
24
|
-
Item,
|
|
25
|
-
Callback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
26
|
-
>(array: Item[], callback: Callback, value: ReturnType<Callback>): boolean;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Does an item with a specific value exist in the array?
|
|
30
|
-
*
|
|
31
|
-
* @param array Array to search in
|
|
32
|
-
* @param key Key to get an item's value for matching
|
|
33
|
-
* @param value Value to match against
|
|
34
|
-
* @returns `true` if the item exists in the array, otherwise `false`
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* exists(
|
|
39
|
-
* [{id: 1}, {id: 2}, {id: 3}],
|
|
40
|
-
* 'id',
|
|
41
|
-
* 2,
|
|
42
|
-
* ); // => true
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export function exists<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
46
|
-
array: Item[],
|
|
47
|
-
key: ItemKey,
|
|
48
|
-
value: Item[ItemKey],
|
|
49
|
-
): boolean;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Does an item in the array match the filter?
|
|
53
|
-
*
|
|
54
|
-
* @param array Array to search in
|
|
55
|
-
* @param filter Filter callback to match items
|
|
56
|
-
* @returns `true` if a matching item exists, otherwise `false`
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* exists(
|
|
61
|
-
* [{id: 1}, {id: 2}, {id: 3}],
|
|
62
|
-
* item => item.id === 2,
|
|
63
|
-
* ); // => true
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export function exists<Item>(
|
|
67
|
-
array: Item[],
|
|
68
|
-
filter: (item: Item, index: number, array: Item[]) => boolean,
|
|
69
|
-
): boolean;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Does the item exist in the array?
|
|
73
|
-
*
|
|
74
|
-
* @param array Array to search in
|
|
75
|
-
* @param item Item to search for
|
|
76
|
-
* @returns `true` if the item exists in the array, otherwise `false`
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```typescript
|
|
80
|
-
* exists([1, 2, 3], 2); // => true
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
export function exists<Item>(array: Item[], item: Item): boolean;
|
|
84
|
-
|
|
85
|
-
export function exists(array: unknown[], ...parameters: unknown[]): boolean {
|
|
86
|
-
if (parameters.length === 1 && typeof parameters[0] !== 'function') {
|
|
87
|
-
return Array.isArray(array) ? array.includes(parameters[0]) : false;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return findValue(FIND_VALUE_INDEX, array, parameters, false) > -1;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// #endregion
|