@oscarpalmer/atoms 0.193.0 → 0.194.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 (204) hide show
  1. package/dist/array/difference.mjs +2 -2
  2. package/dist/array/intersection.mjs +2 -2
  3. package/dist/array/match.mjs +13 -13
  4. package/dist/array/slice.mjs +5 -5
  5. package/dist/array/sort.d.mts +5 -1
  6. package/dist/array/sort.mjs +4 -2
  7. package/dist/array/union.mjs +2 -2
  8. package/dist/beacon.d.mts +8 -1
  9. package/dist/beacon.mjs +52 -60
  10. package/dist/color/constants.d.mts +1 -1
  11. package/dist/color/constants.mjs +3 -5
  12. package/dist/color/instance.mjs +34 -41
  13. package/dist/color/misc/format.d.mts +3 -2
  14. package/dist/color/misc/format.mjs +4 -1
  15. package/dist/color/misc/is.d.mts +9 -1
  16. package/dist/color/misc/is.mjs +11 -1
  17. package/dist/color/misc/state.d.mts +6 -6
  18. package/dist/color/misc/state.mjs +11 -14
  19. package/dist/color/models.d.mts +23 -68
  20. package/dist/function/assert.mjs +2 -2
  21. package/dist/function/limit.d.mts +0 -6
  22. package/dist/function/limit.mjs +2 -2
  23. package/dist/function/memoize.mjs +19 -32
  24. package/dist/function/once.d.mts +0 -3
  25. package/dist/function/once.mjs +16 -13
  26. package/dist/function/retry.d.mts +1 -24
  27. package/dist/function/retry.mjs +1 -1
  28. package/dist/function/work.mjs +13 -11
  29. package/dist/herald.d.mts +30 -31
  30. package/dist/herald.mjs +74 -56
  31. package/dist/index.d.mts +100 -185
  32. package/dist/index.mjs +680 -702
  33. package/dist/internal/abort.d.mts +10 -0
  34. package/dist/internal/abort.mjs +14 -0
  35. package/dist/internal/array/chunk.mjs +2 -2
  36. package/dist/internal/array/find.mjs +2 -2
  37. package/dist/internal/array/sets.d.mts +4 -4
  38. package/dist/internal/array/sets.mjs +7 -7
  39. package/dist/internal/function/timer.mjs +19 -15
  40. package/dist/internal/number.mjs +7 -7
  41. package/dist/internal/result.mjs +3 -3
  42. package/dist/internal/sized.mjs +4 -4
  43. package/dist/internal/string.mjs +4 -4
  44. package/dist/internal/subscription.d.mts +24 -8
  45. package/dist/internal/subscription.mjs +49 -36
  46. package/dist/internal/value/equal.mjs +6 -6
  47. package/dist/internal/value/misc.mjs +14 -14
  48. package/dist/internal/value/set.mjs +2 -2
  49. package/dist/logger.mjs +15 -39
  50. package/dist/promise/constants.d.mts +17 -0
  51. package/dist/promise/constants.mjs +14 -0
  52. package/dist/promise/delay.mjs +7 -10
  53. package/dist/promise/helpers.mjs +1 -1
  54. package/dist/promise/index.mjs +14 -17
  55. package/dist/promise/misc.d.mts +2 -1
  56. package/dist/promise/misc.mjs +8 -7
  57. package/dist/promise/models.d.mts +4 -16
  58. package/dist/promise/models.mjs +4 -13
  59. package/dist/promise/timed.mjs +9 -10
  60. package/dist/query.mjs +15 -15
  61. package/dist/queue.mjs +103 -116
  62. package/dist/random.mjs +7 -7
  63. package/dist/result/index.d.mts +0 -3
  64. package/dist/result/index.mjs +1 -1
  65. package/dist/result/match.d.mts +0 -3
  66. package/dist/result/match.mjs +4 -4
  67. package/dist/result/misc.mjs +2 -2
  68. package/dist/result/work/flow.d.mts +0 -3
  69. package/dist/result/work/flow.mjs +5 -5
  70. package/dist/result/work/pipe.d.mts +0 -3
  71. package/dist/result/work/pipe.mjs +3 -3
  72. package/dist/string/case.mjs +20 -20
  73. package/dist/string/fuzzy.mjs +23 -18
  74. package/dist/string/index.mjs +7 -7
  75. package/dist/string/normalize.mjs +14 -14
  76. package/dist/string/template.mjs +2 -2
  77. package/dist/value/clone.mjs +10 -10
  78. package/dist/value/smush.mjs +2 -2
  79. package/package.json +13 -5
  80. package/src/array/difference.ts +0 -73
  81. package/src/array/exists.ts +0 -93
  82. package/src/array/filter.ts +0 -182
  83. package/src/array/find.ts +0 -183
  84. package/src/array/first.ts +0 -196
  85. package/src/array/flatten.ts +0 -20
  86. package/src/array/from.ts +0 -129
  87. package/src/array/get.ts +0 -131
  88. package/src/array/group-by.ts +0 -369
  89. package/src/array/index.ts +0 -26
  90. package/src/array/insert.ts +0 -52
  91. package/src/array/intersection.ts +0 -72
  92. package/src/array/last.ts +0 -194
  93. package/src/array/match.ts +0 -436
  94. package/src/array/move.ts +0 -315
  95. package/src/array/partition.ts +0 -91
  96. package/src/array/push.ts +0 -23
  97. package/src/array/reverse.ts +0 -33
  98. package/src/array/select.ts +0 -260
  99. package/src/array/single.ts +0 -93
  100. package/src/array/slice.ts +0 -335
  101. package/src/array/sort.ts +0 -607
  102. package/src/array/splice.ts +0 -106
  103. package/src/array/swap.ts +0 -322
  104. package/src/array/to-map.ts +0 -371
  105. package/src/array/to-record.ts +0 -351
  106. package/src/array/to-set.ts +0 -80
  107. package/src/array/toggle.ts +0 -79
  108. package/src/array/union.ts +0 -72
  109. package/src/array/unique.ts +0 -67
  110. package/src/array/update.ts +0 -75
  111. package/src/beacon.ts +0 -378
  112. package/src/color/constants.ts +0 -137
  113. package/src/color/index.ts +0 -83
  114. package/src/color/instance.ts +0 -162
  115. package/src/color/misc/alpha.ts +0 -56
  116. package/src/color/misc/format.ts +0 -29
  117. package/src/color/misc/get.ts +0 -210
  118. package/src/color/misc/is.ts +0 -221
  119. package/src/color/misc/state.ts +0 -243
  120. package/src/color/models.ts +0 -389
  121. package/src/color/space/hex.ts +0 -184
  122. package/src/color/space/hsl.ts +0 -174
  123. package/src/color/space/hwb.ts +0 -153
  124. package/src/color/space/rgb.ts +0 -240
  125. package/src/function/assert.ts +0 -174
  126. package/src/function/index.ts +0 -2
  127. package/src/function/limit.ts +0 -83
  128. package/src/function/memoize.ts +0 -202
  129. package/src/function/once.ts +0 -200
  130. package/src/function/retry.ts +0 -175
  131. package/src/function/work.ts +0 -1007
  132. package/src/herald.ts +0 -216
  133. package/src/index.ts +0 -68
  134. package/src/internal/array/callbacks.ts +0 -46
  135. package/src/internal/array/chunk.ts +0 -51
  136. package/src/internal/array/compact.ts +0 -56
  137. package/src/internal/array/find.ts +0 -200
  138. package/src/internal/array/group.ts +0 -42
  139. package/src/internal/array/index-of.ts +0 -182
  140. package/src/internal/array/insert.ts +0 -80
  141. package/src/internal/array/overlap.ts +0 -35
  142. package/src/internal/array/sets.ts +0 -74
  143. package/src/internal/array/shuffle.ts +0 -33
  144. package/src/internal/array/update.ts +0 -52
  145. package/src/internal/function/misc.ts +0 -8
  146. package/src/internal/function/timer.ts +0 -168
  147. package/src/internal/is.ts +0 -244
  148. package/src/internal/math/aggregate.ts +0 -164
  149. package/src/internal/math/misc.ts +0 -28
  150. package/src/internal/number.ts +0 -129
  151. package/src/internal/random.ts +0 -49
  152. package/src/internal/result.ts +0 -92
  153. package/src/internal/sized.ts +0 -25
  154. package/src/internal/string.ts +0 -128
  155. package/src/internal/subscription.ts +0 -264
  156. package/src/internal/value/compare.ts +0 -170
  157. package/src/internal/value/equal.ts +0 -465
  158. package/src/internal/value/get.ts +0 -57
  159. package/src/internal/value/handlers.ts +0 -95
  160. package/src/internal/value/has.ts +0 -118
  161. package/src/internal/value/misc.ts +0 -125
  162. package/src/internal/value/partial.ts +0 -46
  163. package/src/internal/value/set.ts +0 -132
  164. package/src/is.ts +0 -182
  165. package/src/logger.ts +0 -230
  166. package/src/math.ts +0 -281
  167. package/src/models.ts +0 -286
  168. package/src/number.ts +0 -1
  169. package/src/promise/delay.ts +0 -62
  170. package/src/promise/helpers.ts +0 -96
  171. package/src/promise/index.ts +0 -300
  172. package/src/promise/misc.ts +0 -96
  173. package/src/promise/models.ts +0 -195
  174. package/src/promise/timed.ts +0 -91
  175. package/src/query.ts +0 -147
  176. package/src/queue.ts +0 -814
  177. package/src/random.ts +0 -125
  178. package/src/result/index.ts +0 -105
  179. package/src/result/match.ts +0 -124
  180. package/src/result/misc.ts +0 -129
  181. package/src/result/models.ts +0 -83
  182. package/src/result/work/flow.ts +0 -488
  183. package/src/result/work/pipe.ts +0 -496
  184. package/src/sized/map.ts +0 -110
  185. package/src/sized/set.ts +0 -107
  186. package/src/string/case.ts +0 -236
  187. package/src/string/fuzzy.ts +0 -444
  188. package/src/string/index.ts +0 -199
  189. package/src/string/match.ts +0 -80
  190. package/src/string/normalize.ts +0 -205
  191. package/src/string/template.ts +0 -161
  192. package/src/value/clone.ts +0 -319
  193. package/src/value/collection.ts +0 -63
  194. package/src/value/diff.ts +0 -232
  195. package/src/value/freeze.ts +0 -322
  196. package/src/value/handle.ts +0 -3
  197. package/src/value/index.ts +0 -5
  198. package/src/value/merge.ts +0 -278
  199. package/src/value/omit.ts +0 -20
  200. package/src/value/pick.ts +0 -20
  201. package/src/value/shake.ts +0 -45
  202. package/src/value/smush.ts +0 -89
  203. package/src/value/transform.ts +0 -153
  204. package/src/value/unsmush.ts +0 -84
package/dist/queue.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { createAborter } from "./internal/abort.mjs";
1
2
  import { getNumberOrDefault } from "./internal/number.mjs";
2
3
  //#region src/queue.ts
3
4
  /**
@@ -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
@@ -125,12 +107,6 @@ function createQueue(callback, options, key) {
125
107
  function getBooleanOrDefault(value, defaultValue) {
126
108
  return typeof value === "boolean" ? value : defaultValue;
127
109
  }
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
110
  function getOptions(input) {
135
111
  const options = typeof input === "object" && input != null ? input : {};
136
112
  return {
@@ -140,7 +116,7 @@ function getOptions(input) {
140
116
  };
141
117
  }
142
118
  function getQueue(state, key, add) {
143
- if (typeof key !== "string" || key.trim().length === 0) throw new TypeError(MESSAGE_KEY);
119
+ if (typeof key !== "string" || key.trim().length === 0) throw new TypeError(QUEUE_MESSAGE_KEY);
144
120
  let queue = state.queues.get(key);
145
121
  if (queue == null && add === true) {
146
122
  queue = createQueue(state.callback, state.options, key);
@@ -148,6 +124,12 @@ function getQueue(state, key, add) {
148
124
  }
149
125
  return queue;
150
126
  }
127
+ function getQueueItems(state) {
128
+ const size = {};
129
+ const queues = state.queues.entries();
130
+ for (const [key, queue] of queues) size[key] = queue.size;
131
+ return size;
132
+ }
151
133
  function getStatus(state, status) {
152
134
  const queues = state.queues.entries();
153
135
  const result = [];
@@ -155,8 +137,8 @@ function getStatus(state, status) {
155
137
  return result;
156
138
  }
157
139
  function handleQueuedResult(item, error, result) {
158
- item.signal?.removeEventListener(EVENT_NAME, item.abort);
159
- if (item.signal?.aborted ?? false) {
140
+ item.aborter?.cancel();
141
+ if (item.aborter?.signal?.aborted ?? false) {
160
142
  item.reject();
161
143
  return;
162
144
  }
@@ -185,7 +167,7 @@ function identify(state) {
185
167
  * @returns `true` if the value is a keyed queue, otherwise `false`
186
168
  */
187
169
  function isKeyedQueue(value) {
188
- return isQueueInstance(NAME_KEYED, value);
170
+ return isQueueInstance(QUEUE_NAME_KEYED, value);
189
171
  }
190
172
  /**
191
173
  * Is the value a queue?
@@ -194,13 +176,13 @@ function isKeyedQueue(value) {
194
176
  * @returns `true` if the value is a queue, otherwise `false`
195
177
  */
196
178
  function isQueue(value) {
197
- return isQueueInstance(NAME_QUEUE, value);
179
+ return isQueueInstance(QUEUE_NAME_QUEUE, value);
198
180
  }
199
181
  function isQueueInstance(name, value) {
200
- return typeof value === "object" && value != null && value[KEY_QUEUE] === name;
182
+ return typeof value === "object" && value != null && value[QUEUE_PROPERTY] === name;
201
183
  }
202
184
  function keyedQueue(callback, options) {
203
- if (typeof callback !== "function") throw new TypeError(MESSAGE_CALLBACK);
185
+ if (typeof callback !== "function") throw new TypeError(QUEUE_MESSAGE_CALLBACK);
204
186
  const state = {
205
187
  callback,
206
188
  options: getOptions(options),
@@ -208,26 +190,17 @@ function keyedQueue(callback, options) {
208
190
  };
209
191
  const instance = {
210
192
  add: (key, parameters, signal) => getQueue(state, key, true).add(parameters, signal),
211
- clear: (key) => {
212
- handleQueues(state, HANDLE_CLEAR, key);
213
- },
193
+ clear: (key) => handleQueues(state, QUEUE_HANDLE_CLEAR, key),
214
194
  get: (key) => getQueue(state, key),
215
- pause: (key) => {
216
- handleQueues(state, HANDLE_PAUSE, key);
217
- },
195
+ pause: (key) => handleQueues(state, QUEUE_HANDLE_PAUSE, key),
218
196
  remove: (key, id) => removeQueue(state, key, id),
219
- resume: (key) => {
220
- handleQueues(state, HANDLE_RESUME, key);
221
- }
197
+ resume: (key) => handleQueues(state, QUEUE_HANDLE_RESUME, key)
222
198
  };
223
199
  Object.defineProperties(instance, {
224
- [KEY_QUEUE]: {
225
- enumerable: false,
226
- value: NAME_KEYED
227
- },
200
+ [QUEUE_PROPERTY]: { value: QUEUE_NAME_KEYED },
228
201
  active: {
229
202
  enumerable: true,
230
- get: () => getStatus(state, STATUS_ACTIVE)
203
+ get: () => getStatus(state, QUEUE_STATUS_ACTIVE)
231
204
  },
232
205
  autostart: {
233
206
  enumerable: true,
@@ -239,15 +212,15 @@ function keyedQueue(callback, options) {
239
212
  },
240
213
  empty: {
241
214
  enumerable: true,
242
- get: () => getStatus(state, STATUS_EMPTY)
215
+ get: () => getStatus(state, QUEUE_STATUS_EMPTY)
243
216
  },
244
217
  full: {
245
218
  enumerable: true,
246
- get: () => getStatus(state, STATUS_FULL)
219
+ get: () => getStatus(state, QUEUE_STATUS_FULL)
247
220
  },
248
221
  items: {
249
222
  enumerable: true,
250
- get: () => getItems(state)
223
+ get: () => getQueueItems(state)
251
224
  },
252
225
  keys: {
253
226
  enumerable: true,
@@ -259,7 +232,7 @@ function keyedQueue(callback, options) {
259
232
  },
260
233
  paused: {
261
234
  enumerable: true,
262
- get: () => getStatus(state, STATUS_PAUSED)
235
+ get: () => getStatus(state, QUEUE_STATUS_PAUSED)
263
236
  },
264
237
  queues: {
265
238
  enumerable: true,
@@ -274,7 +247,7 @@ function queue(callback, options) {
274
247
  queue.keyed = keyedQueue;
275
248
  function removeQueue(state, key, id) {
276
249
  if (key == null) {
277
- handleQueues(state, HANDLE_CLEAR);
250
+ handleQueues(state, QUEUE_HANDLE_CLEAR);
278
251
  state.queues.clear();
279
252
  return;
280
253
  }
@@ -287,6 +260,24 @@ function removeQueue(state, key, id) {
287
260
  queue.clear();
288
261
  state.queues.delete(key);
289
262
  }
263
+ function removeQueued(state, id) {
264
+ const index = state.items.findIndex((item) => item.id === id);
265
+ if (index > -1) {
266
+ const { aborter, reject } = state.items.splice(index, 1)[0];
267
+ aborter?.cancel();
268
+ reject(new QueueError(QUEUE_MESSAGE_REMOVE));
269
+ }
270
+ }
271
+ function resumeQueue(state) {
272
+ if (state.paused) {
273
+ const handled = state.handled.splice(0);
274
+ const { length } = handled;
275
+ for (let index = 0; index < length; index += 1) handled[index]();
276
+ }
277
+ state.paused = false;
278
+ const length = Math.min(state.options.concurrency, state.items.length);
279
+ for (let index = 0; index < length; index += 1) run(state);
280
+ }
290
281
  async function run(state) {
291
282
  if (state.paused || state.runners >= state.options.concurrency) return;
292
283
  state.runners += 1;
@@ -295,7 +286,7 @@ async function run(state) {
295
286
  let error = false;
296
287
  let result;
297
288
  try {
298
- if (!(item.signal?.aborted ?? false)) {
289
+ if (!(item.aborter?.signal?.aborted ?? false)) {
299
290
  const parameters = item.key == null ? item.parameters : [item.key, ...item.parameters];
300
291
  result = await state.callback(...parameters);
301
292
  }
@@ -305,9 +296,7 @@ async function run(state) {
305
296
  }
306
297
  if (state.paused) {
307
298
  const paused = item;
308
- state.handled.push(() => {
309
- handleQueuedResult(paused, error, result);
310
- });
299
+ state.handled.push(() => handleQueuedResult(paused, error, result));
311
300
  break;
312
301
  }
313
302
  handleQueuedResult(item, error, result);
@@ -315,23 +304,21 @@ async function run(state) {
315
304
  }
316
305
  state.runners -= 1;
317
306
  }
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";
307
+ const QUEUE_ERROR_NAME = "QueueError";
308
+ const QUEUE_PROPERTY = "$queue";
309
+ const QUEUE_HANDLE_CLEAR = "clear";
310
+ const QUEUE_HANDLE_PAUSE = "pause";
311
+ const QUEUE_HANDLE_RESUME = "resume";
312
+ const QUEUE_MESSAGE_CALLBACK = "A Queue requires a callback function";
313
+ const QUEUE_MESSAGE_CLEAR = "Queue was cleared";
314
+ const QUEUE_MESSAGE_KEY = "Key must be a non-empty string";
315
+ const QUEUE_MESSAGE_MAXIMUM = "Queue has reached its maximum size";
316
+ const QUEUE_MESSAGE_REMOVE = "Item removed from queue";
317
+ const QUEUE_NAME_KEYED = "keyedQueue";
318
+ const QUEUE_NAME_QUEUE = "queue";
319
+ const QUEUE_STATUS_ACTIVE = "active";
320
+ const QUEUE_STATUS_EMPTY = "empty";
321
+ const QUEUE_STATUS_FULL = "full";
322
+ const QUEUE_STATUS_PAUSED = "paused";
336
323
  //#endregion
337
324
  export { QueueError, isKeyedQueue, isQueue, isQueueInstance, keyedQueue, queue };
package/dist/random.mjs CHANGED
@@ -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 };
@@ -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 };
@@ -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 };
@@ -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 };
@@ -5,7 +5,7 @@ async function asyncMatchResult(result, first, error) {
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 };
@@ -33,12 +33,12 @@ function ok(value) {
33
33
  */
34
34
  async function toPromise(result) {
35
35
  const actual = typeof result === "function" ? result() : result;
36
- if (!isResult(actual)) return Promise.reject(new Error(MESSAGE_PROMISE_RESULT));
36
+ if (!isResult(actual)) return Promise.reject(new Error(RESULT_MESSAGE_PROMISE));
37
37
  return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
38
38
  }
39
39
  function unwrap(value, defaultValue) {
40
40
  return isOk(value) ? value.value : defaultValue;
41
41
  }
42
- const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
42
+ const RESULT_MESSAGE_PROMISE = "toPromise expected to receive a Result";
43
43
  //#endregion
44
44
  export { error, getError, isError, isOk, isResult, ok, toPromise, unwrap };
@@ -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 };
@@ -1,11 +1,11 @@
1
1
  import { isError, isOk } from "../../internal/result.mjs";
2
- import { flow } from "../../function/work.mjs";
3
- import { attempt } from "../index.mjs";
2
+ import { asyncFlow, flow } from "../../function/work.mjs";
3
+ import { asyncAttempt, attempt } from "../index.mjs";
4
4
  //#region src/result/work/flow.ts
5
5
  function attemptAsyncFlow(...fns) {
6
6
  let Flow;
7
- return (...args) => attempt.async(() => {
8
- Flow ??= flow.async(...fns);
7
+ return (...args) => asyncAttempt(() => {
8
+ Flow ??= asyncFlow(...fns);
9
9
  return Flow(...args.map((value) => {
10
10
  if (isError(value)) throw value.error;
11
11
  return isOk(value) ? value.value : value;
@@ -22,6 +22,6 @@ function attemptFlow(...fns) {
22
22
  }));
23
23
  });
24
24
  }
25
- attemptFlow.async = attemptAsyncFlow;
25
+ Object.defineProperty(attemptFlow, "async", { value: attemptAsyncFlow });
26
26
  //#endregion
27
27
  export { attemptAsyncFlow, attemptFlow };
@@ -178,8 +178,5 @@ declare function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth
178
178
  * @returns _Piped_ result
179
179
  */
180
180
  declare function attemptPipe<Initial>(initial: GenericCallback | Initial | Result<Initial>, first?: (value: UnwrapValue<Initial>) => unknown, ...seconds: Array<(value: unknown) => unknown>): WrapValue<Initial>;
181
- declare namespace attemptPipe {
182
- var async: typeof attemptAsyncPipe;
183
- }
184
181
  //#endregion
185
182
  export { attemptAsyncPipe, attemptPipe };
@@ -1,9 +1,9 @@
1
1
  import { isError, isOk } from "../../internal/result.mjs";
2
2
  import { asyncPipe, pipe } from "../../function/work.mjs";
3
- import { attempt } from "../index.mjs";
3
+ import { asyncAttempt, attempt } from "../index.mjs";
4
4
  //#region src/result/work/pipe.ts
5
5
  async function attemptAsyncPipe(initial, first, ...seconds) {
6
- return attempt.async(() => {
6
+ return asyncAttempt(() => {
7
7
  if (isError(initial)) throw initial.error;
8
8
  const value = typeof initial === "function" ? initial() : isOk(initial) ? initial.value : initial;
9
9
  if (first == null) return value;
@@ -18,6 +18,6 @@ function attemptPipe(initial, first, ...seconds) {
18
18
  return pipe(value, ...[first, ...seconds]);
19
19
  });
20
20
  }
21
- attemptPipe.async = attemptAsyncPipe;
21
+ Object.defineProperty(attemptPipe, "async", { value: attemptAsyncPipe });
22
22
  //#endregion
23
23
  export { attemptAsyncPipe, attemptPipe };
@@ -8,7 +8,7 @@ import { memoize } from "../function/memoize.mjs";
8
8
  * @returns Camel-cased string
9
9
  */
10
10
  function camelCase(value) {
11
- return toCase(CASE_CAMEL, value, true, false);
11
+ return toCase(STRING_CASE_CAMEL, value, true, false);
12
12
  }
13
13
  /**
14
14
  * Capitalize the first letter of a string _(and lowercase the rest)_
@@ -28,7 +28,7 @@ function capitalize(value) {
28
28
  * @returns Kebab-cased string
29
29
  */
30
30
  function kebabCase(value) {
31
- return toCase(CASE_KEBAB, value, false, false);
31
+ return toCase(STRING_CASE_KEBAB, value, false, false);
32
32
  }
33
33
  /**
34
34
  * Convert a string to lower case
@@ -48,7 +48,7 @@ function lowerCase(value) {
48
48
  * @returns Pascal-cased string
49
49
  */
50
50
  function pascalCase(value) {
51
- return toCase(CASE_PASCAL, value, true, true);
51
+ return toCase(STRING_CASE_PASCAL, value, true, true);
52
52
  }
53
53
  /**
54
54
  * Convert a string to snake case _(this_is_snake_case)_
@@ -57,7 +57,7 @@ function pascalCase(value) {
57
57
  * @returns Snake-cased string
58
58
  */
59
59
  function snakeCase(value) {
60
- return toCase(CASE_SNAKE, value, false, false);
60
+ return toCase(STRING_CASE_SNAKE, value, false, false);
61
61
  }
62
62
  /**
63
63
  * Convert a string to title case _(Capitalizing Every Word)_
@@ -86,7 +86,7 @@ function toCaseCallback(value) {
86
86
  const partsLength = parts.length;
87
87
  const cased = [];
88
88
  for (let partIndex = 0; partIndex < partsLength; partIndex += 1) {
89
- const items = parts[partIndex].replace(EXPRESSION_ACRONYM, (full, one, two, three) => three === S ? full : `${one}-${two}${three}`).replace(EXPRESSION_CAMEL_CASE, REPLACEMENT_CAMEL_CASE).split("-");
89
+ const items = parts[partIndex].replace(STRING_EXPRESSION_ACRONYM, (full, one, two, three) => three === STRING_S ? full : `${one}-${two}${three}`).replace(STRING_EXPRESSION_CAMEL_CASE, STRING_REPLACEMENT_CAMEL_CASE).split("-");
90
90
  const itemsLength = items.length;
91
91
  const partResult = [];
92
92
  let itemCount = 0;
@@ -112,23 +112,23 @@ function upperCase(value) {
112
112
  memoizedUpperCase ??= memoize((v) => v.toLocaleUpperCase());
113
113
  return memoizedUpperCase.run(value);
114
114
  }
115
- const CASE_CAMEL = "camel";
116
- const CASE_KEBAB = "kebab";
117
- const CASE_PASCAL = "pascal";
118
- const CASE_SNAKE = "snake";
119
- const DELIMTER_EMPTY = "";
120
- const DELIMITER_HYPHEN = "-";
121
- const DELIMITER_UNDERSCORE = "_";
122
- const EXPRESSION_CAMEL_CASE = /(\p{Ll})(\p{Lu})/gu;
123
- const EXPRESSION_ACRONYM = /(\p{Lu}*)(\p{Lu})(\p{Ll}+)/gu;
124
- const REPLACEMENT_CAMEL_CASE = "$1-$2";
125
- const S = "s";
115
+ const STRING_CASE_CAMEL = "camel";
116
+ const STRING_CASE_KEBAB = "kebab";
117
+ const STRING_CASE_PASCAL = "pascal";
118
+ const STRING_CASE_SNAKE = "snake";
119
+ const STRING_DELIMTER_EMPTY = "";
120
+ const STRING_DELIMITER_HYPHEN = "-";
121
+ const STRING_DELIMITER_UNDERSCORE = "_";
122
+ const STRING_EXPRESSION_CAMEL_CASE = /(\p{Ll})(\p{Lu})/gu;
123
+ const STRING_EXPRESSION_ACRONYM = /(\p{Lu}*)(\p{Lu})(\p{Ll}+)/gu;
124
+ const STRING_REPLACEMENT_CAMEL_CASE = "$1-$2";
125
+ const STRING_S = "s";
126
126
  const caseMemoizers = {};
127
127
  const delimiters = {
128
- [CASE_CAMEL]: DELIMTER_EMPTY,
129
- [CASE_KEBAB]: DELIMITER_HYPHEN,
130
- [CASE_PASCAL]: DELIMTER_EMPTY,
131
- [CASE_SNAKE]: DELIMITER_UNDERSCORE
128
+ [STRING_CASE_CAMEL]: STRING_DELIMTER_EMPTY,
129
+ [STRING_CASE_KEBAB]: STRING_DELIMITER_HYPHEN,
130
+ [STRING_CASE_PASCAL]: STRING_DELIMTER_EMPTY,
131
+ [STRING_CASE_SNAKE]: STRING_DELIMITER_UNDERSCORE
132
132
  };
133
133
  let memoizedCapitalize;
134
134
  let memoizedLowerCase;