@oscarpalmer/atoms 0.202.0 → 0.204.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 +4 -5
- package/dist/array/exists.d.mts +5 -6
- package/dist/array/filter.d.mts +10 -11
- package/dist/array/filter.mjs +0 -1
- package/dist/array/find.d.mts +10 -11
- package/dist/array/find.mjs +0 -1
- package/dist/array/first.d.mts +10 -11
- package/dist/array/first.mjs +0 -1
- package/dist/array/flatten.d.mts +2 -3
- package/dist/array/from.d.mts +7 -8
- package/dist/array/group-by.d.mts +7 -8
- package/dist/array/group-by.mjs +0 -1
- package/dist/array/insert.d.mts +3 -4
- package/dist/array/intersection.d.mts +4 -5
- package/dist/array/last.d.mts +10 -11
- package/dist/array/last.mjs +0 -1
- package/dist/array/move.d.mts +9 -10
- package/dist/array/move.mjs +0 -4
- package/dist/array/partition.d.mts +5 -6
- package/dist/array/push.d.mts +2 -3
- package/dist/array/reverse.d.mts +2 -3
- package/dist/array/select.d.mts +11 -12
- package/dist/array/select.mjs +0 -1
- package/dist/array/single.d.mts +4 -5
- package/dist/array/slice.d.mts +12 -13
- package/dist/array/sort.d.mts +31 -32
- package/dist/array/sort.mjs +38 -39
- package/dist/array/splice.d.mts +5 -6
- package/dist/array/swap.d.mts +8 -9
- package/dist/array/swap.mjs +0 -1
- package/dist/array/to-map.d.mts +7 -8
- package/dist/array/to-map.mjs +0 -1
- package/dist/array/to-record.d.mts +7 -8
- package/dist/array/to-record.mjs +0 -1
- package/dist/array/to-set.d.mts +4 -5
- package/dist/array/toggle.d.mts +4 -5
- package/dist/array/union.d.mts +4 -5
- package/dist/array/unique.d.mts +4 -5
- package/dist/array/update.d.mts +4 -5
- package/dist/beacon.d.mts +8 -9
- package/dist/beacon.mjs +96 -71
- package/dist/color/constants.d.mts +14 -13
- package/dist/color/constants.mjs +9 -2
- package/dist/color/index.d.mts +2 -2
- package/dist/color/instance.d.mts +3 -3
- package/dist/color/instance.mjs +91 -69
- package/dist/color/misc/alpha.d.mts +7 -6
- package/dist/color/misc/alpha.mjs +8 -2
- package/dist/color/misc/format.d.mts +6 -7
- package/dist/color/misc/format.mjs +15 -12
- package/dist/color/misc/get.d.mts +14 -15
- package/dist/color/misc/is.d.mts +16 -17
- package/dist/color/misc/is.mjs +7 -7
- package/dist/color/misc/state.d.mts +33 -10
- package/dist/color/misc/state.mjs +28 -48
- package/dist/color/models.d.mts +25 -19
- package/dist/color/space/hex.d.mts +14 -11
- package/dist/color/space/hex.mjs +21 -2
- package/dist/color/space/hsl.d.mts +13 -10
- package/dist/color/space/hsl.mjs +25 -4
- package/dist/color/space/hwb.d.mts +14 -11
- package/dist/color/space/hwb.mjs +24 -3
- package/dist/color/space/rgb.d.mts +16 -13
- package/dist/color/space/rgb.mjs +41 -20
- package/dist/function/limit.d.mts +9 -8
- package/dist/function/limit.mjs +5 -7
- package/dist/function/once.d.mts +26 -6
- package/dist/function/once.mjs +129 -76
- package/dist/function/retry.d.mts +5 -6
- package/dist/function/retry.mjs +3 -4
- package/dist/index.d.mts +184 -60
- package/dist/index.mjs +1292 -970
- package/dist/internal/aborter.d.mts +9 -0
- package/dist/internal/{abort.mjs → aborter.mjs} +1 -1
- package/dist/internal/array/callbacks.d.mts +4 -5
- package/dist/internal/array/chunk.d.mts +2 -3
- package/dist/internal/array/compact.d.mts +3 -4
- package/dist/internal/array/find.d.mts +10 -11
- package/dist/internal/array/get.d.mts +7 -8
- package/dist/internal/array/get.mjs +3 -2
- package/dist/internal/array/group.d.mts +2 -3
- package/dist/internal/array/index-of.d.mts +10 -11
- package/dist/internal/array/index-of.mjs +0 -1
- package/dist/internal/array/insert.d.mts +5 -6
- package/dist/internal/array/match.d.mts +17 -18
- package/dist/internal/array/overlap.d.mts +2 -3
- package/dist/internal/array/sets.d.mts +5 -6
- package/dist/internal/array/shuffle.d.mts +2 -3
- package/dist/internal/array/update.d.mts +2 -3
- package/dist/internal/defaults.d.mts +3 -4
- package/dist/internal/function/assert.d.mts +10 -11
- package/dist/internal/function/assert.mjs +0 -7
- package/dist/internal/function/limit.d.mts +41 -0
- package/dist/internal/function/limit.mjs +106 -0
- package/dist/internal/function/memoize.d.mts +4 -5
- package/dist/internal/function/memoize.mjs +55 -31
- package/dist/internal/function/misc.d.mts +2 -3
- package/dist/internal/function/work.d.mts +53 -54
- package/dist/internal/function/work.mjs +0 -2
- package/dist/internal/herald.d.mts +8 -9
- package/dist/internal/herald.mjs +38 -27
- package/dist/internal/is.d.mts +19 -20
- package/dist/internal/math/aggregate.d.mts +14 -15
- package/dist/internal/math/misc.d.mts +3 -4
- package/dist/internal/number.d.mts +4 -5
- package/dist/internal/random.d.mts +3 -4
- package/dist/internal/result/misc.d.mts +29 -14
- package/dist/internal/result/misc.mjs +4 -3
- package/dist/internal/result/models.d.mts +9 -10
- package/dist/internal/sized/map.d.mts +2 -3
- package/dist/internal/sized/misc.d.mts +2 -3
- package/dist/internal/string/case.d.mts +9 -10
- package/dist/internal/string/misc.d.mts +8 -9
- package/dist/internal/subscription.d.mts +10 -11
- package/dist/internal/subscription.mjs +72 -58
- package/dist/internal/value/compare.d.mts +17 -9
- package/dist/internal/value/compare.mjs +6 -11
- package/dist/internal/value/equal.d.mts +34 -15
- package/dist/internal/value/equal.mjs +20 -13
- package/dist/internal/value/get.d.mts +3 -4
- package/dist/internal/value/handlers.d.mts +19 -9
- package/dist/internal/value/handlers.mjs +48 -50
- package/dist/internal/value/has.d.mts +6 -7
- package/dist/internal/value/has.mjs +0 -1
- package/dist/internal/value/misc.d.mts +6 -7
- package/dist/internal/value/misc.mjs +4 -3
- package/dist/internal/value/partial.d.mts +3 -4
- package/dist/internal/value/partial.mjs +2 -1
- package/dist/internal/value/set.d.mts +4 -5
- package/dist/internal/value/set.mjs +2 -1
- package/dist/is.d.mts +13 -13
- package/dist/logger.d.mts +5 -4
- package/dist/logger.mjs +72 -64
- package/dist/math.d.mts +20 -20
- package/dist/models.d.mts +45 -49
- package/dist/promise/constants.d.mts +14 -15
- package/dist/promise/delay.d.mts +3 -4
- package/dist/promise/delay.mjs +5 -5
- package/dist/promise/helpers.d.mts +7 -8
- package/dist/promise/helpers.mjs +4 -3
- package/dist/promise/index.d.mts +13 -14
- package/dist/promise/index.mjs +1 -2
- package/dist/promise/misc.d.mts +7 -7
- package/dist/promise/models.d.mts +17 -18
- package/dist/promise/timed.d.mts +4 -5
- package/dist/promise/timed.mjs +6 -6
- package/dist/query.d.mts +3 -4
- package/dist/queue.d.mts +14 -15
- package/dist/queue.mjs +198 -136
- package/dist/random.d.mts +8 -8
- package/dist/result/index.d.mts +8 -9
- package/dist/result/index.mjs +0 -1
- package/dist/result/match.d.mts +6 -7
- package/dist/result/match.mjs +0 -1
- package/dist/result/misc.d.mts +3 -3
- package/dist/result/work/flow.d.mts +28 -29
- package/dist/result/work/flow.mjs +0 -1
- package/dist/result/work/pipe.d.mts +24 -25
- package/dist/result/work/pipe.mjs +0 -1
- package/dist/sized/set.d.mts +2 -3
- package/dist/string/fuzzy.d.mts +21 -12
- package/dist/string/fuzzy.mjs +77 -52
- package/dist/string/index.d.mts +8 -8
- package/dist/string/match.d.mts +4 -5
- package/dist/string/normalize.d.mts +8 -9
- package/dist/string/normalize.mjs +9 -5
- package/dist/string/template.d.mts +9 -9
- package/dist/string/template.mjs +11 -5
- package/dist/value/clone.d.mts +21 -13
- package/dist/value/clone.mjs +19 -25
- package/dist/value/collection.d.mts +4 -5
- package/dist/value/diff.d.mts +5 -6
- package/dist/value/freeze.d.mts +18 -19
- package/dist/value/freeze.mjs +1 -5
- package/dist/value/merge.d.mts +13 -14
- package/dist/value/merge.mjs +21 -7
- package/dist/value/omit.d.mts +2 -3
- package/dist/value/pick.d.mts +2 -3
- package/dist/value/shake.d.mts +3 -4
- package/dist/value/smush.d.mts +3 -4
- package/dist/value/transform.d.mts +15 -10
- package/dist/value/transform.mjs +12 -8
- package/dist/value/unsmush.d.mts +3 -4
- package/package.json +2 -2
- package/dist/internal/abort.d.mts +0 -10
- package/dist/internal/function/timer.d.mts +0 -10
- package/dist/internal/function/timer.mjs +0 -87
package/dist/promise/timed.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createAborter } from "../internal/
|
|
2
|
-
import {
|
|
1
|
+
import { createAborter } from "../internal/aborter.mjs";
|
|
2
|
+
import { LIMITER_WAIT, getLimiter } from "../internal/function/limit.mjs";
|
|
3
3
|
import { PROMISE_MESSAGE_EXPECTATION_TIMED } from "./constants.mjs";
|
|
4
4
|
import { PromiseTimeoutError } from "./models.mjs";
|
|
5
5
|
import { createPromiseOptions } from "./helpers.mjs";
|
|
@@ -7,17 +7,17 @@ import { settlePromise } from "./misc.mjs";
|
|
|
7
7
|
//#region src/promise/timed.ts
|
|
8
8
|
async function getTimedPromise(promise, time, signal) {
|
|
9
9
|
const aborter = createAborter(signal, () => {
|
|
10
|
-
|
|
10
|
+
limiter.cancel();
|
|
11
11
|
rejector(signal?.reason);
|
|
12
12
|
});
|
|
13
|
-
const
|
|
13
|
+
const limiter = getLimiter(LIMITER_WAIT, () => settlePromise(rejector, new PromiseTimeoutError(), aborter), time);
|
|
14
14
|
let rejector;
|
|
15
15
|
return Promise.race([promise, new Promise((_, reject) => {
|
|
16
16
|
rejector = reject;
|
|
17
|
-
|
|
17
|
+
limiter.run();
|
|
18
18
|
})]).then((value) => {
|
|
19
19
|
aborter?.cancel();
|
|
20
|
-
|
|
20
|
+
limiter.cancel();
|
|
21
21
|
rejector(void 0);
|
|
22
22
|
return value;
|
|
23
23
|
});
|
package/dist/query.d.mts
CHANGED
|
@@ -6,13 +6,12 @@ import { PlainObject } from "./models.mjs";
|
|
|
6
6
|
* @param query Query string to convert
|
|
7
7
|
* @returns Plain object representation of the query string
|
|
8
8
|
*/
|
|
9
|
-
declare function fromQuery(query: string): PlainObject;
|
|
9
|
+
export declare function fromQuery(query: string): PlainObject;
|
|
10
10
|
/**
|
|
11
11
|
* Convert a plain _(nested)_ object to a query string
|
|
12
12
|
*
|
|
13
13
|
* @param parameters Plain object to convert
|
|
14
14
|
* @returns Query string representation of the object
|
|
15
15
|
*/
|
|
16
|
-
declare function toQuery(parameters: PlainObject): string;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { fromQuery, toQuery };
|
|
16
|
+
export declare function toQuery(parameters: PlainObject): string;
|
|
17
|
+
//#endregion
|
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<Callback extends GenericCallback | GenericAsyncCallback, CallbackParameters extends unknown[] = Parameters<Callback>> = {
|
|
6
|
+
export type KeyedQueue<Callback extends GenericCallback | GenericAsyncCallback, CallbackParameters extends unknown[] = Parameters<Callback>> = {
|
|
7
7
|
/**
|
|
8
8
|
* Get keys of all active queues
|
|
9
9
|
*/
|
|
@@ -101,7 +101,7 @@ type KeyedQueue<Callback extends GenericCallback | GenericAsyncCallback, Callbac
|
|
|
101
101
|
/**
|
|
102
102
|
* A queue that can be used to manage (a)synchronous tasks
|
|
103
103
|
*/
|
|
104
|
-
type Queue<Callback extends GenericCallback | GenericAsyncCallback, CallbackParameters extends unknown[] = Parameters<Callback>> = {
|
|
104
|
+
export type Queue<Callback extends GenericCallback | GenericAsyncCallback, CallbackParameters extends unknown[] = Parameters<Callback>> = {
|
|
105
105
|
/**
|
|
106
106
|
* Is the queue active?
|
|
107
107
|
*/
|
|
@@ -167,10 +167,10 @@ type Queue<Callback extends GenericCallback | GenericAsyncCallback, CallbackPara
|
|
|
167
167
|
/**
|
|
168
168
|
* An error thrown by the Queue when an operation fails
|
|
169
169
|
*/
|
|
170
|
-
declare class QueueError extends Error {
|
|
170
|
+
export declare class QueueError extends Error {
|
|
171
171
|
constructor(message: string);
|
|
172
172
|
}
|
|
173
|
-
type QueueOptions = {
|
|
173
|
+
export type QueueOptions = {
|
|
174
174
|
/**
|
|
175
175
|
* Automatically start processing the queue when the first item is added _(defaults to `true`)_
|
|
176
176
|
*/
|
|
@@ -187,7 +187,7 @@ type QueueOptions = {
|
|
|
187
187
|
/**
|
|
188
188
|
* A queued item
|
|
189
189
|
*/
|
|
190
|
-
type Queued<Value> = {
|
|
190
|
+
export type Queued<Value> = {
|
|
191
191
|
/**
|
|
192
192
|
* ID of the queued item _(can be used to remove it from the queue)_
|
|
193
193
|
*/
|
|
@@ -204,15 +204,15 @@ type Tail<Values extends any[]> = Values extends [infer _, ...infer Rest] ? Rest
|
|
|
204
204
|
* @param value Value to check
|
|
205
205
|
* @returns `true` if the value is a keyed queue, otherwise `false`
|
|
206
206
|
*/
|
|
207
|
-
declare function isKeyedQueue(value: unknown): value is KeyedQueue<GenericAsyncCallback>;
|
|
207
|
+
export declare function isKeyedQueue(value: unknown): value is KeyedQueue<GenericAsyncCallback>;
|
|
208
208
|
/**
|
|
209
209
|
* Is the value a queue?
|
|
210
210
|
*
|
|
211
211
|
* @param value Value to check
|
|
212
212
|
* @returns `true` if the value is a queue, otherwise `false`
|
|
213
213
|
*/
|
|
214
|
-
declare function isQueue(value: unknown): value is Queue<GenericCallback | GenericAsyncCallback>;
|
|
215
|
-
declare function isQueueInstance<Instance>(name: string, value: unknown): value is Instance;
|
|
214
|
+
export declare function isQueue(value: unknown): value is Queue<GenericCallback | GenericAsyncCallback>;
|
|
215
|
+
export declare function isQueueInstance<Instance>(name: string, value: unknown): value is Instance;
|
|
216
216
|
/**
|
|
217
217
|
* Create a keyed queue for an asynchronous callback function, where each key has its own queue
|
|
218
218
|
*
|
|
@@ -221,7 +221,7 @@ declare function isQueueInstance<Instance>(name: string, value: unknown): value
|
|
|
221
221
|
* @param callback Callback function for queued items
|
|
222
222
|
* @param options Queue options
|
|
223
223
|
*/
|
|
224
|
-
declare function keyedQueue<Callback extends (key: string, ...parameters: any[]) => Promise<void>>(callback: Callback, options?: QueueOptions): KeyedQueue<Callback, Parameters<Callback>>;
|
|
224
|
+
export declare function keyedQueue<Callback extends (key: string, ...parameters: any[]) => Promise<void>>(callback: Callback, options?: QueueOptions): KeyedQueue<Callback, Parameters<Callback>>;
|
|
225
225
|
/**
|
|
226
226
|
* Create a keyed queue for an asynchronous callback function, where each key has its own queue
|
|
227
227
|
*
|
|
@@ -230,7 +230,7 @@ declare function keyedQueue<Callback extends (key: string, ...parameters: any[])
|
|
|
230
230
|
* @param callback Callback function for queued items
|
|
231
231
|
* @param options Queue options
|
|
232
232
|
*/
|
|
233
|
-
declare function keyedQueue<Callback extends (key: string, ...parameters: any[]) => void>(callback: Callback, options?: QueueOptions): KeyedQueue<Callback, Parameters<Callback>>;
|
|
233
|
+
export declare function keyedQueue<Callback extends (key: string, ...parameters: any[]) => void>(callback: Callback, options?: QueueOptions): KeyedQueue<Callback, Parameters<Callback>>;
|
|
234
234
|
/**
|
|
235
235
|
* Create a queue for an asynchronous callback function
|
|
236
236
|
*
|
|
@@ -238,7 +238,7 @@ declare function keyedQueue<Callback extends (key: string, ...parameters: any[])
|
|
|
238
238
|
* @param options Queue options
|
|
239
239
|
* @returns Queue instance
|
|
240
240
|
*/
|
|
241
|
-
declare function queue<Callback extends GenericAsyncCallback>(callback: Callback, options?: QueueOptions): Queue<Callback, Parameters<Callback>>;
|
|
241
|
+
export declare function queue<Callback extends GenericAsyncCallback>(callback: Callback, options?: QueueOptions): Queue<Callback, Parameters<Callback>>;
|
|
242
242
|
/**
|
|
243
243
|
* Create a queue for a synchronous callback function
|
|
244
244
|
*
|
|
@@ -246,9 +246,8 @@ declare function queue<Callback extends GenericAsyncCallback>(callback: Callback
|
|
|
246
246
|
* @param options Queue options
|
|
247
247
|
* @returns Queue instance
|
|
248
248
|
*/
|
|
249
|
-
declare function queue<Callback extends GenericCallback>(callback: Callback, options?: QueueOptions): Queue<Callback, Parameters<Callback>>;
|
|
250
|
-
declare namespace queue {
|
|
249
|
+
export declare function queue<Callback extends GenericCallback>(callback: Callback, options?: QueueOptions): Queue<Callback, Parameters<Callback>>;
|
|
250
|
+
export declare namespace queue {
|
|
251
251
|
var keyed: typeof keyedQueue;
|
|
252
252
|
}
|
|
253
|
-
//#endregion
|
|
254
|
-
export { KeyedQueue, Queue, QueueError, QueueOptions, Queued, isKeyedQueue, isQueue, isQueueInstance, keyedQueue, queue };
|
|
253
|
+
//#endregion
|
package/dist/queue.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { createAborter } from "./internal/
|
|
1
|
+
import { createAborter } from "./internal/aborter.mjs";
|
|
2
2
|
import { getBooleanOrDefault, getNumberOrDefault } from "./internal/defaults.mjs";
|
|
3
3
|
//#region src/queue.ts
|
|
4
|
+
const QUEUE_NAME_KEYED = "keyedQueue";
|
|
5
|
+
const QUEUE_NAME_QUEUE = "queue";
|
|
6
|
+
const QUEUE_PROPERTY = "$queue";
|
|
4
7
|
/**
|
|
5
8
|
* An error thrown by the Queue when an operation fails
|
|
6
9
|
*/
|
|
@@ -10,10 +13,122 @@ var QueueError = class extends Error {
|
|
|
10
13
|
this.name = QUEUE_ERROR_NAME;
|
|
11
14
|
}
|
|
12
15
|
};
|
|
13
|
-
function
|
|
14
|
-
|
|
16
|
+
function KeyedQueue(callback, options) {
|
|
17
|
+
this[QUEUE_SYMBOL] = {
|
|
18
|
+
callback,
|
|
19
|
+
options: createQueueOptions(options),
|
|
20
|
+
queues: /* @__PURE__ */ new Map()
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
KeyedQueue.prototype[QUEUE_PROPERTY] = QUEUE_NAME_KEYED;
|
|
24
|
+
KeyedQueue.prototype.add = addKeyedQueue;
|
|
25
|
+
KeyedQueue.prototype.clear = clearQueues;
|
|
26
|
+
KeyedQueue.prototype.get = getQueue;
|
|
27
|
+
KeyedQueue.prototype.pause = pauseQueues;
|
|
28
|
+
KeyedQueue.prototype.remove = removeQueue;
|
|
29
|
+
KeyedQueue.prototype.resume = resumeQueues;
|
|
30
|
+
Object.defineProperties(KeyedQueue.prototype, {
|
|
31
|
+
active: {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: getActiveQueues
|
|
34
|
+
},
|
|
35
|
+
autostart: {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: getQueueAutostart
|
|
38
|
+
},
|
|
39
|
+
concurrency: {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: getQueueConcurrency
|
|
42
|
+
},
|
|
43
|
+
empty: {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: getEmptyQueues
|
|
46
|
+
},
|
|
47
|
+
full: {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: getFullQueues
|
|
50
|
+
},
|
|
51
|
+
items: {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: getKeyedQueueItems
|
|
54
|
+
},
|
|
55
|
+
keys: {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: getQueueKeys
|
|
58
|
+
},
|
|
59
|
+
maximum: {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
get: getQueueMaximum
|
|
62
|
+
},
|
|
63
|
+
paused: {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: getPausedQueues
|
|
66
|
+
},
|
|
67
|
+
queues: {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: getKeyedQueueSize
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
function Queue(callback, options, key) {
|
|
73
|
+
this[QUEUE_SYMBOL] = {
|
|
74
|
+
callback,
|
|
75
|
+
key,
|
|
76
|
+
options,
|
|
77
|
+
handled: [],
|
|
78
|
+
id: 0,
|
|
79
|
+
items: [],
|
|
80
|
+
paused: !options.autostart,
|
|
81
|
+
runners: 0
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
Queue.prototype[QUEUE_PROPERTY] = QUEUE_NAME_QUEUE;
|
|
85
|
+
Queue.prototype.add = addToQueue;
|
|
86
|
+
Queue.prototype.clear = clearQueue;
|
|
87
|
+
Queue.prototype.pause = pauseQueue;
|
|
88
|
+
Queue.prototype.remove = removeQueued;
|
|
89
|
+
Queue.prototype.resume = resumeQueue;
|
|
90
|
+
Object.defineProperties(Queue.prototype, {
|
|
91
|
+
active: {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: getQueueActive
|
|
94
|
+
},
|
|
95
|
+
autostart: {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: getQueueAutostart
|
|
98
|
+
},
|
|
99
|
+
concurrency: {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
get: getQueueConcurrency
|
|
102
|
+
},
|
|
103
|
+
empty: {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: getQueueEmpty
|
|
106
|
+
},
|
|
107
|
+
full: {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
get: getQueueFull
|
|
110
|
+
},
|
|
111
|
+
maximum: {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
get: getQueueMaximum
|
|
114
|
+
},
|
|
115
|
+
paused: {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
get: getQueuePaused
|
|
118
|
+
},
|
|
119
|
+
size: {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
get: getQueueSize
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
function addKeyedQueue(key, parameters, signal) {
|
|
125
|
+
return getQueue.call(this, key, true).add(parameters, signal);
|
|
126
|
+
}
|
|
127
|
+
function addToQueue(parameters, signal) {
|
|
128
|
+
if (this.full) throw new QueueError(QUEUE_MESSAGE_MAXIMUM);
|
|
15
129
|
const abortSignal = signal instanceof AbortSignal ? signal : void 0;
|
|
16
130
|
if (abortSignal?.aborted ?? false) throw new Error(abortSignal?.reason);
|
|
131
|
+
const state = this[QUEUE_SYMBOL];
|
|
17
132
|
const id = identify(state);
|
|
18
133
|
let rejector;
|
|
19
134
|
let resolver;
|
|
@@ -37,8 +152,8 @@ function addToQueue(instance, state, parameters, signal) {
|
|
|
37
152
|
promise
|
|
38
153
|
};
|
|
39
154
|
}
|
|
40
|
-
function clearQueue(
|
|
41
|
-
const items =
|
|
155
|
+
function clearQueue() {
|
|
156
|
+
const items = this[QUEUE_SYMBOL].items.splice(0);
|
|
42
157
|
const { length } = items;
|
|
43
158
|
for (let index = 0; index < length; index += 1) {
|
|
44
159
|
const { aborter, reject } = items[index];
|
|
@@ -46,63 +161,12 @@ function clearQueue(state) {
|
|
|
46
161
|
reject(new QueueError(QUEUE_MESSAGE_CLEAR));
|
|
47
162
|
}
|
|
48
163
|
}
|
|
164
|
+
function clearQueues(key) {
|
|
165
|
+
handleQueues(this, QUEUE_HANDLE_CLEAR, key);
|
|
166
|
+
}
|
|
49
167
|
function createQueue(callback, options, key) {
|
|
50
168
|
if (typeof callback !== "function") throw new TypeError(QUEUE_MESSAGE_CALLBACK);
|
|
51
|
-
|
|
52
|
-
callback,
|
|
53
|
-
key,
|
|
54
|
-
handled: [],
|
|
55
|
-
id: 0,
|
|
56
|
-
items: [],
|
|
57
|
-
options: createQueueOptions(options),
|
|
58
|
-
paused: !getBooleanOrDefault(options?.autostart, true),
|
|
59
|
-
runners: 0
|
|
60
|
-
};
|
|
61
|
-
const instance = {
|
|
62
|
-
add: (parameters, signal) => addToQueue(instance, state, parameters, signal),
|
|
63
|
-
clear: () => clearQueue(state),
|
|
64
|
-
pause: () => {
|
|
65
|
-
state.paused = true;
|
|
66
|
-
},
|
|
67
|
-
remove: (id) => removeQueued(state, id),
|
|
68
|
-
resume: () => resumeQueue(state)
|
|
69
|
-
};
|
|
70
|
-
Object.defineProperties(instance, {
|
|
71
|
-
[QUEUE_PROPERTY]: { value: QUEUE_NAME_QUEUE },
|
|
72
|
-
active: {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
get: () => state.runners > 0
|
|
75
|
-
},
|
|
76
|
-
autostart: {
|
|
77
|
-
enumerable: true,
|
|
78
|
-
get: () => state.options.autostart
|
|
79
|
-
},
|
|
80
|
-
concurrency: {
|
|
81
|
-
enumerable: true,
|
|
82
|
-
get: () => state.options.concurrency
|
|
83
|
-
},
|
|
84
|
-
empty: {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
get: () => state.items.length === 0
|
|
87
|
-
},
|
|
88
|
-
full: {
|
|
89
|
-
enumerable: true,
|
|
90
|
-
get: () => state.options.maximum > 0 && state.items.length >= state.options.maximum
|
|
91
|
-
},
|
|
92
|
-
maximum: {
|
|
93
|
-
enumerable: true,
|
|
94
|
-
get: () => state.options.maximum
|
|
95
|
-
},
|
|
96
|
-
paused: {
|
|
97
|
-
enumerable: true,
|
|
98
|
-
get: () => state.paused
|
|
99
|
-
},
|
|
100
|
-
size: {
|
|
101
|
-
enumerable: true,
|
|
102
|
-
get: () => state.items.length
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
return Object.freeze(instance);
|
|
169
|
+
return new Queue(callback, createQueueOptions(options), key);
|
|
106
170
|
}
|
|
107
171
|
function createQueueOptions(input) {
|
|
108
172
|
const options = typeof input === "object" && input != null ? input : {};
|
|
@@ -112,8 +176,31 @@ function createQueueOptions(input) {
|
|
|
112
176
|
maximum: getNumberOrDefault(options.maximum, 0)
|
|
113
177
|
};
|
|
114
178
|
}
|
|
115
|
-
function
|
|
179
|
+
function getActiveQueues() {
|
|
180
|
+
return getStatus(this[QUEUE_SYMBOL], QUEUE_STATUS_ACTIVE);
|
|
181
|
+
}
|
|
182
|
+
function getEmptyQueues() {
|
|
183
|
+
return getStatus(this[QUEUE_SYMBOL], QUEUE_STATUS_EMPTY);
|
|
184
|
+
}
|
|
185
|
+
function getFullQueues() {
|
|
186
|
+
return getStatus(this[QUEUE_SYMBOL], QUEUE_STATUS_FULL);
|
|
187
|
+
}
|
|
188
|
+
function getPausedQueues() {
|
|
189
|
+
return getStatus(this[QUEUE_SYMBOL], QUEUE_STATUS_PAUSED);
|
|
190
|
+
}
|
|
191
|
+
function getKeyedQueueItems() {
|
|
192
|
+
const state = this[QUEUE_SYMBOL];
|
|
193
|
+
const size = {};
|
|
194
|
+
const queues = state.queues.entries();
|
|
195
|
+
for (const [key, queue] of queues) size[key] = queue.size;
|
|
196
|
+
return size;
|
|
197
|
+
}
|
|
198
|
+
function getKeyedQueueSize() {
|
|
199
|
+
return this[QUEUE_SYMBOL].queues.size;
|
|
200
|
+
}
|
|
201
|
+
function getQueue(key, add) {
|
|
116
202
|
if (typeof key !== "string" || key.trim().length === 0) throw new TypeError(QUEUE_MESSAGE_KEY);
|
|
203
|
+
const state = this[QUEUE_SYMBOL];
|
|
117
204
|
let queue = state.queues.get(key);
|
|
118
205
|
if (queue == null && add === true) {
|
|
119
206
|
queue = createQueue(state.callback, state.options, key);
|
|
@@ -121,11 +208,33 @@ function getQueue(state, key, add) {
|
|
|
121
208
|
}
|
|
122
209
|
return queue;
|
|
123
210
|
}
|
|
124
|
-
function
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return
|
|
211
|
+
function getQueueActive() {
|
|
212
|
+
return this[QUEUE_SYMBOL].runners > 0;
|
|
213
|
+
}
|
|
214
|
+
function getQueueAutostart() {
|
|
215
|
+
return this[QUEUE_SYMBOL].options.autostart === true;
|
|
216
|
+
}
|
|
217
|
+
function getQueueConcurrency() {
|
|
218
|
+
return this[QUEUE_SYMBOL].options.concurrency;
|
|
219
|
+
}
|
|
220
|
+
function getQueueEmpty() {
|
|
221
|
+
return this[QUEUE_SYMBOL].items.length === 0;
|
|
222
|
+
}
|
|
223
|
+
function getQueueFull() {
|
|
224
|
+
const state = this[QUEUE_SYMBOL];
|
|
225
|
+
return state.options.maximum > 0 && state.items.length >= state.options.maximum;
|
|
226
|
+
}
|
|
227
|
+
function getQueueKeys() {
|
|
228
|
+
return [...this[QUEUE_SYMBOL].queues.keys()];
|
|
229
|
+
}
|
|
230
|
+
function getQueueMaximum() {
|
|
231
|
+
return this[QUEUE_SYMBOL].options.maximum;
|
|
232
|
+
}
|
|
233
|
+
function getQueuePaused() {
|
|
234
|
+
return this[QUEUE_SYMBOL].paused === true;
|
|
235
|
+
}
|
|
236
|
+
function getQueueSize() {
|
|
237
|
+
return this[QUEUE_SYMBOL].items.length;
|
|
129
238
|
}
|
|
130
239
|
function getStatus(state, status) {
|
|
131
240
|
const queues = state.queues.entries();
|
|
@@ -145,12 +254,12 @@ function handleQueuedResult(item, error, result) {
|
|
|
145
254
|
}
|
|
146
255
|
item.resolve(result);
|
|
147
256
|
}
|
|
148
|
-
function handleQueues(
|
|
257
|
+
function handleQueues(instance, type, key) {
|
|
149
258
|
if (typeof key === "string") {
|
|
150
|
-
getQueue(
|
|
259
|
+
getQueue.call(instance, key)?.[type]();
|
|
151
260
|
return;
|
|
152
261
|
}
|
|
153
|
-
const queues =
|
|
262
|
+
const queues = instance[QUEUE_SYMBOL].queues.values();
|
|
154
263
|
for (const queue of queues) queue[type]();
|
|
155
264
|
}
|
|
156
265
|
function identify(state) {
|
|
@@ -176,78 +285,29 @@ function isQueue(value) {
|
|
|
176
285
|
return isQueueInstance(QUEUE_NAME_QUEUE, value);
|
|
177
286
|
}
|
|
178
287
|
function isQueueInstance(name, value) {
|
|
179
|
-
return typeof value === "object" && value != null && value[QUEUE_PROPERTY] === name;
|
|
288
|
+
return typeof value === "object" && value != null && QUEUE_PROPERTY in value && value[QUEUE_PROPERTY] === name;
|
|
180
289
|
}
|
|
181
290
|
function keyedQueue(callback, options) {
|
|
182
291
|
if (typeof callback !== "function") throw new TypeError(QUEUE_MESSAGE_CALLBACK);
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
clear: (key) => handleQueues(state, QUEUE_HANDLE_CLEAR, key),
|
|
191
|
-
get: (key) => getQueue(state, key),
|
|
192
|
-
pause: (key) => handleQueues(state, QUEUE_HANDLE_PAUSE, key),
|
|
193
|
-
remove: (key, id) => removeQueue(state, key, id),
|
|
194
|
-
resume: (key) => handleQueues(state, QUEUE_HANDLE_RESUME, key)
|
|
195
|
-
};
|
|
196
|
-
Object.defineProperties(instance, {
|
|
197
|
-
[QUEUE_PROPERTY]: { value: QUEUE_NAME_KEYED },
|
|
198
|
-
active: {
|
|
199
|
-
enumerable: true,
|
|
200
|
-
get: () => getStatus(state, QUEUE_STATUS_ACTIVE)
|
|
201
|
-
},
|
|
202
|
-
autostart: {
|
|
203
|
-
enumerable: true,
|
|
204
|
-
get: () => state.options.autostart
|
|
205
|
-
},
|
|
206
|
-
concurrency: {
|
|
207
|
-
enumerable: true,
|
|
208
|
-
get: () => state.options.concurrency
|
|
209
|
-
},
|
|
210
|
-
empty: {
|
|
211
|
-
enumerable: true,
|
|
212
|
-
get: () => getStatus(state, QUEUE_STATUS_EMPTY)
|
|
213
|
-
},
|
|
214
|
-
full: {
|
|
215
|
-
enumerable: true,
|
|
216
|
-
get: () => getStatus(state, QUEUE_STATUS_FULL)
|
|
217
|
-
},
|
|
218
|
-
items: {
|
|
219
|
-
enumerable: true,
|
|
220
|
-
get: () => getQueueItems(state)
|
|
221
|
-
},
|
|
222
|
-
keys: {
|
|
223
|
-
enumerable: true,
|
|
224
|
-
get: () => [...state.queues.keys()]
|
|
225
|
-
},
|
|
226
|
-
maximum: {
|
|
227
|
-
enumerable: true,
|
|
228
|
-
get: () => state.options.maximum
|
|
229
|
-
},
|
|
230
|
-
paused: {
|
|
231
|
-
enumerable: true,
|
|
232
|
-
get: () => getStatus(state, QUEUE_STATUS_PAUSED)
|
|
233
|
-
},
|
|
234
|
-
queues: {
|
|
235
|
-
enumerable: true,
|
|
236
|
-
get: () => state.queues.size
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
return Object.freeze(instance);
|
|
292
|
+
return new KeyedQueue(callback, createQueueOptions(options));
|
|
293
|
+
}
|
|
294
|
+
function pauseQueue() {
|
|
295
|
+
this[QUEUE_SYMBOL].paused = true;
|
|
296
|
+
}
|
|
297
|
+
function pauseQueues(key) {
|
|
298
|
+
handleQueues(this, QUEUE_HANDLE_PAUSE, key);
|
|
240
299
|
}
|
|
241
300
|
function queue(callback, options) {
|
|
242
301
|
return createQueue(callback, options);
|
|
243
302
|
}
|
|
244
|
-
function removeQueue(
|
|
303
|
+
function removeQueue(key, id) {
|
|
304
|
+
const state = this[QUEUE_SYMBOL];
|
|
245
305
|
if (key == null) {
|
|
246
|
-
handleQueues(
|
|
306
|
+
handleQueues(this, QUEUE_HANDLE_CLEAR);
|
|
247
307
|
state.queues.clear();
|
|
248
308
|
return;
|
|
249
309
|
}
|
|
250
|
-
const queue = getQueue(
|
|
310
|
+
const queue = getQueue.call(this, key);
|
|
251
311
|
if (queue == null) return;
|
|
252
312
|
if (typeof id === "number") {
|
|
253
313
|
queue.remove(id);
|
|
@@ -256,7 +316,8 @@ function removeQueue(state, key, id) {
|
|
|
256
316
|
queue.clear();
|
|
257
317
|
state.queues.delete(key);
|
|
258
318
|
}
|
|
259
|
-
function removeQueued(
|
|
319
|
+
function removeQueued(id) {
|
|
320
|
+
const state = this[QUEUE_SYMBOL];
|
|
260
321
|
const index = state.items.findIndex((item) => item.id === id);
|
|
261
322
|
if (index > -1) {
|
|
262
323
|
const { aborter, reject } = state.items.splice(index, 1)[0];
|
|
@@ -264,7 +325,8 @@ function removeQueued(state, id) {
|
|
|
264
325
|
reject(new QueueError(QUEUE_MESSAGE_REMOVE));
|
|
265
326
|
}
|
|
266
327
|
}
|
|
267
|
-
function resumeQueue(
|
|
328
|
+
function resumeQueue() {
|
|
329
|
+
const state = this[QUEUE_SYMBOL];
|
|
268
330
|
if (state.paused) {
|
|
269
331
|
const handled = state.handled.splice(0);
|
|
270
332
|
const { length } = handled;
|
|
@@ -274,6 +336,9 @@ function resumeQueue(state) {
|
|
|
274
336
|
const length = Math.min(state.options.concurrency, state.items.length);
|
|
275
337
|
for (let index = 0; index < length; index += 1) run(state);
|
|
276
338
|
}
|
|
339
|
+
function resumeQueues(key) {
|
|
340
|
+
handleQueues(this, QUEUE_HANDLE_RESUME, key);
|
|
341
|
+
}
|
|
277
342
|
async function run(state) {
|
|
278
343
|
if (state.paused || state.runners >= state.options.concurrency) return;
|
|
279
344
|
state.runners += 1;
|
|
@@ -301,7 +366,6 @@ async function run(state) {
|
|
|
301
366
|
state.runners -= 1;
|
|
302
367
|
}
|
|
303
368
|
const QUEUE_ERROR_NAME = "QueueError";
|
|
304
|
-
const QUEUE_PROPERTY = "$queue";
|
|
305
369
|
const QUEUE_HANDLE_CLEAR = "clear";
|
|
306
370
|
const QUEUE_HANDLE_PAUSE = "pause";
|
|
307
371
|
const QUEUE_HANDLE_RESUME = "resume";
|
|
@@ -310,13 +374,11 @@ const QUEUE_MESSAGE_CLEAR = "Queue was cleared";
|
|
|
310
374
|
const QUEUE_MESSAGE_KEY = "Key must be a non-empty string";
|
|
311
375
|
const QUEUE_MESSAGE_MAXIMUM = "Queue has reached its maximum size";
|
|
312
376
|
const QUEUE_MESSAGE_REMOVE = "Item removed from queue";
|
|
313
|
-
const QUEUE_NAME_KEYED = "keyedQueue";
|
|
314
|
-
const QUEUE_NAME_QUEUE = "queue";
|
|
315
377
|
const QUEUE_STATUS_ACTIVE = "active";
|
|
316
378
|
const QUEUE_STATUS_EMPTY = "empty";
|
|
317
379
|
const QUEUE_STATUS_FULL = "full";
|
|
318
380
|
const QUEUE_STATUS_PAUSED = "paused";
|
|
381
|
+
const QUEUE_SYMBOL = Symbol(QUEUE_PROPERTY);
|
|
319
382
|
queue.keyed = keyedQueue;
|
|
320
|
-
Object.defineProperty(queue, "keyed", { value: keyedQueue });
|
|
321
383
|
//#endregion
|
|
322
384
|
export { QueueError, isKeyedQueue, isQueue, isQueueInstance, keyedQueue, queue };
|
package/dist/random.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ import { getRandomFloatingNumber, getRandomInteger } from "./internal/random.mjs
|
|
|
5
5
|
*
|
|
6
6
|
* @returns Random boolean
|
|
7
7
|
*/
|
|
8
|
-
declare function getRandomBoolean(): boolean;
|
|
8
|
+
export declare function getRandomBoolean(): boolean;
|
|
9
9
|
/**
|
|
10
10
|
* Get a random string of characters with a specified length
|
|
11
11
|
*
|
|
@@ -13,27 +13,27 @@ declare function getRandomBoolean(): boolean;
|
|
|
13
13
|
* @param selection String of characters to select from _(defaults to lowercase English alphabet)_
|
|
14
14
|
* @returns Random string of characters
|
|
15
15
|
*/
|
|
16
|
-
declare function getRandomCharacters(length: number, selection?: string): string;
|
|
16
|
+
export declare function getRandomCharacters(length: number, selection?: string): string;
|
|
17
17
|
/**
|
|
18
18
|
* Get a random hexadecimal color
|
|
19
19
|
*
|
|
20
20
|
* @param prefix Prefix the color with `#`? _(defaults to `false`)_
|
|
21
21
|
* @returns Random hexadecimal color string in the format `(#)RRGGBB`
|
|
22
22
|
*/
|
|
23
|
-
declare function getRandomColor(prefix?: boolean): string;
|
|
23
|
+
export declare function getRandomColor(prefix?: boolean): string;
|
|
24
24
|
/**
|
|
25
25
|
* Get a random hexadecimal character
|
|
26
26
|
*
|
|
27
27
|
* @returns Random hexadecimal character from `0-9` and `A-F`
|
|
28
28
|
*/
|
|
29
|
-
declare function getRandomHex(): string;
|
|
29
|
+
export declare function getRandomHex(): string;
|
|
30
30
|
/**
|
|
31
31
|
* Get a random item from an array
|
|
32
32
|
*
|
|
33
33
|
* @param array Array to get a random item from
|
|
34
34
|
* @returns Random item from the array, or `undefined` if unable to retrieve one
|
|
35
35
|
*/
|
|
36
|
-
declare function getRandomItem<Value>(array: Value[]): Value | undefined;
|
|
36
|
+
export declare function getRandomItem<Value>(array: Value[]): Value | undefined;
|
|
37
37
|
/**
|
|
38
38
|
* Get an amount of random items from an array
|
|
39
39
|
*
|
|
@@ -41,13 +41,13 @@ declare function getRandomItem<Value>(array: Value[]): Value | undefined;
|
|
|
41
41
|
* @param amount Amount of items to return
|
|
42
42
|
* @returns Array of random items
|
|
43
43
|
*/
|
|
44
|
-
declare function getRandomItems<Value>(array: Value[], amount: number): Value[];
|
|
44
|
+
export declare function getRandomItems<Value>(array: Value[], amount: number): Value[];
|
|
45
45
|
/**
|
|
46
46
|
* Get a shuffled array
|
|
47
47
|
*
|
|
48
48
|
* @param array Array to get random items from
|
|
49
49
|
* @returns Shuffled version of the original array
|
|
50
50
|
*/
|
|
51
|
-
declare function getRandomItems<Value>(array: Value[]): Value[];
|
|
51
|
+
export declare function getRandomItems<Value>(array: Value[]): Value[];
|
|
52
52
|
//#endregion
|
|
53
|
-
export {
|
|
53
|
+
export { getRandomFloatingNumber as getRandomFloat, getRandomInteger };
|