@alextheman/utility 4.16.2 → 5.0.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.
package/dist/index.js CHANGED
@@ -2,19 +2,19 @@ import z, { z as z$1 } from "zod";
2
2
  import path from "node:path";
3
3
  import sodium from "libsodium-wrappers";
4
4
 
5
- //#region src/constants/FILE_PATH_REGEX.ts
5
+ //#region src/root/constants/FILE_PATH_REGEX.ts
6
6
  const FILE_PATH_REGEX = String.raw`^(?<directory>.+)[\/\\](?<base>[^\/\\]+)$`;
7
7
 
8
8
  //#endregion
9
- //#region src/constants/NAMESPACE_EXPORT_REGEX.ts
9
+ //#region src/root/constants/NAMESPACE_EXPORT_REGEX.ts
10
10
  const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
11
11
 
12
12
  //#endregion
13
- //#region src/constants/VERSION_NUMBER_REGEX.ts
13
+ //#region src/root/constants/VERSION_NUMBER_REGEX.ts
14
14
  const VERSION_NUMBER_REGEX = "^(?:v)?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$";
15
15
 
16
16
  //#endregion
17
- //#region src/functions/arrayHelpers/fillArray.ts
17
+ //#region src/root/functions/arrayHelpers/fillArray.ts
18
18
  /**
19
19
  * Creates a new array where each element is the result of the provided callback.
20
20
  *
@@ -41,7 +41,7 @@ function fillArray(callback, length = 1) {
41
41
  }
42
42
 
43
43
  //#endregion
44
- //#region src/functions/arrayHelpers/paralleliseArrays.ts
44
+ //#region src/root/functions/arrayHelpers/paralleliseArrays.ts
45
45
  /**
46
46
  * Creates a new array of tuples, each containing the item at the given index from both arrays.
47
47
  *
@@ -65,7 +65,7 @@ function paralleliseArrays(firstArray, secondArray) {
65
65
  }
66
66
 
67
67
  //#endregion
68
- //#region src/types/APIError.ts
68
+ //#region src/root/types/APIError.ts
69
69
  const httpErrorCodeLookup = {
70
70
  400: "BAD_REQUEST",
71
71
  401: "UNAUTHORISED",
@@ -109,11 +109,13 @@ var APIError = class APIError extends Error {
109
109
  };
110
110
 
111
111
  //#endregion
112
- //#region src/types/DataError.ts
112
+ //#region src/root/types/DataError.ts
113
113
  /**
114
114
  * Represents errors you may get that may've been caused by a specific piece of data.
115
115
  *
116
116
  * @category Types
117
+ *
118
+ * @template DataType - The type of the data that caused the error.
117
119
  */
118
120
  var DataError = class DataError extends Error {
119
121
  code;
@@ -148,7 +150,7 @@ var DataError = class DataError extends Error {
148
150
  };
149
151
 
150
152
  //#endregion
151
- //#region src/types/VersionNumber.ts
153
+ //#region src/root/types/VersionNumber.ts
152
154
  /**
153
155
  * Represents a software version number, considered to be made up of a major, minor, and patch part.
154
156
  *
@@ -171,7 +173,7 @@ var VersionNumber = class VersionNumber {
171
173
  this.minor = input.minor;
172
174
  this.patch = input.patch;
173
175
  } else if (typeof input === "string") {
174
- if (!RegExp(VERSION_NUMBER_REGEX).test(input)) throw new DataError(input, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
176
+ if (!RegExp(VERSION_NUMBER_REGEX).test(input)) throw new DataError({ input }, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
175
177
  const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
176
178
  return parseIntStrict(number);
177
179
  });
@@ -179,10 +181,10 @@ var VersionNumber = class VersionNumber {
179
181
  this.minor = minor;
180
182
  this.patch = patch;
181
183
  } else if (Array.isArray(input)) {
182
- if (input.length !== 3) throw new DataError(input, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
184
+ if (input.length !== 3) throw new DataError({ input }, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
183
185
  const [major, minor, patch] = input.map((number) => {
184
186
  const parsedInteger = parseIntStrict(number?.toString());
185
- if (parsedInteger < 0) throw new DataError(input, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
187
+ if (parsedInteger < 0) throw new DataError({ input }, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
186
188
  return parsedInteger;
187
189
  });
188
190
  this.major = major;
@@ -216,33 +218,60 @@ var VersionNumber = class VersionNumber {
216
218
  return firstVersion.major === secondVersion.major && firstVersion.minor === secondVersion.minor && firstVersion.patch === secondVersion.patch;
217
219
  }
218
220
  /**
221
+ * Get a formatted string representation of the current version number
222
+ *
223
+ * @param options - Options to apply to the string formatting.
224
+ *
225
+ * @returns A formatted string representation of the current version number with the options applied.
226
+ */
227
+ format(options) {
228
+ let baseOutput = `${this.major}`;
229
+ if (!options?.omitMinor) {
230
+ baseOutput += `.${this.minor}`;
231
+ if (!options?.omitPatch) baseOutput += `.${this.patch}`;
232
+ }
233
+ return VersionNumber.formatString(baseOutput, { omitPrefix: options?.omitPrefix });
234
+ }
235
+ /**
219
236
  * Increments the current version number by the given increment type, returning the result as a new reference in memory.
220
237
  *
221
238
  * @param incrementType - The type of increment. Can be one of the following:
222
239
  * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
223
240
  * - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
224
241
  * - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
242
+ * @param incrementAmount - The amount to increment by (defaults to 1).
225
243
  *
226
244
  * @returns A new instance of `VersionNumber` with the increment applied.
227
245
  */
228
- increment(incrementType) {
229
- return {
230
- major: new VersionNumber([
231
- this.major + 1,
246
+ increment(incrementType, incrementAmount = 1) {
247
+ const incrementBy = parseIntStrict(String(incrementAmount));
248
+ const calculatedRawVersion = {
249
+ major: [
250
+ this.major + incrementBy,
232
251
  0,
233
252
  0
234
- ]),
235
- minor: new VersionNumber([
253
+ ],
254
+ minor: [
236
255
  this.major,
237
- this.minor + 1,
256
+ this.minor + incrementBy,
238
257
  0
239
- ]),
240
- patch: new VersionNumber([
258
+ ],
259
+ patch: [
241
260
  this.major,
242
261
  this.minor,
243
- this.patch + 1
244
- ])
262
+ this.patch + incrementBy
263
+ ]
245
264
  }[incrementType];
265
+ try {
266
+ return new VersionNumber(calculatedRawVersion);
267
+ } catch (error) {
268
+ if (DataError.check(error) && error.code === "NEGATIVE_INPUTS") throw new DataError({
269
+ currentVersion: this.toString(),
270
+ calculatedRawVersion: `v${calculatedRawVersion.join(".")}`,
271
+ incrementAmount
272
+ }, "NEGATIVE_VERSION", "Cannot apply this increment amount as it would lead to a negative version number.");
273
+ else throw error;
274
+ }
246
275
  }
247
276
  /**
248
277
  * Ensures that the VersionNumber behaves correctly when attempted to be coerced to a string.
@@ -252,7 +281,7 @@ var VersionNumber = class VersionNumber {
252
281
  * @returns A stringified representation of the current version number, prefixed with `v`.
253
282
  */
254
283
  [Symbol.toPrimitive](hint) {
255
- if (hint === "number") throw new DataError(this.toString(), "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
284
+ if (hint === "number") throw new DataError({ thisVersion: this.toString() }, "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
256
285
  return this.toString();
257
286
  }
258
287
  /**
@@ -266,13 +295,11 @@ var VersionNumber = class VersionNumber {
266
295
  /**
267
296
  * Get a string representation of the current version number.
268
297
  *
269
- * @param options - Extra additional options to apply.
270
- *
271
- * @returns A stringified representation of the current version number, leaving out the prefix if `omitPrefix` option was set to true.
298
+ * @returns A stringified representation of the current version number with the prefix.
272
299
  */
273
- toString(options) {
300
+ toString() {
274
301
  const rawString = `${this.major}.${this.minor}.${this.patch}`;
275
- return VersionNumber.formatString(rawString, options);
302
+ return VersionNumber.formatString(rawString, { omitPrefix: false });
276
303
  }
277
304
  };
278
305
  const zodVersionNumber = z.union([
@@ -288,7 +315,7 @@ const zodVersionNumber = z.union([
288
315
  });
289
316
 
290
317
  //#endregion
291
- //#region src/functions/parsers/parseIntStrict.ts
318
+ //#region src/root/functions/parsers/parseIntStrict.ts
292
319
  /**
293
320
  * Converts a string to an integer and throws an error if it cannot be converted.
294
321
  *
@@ -307,7 +334,7 @@ function parseIntStrict(string, radix) {
307
334
  if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new DataError(radix ? {
308
335
  string,
309
336
  radix
310
- } : string, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
337
+ } : { string }, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
311
338
  if (radix && radix < 10 && [...trimmedString].some((character) => {
312
339
  return parseInt(character) >= radix;
313
340
  })) throw new DataError({
@@ -315,12 +342,12 @@ function parseIntStrict(string, radix) {
315
342
  radix
316
343
  }, "INTEGER_PARSING_ERROR", "Value contains one or more digits outside of the range of the given radix.");
317
344
  const parseIntResult = parseInt(trimmedString, radix);
318
- if (isNaN(parseIntResult)) throw new DataError(string, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
345
+ if (isNaN(parseIntResult)) throw new DataError({ string }, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
319
346
  return parseIntResult;
320
347
  }
321
348
 
322
349
  //#endregion
323
- //#region src/functions/miscellaneous/getRandomNumber.ts
350
+ //#region src/root/functions/miscellaneous/getRandomNumber.ts
324
351
  /**
325
352
  * Gets a random number between the given bounds.
326
353
  *
@@ -338,7 +365,7 @@ function getRandomNumber(lowerBound, upperBound) {
338
365
  }
339
366
 
340
367
  //#endregion
341
- //#region src/functions/arrayHelpers/randomiseArray.ts
368
+ //#region src/root/functions/arrayHelpers/randomiseArray.ts
342
369
  /**
343
370
  * Randomises the order of a given array and returns the result in a new array without mutating the original.
344
371
  *
@@ -361,7 +388,7 @@ function randomiseArray(array) {
361
388
  }
362
389
 
363
390
  //#endregion
364
- //#region src/functions/arrayHelpers/range.ts
391
+ //#region src/root/functions/arrayHelpers/range.ts
365
392
  /**
366
393
  * Creates an array of numbers within a given range.
367
394
  *
@@ -393,7 +420,7 @@ function range(start, stop, step = 1) {
393
420
  }
394
421
 
395
422
  //#endregion
396
- //#region src/functions/arrayHelpers/removeDuplicates.ts
423
+ //#region src/root/functions/arrayHelpers/removeDuplicates.ts
397
424
  /**
398
425
  * Removes duplicate values from an array.
399
426
  *
@@ -412,7 +439,7 @@ function removeDuplicates(array) {
412
439
  }
413
440
 
414
441
  //#endregion
415
- //#region src/functions/date/addDaysToDate.ts
442
+ //#region src/root/functions/date/addDaysToDate.ts
416
443
  /**
417
444
  * Adds a given number of days to the provided date, returning the result as a new instance of Date.
418
445
  *
@@ -430,7 +457,7 @@ function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement =
430
457
  }
431
458
 
432
459
  //#endregion
433
- //#region src/functions/date/isSameDate.ts
460
+ //#region src/root/functions/date/isSameDate.ts
434
461
  /**
435
462
  * Checks if the provided dates happen on the exact same day, month, and year.
436
463
  *
@@ -446,7 +473,7 @@ function isSameDate(firstDate, secondDate) {
446
473
  }
447
474
 
448
475
  //#endregion
449
- //#region src/functions/date/formatDateAndTime.ts
476
+ //#region src/root/functions/date/formatDateAndTime.ts
450
477
  /**
451
478
  * Creates a human-readable string with information about the input date.
452
479
  *
@@ -470,7 +497,7 @@ function formatDateAndTime(inputDate) {
470
497
  }
471
498
 
472
499
  //#endregion
473
- //#region src/functions/date/isLeapYear.ts
500
+ //#region src/root/functions/date/isLeapYear.ts
474
501
  /**
475
502
  * Checks if the provided year is a leap year.
476
503
  *
@@ -488,7 +515,7 @@ function isLeapYear(year) {
488
515
  }
489
516
 
490
517
  //#endregion
491
- //#region src/functions/date/isAnniversary.ts
518
+ //#region src/root/functions/date/isAnniversary.ts
492
519
  function checkLeapYear(firstDate, secondDate) {
493
520
  if (isLeapYear(firstDate.getFullYear()) && firstDate.getMonth() === 1 && secondDate.getMonth() === 1) return firstDate.getDate() === 29 && secondDate.getDate() === 28;
494
521
  return false;
@@ -509,7 +536,7 @@ function isAnniversary(firstDate, secondDate) {
509
536
  }
510
537
 
511
538
  //#endregion
512
- //#region src/functions/date/isMonthlyMultiple.ts
539
+ //#region src/root/functions/date/isMonthlyMultiple.ts
513
540
  function endOfMonthChecksButNotFebruary(firstDate, secondDate) {
514
541
  if ([
515
542
  3,
@@ -558,7 +585,7 @@ function isMonthlyMultiple(firstDate, secondDate) {
558
585
  }
559
586
 
560
587
  //#endregion
561
- //#region src/functions/miscellaneous/convertFileToBase64.ts
588
+ //#region src/root/functions/miscellaneous/convertFileToBase64.ts
562
589
  /**
563
590
  * Asynchronously converts a file to a base 64 string
564
591
  *
@@ -588,7 +615,7 @@ function convertFileToBase64(file) {
588
615
  }
589
616
 
590
617
  //#endregion
591
- //#region src/functions/miscellaneous/createFormData.ts
618
+ //#region src/root/functions/miscellaneous/createFormData.ts
592
619
  function getNullableResolutionStrategy(key, strategy) {
593
620
  return (typeof strategy === "object" ? strategy[key] : strategy) ?? "empty";
594
621
  }
@@ -657,7 +684,26 @@ function createFormData(data, options = {
657
684
  }
658
685
 
659
686
  //#endregion
660
- //#region src/functions/miscellaneous/isOrdered.ts
687
+ //#region src/root/functions/miscellaneous/getDependenciesFromGroup.ts
688
+ /**
689
+ * Get the dependencies from a given dependency group in `package.json`.
690
+ *
691
+ * @category Miscellaneous
692
+ *
693
+ * @param packageInfo - The data coming from `package.json`.
694
+ * @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
695
+ *
696
+ * @returns A record consisting of the package names and version ranges from the given dependency group.
697
+ */
698
+ function getDependenciesFromGroup(packageInfo, dependencyGroup) {
699
+ return {
700
+ dependencies: parseZodSchema(z.record(z.string(), z.string()), packageInfo.dependencies ?? {}),
701
+ devDependencies: parseZodSchema(z.record(z.string(), z.string()), packageInfo.devDependencies ?? {})
702
+ }[dependencyGroup];
703
+ }
704
+
705
+ //#endregion
706
+ //#region src/root/functions/miscellaneous/isOrdered.ts
661
707
  /**
662
708
  * Checks to see if the given array is sorted in ascending order.
663
709
  *
@@ -675,7 +721,7 @@ function isOrdered(array) {
675
721
  }
676
722
 
677
723
  //#endregion
678
- //#region src/functions/recursive/deepFreeze.ts
724
+ //#region src/root/functions/recursive/deepFreeze.ts
679
725
  /**
680
726
  * Deeply freezes an object or array such that all child objects/arrays are also frozen.
681
727
  *
@@ -699,7 +745,7 @@ function deepFreeze(object) {
699
745
  }
700
746
 
701
747
  //#endregion
702
- //#region src/functions/taggedTemplate/createTemplateStringsArray.ts
748
+ //#region src/root/functions/taggedTemplate/createTemplateStringsArray.ts
703
749
  /**
704
750
  * Creates a template strings array given a regular array of strings
705
751
  *
@@ -714,31 +760,7 @@ function createTemplateStringsArray(strings) {
714
760
  }
715
761
 
716
762
  //#endregion
717
- //#region src/functions/taggedTemplate/getInterpolations.ts
718
- /**
719
- *
720
- * Gets the strings and interpolations separately from a template string.
721
- * You can pass a template string directly by doing:
722
- *
723
- * ```typescript
724
- * getInterpolations`Template string here`.
725
- * ```
726
- *
727
- * @category Tagged Template
728
- *
729
- * @deprecated Please use `getStringsAndInterpolations` instead.
730
- *
731
- * @param strings - The strings from the template to process.
732
- * @param interpolations - An array of all interpolations from the template.
733
- *
734
- * @returns A tuple where the first item is the strings from the template, and the second is the interpolations.
735
- */
736
- function getInterpolations(strings, ...interpolations) {
737
- return [strings, interpolations];
738
- }
739
-
740
- //#endregion
741
- //#region src/functions/taggedTemplate/getStringsAndInterpolations.ts
763
+ //#region src/root/functions/taggedTemplate/getStringsAndInterpolations.ts
742
764
  /**
743
765
  *
744
766
  * Gets the strings and interpolations separately from a template string.
@@ -779,7 +801,7 @@ function getStringsAndInterpolations(strings, ...interpolations) {
779
801
  }
780
802
 
781
803
  //#endregion
782
- //#region src/functions/taggedTemplate/interpolate.ts
804
+ //#region src/root/functions/taggedTemplate/interpolate.ts
783
805
  /**
784
806
  * Returns the result of interpolating a template string when given the strings and interpolations separately.
785
807
  *
@@ -807,7 +829,7 @@ function interpolate(strings, ...interpolations) {
807
829
  }
808
830
 
809
831
  //#endregion
810
- //#region src/functions/taggedTemplate/interpolateObjects.ts
832
+ //#region src/root/functions/taggedTemplate/interpolateObjects.ts
811
833
  /**
812
834
  * Returns the result of interpolating a template string, also stringifying objects.
813
835
  *
@@ -836,7 +858,7 @@ function interpolateObjects(strings, ...interpolations) {
836
858
  }
837
859
 
838
860
  //#endregion
839
- //#region src/functions/taggedTemplate/isTemplateStringsArray.ts
861
+ //#region src/root/functions/taggedTemplate/isTemplateStringsArray.ts
840
862
  /**
841
863
  * Determines whether or not the input is a valid `TemplateStringsArray`.
842
864
  *
@@ -851,7 +873,7 @@ function isTemplateStringsArray(input) {
851
873
  }
852
874
 
853
875
  //#endregion
854
- //#region src/functions/taggedTemplate/normaliseIndents.ts
876
+ //#region src/root/functions/taggedTemplate/normaliseIndents.ts
855
877
  function calculateTabSize(line, whitespaceLength) {
856
878
  const potentialWhitespacePart = line.slice(0, whitespaceLength);
857
879
  const trimmedString = line.trimStart();
@@ -940,7 +962,7 @@ function normaliseIndents(first, ...args) {
940
962
  const normalizeIndents = normaliseIndents;
941
963
 
942
964
  //#endregion
943
- //#region src/functions/miscellaneous/sayHello.ts
965
+ //#region src/root/functions/miscellaneous/sayHello.ts
944
966
  /**
945
967
  * Returns a string representing the lyrics to the package's theme song, Commit To You
946
968
  *
@@ -1054,7 +1076,7 @@ function sayHello() {
1054
1076
  }
1055
1077
 
1056
1078
  //#endregion
1057
- //#region src/functions/miscellaneous/stringifyDotenv.ts
1079
+ //#region src/root/functions/miscellaneous/stringifyDotenv.ts
1058
1080
  /**
1059
1081
  * Converts an object into a string in .env file format.
1060
1082
  *
@@ -1090,7 +1112,7 @@ function stringifyDotenv(contents, options) {
1090
1112
  }
1091
1113
 
1092
1114
  //#endregion
1093
- //#region src/functions/miscellaneous/stringListToArray.ts
1115
+ //#region src/root/functions/miscellaneous/stringListToArray.ts
1094
1116
  /**
1095
1117
  * Converts a stringly-typed list to a proper array.
1096
1118
  *
@@ -1112,7 +1134,7 @@ function stringListToArray(stringList, { separator = ",", trimWhitespace = true
1112
1134
  }
1113
1135
 
1114
1136
  //#endregion
1115
- //#region src/functions/miscellaneous/wait.ts
1137
+ //#region src/root/functions/miscellaneous/wait.ts
1116
1138
  /**
1117
1139
  * Waits for the given number of seconds
1118
1140
  *
@@ -1131,7 +1153,7 @@ function wait(seconds) {
1131
1153
  }
1132
1154
 
1133
1155
  //#endregion
1134
- //#region src/functions/objectHelpers/getRecordKeys.ts
1156
+ //#region src/root/functions/objectHelpers/getRecordKeys.ts
1135
1157
  /**
1136
1158
  * Gets the keys from a given record object, properly typed to be an array of the key of the input object's type.
1137
1159
  *
@@ -1148,7 +1170,7 @@ function getRecordKeys(record) {
1148
1170
  }
1149
1171
 
1150
1172
  //#endregion
1151
- //#region src/functions/objectHelpers/omitProperties.ts
1173
+ //#region src/root/functions/objectHelpers/omitProperties.ts
1152
1174
  /**
1153
1175
  * Omits properties from a given object.
1154
1176
  *
@@ -1171,7 +1193,7 @@ function omitProperties(object, keysToOmit) {
1171
1193
  }
1172
1194
 
1173
1195
  //#endregion
1174
- //#region src/functions/objectHelpers/removeUndefinedFromObject.ts
1196
+ //#region src/root/functions/objectHelpers/removeUndefinedFromObject.ts
1175
1197
  /**
1176
1198
  * Removes entries whose values are `undefined` from a given object (not including null etc.).
1177
1199
  *
@@ -1186,7 +1208,7 @@ function removeUndefinedFromObject(object) {
1186
1208
  }
1187
1209
 
1188
1210
  //#endregion
1189
- //#region src/functions/parsers/parseBoolean.ts
1211
+ //#region src/root/functions/parsers/parseBoolean.ts
1190
1212
  /**
1191
1213
  * Takes a stringly-typed boolean and converts it to an actual boolean type.
1192
1214
  *
@@ -1200,13 +1222,13 @@ function removeUndefinedFromObject(object) {
1200
1222
  */
1201
1223
  function parseBoolean(inputString) {
1202
1224
  const normalisedString = inputString.toLowerCase();
1203
- if (!["true", "false"].includes(normalisedString)) throw new DataError(inputString, "INVALID_BOOLEAN_STRING", "The provided boolean string must be one of `true | false`");
1225
+ if (!["true", "false"].includes(normalisedString)) throw new DataError({ inputString }, "INVALID_BOOLEAN_STRING", "The provided boolean string must be one of `true | false`");
1204
1226
  return normalisedString === "true";
1205
1227
  }
1206
1228
 
1207
1229
  //#endregion
1208
- //#region src/functions/parsers/zod/_parseZodSchema.ts
1209
- function _parseZodSchema(parsedResult, data, onError) {
1230
+ //#region src/root/functions/parsers/zod/_parseZodSchema.ts
1231
+ function _parseZodSchema(parsedResult, input, onError) {
1210
1232
  if (!parsedResult.success) {
1211
1233
  if (onError) {
1212
1234
  if (onError instanceof Error) throw onError;
@@ -1220,7 +1242,7 @@ function _parseZodSchema(parsedResult, data, onError) {
1220
1242
  const code = issue.code.toUpperCase();
1221
1243
  allErrorCodes[code] = (allErrorCodes[code] ?? 0) + 1;
1222
1244
  }
1223
- throw new DataError(data, Object.entries(allErrorCodes).toSorted(([_, firstCount], [__, secondCount]) => {
1245
+ throw new DataError({ input }, Object.entries(allErrorCodes).toSorted(([_, firstCount], [__, secondCount]) => {
1224
1246
  return secondCount - firstCount;
1225
1247
  }).map(([code, count], _, allErrorCodes) => {
1226
1248
  return allErrorCodes.length === 1 && count === 1 ? code : `${code}×${count}`;
@@ -1230,7 +1252,7 @@ function _parseZodSchema(parsedResult, data, onError) {
1230
1252
  }
1231
1253
 
1232
1254
  //#endregion
1233
- //#region src/functions/parsers/zod/parseZodSchema.ts
1255
+ //#region src/root/functions/parsers/zod/parseZodSchema.ts
1234
1256
  /**
1235
1257
  * An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
1236
1258
  *
@@ -1242,19 +1264,19 @@ function _parseZodSchema(parsedResult, data, onError) {
1242
1264
  * @template ErrorType - The type of error to throw on invalid data.
1243
1265
  *
1244
1266
  * @param schema - The Zod schema to use in parsing.
1245
- * @param data - The data to parse.
1267
+ * @param input - The data to parse.
1246
1268
  * @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
1247
1269
  *
1248
1270
  * @throws {DataError} If the given data cannot be parsed according to the schema.
1249
1271
  *
1250
1272
  * @returns The parsed data from the Zod schema.
1251
1273
  */
1252
- function parseZodSchema(schema, data, onError) {
1253
- return _parseZodSchema(schema.safeParse(data), data, onError);
1274
+ function parseZodSchema(schema, input, onError) {
1275
+ return _parseZodSchema(schema.safeParse(input), input, onError);
1254
1276
  }
1255
1277
 
1256
1278
  //#endregion
1257
- //#region src/functions/parsers/parseEnv.ts
1279
+ //#region src/root/functions/parsers/parseEnv.ts
1258
1280
  /**
1259
1281
  * Represents the three common development environments.
1260
1282
  *
@@ -1270,18 +1292,18 @@ const Env = {
1270
1292
  *
1271
1293
  * @category Parsers
1272
1294
  *
1273
- * @param data - The data to parse.
1295
+ * @param input - The data to parse.
1274
1296
  *
1275
1297
  * @throws {DataError} If the data does not match one of the environments allowed by the Env types ("test" | "development" | "production").
1276
1298
  *
1277
1299
  * @returns The specified environment if allowed.
1278
1300
  */
1279
- function parseEnv(data) {
1280
- return parseZodSchema(z$1.enum(Env), data, new DataError(data, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
1301
+ function parseEnv(input) {
1302
+ return parseZodSchema(z$1.enum(Env), input, new DataError({ input }, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
1281
1303
  }
1282
1304
 
1283
1305
  //#endregion
1284
- //#region src/functions/parsers/parseFilePath.ts
1306
+ //#region src/root/functions/parsers/parseFilePath.ts
1285
1307
  /**
1286
1308
  * Takes a file path string and parses it into the directory part, the base part, and the full path.
1287
1309
  *
@@ -1312,7 +1334,7 @@ function parseFilePath(filePath) {
1312
1334
  }
1313
1335
 
1314
1336
  //#endregion
1315
- //#region src/functions/parsers/parseFormData.ts
1337
+ //#region src/root/functions/parsers/parseFormData.ts
1316
1338
  /**
1317
1339
  * Returns an object given FormData and an optional data parser function to call on the resulting object.
1318
1340
  *
@@ -1335,7 +1357,7 @@ function parseFormData(formData, dataParser) {
1335
1357
  }
1336
1358
 
1337
1359
  //#endregion
1338
- //#region src/functions/parsers/parseVersionType.ts
1360
+ //#region src/root/functions/parsers/parseVersionType.ts
1339
1361
  /**
1340
1362
  * Represents the three common software version types.
1341
1363
  *
@@ -1351,18 +1373,18 @@ const VersionType = {
1351
1373
  *
1352
1374
  * @category Parsers
1353
1375
  *
1354
- * @param data - The data to parse.
1376
+ * @param input - The data to parse.
1355
1377
  *
1356
1378
  * @throws {DataError} If the data does not match one of the allowed version types (`"major" | "minor" | "patch"`).
1357
1379
  *
1358
1380
  * @returns The given version type if allowed.
1359
1381
  */
1360
- function parseVersionType(data) {
1361
- return parseZodSchema(z.enum(VersionType), data, new DataError(data, "INVALID_VERSION_TYPE", "The provided version type must be one of `major | minor | patch`"));
1382
+ function parseVersionType(input) {
1383
+ return parseZodSchema(z.enum(VersionType), input, new DataError({ input }, "INVALID_VERSION_TYPE", "The provided version type must be one of `major | minor | patch`"));
1362
1384
  }
1363
1385
 
1364
1386
  //#endregion
1365
- //#region src/functions/parsers/zod/parseZodSchemaAsync.ts
1387
+ //#region src/root/functions/parsers/zod/parseZodSchemaAsync.ts
1366
1388
  /**
1367
1389
  * An alternative function to zodSchema.parseAsync() that can be used to strictly parse asynchronous Zod schemas.
1368
1390
  *
@@ -1372,19 +1394,19 @@ function parseVersionType(data) {
1372
1394
  * @template ErrorType - The type of error to throw on invalid data.
1373
1395
  *
1374
1396
  * @param schema - The Zod schema to use in parsing.
1375
- * @param data - The data to parse.
1397
+ * @param input - The data to parse.
1376
1398
  * @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
1377
1399
  *
1378
1400
  * @throws {DataError} If the given data cannot be parsed according to the schema.
1379
1401
  *
1380
1402
  * @returns The parsed data from the Zod schema.
1381
1403
  */
1382
- async function parseZodSchemaAsync(schema, data, onError) {
1383
- return _parseZodSchema(await schema.safeParseAsync(data), data, onError);
1404
+ async function parseZodSchemaAsync(schema, input, onError) {
1405
+ return _parseZodSchema(await schema.safeParseAsync(input), input, onError);
1384
1406
  }
1385
1407
 
1386
1408
  //#endregion
1387
- //#region src/functions/recursive/deepCopy.ts
1409
+ //#region src/root/functions/recursive/deepCopy.ts
1388
1410
  function callDeepCopy(input) {
1389
1411
  return typeof input === "object" && input !== null ? deepCopy(input) : input;
1390
1412
  }
@@ -1412,7 +1434,7 @@ function deepCopy(object) {
1412
1434
  }
1413
1435
 
1414
1436
  //#endregion
1415
- //#region src/functions/security/encryptWithKey.ts
1437
+ //#region src/root/functions/security/encryptWithKey.ts
1416
1438
  /**
1417
1439
  * Encrypt a secret given the public base64 key and the thing you want to encrypt.
1418
1440
  *
@@ -1433,32 +1455,7 @@ async function encryptWithKey(publicKey, plaintextValue) {
1433
1455
  }
1434
1456
 
1435
1457
  //#endregion
1436
- //#region src/functions/security/getPublicAndPrivateKey.ts
1437
- /**
1438
- * Returns the public key and private key, properly narrowing down types depending on the provided `outputFormat`.
1439
- *
1440
- * @deprecated Please use `sodium.crypto_box_keypair` from `libsodium-wrappers` instead.
1441
- *
1442
- * This function was initially created to deal with a typing issue with the package introduced in v0.8.1 of said package, but this seems to have been fixed in v0.8.2
1443
- *
1444
- * @param outputFormat - The format of the resulting publicKey and privateKey you would like to use.
1445
- *
1446
- * @returns An object containing both the publicKey and privateKey, along with a keyType.
1447
- */
1448
- function getPublicAndPrivateKey(outputFormat) {
1449
- const keys = sodium.crypto_box_keypair(outputFormat);
1450
- if (outputFormat === "uint8array" || outputFormat === void 0) {
1451
- if (!(keys?.publicKey instanceof Uint8Array && keys?.privateKey instanceof Uint8Array)) throw new DataError({
1452
- publicKey: `<redacted: ${keys?.publicKey?.constructor?.name ?? typeof keys?.publicKey}>`,
1453
- privateKey: `<redacted: ${keys?.privateKey?.constructor?.name ?? typeof keys?.privateKey}>`
1454
- }, "INVALID_KEY_TYPES", "Expected Uint8Array keypair from libsodium.");
1455
- return keys;
1456
- }
1457
- return keys;
1458
- }
1459
-
1460
- //#endregion
1461
- //#region src/functions/stringHelpers/appendSemicolon.ts
1458
+ //#region src/root/functions/stringHelpers/appendSemicolon.ts
1462
1459
  /**
1463
1460
  * Appends a semicolon to the end of a string, trimming where necessary first.
1464
1461
  *
@@ -1478,7 +1475,7 @@ function appendSemicolon(stringToAppendTo) {
1478
1475
  }
1479
1476
 
1480
1477
  //#endregion
1481
- //#region src/functions/stringHelpers/camelToKebab.ts
1478
+ //#region src/root/functions/stringHelpers/camelToKebab.ts
1482
1479
  /**
1483
1480
  * Converts a string from camelCase to kebab-case
1484
1481
  *
@@ -1517,7 +1514,7 @@ function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
1517
1514
  }
1518
1515
 
1519
1516
  //#endregion
1520
- //#region src/functions/stringHelpers/kebabToCamel.ts
1517
+ //#region src/root/functions/stringHelpers/kebabToCamel.ts
1521
1518
  /**
1522
1519
  * Converts a string from kebab-case to camelCase
1523
1520
  *
@@ -1556,44 +1553,7 @@ function kebabToCamel(string, options) {
1556
1553
  }
1557
1554
 
1558
1555
  //#endregion
1559
- //#region src/functions/stringHelpers/normalizeImportPath.ts
1560
- /**
1561
- * Normalizes an import path meant for use in an import statement in JavaScript.
1562
- * When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. If the path is a zero-length string, '.' is returned, representing the current working directory.
1563
- *
1564
- * If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
1565
- *
1566
- * Helpful for custom linter rules that need to check (or fix) import paths.
1567
- *
1568
- * @category String Helpers
1569
- *
1570
- * @param importPath - The import path to normalize.
1571
- *
1572
- * @returns The import path normalized.
1573
- */
1574
- function normalizeImportPath(importPath) {
1575
- const normalizedPath = path.posix.normalize(importPath);
1576
- if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) return `./${normalizedPath}`;
1577
- return normalizedPath;
1578
- }
1579
- /**
1580
- * Normalises an import path meant for use in an import statement in JavaScript.
1581
- * When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. If the path is a zero-length string, '.' is returned, representing the current working directory.
1582
- *
1583
- * If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
1584
- *
1585
- * Helpful for custom linter rules that need to check (or fix) import paths.
1586
- *
1587
- * @category String Helpers
1588
- *
1589
- * @param importPath - The import path to normalise.
1590
- *
1591
- * @returns The import path normalised.
1592
- */
1593
- const normaliseImportPath = normalizeImportPath;
1594
-
1595
- //#endregion
1596
- //#region src/functions/stringHelpers/truncate.ts
1556
+ //#region src/root/functions/stringHelpers/truncate.ts
1597
1557
  /**
1598
1558
  * Truncates a string and appends `...` to the end of it
1599
1559
  *
@@ -1609,92 +1569,4 @@ function truncate(stringToTruncate, maxLength = 5) {
1609
1569
  }
1610
1570
 
1611
1571
  //#endregion
1612
- //#region src/functions/versioning/parseVersion.ts
1613
- /**
1614
- * Parses a string and verifies it is a valid package version number.
1615
- *
1616
- * Valid formats: `X.Y.Z` or `vX.Y.Z`, where X, Y, and Z are non-negative integers.
1617
- *
1618
- * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(input)` instead.
1619
- *
1620
- * @param input - The version string to parse.
1621
- * @param options - Extra options to apply.
1622
- *
1623
- * @throws {DataError} If the input is not a valid version number.
1624
- *
1625
- * @returns The validated version number, prefixed with `v` if it was not already.
1626
- */
1627
- function parseVersion(input, options) {
1628
- if (!RegExp(VERSION_NUMBER_REGEX).test(input)) throw new DataError(input, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
1629
- if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
1630
- return input.startsWith("v") ? input : `v${input}`;
1631
- }
1632
-
1633
- //#endregion
1634
- //#region src/functions/versioning/getIndividualVersionNumbers.ts
1635
- /**
1636
- * Gets the individual version numbers from a given version number as a tuple of numbers.
1637
- *
1638
- * @deprecated This function does not support the new class-based handling of VersionNumber. Please use one of the following instead:
1639
- * ```typescript
1640
- * new VersionNumber(version).major
1641
- * new VersionNumber(version).minor
1642
- * new VersionNumber(version).patch
1643
- * ```
1644
- *
1645
- * @param version - The version number.
1646
- *
1647
- * @returns A tuple of three numbers indicating `[major, minor, patch]`.
1648
- */
1649
- function getIndividualVersionNumbers(version) {
1650
- return parseVersion(version, { omitPrefix: true }).split(".").map((versionNumber) => {
1651
- return parseIntStrict(versionNumber);
1652
- });
1653
- }
1654
-
1655
- //#endregion
1656
- //#region src/functions/versioning/determineVersionType.ts
1657
- /**
1658
- * Determines whether the given version is a major, minor, or patch version.
1659
- *
1660
- * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).type` instead.
1661
- *
1662
- * @param version - The version number.
1663
- *
1664
- * @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
1665
- */
1666
- function determineVersionType(version) {
1667
- const [_major, minor, patch] = getIndividualVersionNumbers(version);
1668
- if (minor === 0 && patch === 0) return "major";
1669
- if (patch === 0) return "minor";
1670
- return "patch";
1671
- }
1672
-
1673
- //#endregion
1674
- //#region src/functions/versioning/incrementVersion.ts
1675
- /**
1676
- * Increments the given input version depending on the given increment type.
1677
- *
1678
- * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).increment(incrementType)` instead.
1679
- *
1680
- * @param version - The version to increment
1681
- * @param incrementType - The type of increment. Can be one of the following:
1682
- * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
1683
- * - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
1684
- * - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
1685
- * @param options - Extra options to apply.
1686
- *
1687
- * @returns A new string representing the version with the increment applied.
1688
- */
1689
- function incrementVersion(version, incrementType, options) {
1690
- const [major, minor, patch] = getIndividualVersionNumbers(version);
1691
- const newVersion = {
1692
- major: `${major + 1}.0.0`,
1693
- minor: `${major}.${minor + 1}.0`,
1694
- patch: `${major}.${minor}.${patch + 1}`
1695
- }[incrementType];
1696
- return parseVersion(newVersion, { omitPrefix: options?.omitPrefix });
1697
- }
1698
-
1699
- //#endregion
1700
- export { APIError, DataError, Env, FILE_PATH_REGEX, NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getPublicAndPrivateKey, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFilePath, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
1572
+ export { APIError, DataError, Env, FILE_PATH_REGEX, NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, encryptWithKey, fillArray, formatDateAndTime, getDependenciesFromGroup, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFilePath, parseFormData, parseIntStrict, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };