@byloth/core 2.0.0 → 2.0.2

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 (39) hide show
  1. package/README.md +1 -0
  2. package/dist/core.js +900 -187
  3. package/dist/core.js.map +1 -1
  4. package/dist/core.umd.cjs +2 -2
  5. package/dist/core.umd.cjs.map +1 -1
  6. package/package.json +13 -10
  7. package/src/core/types.ts +43 -10
  8. package/src/index.ts +3 -2
  9. package/src/models/aggregators/aggregated-async-iterator.ts +161 -1
  10. package/src/models/aggregators/aggregated-iterator.ts +146 -1
  11. package/src/models/aggregators/reduced-iterator.ts +148 -8
  12. package/src/models/aggregators/types.ts +35 -0
  13. package/src/models/callbacks/callable-object.ts +7 -0
  14. package/src/models/callbacks/publisher.ts +33 -8
  15. package/src/models/callbacks/switchable-callback.ts +102 -21
  16. package/src/models/callbacks/types.ts +32 -0
  17. package/src/models/exceptions/core.ts +29 -0
  18. package/src/models/exceptions/index.ts +105 -1
  19. package/src/models/iterators/smart-async-iterator.ts +145 -0
  20. package/src/models/iterators/smart-iterator.ts +130 -0
  21. package/src/models/iterators/types.ts +79 -1
  22. package/src/models/json/json-storage.ts +123 -0
  23. package/src/models/json/types.ts +1 -1
  24. package/src/models/promises/deferred-promise.ts +15 -0
  25. package/src/models/promises/smart-promise.ts +45 -0
  26. package/src/models/promises/timed-promise.ts +10 -0
  27. package/src/models/promises/types.ts +30 -0
  28. package/src/models/timers/clock.ts +21 -0
  29. package/src/models/timers/countdown.ts +30 -0
  30. package/src/models/timers/game-loop.ts +26 -0
  31. package/src/models/types.ts +1 -1
  32. package/src/utils/async.ts +15 -0
  33. package/src/utils/curve.ts +11 -1
  34. package/src/utils/date.ts +36 -6
  35. package/src/utils/dom.ts +5 -0
  36. package/src/utils/iterator.ts +40 -0
  37. package/src/utils/math.ts +15 -0
  38. package/src/utils/random.ts +34 -0
  39. package/src/utils/string.ts +5 -0
@@ -6,6 +6,9 @@ import Exception from "./core.js";
6
6
  *
7
7
  * It can also be used to catch all file-related exceptions at once.
8
8
  *
9
+ * ---
10
+ *
11
+ * @example
9
12
  * ```ts
10
13
  * try { [...] }
11
14
  * catch (error)
@@ -22,10 +25,15 @@ export class FileException extends Exception
22
25
  /**
23
26
  * Initializes a new instance of the {@link FileException} class.
24
27
  *
28
+ * ---
29
+ *
30
+ * @example
25
31
  * ```ts
26
32
  * throw new FileException("An error occurred while trying to read the file.");
27
33
  * ```
28
34
  *
35
+ * ---
36
+ *
29
37
  * @param message The message that describes the error.
30
38
  * @param cause The previous caught error that caused this one, if any.
31
39
  * @param name The name of the exception. Default is `"FileException"`.
@@ -41,6 +49,9 @@ export class FileException extends Exception
41
49
  /**
42
50
  * A class representing an exception that can be thrown when a file already exists.
43
51
  *
52
+ * ---
53
+ *
54
+ * @example
44
55
  * ```ts
45
56
  * import { existsSync } from "node:fs";
46
57
  *
@@ -55,10 +66,15 @@ export class FileExistsException extends FileException
55
66
  /**
56
67
  * Initializes a new instance of the {@link FileExistsException} class.
57
68
  *
69
+ * ---
70
+ *
71
+ * @example
58
72
  * ```ts
59
73
  * throw new FileExistsException("The file named 'data.json' already exists on the server.");
60
74
  * ```
61
75
  *
76
+ * ---
77
+ *
62
78
  * @param message The message that describes the error.
63
79
  * @param cause The previous caught error that caused this one, if any.
64
80
  * @param name The name of the exception. Default is `"FileExistsException"`.
@@ -74,6 +90,9 @@ export class FileExistsException extends FileException
74
90
  /**
75
91
  * A class representing an exception that can be thrown when a file isn't found.
76
92
  *
93
+ * ---
94
+ *
95
+ * @example
77
96
  * ```ts
78
97
  * import { existsSync } from "node:fs";
79
98
  *
@@ -88,10 +107,15 @@ export class FileNotFoundException extends FileException
88
107
  /**
89
108
  * Initializes a new instance of the {@link FileNotFoundException} class.
90
109
  *
110
+ * ---
111
+ *
112
+ * @example
91
113
  * ```ts
92
114
  * throw new FileNotFoundException("The file named 'data.json' wasn't found on the server.");
93
115
  * ```
94
116
  *
117
+ * ---
118
+ *
95
119
  * @param message The message that describes the error.
96
120
  * @param cause The previous caught error that caused this one, if any.
97
121
  * @param name The name of the exception. Default is `"FileNotFoundException"`.
@@ -108,6 +132,9 @@ export class FileNotFoundException extends FileException
108
132
  * A class representing an exception that can be thrown when a key is invalid or not found.
109
133
  * It's commonly used when working with dictionaries, maps, objects, sets, etc...
110
134
  *
135
+ * ---
136
+ *
137
+ * @example
111
138
  * ```ts
112
139
  * const map = new Map<string, number>();
113
140
  * if (!map.has("hash"))
@@ -121,10 +148,15 @@ export class KeyException extends Exception
121
148
  /**
122
149
  * Initializes a new instance of the {@link KeyException} class.
123
150
  *
151
+ * ---
152
+ *
153
+ * @example
124
154
  * ```ts
125
155
  * throw new KeyException("The 'id' key wasn't found in the dictionary.");
126
156
  * ```
127
157
  *
158
+ * ---
159
+ *
128
160
  * @param message The message that describes the error.
129
161
  * @param cause The previous caught error that caused this one, if any.
130
162
  * @param name The name of the exception. Default is `"KeyException"`.
@@ -141,6 +173,9 @@ export class KeyException extends Exception
141
173
  * A class representing an exception that can be thrown when a network operation fails.
142
174
  * It's commonly used when it's unable to connect to a server or when a request times out.
143
175
  *
176
+ * ---
177
+ *
178
+ * @example
144
179
  * ```ts
145
180
  * import axios, { isAxiosError } from "axios";
146
181
  *
@@ -162,10 +197,15 @@ export class NetworkException extends Exception
162
197
  /**
163
198
  * Initializes a new instance of the {@link NetworkException} class.
164
199
  *
200
+ * ---
201
+ *
202
+ * @example
165
203
  * ```ts
166
204
  * throw new NetworkException("Couldn't connect to the server. Please, try again later.");
167
205
  * ```
168
206
  *
207
+ * ---
208
+ *
169
209
  * @param message The message that describes the error.
170
210
  * @param cause The previous caught error that caused this one, if any.
171
211
  * @param name The name of the exception. Default is `"NetworkException"`.
@@ -180,8 +220,11 @@ export class NetworkException extends Exception
180
220
 
181
221
  /**
182
222
  * A class representing an exception that can be thrown when a permission is denied.
183
- * It's commonly used when a user tries to access a restricted resource or perform a forbidden action.
223
+ * It's commonly used when an user tries to access a restricted resource or perform a forbidden action.
184
224
  *
225
+ * ---
226
+ *
227
+ * @example
185
228
  * ```ts
186
229
  * const $user = useUserStore();
187
230
  * if (!$user.isAdmin)
@@ -195,10 +238,15 @@ export class PermissionException extends Exception
195
238
  /**
196
239
  * Initializes a new instance of the {@link PermissionException} class.
197
240
  *
241
+ * ---
242
+ *
243
+ * @example
198
244
  * ```ts
199
245
  * throw new PermissionException("You don't have permission to access this resource.");
200
246
  * ```
201
247
  *
248
+ * ---
249
+ *
202
250
  * @param message The message that describes the error.
203
251
  * @param cause The previous caught error that caused this one, if any.
204
252
  * @param name The name of the exception. Default is `"PermissionException"`.
@@ -215,6 +263,9 @@ export class PermissionException extends Exception
215
263
  * A class representing an exception that can be thrown when a reference is invalid or not found.
216
264
  * It's commonly used when a variable is `null`, `undefined` or when an object doesn't exist.
217
265
  *
266
+ * ---
267
+ *
268
+ * @example
218
269
  * ```ts
219
270
  * const $el = document.getElementById("app");
220
271
  * if ($el === null)
@@ -228,10 +279,15 @@ export class ReferenceException extends Exception
228
279
  /**
229
280
  * Initializes a new instance of the {@link ReferenceException} class.
230
281
  *
282
+ * ---
283
+ *
284
+ * @example
231
285
  * ```ts
232
286
  * throw new ReferenceException("The 'canvas' element wasn't found in the document.");
233
287
  * ```
234
288
  *
289
+ * ---
290
+ *
235
291
  * @param message The message that describes the error.
236
292
  * @param cause The previous caught error that caused this one, if any.
237
293
  * @param name The name of the exception. Default is `"ReferenceException"`.
@@ -248,6 +304,9 @@ export class ReferenceException extends Exception
248
304
  * A class representing an exception that can be thrown when a runtime error occurs.
249
305
  * It's commonly used when an unexpected condition is encountered during the execution of a program.
250
306
  *
307
+ * ---
308
+ *
309
+ * @example
251
310
  * ```ts
252
311
  * let status: "enabled" | "disabled" = "enabled";
253
312
  *
@@ -263,10 +322,15 @@ export class RuntimeException extends Exception
263
322
  /**
264
323
  * Initializes a new instance of the {@link RuntimeException} class.
265
324
  *
325
+ * ---
326
+ *
327
+ * @example
266
328
  * ```ts
267
329
  * throw new RuntimeException("The received input seems to be malformed or corrupted.");
268
330
  * ```
269
331
  *
332
+ * ---
333
+ *
270
334
  * @param message The message that describes the error.
271
335
  * @param cause The previous caught error that caused this one, if any.
272
336
  * @param name The name of the exception. Default is `"RuntimeException"`.
@@ -284,6 +348,9 @@ export class RuntimeException extends Exception
284
348
  * isn't properly configured or when a required variable isn't set.
285
349
  * It can also be used when the environment on which the program is running is unsupported.
286
350
  *
351
+ * ---
352
+ *
353
+ * @example
287
354
  * ```ts
288
355
  * if (!navigator.geolocation)
289
356
  * {
@@ -296,10 +363,15 @@ export class EnvironmentException extends RuntimeException
296
363
  /**
297
364
  * Initializes a new instance of the {@link EnvironmentException} class.
298
365
  *
366
+ * ---
367
+ *
368
+ * @example
299
369
  * ```ts
300
370
  * throw new EnvironmentException("The required environment variable 'API_KEY' isn't set.");
301
371
  * ```
302
372
  *
373
+ * ---
374
+ *
303
375
  * @param message The message that describes the error.
304
376
  * @param cause The previous caught error that caused this one, if any.
305
377
  * @param name The name of the exception. Default is `"EnvironmentException"`.
@@ -316,6 +388,9 @@ export class EnvironmentException extends RuntimeException
316
388
  * A class representing an exception that can be thrown when a timeout occurs.
317
389
  * It's commonly used when a task takes too long to complete or when a request times out.
318
390
  *
391
+ * ---
392
+ *
393
+ * @example
319
394
  * ```ts
320
395
  * const timeoutId = setTimeout(() => { throw new TimeoutException("The request timed out."); }, 5_000);
321
396
  * const response = await fetch("https://api.example.com/data");
@@ -328,10 +403,15 @@ export class TimeoutException extends Exception
328
403
  /**
329
404
  * Initializes a new instance of the {@link TimeoutException} class.
330
405
  *
406
+ * ---
407
+ *
408
+ * @example
331
409
  * ```ts
332
410
  * throw new TimeoutException("The task took too long to complete.");
333
411
  * ```
334
412
  *
413
+ * ---
414
+ *
335
415
  * @param message The message that describes the error.
336
416
  * @param cause The previous caught error that caused this one, if any.
337
417
  * @param name The name of the exception. Default is `"TimeoutException"`.
@@ -348,6 +428,9 @@ export class TimeoutException extends Exception
348
428
  * A class representing an exception that can be thrown when a type is invalid or not supported.
349
429
  * It's commonly used when a function receives an unexpected type of argument.
350
430
  *
431
+ * ---
432
+ *
433
+ * @example
351
434
  * ```ts
352
435
  * function greet(name: string): void
353
436
  * {
@@ -363,10 +446,15 @@ export class TypeException extends Exception
363
446
  /**
364
447
  * Initializes a new instance of the {@link TypeException} class.
365
448
  *
449
+ * ---
450
+ *
451
+ * @example
366
452
  * ```ts
367
453
  * throw new TypeException("The 'username' argument must be a valid string.");
368
454
  * ```
369
455
  *
456
+ * ---
457
+ *
370
458
  * @param message The message that describes the error.
371
459
  * @param cause The previous caught error that caused this one, if any.
372
460
  * @param name The name of the exception. Default is `"TypeException"`.
@@ -383,6 +471,9 @@ export class TypeException extends Exception
383
471
  * A class representing an exception that can be thrown when a value is invalid.
384
472
  * It's commonly used when a function receives an unexpected value as an argument.
385
473
  *
474
+ * ---
475
+ *
476
+ * @example
386
477
  * ```ts
387
478
  * function setVolume(value: number): void
388
479
  * {
@@ -398,10 +489,15 @@ export class ValueException extends Exception
398
489
  /**
399
490
  * Initializes a new instance of the {@link ValueException} class.
400
491
  *
492
+ * ---
493
+ *
494
+ * @example
401
495
  * ```ts
402
496
  * throw new ValueException("The 'grade' argument cannot be negative.");
403
497
  * ```
404
498
  *
499
+ * ---
500
+ *
405
501
  * @param message The message that describes the error.
406
502
  * @param cause The previous caught error that caused this one, if any.
407
503
  * @param name The name of the exception. Default is `"ValueException"`.
@@ -418,6 +514,9 @@ export class ValueException extends Exception
418
514
  * A class representing an exception that can be thrown when a value is out of range.
419
515
  * It's commonly used when a function receives an unexpected value as an argument.
420
516
  *
517
+ * ---
518
+ *
519
+ * @example
421
520
  * ```ts
422
521
  * function setVolume(value: number): void
423
522
  * {
@@ -433,10 +532,15 @@ export class RangeException extends ValueException
433
532
  /**
434
533
  * Initializes a new instance of the {@link RangeException} class.
435
534
  *
535
+ * ---
536
+ *
537
+ * @example
436
538
  * ```ts
437
539
  * throw new RangeException("The 'percentage' argument must be between 0 and 100.");
438
540
  * ```
439
541
  *
542
+ * ---
543
+ *
440
544
  * @param message The message that describes the error.
441
545
  * @param cause The previous caught error that caused this one, if any.
442
546
  * @param name The name of the exception. Default is `"RangeException"`.