@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
@@ -1,496 +0,0 @@
1
- import {asyncPipe, pipe} from '../../function/work';
2
- import {isError, isOk} from '../../internal/result';
3
- import type {GenericCallback} from '../../models';
4
- import {attempt} from '../index';
5
- import type {Result, UnwrapValue} from '../models';
6
-
7
- // #region Types
8
-
9
- type WrapValue<Value> = Result<UnwrapValue<Value>>;
10
-
11
- // #endregion
12
-
13
- // #region Functions
14
-
15
- // #region Asynchronous
16
-
17
- /**
18
- * Attempt to pipe a value through a function
19
- *
20
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
21
- *
22
- * @param initial Initial value
23
- * @returns _Piped_ result
24
- */
25
- export async function attemptAsyncPipe<Initial, Piped>(
26
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
27
- pipe: (value: UnwrapValue<Initial>) => Piped,
28
- ): Promise<WrapValue<Piped>>;
29
-
30
- /**
31
- * Attempt to pipe a value through a series of functions
32
- *
33
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
34
- *
35
- * @param initial Initial value
36
- * @returns _Piped_ result
37
- */
38
- export async function attemptAsyncPipe<Initial, First, Second>(
39
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
40
- first: (value: UnwrapValue<Initial>) => First,
41
- second: (value: UnwrapValue<First>) => Second,
42
- ): Promise<WrapValue<Second>>;
43
-
44
- /**
45
- * Attempt to pipe a value through a series of functions
46
- *
47
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
48
- *
49
- * @param initial Initial value
50
- * @returns _Piped_ result
51
- */
52
- export async function attemptAsyncPipe<Initial, First, Second, Third>(
53
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
54
- first: (value: UnwrapValue<Initial>) => First,
55
- second: (value: UnwrapValue<First>) => Second,
56
- third: (value: UnwrapValue<Second>) => Third,
57
- ): Promise<WrapValue<Third>>;
58
-
59
- /**
60
- * Attempt to pipe a value through a series of functions
61
- *
62
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
63
- *
64
- * @param initial Initial value
65
- * @returns _Piped_ result
66
- */
67
- export async function attemptAsyncPipe<Initial, First, Second, Third, Fourth>(
68
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
69
- first: (value: UnwrapValue<Initial>) => First,
70
- second: (value: UnwrapValue<First>) => Second,
71
- third: (value: UnwrapValue<Second>) => Third,
72
- fourth: (value: UnwrapValue<Third>) => Fourth,
73
- ): Promise<WrapValue<Fourth>>;
74
-
75
- /**
76
- * Attempt to pipe a value through a series of functions
77
- *
78
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
79
- *
80
- * @param initial Initial value
81
- * @returns _Piped_ result
82
- */
83
- export async function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth>(
84
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
85
- first: (value: UnwrapValue<Initial>) => First,
86
- second: (value: UnwrapValue<First>) => Second,
87
- third: (value: UnwrapValue<Second>) => Third,
88
- fourth: (value: UnwrapValue<Third>) => Fourth,
89
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
90
- ): Promise<WrapValue<Fifth>>;
91
-
92
- /**
93
- * Attempt to pipe a value through a series of functions
94
- *
95
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
96
- *
97
- * @param initial Initial value
98
- * @returns _Piped_ result
99
- */
100
- export async function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(
101
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
102
- first: (value: UnwrapValue<Initial>) => First,
103
- second: (value: UnwrapValue<First>) => Second,
104
- third: (value: UnwrapValue<Second>) => Third,
105
- fourth: (value: UnwrapValue<Third>) => Fourth,
106
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
107
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
108
- ): Promise<WrapValue<Sixth>>;
109
-
110
- /**
111
- * Attempt to pipe a value through a series of functions
112
- *
113
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
114
- *
115
- * @param initial Initial value
116
- * @returns _Piped_ result
117
- */
118
- export async function attemptAsyncPipe<
119
- Initial,
120
- First,
121
- Second,
122
- Third,
123
- Fourth,
124
- Fifth,
125
- Sixth,
126
- Seventh,
127
- >(
128
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
129
- first: (value: UnwrapValue<Initial>) => First,
130
- second: (value: UnwrapValue<First>) => Second,
131
- third: (value: UnwrapValue<Second>) => Third,
132
- fourth: (value: UnwrapValue<Third>) => Fourth,
133
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
134
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
135
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
136
- ): Promise<WrapValue<Seventh>>;
137
-
138
- /**
139
- * Attempt to pipe a value through a series of functions
140
- *
141
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
142
- *
143
- * @param initial Initial value
144
- * @returns _Piped_ result
145
- */
146
- export async function attemptAsyncPipe<
147
- Initial,
148
- First,
149
- Second,
150
- Third,
151
- Fourth,
152
- Fifth,
153
- Sixth,
154
- Seventh,
155
- Eighth,
156
- >(
157
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
158
- first: (value: UnwrapValue<Initial>) => First,
159
- second: (value: UnwrapValue<First>) => Second,
160
- third: (value: UnwrapValue<Second>) => Third,
161
- fourth: (value: UnwrapValue<Third>) => Fourth,
162
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
163
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
164
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
165
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
166
- ): Promise<WrapValue<Eighth>>;
167
-
168
- /**
169
- * Attempt to pipe a value through a series of functions
170
- *
171
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
172
- *
173
- * @param initial Initial value
174
- * @returns _Piped_ result
175
- */
176
- export async function attemptAsyncPipe<
177
- Initial,
178
- First,
179
- Second,
180
- Third,
181
- Fourth,
182
- Fifth,
183
- Sixth,
184
- Seventh,
185
- Eighth,
186
- Ninth,
187
- >(
188
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
189
- first: (value: UnwrapValue<Initial>) => First,
190
- second: (value: UnwrapValue<First>) => Second,
191
- third: (value: UnwrapValue<Second>) => Third,
192
- fourth: (value: UnwrapValue<Third>) => Fourth,
193
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
194
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
195
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
196
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
197
- ninth: (value: UnwrapValue<Eighth>) => Ninth,
198
- ): Promise<WrapValue<Ninth>>;
199
-
200
- /**
201
- * Attempt to pipe a value through a series of functions
202
- *
203
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
204
- *
205
- * @param initial Initial value
206
- * @returns _Piped_ result
207
- */
208
- export async function attemptAsyncPipe<
209
- Initial,
210
- First,
211
- Second,
212
- Third,
213
- Fourth,
214
- Fifth,
215
- Sixth,
216
- Seventh,
217
- Eighth,
218
- Ninth,
219
- Tenth,
220
- >(
221
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
222
- first: (value: UnwrapValue<Initial>) => First,
223
- second: (value: UnwrapValue<First>) => Second,
224
- third: (value: UnwrapValue<Second>) => Third,
225
- fourth: (value: UnwrapValue<Third>) => Fourth,
226
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
227
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
228
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
229
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
230
- ninth: (value: UnwrapValue<Eighth>) => Ninth,
231
- tenth: (value: UnwrapValue<Ninth>) => Tenth,
232
- ): Promise<WrapValue<Tenth>>;
233
-
234
- /**
235
- * Attempt to pipe a result through a series of functions
236
- *
237
- * _Available as `attemptAsyncPipe` and `attemptPipe.async`_
238
- *
239
- * @param initial Initial result
240
- * @returns _Piped_ result
241
- */
242
- export async function attemptAsyncPipe<Initial>(
243
- initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>,
244
- first?: (value: UnwrapValue<Initial>) => unknown,
245
- ...seconds: Array<(value: unknown) => unknown>
246
- ): Promise<WrapValue<Initial>>;
247
-
248
- export async function attemptAsyncPipe(
249
- initial: unknown,
250
- first?: (value: unknown) => unknown,
251
- ...seconds: Array<(value: unknown) => unknown>
252
- ): Promise<Result<unknown>> {
253
- return attempt.async(() => {
254
- if (isError(initial)) {
255
- throw initial.error;
256
- }
257
-
258
- const value =
259
- typeof initial === 'function'
260
- ? (initial as Function)()
261
- : isOk(initial)
262
- ? initial.value
263
- : initial;
264
-
265
- if (first == null) {
266
- return value;
267
- }
268
-
269
- return asyncPipe(value, ...([first, ...seconds] as GenericCallback[]));
270
- });
271
- }
272
-
273
- // #endregion
274
-
275
- // #region Synchronous
276
-
277
- /**
278
- * Attempt to pipe a value through a function
279
- *
280
- * @param initial Initial value
281
- * @returns _Piped_ result
282
- */
283
- export function attemptPipe<Initial, Pipe>(
284
- initial: GenericCallback | Initial | Result<Initial>,
285
- pipe: (value: UnwrapValue<Initial>) => Pipe,
286
- ): WrapValue<Pipe>;
287
-
288
- /**
289
- * Attempt to pipe a value through a series of functions
290
- *
291
- * @param initial Initial value
292
- * @returns _Piped_ result
293
- */
294
- export function attemptPipe<Initial, First, Second>(
295
- initial: GenericCallback | Initial | Result<Initial>,
296
- first: (value: UnwrapValue<Initial>) => First,
297
- second: (value: UnwrapValue<First>) => Second,
298
- ): WrapValue<Second>;
299
-
300
- /**
301
- * Attempt to pipe a value through a series of functions
302
- *
303
- * @param initial Initial value
304
- * @returns _Piped_ result
305
- */
306
- export function attemptPipe<Initial, First, Second, Third>(
307
- initial: GenericCallback | Initial | Result<Initial>,
308
- first: (value: UnwrapValue<Initial>) => First,
309
- second: (value: UnwrapValue<First>) => Second,
310
- third: (value: UnwrapValue<Second>) => Third,
311
- ): WrapValue<Third>;
312
-
313
- /**
314
- * Attempt to pipe a value through a series of functions
315
- *
316
- * @param initial Initial value
317
- * @returns _Piped_ result
318
- */
319
- export function attemptPipe<Initial, First, Second, Third, Fourth>(
320
- initial: GenericCallback | Initial | Result<Initial>,
321
- first: (value: UnwrapValue<Initial>) => First,
322
- second: (value: UnwrapValue<First>) => Second,
323
- third: (value: UnwrapValue<Second>) => Third,
324
- fourth: (value: UnwrapValue<Third>) => Fourth,
325
- ): WrapValue<Fourth>;
326
-
327
- /**
328
- * Attempt to pipe a value through a series of functions
329
- *
330
- * @param initial Initial value
331
- * @returns _Piped_ result
332
- */
333
- export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth>(
334
- initial: GenericCallback | Initial | Result<Initial>,
335
- first: (value: UnwrapValue<Initial>) => First,
336
- second: (value: UnwrapValue<First>) => Second,
337
- third: (value: UnwrapValue<Second>) => Third,
338
- fourth: (value: UnwrapValue<Third>) => Fourth,
339
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
340
- ): WrapValue<Fifth>;
341
-
342
- /**
343
- * Attempt to pipe a value through a series of functions
344
- *
345
- * @param initial Initial value
346
- * @returns _Piped_ result
347
- */
348
- export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(
349
- initial: GenericCallback | Initial | Result<Initial>,
350
- first: (value: UnwrapValue<Initial>) => First,
351
- second: (value: UnwrapValue<First>) => Second,
352
- third: (value: UnwrapValue<Second>) => Third,
353
- fourth: (value: UnwrapValue<Third>) => Fourth,
354
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
355
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
356
- ): WrapValue<Sixth>;
357
-
358
- /**
359
- * Attempt to pipe a value through a series of functions
360
- *
361
- * @param initial Initial value
362
- * @returns _Piped_ result
363
- */
364
- export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(
365
- initial: GenericCallback | Initial | Result<Initial>,
366
- first: (value: UnwrapValue<Initial>) => First,
367
- second: (value: UnwrapValue<First>) => Second,
368
- third: (value: UnwrapValue<Second>) => Third,
369
- fourth: (value: UnwrapValue<Third>) => Fourth,
370
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
371
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
372
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
373
- ): WrapValue<Seventh>;
374
-
375
- /**
376
- * Attempt to pipe a value through a series of functions
377
- *
378
- * @param initial Initial value
379
- * @returns _Piped_ result
380
- */
381
- export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(
382
- initial: GenericCallback | Initial | Result<Initial>,
383
- first: (value: UnwrapValue<Initial>) => First,
384
- second: (value: UnwrapValue<First>) => Second,
385
- third: (value: UnwrapValue<Second>) => Third,
386
- fourth: (value: UnwrapValue<Third>) => Fourth,
387
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
388
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
389
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
390
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
391
- ): WrapValue<Eighth>;
392
-
393
- /**
394
- * Attempt to pipe a value through a series of functions
395
- *
396
- * @param initial Initial value
397
- * @returns _Piped_ result
398
- */
399
- export function attemptPipe<
400
- Initial,
401
- First,
402
- Second,
403
- Third,
404
- Fourth,
405
- Fifth,
406
- Sixth,
407
- Seventh,
408
- Eighth,
409
- Ninth,
410
- >(
411
- initial: GenericCallback | Initial | Result<Initial>,
412
- first: (value: UnwrapValue<Initial>) => First,
413
- second: (value: UnwrapValue<First>) => Second,
414
- third: (value: UnwrapValue<Second>) => Third,
415
- fourth: (value: UnwrapValue<Third>) => Fourth,
416
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
417
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
418
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
419
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
420
- ninth: (value: UnwrapValue<Eighth>) => Ninth,
421
- ): WrapValue<Ninth>;
422
-
423
- /**
424
- * Attempt to pipe a value through a series of functions
425
- *
426
- * @param initial Initial value
427
- * @returns _Piped_ result
428
- */
429
- export function attemptPipe<
430
- Initial,
431
- First,
432
- Second,
433
- Third,
434
- Fourth,
435
- Fifth,
436
- Sixth,
437
- Seventh,
438
- Eighth,
439
- Ninth,
440
- Tenth,
441
- >(
442
- initial: GenericCallback | Initial | Result<Initial>,
443
- first: (value: UnwrapValue<Initial>) => First,
444
- second: (value: UnwrapValue<First>) => Second,
445
- third: (value: UnwrapValue<Second>) => Third,
446
- fourth: (value: UnwrapValue<Third>) => Fourth,
447
- fifth: (value: UnwrapValue<Fourth>) => Fifth,
448
- sixth: (value: UnwrapValue<Fifth>) => Sixth,
449
- seventh: (value: UnwrapValue<Sixth>) => Seventh,
450
- eighth: (value: UnwrapValue<Seventh>) => Eighth,
451
- ninth: (value: UnwrapValue<Eighth>) => Ninth,
452
- tenth: (value: UnwrapValue<Ninth>) => Tenth,
453
- ): WrapValue<Tenth>;
454
-
455
- /**
456
- * Attempt to pipe a result through a series of functions
457
- *
458
- * @param initial Initial result
459
- * @returns _Piped_ result
460
- */
461
- export function attemptPipe<Initial>(
462
- initial: GenericCallback | Initial | Result<Initial>,
463
- first?: (value: UnwrapValue<Initial>) => unknown,
464
- ...seconds: Array<(value: unknown) => unknown>
465
- ): WrapValue<Initial>;
466
-
467
- export function attemptPipe(
468
- initial: unknown,
469
- first?: (value: unknown) => unknown,
470
- ...seconds: Array<(value: unknown) => unknown>
471
- ): WrapValue<unknown> {
472
- return attempt(() => {
473
- if (isError(initial)) {
474
- throw initial.error;
475
- }
476
-
477
- const value =
478
- typeof initial === 'function'
479
- ? (initial as Function)()
480
- : isOk(initial)
481
- ? initial.value
482
- : initial;
483
-
484
- if (first == null) {
485
- return value;
486
- }
487
-
488
- return pipe(value, ...([first, ...seconds] as GenericCallback[]));
489
- });
490
- }
491
-
492
- attemptPipe.async = attemptAsyncPipe;
493
-
494
- // #endregion
495
-
496
- // #endregion
package/src/sized/map.ts DELETED
@@ -1,110 +0,0 @@
1
- import {getSizedMaximum} from '../internal/sized';
2
-
3
- // #region Types and classes
4
-
5
- /**
6
- * A _Map_ with a maximum size
7
- *
8
- * Behavior is similar to a _LRU_ cache, where the least recently used entries are removed
9
- */
10
- export class SizedMap<SizedKey = unknown, SizedValue = unknown> extends Map<SizedKey, SizedValue> {
11
- /**
12
- * The maximum size of the _Map_
13
- */
14
- readonly #maximumSize: number;
15
-
16
- /**
17
- * Is the _Map_ full?
18
- */
19
- get full(): boolean {
20
- return super.size >= this.#maximumSize;
21
- }
22
-
23
- get maximum(): number {
24
- return this.#maximumSize;
25
- }
26
-
27
- /**
28
- * Create a new _SizedMap_ with entries and a maximum size _(2^20)_
29
- *
30
- * @param entries Array of key-value pairs to initialize the _SizedMap_ with
31
- * @template SizedKey Type of the keys in the _SizedMap_
32
- * @template SizedValue Type of the values in the _SizedMap_
33
- */
34
- constructor(entries: [SizedKey, SizedValue][]);
35
-
36
- /**
37
- * Create a new _SizedMap_ with a maximum size _(but clamped at 2^24)_
38
- *
39
- * @param maximum Maximum size of the _SizedMap_
40
- * @template SizedKey Type of the keys in the _SizedMap_
41
- * @template SizedValue Type of the values in the _SizedMap_
42
- */
43
- constructor(maximum: number);
44
-
45
- /**
46
- * Create a new _SizedMap_ with _(optional)_ entries and a maximum size
47
- *
48
- * @param entries Array of key-value pairs to initialize the _SizedMap_ with
49
- * @param maximum Maximum size of the _SizedMap_ _(defaults to 2^20; clamped at 2^24)_
50
- * @template SizedKey Type of the keys in the _SizedMap_
51
- * @template SizedValue Type of the values in the _SizedMap_
52
- */
53
- constructor(entries?: [SizedKey, SizedValue][], maximum?: number);
54
-
55
- constructor(first?: [SizedKey, SizedValue][] | number, second?: number) {
56
- const maximum = getSizedMaximum(first, second);
57
-
58
- super();
59
-
60
- this.#maximumSize = maximum;
61
-
62
- if (Array.isArray(first)) {
63
- const {length} = first;
64
-
65
- if (length <= maximum) {
66
- for (let index = 0; index < length; index += 1) {
67
- this.set(...first[index]);
68
- }
69
- } else {
70
- for (let index = 0; index < maximum; index += 1) {
71
- this.set(...first[length - maximum + index]);
72
- }
73
- }
74
- }
75
- }
76
-
77
- /**
78
- * @inheritdoc
79
- */
80
- override get(key: SizedKey): SizedValue | undefined {
81
- if (super.has(key)) {
82
- const value = super.get(key) as SizedValue;
83
-
84
- this.#setValue(key, value, true);
85
-
86
- return value;
87
- }
88
- }
89
-
90
- /**
91
- * @inheritdoc
92
- */
93
- override set(key: SizedKey, value: SizedValue): this {
94
- return this.#setValue(key, value, super.has(key));
95
- }
96
-
97
- #setValue(key: SizedKey, value: SizedValue, has: boolean): this {
98
- if (has) {
99
- super.delete(key);
100
- } else if (super.size >= this.#maximumSize) {
101
- super.delete(super.keys().next().value as SizedKey);
102
- }
103
-
104
- super.set(key, value);
105
-
106
- return this;
107
- }
108
- }
109
-
110
- // #endregion
package/src/sized/set.ts DELETED
@@ -1,107 +0,0 @@
1
- import {getSizedMaximum} from '../internal/sized';
2
-
3
- // #region Types
4
-
5
- /**
6
- * A _Set_ with a maximum size
7
- *
8
- * Behavior is similar to a _LRU_ cache, where the oldest values are removed
9
- */
10
- export class SizedSet<Value = unknown> extends Set<Value> {
11
- /**
12
- * The maximum size of the _Set_
13
- */
14
- readonly #maximumSize: number;
15
-
16
- /**
17
- * Is the _Set_ full?
18
- */
19
- get full(): boolean {
20
- return this.size >= this.#maximumSize;
21
- }
22
-
23
- get maximum(): number {
24
- return this.#maximumSize;
25
- }
26
-
27
- /**
28
- * Create a new _SizedSet_ with values and a maximum size _(2^20)_
29
- *
30
- * @param values Array of values to initialize the _SizedSet_ with
31
- * @template Value Type of the values in the _SizedSet_
32
- */
33
- constructor(values: Value[]);
34
-
35
- /**
36
- * Create a new _SizedSet_ with a maximum size _(but clamped at 2^24)_
37
- *
38
- * @param maximum Maximum size of the _SizedSet_ _(defaults to 2^20; clamped at 2^24)_
39
- * @template Value Type of the values in the _SizedSet_
40
- */
41
- constructor(maximum: number);
42
-
43
- /**
44
- * Create a new _SizedSet_ with _(optional)_ values and a maximum size
45
- *
46
- * @param values Array of values to initialize the _SizedSet_ with
47
- * @param maximum Maximum size of the _SizedSet_ _(defaults to 2^20; clamped at 2^24)_
48
- * @template Value Type of the values in the _SizedSet_
49
- */
50
- constructor(values?: Value[], maximum?: number);
51
-
52
- constructor(first?: Value[] | number, second?: number) {
53
- const maximum = getSizedMaximum(first, second);
54
-
55
- super();
56
-
57
- this.#maximumSize = maximum;
58
-
59
- if (Array.isArray(first)) {
60
- const {length} = first;
61
-
62
- if (length <= maximum) {
63
- for (let index = 0; index < length; index += 1) {
64
- this.add(first[index]);
65
- }
66
- } else {
67
- for (let index = 0; index < maximum; index += 1) {
68
- this.add(first[length - maximum + index]);
69
- }
70
- }
71
- }
72
- }
73
-
74
- /**
75
- * @inheritdoc
76
- */
77
- override add(value: Value): this {
78
- if (super.has(value)) {
79
- super.delete(value);
80
- } else if (this.size >= this.#maximumSize) {
81
- super.delete(this.values().next().value as Value);
82
- }
83
-
84
- return super.add(value);
85
- }
86
-
87
- /**
88
- * Get a value from the _SizedSet_, if it exists _(and optionally move it to the end)_
89
- *
90
- * @param value Value to get from the _SizedSet_
91
- * @param update Update the value's position in the _SizedSet_? _(defaults to `false`)_
92
- * @returns Found value if it exists, otherwise `undefined`
93
- */
94
- get(value: Value, update?: boolean): Value | undefined {
95
- if (super.has(value)) {
96
- if (update ?? false) {
97
- super.delete(value);
98
-
99
- this.add(value);
100
- }
101
-
102
- return value;
103
- }
104
- }
105
- }
106
-
107
- // #endregion