@oscarpalmer/atoms 0.193.1 → 0.195.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.
Files changed (121) hide show
  1. package/dist/array/difference.mjs +2 -2
  2. package/dist/array/index.d.mts +2 -2
  3. package/dist/array/index.mjs +2 -2
  4. package/dist/array/intersection.mjs +2 -2
  5. package/dist/array/move.mjs +1 -1
  6. package/dist/array/slice.mjs +5 -5
  7. package/dist/array/sort.d.mts +5 -1
  8. package/dist/array/sort.mjs +4 -2
  9. package/dist/array/swap.mjs +1 -1
  10. package/dist/array/union.mjs +2 -2
  11. package/dist/beacon.d.mts +8 -1
  12. package/dist/beacon.mjs +52 -60
  13. package/dist/color/constants.d.mts +1 -1
  14. package/dist/color/constants.mjs +3 -5
  15. package/dist/color/instance.mjs +34 -41
  16. package/dist/color/misc/format.d.mts +3 -2
  17. package/dist/color/misc/format.mjs +4 -1
  18. package/dist/color/misc/is.d.mts +9 -1
  19. package/dist/color/misc/is.mjs +11 -1
  20. package/dist/color/misc/state.d.mts +6 -6
  21. package/dist/color/misc/state.mjs +11 -14
  22. package/dist/color/models.d.mts +23 -68
  23. package/dist/color/space/hex.mjs +1 -1
  24. package/dist/color/space/rgb.mjs +1 -1
  25. package/dist/function/index.d.mts +1 -2
  26. package/dist/function/index.mjs +1 -2
  27. package/dist/function/limit.d.mts +0 -6
  28. package/dist/function/limit.mjs +2 -2
  29. package/dist/function/once.d.mts +0 -3
  30. package/dist/function/once.mjs +17 -14
  31. package/dist/function/retry.d.mts +1 -24
  32. package/dist/function/retry.mjs +1 -1
  33. package/dist/herald.d.mts +2 -72
  34. package/dist/herald.mjs +2 -92
  35. package/dist/index.d.mts +3332 -3418
  36. package/dist/index.mjs +1850 -1870
  37. package/dist/internal/abort.d.mts +10 -0
  38. package/dist/internal/abort.mjs +14 -0
  39. package/dist/internal/array/chunk.mjs +2 -2
  40. package/dist/internal/array/find.mjs +2 -2
  41. package/dist/{array → internal/array}/get.d.mts +2 -2
  42. package/dist/{array → internal/array}/get.mjs +2 -2
  43. package/dist/{array → internal/array}/match.d.mts +2 -2
  44. package/dist/{array → internal/array}/match.mjs +15 -15
  45. package/dist/internal/array/sets.d.mts +4 -4
  46. package/dist/internal/array/sets.mjs +7 -7
  47. package/dist/internal/defaults.d.mts +5 -0
  48. package/dist/internal/defaults.mjs +9 -0
  49. package/dist/{function → internal/function}/assert.d.mts +2 -2
  50. package/dist/{function → internal/function}/assert.mjs +4 -4
  51. package/dist/{function → internal/function}/memoize.d.mts +2 -2
  52. package/dist/{function → internal/function}/memoize.mjs +22 -35
  53. package/dist/internal/function/timer.mjs +19 -15
  54. package/dist/{function → internal/function}/work.d.mts +2 -2
  55. package/dist/{function → internal/function}/work.mjs +15 -13
  56. package/dist/internal/herald.d.mts +71 -0
  57. package/dist/internal/herald.mjs +110 -0
  58. package/dist/internal/number.d.mts +1 -2
  59. package/dist/internal/number.mjs +8 -11
  60. package/dist/internal/{result.d.mts → result/misc.d.mts} +42 -3
  61. package/dist/internal/result/misc.mjs +51 -0
  62. package/dist/{result → internal/result}/models.d.mts +2 -2
  63. package/dist/{sized → internal/sized}/map.d.mts +1 -1
  64. package/dist/{sized → internal/sized}/map.mjs +2 -2
  65. package/dist/internal/{sized.d.mts → sized/misc.d.mts} +1 -1
  66. package/dist/internal/sized/misc.mjs +12 -0
  67. package/dist/{string → internal/string}/case.d.mts +1 -1
  68. package/dist/{string → internal/string}/case.mjs +22 -22
  69. package/dist/internal/{string.d.mts → string/misc.d.mts} +1 -1
  70. package/dist/internal/{string.mjs → string/misc.mjs} +5 -5
  71. package/dist/internal/subscription.d.mts +24 -8
  72. package/dist/internal/subscription.mjs +49 -36
  73. package/dist/internal/value/compare.mjs +1 -1
  74. package/dist/internal/value/equal.mjs +6 -6
  75. package/dist/internal/value/has.d.mts +1 -1
  76. package/dist/internal/value/misc.d.mts +1 -1
  77. package/dist/internal/value/misc.mjs +16 -16
  78. package/dist/internal/value/set.mjs +2 -2
  79. package/dist/is.mjs +2 -2
  80. package/dist/logger.mjs +15 -39
  81. package/dist/promise/constants.d.mts +17 -0
  82. package/dist/promise/constants.mjs +14 -0
  83. package/dist/promise/delay.mjs +7 -10
  84. package/dist/promise/helpers.d.mts +1 -1
  85. package/dist/promise/helpers.mjs +3 -3
  86. package/dist/promise/index.d.mts +1 -1
  87. package/dist/promise/index.mjs +14 -17
  88. package/dist/promise/misc.d.mts +3 -2
  89. package/dist/promise/misc.mjs +10 -8
  90. package/dist/promise/models.d.mts +5 -17
  91. package/dist/promise/models.mjs +4 -13
  92. package/dist/promise/timed.mjs +9 -10
  93. package/dist/query.mjs +16 -16
  94. package/dist/queue.mjs +104 -120
  95. package/dist/random.mjs +8 -8
  96. package/dist/result/index.d.mts +1 -4
  97. package/dist/result/index.mjs +2 -2
  98. package/dist/result/match.d.mts +1 -4
  99. package/dist/result/match.mjs +5 -5
  100. package/dist/result/misc.d.mts +3 -42
  101. package/dist/result/misc.mjs +4 -30
  102. package/dist/result/work/flow.d.mts +1 -4
  103. package/dist/result/work/flow.mjs +6 -6
  104. package/dist/result/work/pipe.d.mts +1 -4
  105. package/dist/result/work/pipe.mjs +5 -5
  106. package/dist/sized/set.mjs +1 -1
  107. package/dist/string/fuzzy.mjs +25 -20
  108. package/dist/string/index.d.mts +1 -1
  109. package/dist/string/index.mjs +8 -8
  110. package/dist/string/match.mjs +1 -1
  111. package/dist/string/normalize.mjs +16 -16
  112. package/dist/string/template.mjs +3 -3
  113. package/dist/subscription.d.mts +2 -0
  114. package/dist/subscription.mjs +2 -0
  115. package/dist/value/clone.mjs +10 -10
  116. package/dist/value/diff.mjs +1 -1
  117. package/dist/value/smush.mjs +3 -3
  118. package/package.json +35 -14
  119. package/dist/internal/result.mjs +0 -25
  120. package/dist/internal/sized.mjs +0 -12
  121. /package/dist/{result → internal/result}/models.mjs +0 -0
package/dist/query.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { isPlainObject } from "./internal/is.mjs";
2
- import { getString, ignoreKey, join, tryDecode, tryEncode } from "./internal/string.mjs";
2
+ import { getString, ignoreKey, join, tryDecode, tryEncode } from "./internal/string/misc.mjs";
3
3
  import { getNumber } from "./internal/number.mjs";
4
4
  import { setValue } from "./internal/value/set.mjs";
5
5
  //#region src/query.ts
@@ -11,15 +11,15 @@ import { setValue } from "./internal/value/set.mjs";
11
11
  */
12
12
  function fromQuery(query) {
13
13
  if (typeof query !== "string" || query.trim().length === 0) return {};
14
- const parts = query.split(AMPERSAND).map((part) => part.split(EQUAL).map(tryDecode)).sort(([first], [second]) => first.localeCompare(second));
14
+ const parts = query.split(QUERY_AMPERSAND).map((part) => part.split(QUERY_EQUAL).map(tryDecode)).sort(([first], [second]) => first.localeCompare(second));
15
15
  const { length } = parts;
16
16
  const parameters = {};
17
17
  let position = 0;
18
18
  let array;
19
19
  for (let index = 0; index < length; index += 1) {
20
20
  const [key, value] = parts[index];
21
- if (EXPRESSION_ARRAY_SUFFIX.test(key)) {
22
- const named = key.replace(EXPRESSION_ARRAY_SUFFIX, "");
21
+ if (QUERY_EXPRESSION_ARRAY_SUFFIX.test(key)) {
22
+ const named = key.replace(QUERY_EXPRESSION_ARRAY_SUFFIX, "");
23
23
  if (named !== array) {
24
24
  array = named;
25
25
  position = 0;
@@ -41,9 +41,9 @@ function getParts(value, fromArray, prefix) {
41
41
  for (let index = 0; index < length; index += 1) {
42
42
  const key = keys[index];
43
43
  const val = value[key];
44
- const fullKey = join([prefix, fromArray ? void 0 : key], DOT);
44
+ const fullKey = join([prefix, fromArray ? void 0 : key], QUERY_DOT);
45
45
  const encodedKey = getString(tryEncode(fullKey));
46
- const prefixedKey = fromArray ? join([encodedKey, index], DOT) : encodedKey;
46
+ const prefixedKey = fromArray ? join([encodedKey, index], QUERY_DOT) : encodedKey;
47
47
  if (Array.isArray(val)) parts.push(...getParts(val, true, fullKey));
48
48
  else if (isPlainObject(val)) parts.push(...getParts(val, false, fullKey));
49
49
  else if (isDecodable(val)) parts.push(`${prefixedKey}=${getString(tryEncode(val))}`);
@@ -52,7 +52,7 @@ function getParts(value, fromArray, prefix) {
52
52
  return parts;
53
53
  }
54
54
  function getQueryValue(value) {
55
- if (EXPRESSION_BOOLEAN.test(value)) return value === TRUE;
55
+ if (QUERY_EXPRESSION_BOOLEAN.test(value)) return value === QUERY_TRUE;
56
56
  const asNumber = getNumber(value);
57
57
  if (!Number.isNaN(asNumber)) return asNumber;
58
58
  const parsed = Date.parse(value);
@@ -61,7 +61,7 @@ function getQueryValue(value) {
61
61
  return date.toJSON() === value ? date : value;
62
62
  }
63
63
  function isDecodable(value) {
64
- return TYPES.has(typeof value);
64
+ return QUERY_TYPES.has(typeof value);
65
65
  }
66
66
  /**
67
67
  * Convert a plain _(nested)_ object to a query string
@@ -70,15 +70,15 @@ function isDecodable(value) {
70
70
  * @returns Query string representation of the object
71
71
  */
72
72
  function toQuery(parameters) {
73
- return isPlainObject(parameters) ? join(getParts(parameters, false).filter((part) => part.length > 0), AMPERSAND) : "";
73
+ return isPlainObject(parameters) ? join(getParts(parameters, false).filter((part) => part.length > 0), QUERY_AMPERSAND) : "";
74
74
  }
75
- const AMPERSAND = "&";
76
- const DOT = ".";
77
- const EQUAL = "=";
78
- const EXPRESSION_ARRAY_SUFFIX = /\[\]$/;
79
- const EXPRESSION_BOOLEAN = /^(false|true)$/;
80
- const TRUE = "true";
81
- const TYPES = /* @__PURE__ */ new Set([
75
+ const QUERY_AMPERSAND = "&";
76
+ const QUERY_DOT = ".";
77
+ const QUERY_EQUAL = "=";
78
+ const QUERY_EXPRESSION_ARRAY_SUFFIX = /\[\]$/;
79
+ const QUERY_EXPRESSION_BOOLEAN = /^(false|true)$/;
80
+ const QUERY_TRUE = "true";
81
+ const QUERY_TYPES = /* @__PURE__ */ new Set([
82
82
  "boolean",
83
83
  "number",
84
84
  "string"
package/dist/queue.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { getNumberOrDefault } from "./internal/number.mjs";
1
+ import { createAborter } from "./internal/abort.mjs";
2
+ import { getBooleanOrDefault, getNumberOrDefault } from "./internal/defaults.mjs";
2
3
  //#region src/queue.ts
3
4
  /**
4
5
  * An error thrown by the Queue when an operation fails
@@ -6,11 +7,47 @@ import { getNumberOrDefault } from "./internal/number.mjs";
6
7
  var QueueError = class extends Error {
7
8
  constructor(message) {
8
9
  super(message);
9
- this.name = ERROR_NAME;
10
+ this.name = QUEUE_ERROR_NAME;
10
11
  }
11
12
  };
13
+ function addToQueue(instance, state, parameters, signal) {
14
+ if (instance.full) throw new QueueError(QUEUE_MESSAGE_MAXIMUM);
15
+ const abortSignal = signal instanceof AbortSignal ? signal : void 0;
16
+ if (abortSignal?.aborted ?? false) throw new Error(abortSignal?.reason);
17
+ const id = identify(state);
18
+ let rejector;
19
+ let resolver;
20
+ const promise = new Promise((resolve, reject) => {
21
+ rejector = reject;
22
+ resolver = resolve;
23
+ });
24
+ const aborter = createAborter(abortSignal, () => rejector(abortSignal?.reason));
25
+ state.items.push({
26
+ aborter,
27
+ id,
28
+ parameters,
29
+ promise,
30
+ key: state.key,
31
+ reject: rejector,
32
+ resolve: resolver
33
+ });
34
+ if (state.options.autostart) run(state);
35
+ return {
36
+ id,
37
+ promise
38
+ };
39
+ }
40
+ function clearQueue(state) {
41
+ const items = state.items.splice(0);
42
+ const { length } = items;
43
+ for (let index = 0; index < length; index += 1) {
44
+ const { aborter, reject } = items[index];
45
+ aborter?.cancel();
46
+ reject(new QueueError(QUEUE_MESSAGE_CLEAR));
47
+ }
48
+ }
12
49
  function createQueue(callback, options, key) {
13
- if (typeof callback !== "function") throw new TypeError(MESSAGE_CALLBACK);
50
+ if (typeof callback !== "function") throw new TypeError(QUEUE_MESSAGE_CALLBACK);
14
51
  const state = {
15
52
  callback,
16
53
  key,
@@ -22,71 +59,16 @@ function createQueue(callback, options, key) {
22
59
  runners: 0
23
60
  };
24
61
  const instance = {
25
- add: (parameters, signal) => {
26
- if (instance.full) throw new QueueError(MESSAGE_MAXIMUM);
27
- const abortSignal = signal instanceof AbortSignal ? signal : void 0;
28
- if (abortSignal?.aborted ?? false) throw new Error(abortSignal.reason);
29
- const id = identify(state);
30
- let rejector;
31
- let resolver;
32
- const promise = new Promise((resolve, reject) => {
33
- rejector = reject;
34
- resolver = resolve;
35
- });
36
- const aborter = abortSignal == null ? void 0 : () => rejector(abortSignal.reason);
37
- signal?.addEventListener(EVENT_NAME, aborter, EVENT_OPTIONS);
38
- state.items.push({
39
- id,
40
- parameters,
41
- promise,
42
- abort: aborter,
43
- key: state.key,
44
- reject: rejector,
45
- resolve: resolver,
46
- signal: abortSignal
47
- });
48
- if (state.options.autostart) run(state);
49
- return {
50
- id,
51
- promise
52
- };
53
- },
54
- clear: () => {
55
- const items = state.items.splice(0);
56
- const { length } = items;
57
- for (let index = 0; index < length; index += 1) {
58
- const { abort, reject, signal } = items[index];
59
- reject(new QueueError(MESSAGE_CLEAR));
60
- signal?.removeEventListener(EVENT_NAME, abort);
61
- }
62
- },
62
+ add: (parameters, signal) => addToQueue(instance, state, parameters, signal),
63
+ clear: () => clearQueue(state),
63
64
  pause: () => {
64
65
  state.paused = true;
65
66
  },
66
- remove: (id) => {
67
- const index = state.items.findIndex((item) => item.id === id);
68
- if (index > -1) {
69
- const { abort, reject, signal } = state.items.splice(index, 1)[0];
70
- reject(new QueueError(MESSAGE_REMOVE));
71
- signal?.removeEventListener(EVENT_NAME, abort);
72
- }
73
- },
74
- resume: () => {
75
- if (state.paused) {
76
- const handled = state.handled.splice(0);
77
- const { length } = handled;
78
- for (let index = 0; index < length; index += 1) handled[index]();
79
- }
80
- state.paused = false;
81
- const length = Math.min(state.options.concurrency, state.items.length);
82
- for (let index = 0; index < length; index += 1) run(state);
83
- }
67
+ remove: (id) => removeQueued(state, id),
68
+ resume: () => resumeQueue(state)
84
69
  };
85
70
  Object.defineProperties(instance, {
86
- [KEY_QUEUE]: {
87
- enumerable: false,
88
- value: NAME_QUEUE
89
- },
71
+ [QUEUE_PROPERTY]: { value: QUEUE_NAME_QUEUE },
90
72
  active: {
91
73
  enumerable: true,
92
74
  get: () => state.runners > 0
@@ -122,15 +104,6 @@ function createQueue(callback, options, key) {
122
104
  });
123
105
  return Object.freeze(instance);
124
106
  }
125
- function getBooleanOrDefault(value, defaultValue) {
126
- return typeof value === "boolean" ? value : defaultValue;
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
- }
134
107
  function getOptions(input) {
135
108
  const options = typeof input === "object" && input != null ? input : {};
136
109
  return {
@@ -140,7 +113,7 @@ function getOptions(input) {
140
113
  };
141
114
  }
142
115
  function getQueue(state, key, add) {
143
- if (typeof key !== "string" || key.trim().length === 0) throw new TypeError(MESSAGE_KEY);
116
+ if (typeof key !== "string" || key.trim().length === 0) throw new TypeError(QUEUE_MESSAGE_KEY);
144
117
  let queue = state.queues.get(key);
145
118
  if (queue == null && add === true) {
146
119
  queue = createQueue(state.callback, state.options, key);
@@ -148,6 +121,12 @@ function getQueue(state, key, add) {
148
121
  }
149
122
  return queue;
150
123
  }
124
+ function getQueueItems(state) {
125
+ const size = {};
126
+ const queues = state.queues.entries();
127
+ for (const [key, queue] of queues) size[key] = queue.size;
128
+ return size;
129
+ }
151
130
  function getStatus(state, status) {
152
131
  const queues = state.queues.entries();
153
132
  const result = [];
@@ -155,8 +134,8 @@ function getStatus(state, status) {
155
134
  return result;
156
135
  }
157
136
  function handleQueuedResult(item, error, result) {
158
- item.signal?.removeEventListener(EVENT_NAME, item.abort);
159
- if (item.signal?.aborted ?? false) {
137
+ item.aborter?.cancel();
138
+ if (item.aborter?.signal?.aborted ?? false) {
160
139
  item.reject();
161
140
  return;
162
141
  }
@@ -185,7 +164,7 @@ function identify(state) {
185
164
  * @returns `true` if the value is a keyed queue, otherwise `false`
186
165
  */
187
166
  function isKeyedQueue(value) {
188
- return isQueueInstance(NAME_KEYED, value);
167
+ return isQueueInstance(QUEUE_NAME_KEYED, value);
189
168
  }
190
169
  /**
191
170
  * Is the value a queue?
@@ -194,13 +173,13 @@ function isKeyedQueue(value) {
194
173
  * @returns `true` if the value is a queue, otherwise `false`
195
174
  */
196
175
  function isQueue(value) {
197
- return isQueueInstance(NAME_QUEUE, value);
176
+ return isQueueInstance(QUEUE_NAME_QUEUE, value);
198
177
  }
199
178
  function isQueueInstance(name, value) {
200
- return typeof value === "object" && value != null && value[KEY_QUEUE] === name;
179
+ return typeof value === "object" && value != null && value[QUEUE_PROPERTY] === name;
201
180
  }
202
181
  function keyedQueue(callback, options) {
203
- if (typeof callback !== "function") throw new TypeError(MESSAGE_CALLBACK);
182
+ if (typeof callback !== "function") throw new TypeError(QUEUE_MESSAGE_CALLBACK);
204
183
  const state = {
205
184
  callback,
206
185
  options: getOptions(options),
@@ -208,26 +187,17 @@ function keyedQueue(callback, options) {
208
187
  };
209
188
  const instance = {
210
189
  add: (key, parameters, signal) => getQueue(state, key, true).add(parameters, signal),
211
- clear: (key) => {
212
- handleQueues(state, HANDLE_CLEAR, key);
213
- },
190
+ clear: (key) => handleQueues(state, QUEUE_HANDLE_CLEAR, key),
214
191
  get: (key) => getQueue(state, key),
215
- pause: (key) => {
216
- handleQueues(state, HANDLE_PAUSE, key);
217
- },
192
+ pause: (key) => handleQueues(state, QUEUE_HANDLE_PAUSE, key),
218
193
  remove: (key, id) => removeQueue(state, key, id),
219
- resume: (key) => {
220
- handleQueues(state, HANDLE_RESUME, key);
221
- }
194
+ resume: (key) => handleQueues(state, QUEUE_HANDLE_RESUME, key)
222
195
  };
223
196
  Object.defineProperties(instance, {
224
- [KEY_QUEUE]: {
225
- enumerable: false,
226
- value: NAME_KEYED
227
- },
197
+ [QUEUE_PROPERTY]: { value: QUEUE_NAME_KEYED },
228
198
  active: {
229
199
  enumerable: true,
230
- get: () => getStatus(state, STATUS_ACTIVE)
200
+ get: () => getStatus(state, QUEUE_STATUS_ACTIVE)
231
201
  },
232
202
  autostart: {
233
203
  enumerable: true,
@@ -239,15 +209,15 @@ function keyedQueue(callback, options) {
239
209
  },
240
210
  empty: {
241
211
  enumerable: true,
242
- get: () => getStatus(state, STATUS_EMPTY)
212
+ get: () => getStatus(state, QUEUE_STATUS_EMPTY)
243
213
  },
244
214
  full: {
245
215
  enumerable: true,
246
- get: () => getStatus(state, STATUS_FULL)
216
+ get: () => getStatus(state, QUEUE_STATUS_FULL)
247
217
  },
248
218
  items: {
249
219
  enumerable: true,
250
- get: () => getItems(state)
220
+ get: () => getQueueItems(state)
251
221
  },
252
222
  keys: {
253
223
  enumerable: true,
@@ -259,7 +229,7 @@ function keyedQueue(callback, options) {
259
229
  },
260
230
  paused: {
261
231
  enumerable: true,
262
- get: () => getStatus(state, STATUS_PAUSED)
232
+ get: () => getStatus(state, QUEUE_STATUS_PAUSED)
263
233
  },
264
234
  queues: {
265
235
  enumerable: true,
@@ -274,7 +244,7 @@ function queue(callback, options) {
274
244
  queue.keyed = keyedQueue;
275
245
  function removeQueue(state, key, id) {
276
246
  if (key == null) {
277
- handleQueues(state, HANDLE_CLEAR);
247
+ handleQueues(state, QUEUE_HANDLE_CLEAR);
278
248
  state.queues.clear();
279
249
  return;
280
250
  }
@@ -287,6 +257,24 @@ function removeQueue(state, key, id) {
287
257
  queue.clear();
288
258
  state.queues.delete(key);
289
259
  }
260
+ function removeQueued(state, id) {
261
+ const index = state.items.findIndex((item) => item.id === id);
262
+ if (index > -1) {
263
+ const { aborter, reject } = state.items.splice(index, 1)[0];
264
+ aborter?.cancel();
265
+ reject(new QueueError(QUEUE_MESSAGE_REMOVE));
266
+ }
267
+ }
268
+ function resumeQueue(state) {
269
+ if (state.paused) {
270
+ const handled = state.handled.splice(0);
271
+ const { length } = handled;
272
+ for (let index = 0; index < length; index += 1) handled[index]();
273
+ }
274
+ state.paused = false;
275
+ const length = Math.min(state.options.concurrency, state.items.length);
276
+ for (let index = 0; index < length; index += 1) run(state);
277
+ }
290
278
  async function run(state) {
291
279
  if (state.paused || state.runners >= state.options.concurrency) return;
292
280
  state.runners += 1;
@@ -295,7 +283,7 @@ async function run(state) {
295
283
  let error = false;
296
284
  let result;
297
285
  try {
298
- if (!(item.signal?.aborted ?? false)) {
286
+ if (!(item.aborter?.signal?.aborted ?? false)) {
299
287
  const parameters = item.key == null ? item.parameters : [item.key, ...item.parameters];
300
288
  result = await state.callback(...parameters);
301
289
  }
@@ -305,9 +293,7 @@ async function run(state) {
305
293
  }
306
294
  if (state.paused) {
307
295
  const paused = item;
308
- state.handled.push(() => {
309
- handleQueuedResult(paused, error, result);
310
- });
296
+ state.handled.push(() => handleQueuedResult(paused, error, result));
311
297
  break;
312
298
  }
313
299
  handleQueuedResult(item, error, result);
@@ -315,23 +301,21 @@ async function run(state) {
315
301
  }
316
302
  state.runners -= 1;
317
303
  }
318
- const ERROR_NAME = "QueueError";
319
- const EVENT_NAME = "abort";
320
- const EVENT_OPTIONS = { once: true };
321
- const KEY_QUEUE = "$queue";
322
- const HANDLE_CLEAR = "clear";
323
- const HANDLE_PAUSE = "pause";
324
- const HANDLE_RESUME = "resume";
325
- const MESSAGE_CALLBACK = "A Queue requires a callback function";
326
- const MESSAGE_CLEAR = "Queue was cleared";
327
- const MESSAGE_KEY = "Key must be a non-empty string";
328
- const MESSAGE_MAXIMUM = "Queue has reached its maximum size";
329
- const MESSAGE_REMOVE = "Item removed from queue";
330
- const NAME_KEYED = "keyedQueue";
331
- const NAME_QUEUE = "queue";
332
- const STATUS_ACTIVE = "active";
333
- const STATUS_EMPTY = "empty";
334
- const STATUS_FULL = "full";
335
- const STATUS_PAUSED = "paused";
304
+ const QUEUE_ERROR_NAME = "QueueError";
305
+ const QUEUE_PROPERTY = "$queue";
306
+ const QUEUE_HANDLE_CLEAR = "clear";
307
+ const QUEUE_HANDLE_PAUSE = "pause";
308
+ const QUEUE_HANDLE_RESUME = "resume";
309
+ const QUEUE_MESSAGE_CALLBACK = "A Queue requires a callback function";
310
+ const QUEUE_MESSAGE_CLEAR = "Queue was cleared";
311
+ const QUEUE_MESSAGE_KEY = "Key must be a non-empty string";
312
+ const QUEUE_MESSAGE_MAXIMUM = "Queue has reached its maximum size";
313
+ const QUEUE_MESSAGE_REMOVE = "Item removed from queue";
314
+ const QUEUE_NAME_KEYED = "keyedQueue";
315
+ const QUEUE_NAME_QUEUE = "queue";
316
+ const QUEUE_STATUS_ACTIVE = "active";
317
+ const QUEUE_STATUS_EMPTY = "empty";
318
+ const QUEUE_STATUS_FULL = "full";
319
+ const QUEUE_STATUS_PAUSED = "paused";
336
320
  //#endregion
337
321
  export { QueueError, isKeyedQueue, isQueue, isQueueInstance, keyedQueue, queue };
package/dist/random.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { getRandomFloatingNumber, getRandomInteger } from "./internal/random.mjs";
2
2
  import { shuffle } from "./internal/array/shuffle.mjs";
3
- import { join } from "./internal/string.mjs";
3
+ import { join } from "./internal/string/misc.mjs";
4
4
  //#region src/random.ts
5
5
  /**
6
6
  * Get a random boolean
@@ -8,7 +8,7 @@ import { join } from "./internal/string.mjs";
8
8
  * @returns Random boolean
9
9
  */
10
10
  function getRandomBoolean() {
11
- return Math.random() > BOOLEAN_MODIFIER;
11
+ return Math.random() > RANDOM_BOOLEAN_MODIFIER;
12
12
  }
13
13
  /**
14
14
  * Get a random string of characters with a specified length
@@ -19,7 +19,7 @@ function getRandomBoolean() {
19
19
  */
20
20
  function getRandomCharacters(length, selection) {
21
21
  if (typeof length !== "number" || length <= 0) return "";
22
- const actual = typeof selection === "string" && selection.length > 0 ? selection : ALPHABET;
22
+ const actual = typeof selection === "string" && selection.length > 0 ? selection : RANDOM_ALPHABET;
23
23
  let characters = "";
24
24
  for (let index = 0; index < length; index += 1) characters += actual.charAt(getRandomInteger(0, actual.length - 1));
25
25
  return characters;
@@ -39,7 +39,7 @@ function getRandomColor(prefix) {
39
39
  * @returns Random hexadecimal character from `0-9` and `A-F`
40
40
  */
41
41
  function getRandomHex() {
42
- return HEX_CHARACTERS[getRandomInteger(0, HEX_MAXIMUM)];
42
+ return RANDOM_HEX_CHARACTERS[getRandomInteger(0, RANDOM_HEX_MAXIMUM)];
43
43
  }
44
44
  /**
45
45
  * Get a random item from an array
@@ -57,9 +57,9 @@ function getRandomItems(array, amount) {
57
57
  if (amount === 1) return [array[getRandomInteger(0, array.length - 1)]];
58
58
  return typeof amount !== "number" || amount <= 0 || amount >= array.length ? shuffle(array) : shuffle(array).slice(0, amount);
59
59
  }
60
- const ALPHABET = "abcdefghijklmnopqrstuvwxyz";
61
- const BOOLEAN_MODIFIER = .5;
62
- const HEX_CHARACTERS = "0123456789ABCDEF";
63
- const HEX_MAXIMUM = 15;
60
+ const RANDOM_ALPHABET = "abcdefghijklmnopqrstuvwxyz";
61
+ const RANDOM_BOOLEAN_MODIFIER = .5;
62
+ const RANDOM_HEX_CHARACTERS = "0123456789ABCDEF";
63
+ const RANDOM_HEX_MAXIMUM = 15;
64
64
  //#endregion
65
65
  export { getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems };
@@ -1,4 +1,4 @@
1
- import { ExtendedResult, Result } from "./models.mjs";
1
+ import { ExtendedResult, Result } from "../internal/result/models.mjs";
2
2
  //#region src/result/index.d.ts
3
3
  /**
4
4
  * Executes a _Promise_, catching any errors, and returns a result
@@ -53,8 +53,5 @@ declare function attempt<Value, E>(callback: () => Value, error: E): ExtendedRes
53
53
  * @returns Callback result
54
54
  */
55
55
  declare function attempt<Value>(callback: () => Value): Result<Value, Error>;
56
- declare namespace attempt {
57
- var async: typeof asyncAttempt;
58
- }
59
56
  //#endregion
60
57
  export { asyncAttempt, attempt };
@@ -1,4 +1,4 @@
1
- import { getError, ok } from "./misc.mjs";
1
+ import { getError, ok } from "../internal/result/misc.mjs";
2
2
  //#region src/result/index.ts
3
3
  async function asyncAttempt(value, err) {
4
4
  try {
@@ -17,6 +17,6 @@ function attempt(callback, err) {
17
17
  return getError(err ?? thrown, err == null ? void 0 : thrown);
18
18
  }
19
19
  }
20
- attempt.async = asyncAttempt;
20
+ Object.defineProperty(attempt, "async", { value: asyncAttempt });
21
21
  //#endregion
22
22
  export { asyncAttempt, attempt };
@@ -1,4 +1,4 @@
1
- import { AnyResult, ResultMatch } from "./models.mjs";
1
+ import { AnyResult, ResultMatch } from "../internal/result/models.mjs";
2
2
  //#region src/result/match.d.ts
3
3
  /**
4
4
  * Handles a _Result_ with match callbacks
@@ -38,8 +38,5 @@ declare function matchResult<Value, Returned, E = Error>(result: AnyResult<Value
38
38
  * @returns Matched value
39
39
  */
40
40
  declare function matchResult<Value, Returned, E = Error>(result: AnyResult<Value, E> | (() => AnyResult<Value, E>), ok: ResultMatch<Value, Returned, E>['ok'], error: ResultMatch<Value, Returned, E>['error']): Returned;
41
- declare namespace matchResult {
42
- var async: typeof asyncMatchResult;
43
- }
44
41
  //#endregion
45
42
  export { asyncMatchResult, matchResult };
@@ -1,11 +1,11 @@
1
- import { isOk, isResult } from "../internal/result.mjs";
1
+ import { isOk, isResult } from "../internal/result/misc.mjs";
2
2
  //#region src/result/match.ts
3
3
  async function asyncMatchResult(result, first, error) {
4
4
  let value;
5
5
  if (typeof result === "function") value = await result();
6
6
  else if (result instanceof Promise) value = await result;
7
7
  else value = result;
8
- if (!isResult(value)) throw new Error(MESSAGE_RESULT);
8
+ if (!isResult(value)) throw new Error(MATCH_MESSAGE);
9
9
  const hasObj = typeof first === "object" && first !== null;
10
10
  const okHandler = hasObj ? first.ok : first;
11
11
  const errorHandler = hasObj ? first.error : error;
@@ -14,14 +14,14 @@ async function asyncMatchResult(result, first, error) {
14
14
  }
15
15
  function matchResult(result, first, error) {
16
16
  const value = typeof result === "function" ? result() : result;
17
- if (!isResult(value)) throw new Error(MESSAGE_RESULT);
17
+ if (!isResult(value)) throw new Error(MATCH_MESSAGE);
18
18
  const hasObj = typeof first === "object" && first !== null;
19
19
  const okHandler = hasObj ? first.ok : first;
20
20
  const errorHandler = hasObj ? first.error : error;
21
21
  if (isOk(value)) return okHandler(value.value);
22
22
  return errorHandler(value.error, value.original);
23
23
  }
24
- matchResult.async = asyncMatchResult;
25
- const MESSAGE_RESULT = "`result.match` expected a Result or a function that returns a Result";
24
+ const MATCH_MESSAGE = "`result.match` expected a Result or a function that returns a Result";
25
+ Object.defineProperty(matchResult, "async", { value: asyncMatchResult });
26
26
  //#endregion
27
27
  export { asyncMatchResult, matchResult };
@@ -1,29 +1,6 @@
1
- import { AnyResult, Err, ExtendedErr, Ok, Result } from "./models.mjs";
2
- import { isError, isOk, isResult } from "../internal/result.mjs";
1
+ import { AnyResult } from "../internal/result/models.mjs";
2
+ import { error, isError, isOk, isResult, ok, unwrap } from "../internal/result/misc.mjs";
3
3
  //#region src/result/misc.d.ts
4
- /**
5
- * Creates an extended error result
6
- *
7
- * @param value Error value
8
- * @param original Original error
9
- * @returns Error result
10
- */
11
- declare function error<E>(value: E, original: Error): ExtendedErr<E>;
12
- /**
13
- * Creates an error result
14
- *
15
- * @param value Error value
16
- * @returns Error result
17
- */
18
- declare function error<E>(value: E): Err<E>;
19
- declare function getError<E>(value: E, original?: Error): Err<E> | ExtendedErr<E>;
20
- /**
21
- * Creates an ok result
22
- *
23
- * @param value Value
24
- * @returns Ok result
25
- */
26
- declare function ok<Value>(value: Value): Ok<Value>;
27
4
  /**
28
5
  * Converts a result to a _Promise_
29
6
  *
@@ -42,21 +19,5 @@ declare function toPromise<Value, E = Error>(callback: () => AnyResult<Value, E>
42
19
  * @returns Promised result
43
20
  */
44
21
  declare function toPromise<Value, E = Error>(result: AnyResult<Value, E>): Promise<Value>;
45
- /**
46
- * Gets the value of an ok result _(or a default value)_
47
- *
48
- * @param value _Result_ to unwrap
49
- * @param defaultValue Default value
50
- * @returns Value of the _Result_ _(or the default value)_
51
- */
52
- declare function unwrap<Value, E = Error>(value: Result<Value, E>, defaultValue: Value): Value;
53
- /**
54
- * Gets the value of an ok result _(or a default value)_
55
- *
56
- * @param value _Result_ to unwrap
57
- * @param defaultValue Default value
58
- * @returns Value of the _Result_ _(or the default value)_
59
- */
60
- declare function unwrap(value: unknown, defaultValue: unknown): unknown;
61
22
  //#endregion
62
- export { error, getError, isError, isOk, isResult, ok, toPromise, unwrap };
23
+ export { error, isError, isOk, isResult, ok, toPromise, unwrap };
@@ -1,28 +1,5 @@
1
- import { isError, isOk, isResult } from "../internal/result.mjs";
1
+ import { error, isError, isOk, isResult, ok, unwrap } from "../internal/result/misc.mjs";
2
2
  //#region src/result/misc.ts
3
- function error(value, original) {
4
- return getError(value, original);
5
- }
6
- function getError(value, original) {
7
- const errorResult = {
8
- error: value,
9
- ok: false
10
- };
11
- if (original instanceof Error) errorResult.original = original;
12
- return errorResult;
13
- }
14
- /**
15
- * Creates an ok result
16
- *
17
- * @param value Value
18
- * @returns Ok result
19
- */
20
- function ok(value) {
21
- return {
22
- ok: true,
23
- value
24
- };
25
- }
26
3
  /**
27
4
  * Converts a _Result_ to a _Promise_
28
5
  *
@@ -33,12 +10,9 @@ function ok(value) {
33
10
  */
34
11
  async function toPromise(result) {
35
12
  const actual = typeof result === "function" ? result() : result;
36
- if (!isResult(actual)) return Promise.reject(new Error(MESSAGE_PROMISE_RESULT));
13
+ if (!isResult(actual)) return Promise.reject(new Error(RESULT_MESSAGE_PROMISE));
37
14
  return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
38
15
  }
39
- function unwrap(value, defaultValue) {
40
- return isOk(value) ? value.value : defaultValue;
41
- }
42
- const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
16
+ const RESULT_MESSAGE_PROMISE = "toPromise expected to receive a Result";
43
17
  //#endregion
44
- export { error, getError, isError, isOk, isResult, ok, toPromise, unwrap };
18
+ export { error, isError, isOk, isResult, ok, toPromise, unwrap };
@@ -1,5 +1,5 @@
1
1
  import { GenericCallback } from "../../models.mjs";
2
- import { Result, UnwrapValue } from "../models.mjs";
2
+ import { Result, UnwrapValue } from "../../internal/result/models.mjs";
3
3
  //#region src/result/work/flow.d.ts
4
4
  /**
5
5
  * A synchronous _Flow_, a function that attempts to pipe values through a series of functions
@@ -177,8 +177,5 @@ declare function attemptFlow<First extends GenericCallback>(first: First, ...fns
177
177
  * @returns _Flow_ function
178
178
  */
179
179
  declare function attemptFlow(...fns: GenericCallback[]): (...args: unknown[]) => Result<unknown>;
180
- declare namespace attemptFlow {
181
- var async: typeof attemptAsyncFlow;
182
- }
183
180
  //#endregion
184
181
  export { AttemptFlow, AttemptFlowPromise, attemptAsyncFlow, attemptFlow };