@alextheman/utility 5.12.0 → 5.13.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.
@@ -202,147 +202,42 @@ function normaliseIndents(first, ...args) {
202
202
  return reduceLines(interpolate(strings, ...[...args]).split("\n"), options);
203
203
  }
204
204
  //#endregion
205
- //#region src/root/functions/miscellaneous/sayHello.ts
205
+ //#region src/v6/CodeError.ts
206
206
  /**
207
- * Returns a string representing the lyrics to the package's theme song, Commit To You
208
- *
209
- * [Pls listen!](https://www.youtube.com/watch?v=mH-Sg-8EnxM)
210
- *
211
- * @returns The lyrics string in markdown format.
212
- */
213
- function sayHello() {
214
- return normaliseIndents`
215
- # Commit To You
216
-
217
- ### Verse 1
218
-
219
- I know you've been checking me out,
220
- Shall we take it to the next level now?
221
- 'Cause I really wanna be there all for you,
222
- All for you!
223
- Come on now, let's make a fresh start!
224
- Pin my number, then you can take me out!
225
- Can't you see I really do care about you,
226
- About you!
227
-
228
- ### Pre-chorus 1
229
- Although our calendars are imperfect, at best,
230
- I'd like to organise time with you! (with you!).
231
- Just tell me when and I'll make it clear,
232
- All clear for you,
233
- All clear for you!
234
- (One, two, three, go!)
235
-
236
- ### Chorus
237
- I wanna be of utility, I'll help you on the run!
238
- I'll be the one here in the back, while you go have some fun!
239
- Looking out for you tonight, I'll be the one you can rely on!
240
- Watch you go and watch me pass by,
241
- I'll be here!
242
- I'll commit to you!
243
-
244
- ### Verse 2
245
- Though sometimes it won't be easy,
246
- You'll be here to bring out the best in me,
247
- And I'll hold myself to high standards for you!
248
- All for you!
249
- We'll grow as a pair, you and me,
250
- We'll build up a healthy dependency,
251
- You can build with me and I'll develop with you!
252
- I'm with you!
253
-
254
- ### Pre-chorus 2
255
- I'll be with you when you're up or you're down,
256
- We'll deal with all our problems together (together!)
257
- Just tell me what you want, I'll make it clear,
258
- All clear for you,
259
- All clear for you!
260
- (One, three, one, go!)
261
-
262
- ### Chorus
263
- I wanna be of utility, I'll help you on the run!
264
- (help you on the run!)
265
- I'll be the one here in the back, while you go have some fun!
266
- (you go have some fun!)
267
- Looking out for you tonight, I'll be the one you can rely on!
268
- Watch you go and watch me pass by,
269
- I'll be here!
270
- I'll commit to you!
271
-
272
- ### Bridge
273
- Looking into our stack!
274
- I'll commit to you!
275
- We've got a lot to unpack!
276
- I'll commit to you!
277
- The environment that we're in!
278
- I'll commit to you!
279
- Delicate as a string!
280
- I'll commit to you!
281
-
282
- But I think you're my type!
283
- I'll commit to you!
284
- Oh, this feels all so right!
285
- I'll commit to you!
286
- Nothing stopping us now!
287
- I'll commit to you!
288
- Let's show them what we're about!
289
- Two, three, four, go!
290
-
291
- ### Final Chorus
292
- I wanna be of utility, I'll help you on the run!
293
- (help you on the run!)
294
- I'll be the one here in the back, while you go have some fun!
295
- (you go have some fun!)
296
- Looking out for you tonight, I'll be the one you can rely on!
297
- Watch you go and watch me pass by,
298
- I'll be here!
299
- I'll commit to you!
300
-
301
- I wanna be of utility, I'll help you on the run!
302
- (I'll commit to you!)
303
- I'll be the one here in the back, while you go have some fun!
304
- (I'll commit to you!)
305
- Looking out for you tonight, I'll be the one you can rely on!
306
- (I'll commit to you!)
307
- Watch you go and watch me pass by,
308
- (I'll commit to you!)
309
- I'll be here!
310
-
311
- ### Outro
312
- I'll commit to you!
313
- I'll commit to you!
314
- I'll commit to you!
315
- `;
316
- }
317
- //#endregion
318
- //#region src/root/types/DataError.ts
319
- /**
320
- * Represents errors you may get that may've been caused by a specific piece of data.
207
+ * Represents errors that can be described using a standardised error code, and a human-readable error message.
321
208
  *
322
209
  * @category Types
323
210
  *
324
- * @template DataType - The type of the data that caused the error.
211
+ * @template ErrorCode The type of the standardised error code.
325
212
  */
326
- var DataError = class DataError extends Error {
213
+ var CodeError = class CodeError extends Error {
327
214
  code;
328
- data;
329
215
  /**
330
- * @param data - The data that caused the error.
331
216
  * @param code - A standardised code (e.g. UNEXPECTED_DATA).
332
217
  * @param message - A human-readable error message (e.g. The data provided is invalid).
333
218
  * @param options - Extra options to pass to super Error constructor.
334
219
  */
335
- constructor(data, code = "INVALID_DATA", message = "The data provided is invalid", options) {
220
+ constructor(code, message = "Something went wrong.", options) {
336
221
  super(message, options);
337
222
  if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
338
223
  this.name = new.target.name;
339
224
  this.code = code;
340
- this.data = data;
341
225
  Object.defineProperty(this, "message", { enumerable: true });
342
226
  Object.setPrototypeOf(this, new.target.prototype);
343
227
  }
228
+ /**
229
+ * Checks whether the given input may have been caused by a CodeError.
230
+ *
231
+ * @param input - The input to check.
232
+ *
233
+ * @returns `true` if the input is a CodeError, and `false` otherwise. The type of the input will also be narrowed down to CodeError if `true`.
234
+ */
235
+ static check(input) {
236
+ if (input instanceof CodeError) return true;
237
+ return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string";
238
+ }
344
239
  static checkCaughtError(error, options) {
345
- if (DataError.check(error)) {
240
+ if (this.check(error)) {
346
241
  if (options?.expectedCode && error.code !== options.expectedCode) throw new Error(normaliseIndents`The error code on the thrown error does not match the expected error code.
347
242
 
348
243
  Expected: ${options.expectedCode}
@@ -353,6 +248,71 @@ var DataError = class DataError extends Error {
353
248
  throw error;
354
249
  }
355
250
  /**
251
+ * Gets the thrown `CodeError` from a given function if one was thrown, and re-throws any other errors, or throws a default `CodeError` if no error thrown.
252
+ *
253
+ * @param errorFunction - The function expected to throw the error.
254
+ * @param options - Extra options to apply.
255
+ *
256
+ * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `CodeError`.
257
+ * @throws {Error} If no `CodeError` was thrown by the `errorFunction`
258
+ *
259
+ * @returns The `CodeError` that was thrown by the `errorFunction`
260
+ */
261
+ static expectError(errorFunction, options) {
262
+ try {
263
+ errorFunction();
264
+ } catch (error) {
265
+ return this.checkCaughtError(error, options);
266
+ }
267
+ throw new Error(`Expected a ${this.name} to be thrown but none was thrown`);
268
+ }
269
+ /**
270
+ * Gets the thrown `CodeError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `CodeError` if no error thrown.
271
+ *
272
+ * @param errorFunction - The function expected to throw the error.
273
+ * @param options - Extra options to apply.
274
+ *
275
+ * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `CodeError`.
276
+ * @throws {Error} If no `CodeError` was thrown by the `errorFunction`
277
+ *
278
+ * @returns The `CodeError` that was thrown by the `errorFunction`
279
+ */
280
+ static async expectErrorAsync(errorFunction, options) {
281
+ try {
282
+ await errorFunction();
283
+ } catch (error) {
284
+ return this.checkCaughtError(error, options);
285
+ }
286
+ throw new Error(`Expected a ${this.name} to be thrown but none was thrown`);
287
+ }
288
+ };
289
+ //#endregion
290
+ //#region src/v6/DataError.ts
291
+ /**
292
+ * Represents errors you may get that may've been caused by a specific piece of data.
293
+ *
294
+ * @category Types
295
+ *
296
+ * @template DataType - The type of the data that caused the error.
297
+ */
298
+ var DataError = class DataError extends CodeError {
299
+ data;
300
+ /**
301
+ * @param data - The data that caused the error.
302
+ * @param code - A standardised code (e.g. UNEXPECTED_DATA).
303
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
304
+ * @param options - Extra options to pass to super Error constructor.
305
+ */
306
+ constructor(data, code = "INVALID_DATA", message = "The data provided is invalid", options) {
307
+ super(code, message, options);
308
+ if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
309
+ this.name = new.target.name;
310
+ this.code = code;
311
+ this.data = data;
312
+ Object.defineProperty(this, "message", { enumerable: true });
313
+ Object.setPrototypeOf(this, new.target.prototype);
314
+ }
315
+ /**
356
316
  * Checks whether the given input may have been caused by a DataError.
357
317
  *
358
318
  * @param input - The input to check.
@@ -361,8 +321,7 @@ var DataError = class DataError extends Error {
361
321
  */
362
322
  static check(input) {
363
323
  if (input instanceof DataError) return true;
364
- const data = input;
365
- return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
324
+ return typeof input === "object" && input !== null && "message" in input && typeof input.message === "string" && "code" in input && typeof input.code === "string" && "data" in input;
366
325
  }
367
326
  /**
368
327
  * Gets the thrown `DataError` from a given function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
@@ -376,12 +335,7 @@ var DataError = class DataError extends Error {
376
335
  * @returns The `DataError` that was thrown by the `errorFunction`
377
336
  */
378
337
  static expectError(errorFunction, options) {
379
- try {
380
- errorFunction();
381
- } catch (error) {
382
- return DataError.checkCaughtError(error, options);
383
- }
384
- throw new Error("Expected a DataError to be thrown but none was thrown");
338
+ return super.expectError(errorFunction, options);
385
339
  }
386
340
  /**
387
341
  * Gets the thrown `DataError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
@@ -395,12 +349,7 @@ var DataError = class DataError extends Error {
395
349
  * @returns The `DataError` that was thrown by the `errorFunction`
396
350
  */
397
351
  static async expectErrorAsync(errorFunction, options) {
398
- try {
399
- await errorFunction();
400
- } catch (error) {
401
- return DataError.checkCaughtError(error, options);
402
- }
403
- throw new Error("Expected a DataError to be thrown but none was thrown");
352
+ return await super.expectErrorAsync(errorFunction, options);
404
353
  }
405
354
  };
406
355
  //#endregion
@@ -435,9 +384,119 @@ function parseFilePath(filePath) {
435
384
  }
436
385
  //#endregion
437
386
  //#region src/node/functions/sayHello.ts
438
- var sayHello_default = sayHello;
387
+ /**
388
+ * Returns a string representing the lyrics to the package's theme song, Commit To You
389
+ *
390
+ * [Pls listen!](https://www.youtube.com/watch?v=mH-Sg-8EnxM)
391
+ *
392
+ * @returns The lyrics string in markdown format.
393
+ */
394
+ function sayHello() {
395
+ return `
396
+ # Commit To You
397
+
398
+ ### Verse 1
399
+
400
+ I know you've been checking me out,
401
+ Shall we take it to the next level now?
402
+ 'Cause I really wanna be there all for you,
403
+ All for you!
404
+ Come on now, let's make a fresh start!
405
+ Pin my number, then you can take me out!
406
+ Can't you see I really do care about you,
407
+ About you!
408
+
409
+ ### Pre-chorus 1
410
+ Although our calendars are imperfect, at best,
411
+ I'd like to organise time with you! (with you!).
412
+ Just tell me when and I'll make it clear,
413
+ All clear for you,
414
+ All clear for you!
415
+ (One, two, three, go!)
416
+
417
+ ### Chorus
418
+ I wanna be of utility, I'll help you on the run!
419
+ I'll be the one here in the back, while you go have some fun!
420
+ Looking out for you tonight, I'll be the one you can rely on!
421
+ Watch you go and watch me pass by,
422
+ I'll be here!
423
+ I'll commit to you!
424
+
425
+ ### Verse 2
426
+ Though sometimes it won't be easy,
427
+ You'll be here to bring out the best in me,
428
+ And I'll hold myself to high standards for you!
429
+ All for you!
430
+ We'll grow as a pair, you and me,
431
+ We'll build up a healthy dependency,
432
+ You can build with me and I'll develop with you!
433
+ I'm with you!
434
+
435
+ ### Pre-chorus 2
436
+ I'll be with you when you're up or you're down,
437
+ We'll deal with all our problems together (together!)
438
+ Just tell me what you want, I'll make it clear,
439
+ All clear for you,
440
+ All clear for you!
441
+ (One, three, one, go!)
442
+
443
+ ### Chorus
444
+ I wanna be of utility, I'll help you on the run!
445
+ (help you on the run!)
446
+ I'll be the one here in the back, while you go have some fun!
447
+ (you go have some fun!)
448
+ Looking out for you tonight, I'll be the one you can rely on!
449
+ Watch you go and watch me pass by,
450
+ I'll be here!
451
+ I'll commit to you!
452
+
453
+ ### Bridge
454
+ Looking into our stack!
455
+ I'll commit to you!
456
+ We've got a lot to unpack!
457
+ I'll commit to you!
458
+ The environment that we're in!
459
+ I'll commit to you!
460
+ Delicate as a string!
461
+ I'll commit to you!
462
+
463
+ But I think you're my type!
464
+ I'll commit to you!
465
+ Oh, this feels all so right!
466
+ I'll commit to you!
467
+ Nothing stopping us now!
468
+ I'll commit to you!
469
+ Let's show them what we're about!
470
+ Two, three, four, go!
471
+
472
+ ### Final Chorus
473
+ I wanna be of utility, I'll help you on the run!
474
+ (help you on the run!)
475
+ I'll be the one here in the back, while you go have some fun!
476
+ (you go have some fun!)
477
+ Looking out for you tonight, I'll be the one you can rely on!
478
+ Watch you go and watch me pass by,
479
+ I'll be here!
480
+ I'll commit to you!
481
+
482
+ I wanna be of utility, I'll help you on the run!
483
+ (I'll commit to you!)
484
+ I'll be the one here in the back, while you go have some fun!
485
+ (I'll commit to you!)
486
+ Looking out for you tonight, I'll be the one you can rely on!
487
+ (I'll commit to you!)
488
+ Watch you go and watch me pass by,
489
+ (I'll commit to you!)
490
+ I'll be here!
491
+
492
+ ### Outro
493
+ I'll commit to you!
494
+ I'll commit to you!
495
+ I'll commit to you!
496
+ `;
497
+ }
439
498
  //#endregion
440
499
  exports.normaliseImportPath = normaliseImportPath;
441
500
  exports.normalizeImportPath = normalizeImportPath;
442
501
  exports.parseFilePath = parseFilePath;
443
- exports.sayHello = sayHello_default;
502
+ exports.sayHello = sayHello;
@@ -52,7 +52,7 @@ interface FilePathData {
52
52
  */
53
53
  declare function parseFilePath(filePath: string): FilePathData;
54
54
  //#endregion
55
- //#region src/root/functions/miscellaneous/sayHello.d.ts
55
+ //#region src/node/functions/sayHello.d.ts
56
56
  /**
57
57
  * Returns a string representing the lyrics to the package's theme song, Commit To You
58
58
  *
@@ -52,7 +52,7 @@ interface FilePathData {
52
52
  */
53
53
  declare function parseFilePath(filePath: string): FilePathData;
54
54
  //#endregion
55
- //#region src/root/functions/miscellaneous/sayHello.d.ts
55
+ //#region src/node/functions/sayHello.d.ts
56
56
  /**
57
57
  * Returns a string representing the lyrics to the package's theme song, Commit To You
58
58
  *