@alextheman/utility 4.12.3 → 4.14.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.cjs +476 -349
- package/dist/index.d.cts +67 -6
- package/dist/index.d.ts +67 -6
- package/dist/index.js +419 -296
- package/package.json +11 -9
package/dist/index.js
CHANGED
|
@@ -4,17 +4,14 @@ import sodium from "libsodium-wrappers";
|
|
|
4
4
|
|
|
5
5
|
//#region src/constants/FILE_PATH_REGEX.ts
|
|
6
6
|
const FILE_PATH_REGEX = String.raw`^(?<directory>.+)[\/\\](?<base>[^\/\\]+)$`;
|
|
7
|
-
var FILE_PATH_REGEX_default = FILE_PATH_REGEX;
|
|
8
7
|
|
|
9
8
|
//#endregion
|
|
10
9
|
//#region src/constants/NAMESPACE_EXPORT_REGEX.ts
|
|
11
10
|
const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
12
|
-
var NAMESPACE_EXPORT_REGEX_default = NAMESPACE_EXPORT_REGEX;
|
|
13
11
|
|
|
14
12
|
//#endregion
|
|
15
13
|
//#region src/constants/VERSION_NUMBER_REGEX.ts
|
|
16
14
|
const VERSION_NUMBER_REGEX = "^(?:v)?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$";
|
|
17
|
-
var VERSION_NUMBER_REGEX_default = VERSION_NUMBER_REGEX;
|
|
18
15
|
|
|
19
16
|
//#endregion
|
|
20
17
|
//#region src/functions/arrayHelpers/fillArray.ts
|
|
@@ -42,7 +39,6 @@ function fillArray(callback, length = 1) {
|
|
|
42
39
|
})) return Promise.all(outputArray);
|
|
43
40
|
return outputArray;
|
|
44
41
|
}
|
|
45
|
-
var fillArray_default = fillArray;
|
|
46
42
|
|
|
47
43
|
//#endregion
|
|
48
44
|
//#region src/functions/arrayHelpers/paralleliseArrays.ts
|
|
@@ -67,7 +63,6 @@ function paralleliseArrays(firstArray, secondArray) {
|
|
|
67
63
|
for (let i = 0; i < firstArray.length; i++) outputArray.push([firstArray[i], secondArray[i]]);
|
|
68
64
|
return outputArray;
|
|
69
65
|
}
|
|
70
|
-
var paralleliseArrays_default = paralleliseArrays;
|
|
71
66
|
|
|
72
67
|
//#endregion
|
|
73
68
|
//#region src/types/APIError.ts
|
|
@@ -111,7 +106,6 @@ var APIError = class extends Error {
|
|
|
111
106
|
return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
|
|
112
107
|
}
|
|
113
108
|
};
|
|
114
|
-
var APIError_default = APIError;
|
|
115
109
|
|
|
116
110
|
//#endregion
|
|
117
111
|
//#region src/types/DataError.ts
|
|
@@ -150,7 +144,6 @@ var DataError = class extends Error {
|
|
|
150
144
|
return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
|
|
151
145
|
}
|
|
152
146
|
};
|
|
153
|
-
var DataError_default = DataError;
|
|
154
147
|
|
|
155
148
|
//#endregion
|
|
156
149
|
//#region src/types/VersionNumber.ts
|
|
@@ -176,18 +169,18 @@ var VersionNumber = class VersionNumber {
|
|
|
176
169
|
this.minor = input.minor;
|
|
177
170
|
this.patch = input.patch;
|
|
178
171
|
} else if (typeof input === "string") {
|
|
179
|
-
if (!RegExp(
|
|
172
|
+
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.`);
|
|
180
173
|
const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
|
|
181
|
-
return
|
|
174
|
+
return parseIntStrict(number);
|
|
182
175
|
});
|
|
183
176
|
this.major = major;
|
|
184
177
|
this.minor = minor;
|
|
185
178
|
this.patch = patch;
|
|
186
179
|
} else if (Array.isArray(input)) {
|
|
187
|
-
if (input.length !== 3) throw new
|
|
180
|
+
if (input.length !== 3) throw new DataError(input, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
188
181
|
const [major, minor, patch] = input.map((number) => {
|
|
189
|
-
const parsedInteger =
|
|
190
|
-
if (parsedInteger < 0) throw new
|
|
182
|
+
const parsedInteger = parseIntStrict(number?.toString());
|
|
183
|
+
if (parsedInteger < 0) throw new DataError(input, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
191
184
|
return parsedInteger;
|
|
192
185
|
});
|
|
193
186
|
this.major = major;
|
|
@@ -257,7 +250,7 @@ var VersionNumber = class VersionNumber {
|
|
|
257
250
|
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
258
251
|
*/
|
|
259
252
|
[Symbol.toPrimitive](hint) {
|
|
260
|
-
if (hint === "number") throw new
|
|
253
|
+
if (hint === "number") throw new DataError(this.toString(), "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
|
|
261
254
|
return this.toString();
|
|
262
255
|
}
|
|
263
256
|
/**
|
|
@@ -280,7 +273,6 @@ var VersionNumber = class VersionNumber {
|
|
|
280
273
|
return VersionNumber.formatString(rawString, options);
|
|
281
274
|
}
|
|
282
275
|
};
|
|
283
|
-
var VersionNumber_default = VersionNumber;
|
|
284
276
|
|
|
285
277
|
//#endregion
|
|
286
278
|
//#region src/functions/parsers/parseIntStrict.ts
|
|
@@ -299,21 +291,20 @@ var VersionNumber_default = VersionNumber;
|
|
|
299
291
|
function parseIntStrict(string, radix) {
|
|
300
292
|
const trimmedString = string.trim();
|
|
301
293
|
const maxAllowedAlphabeticalCharacter = radix && radix > 10 && radix <= 36 ? String.fromCharCode(87 + radix - 1) : void 0;
|
|
302
|
-
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new
|
|
294
|
+
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new DataError(radix ? {
|
|
303
295
|
string,
|
|
304
296
|
radix
|
|
305
297
|
} : string, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
|
|
306
298
|
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
307
299
|
return parseInt(character) >= radix;
|
|
308
|
-
})) throw new
|
|
300
|
+
})) throw new DataError({
|
|
309
301
|
string,
|
|
310
302
|
radix
|
|
311
303
|
}, "INTEGER_PARSING_ERROR", "Value contains one or more digits outside of the range of the given radix.");
|
|
312
304
|
const parseIntResult = parseInt(trimmedString, radix);
|
|
313
|
-
if (isNaN(parseIntResult)) throw new
|
|
305
|
+
if (isNaN(parseIntResult)) throw new DataError(string, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
|
|
314
306
|
return parseIntResult;
|
|
315
307
|
}
|
|
316
|
-
var parseIntStrict_default = parseIntStrict;
|
|
317
308
|
|
|
318
309
|
//#endregion
|
|
319
310
|
//#region src/functions/miscellaneous/getRandomNumber.ts
|
|
@@ -328,11 +319,10 @@ var parseIntStrict_default = parseIntStrict;
|
|
|
328
319
|
* @returns A random number between the provided lower bound and upper bound.
|
|
329
320
|
*/
|
|
330
321
|
function getRandomNumber(lowerBound, upperBound) {
|
|
331
|
-
const parsedLowerBound =
|
|
332
|
-
const parsedUpperBound =
|
|
322
|
+
const parsedLowerBound = parseIntStrict(`${lowerBound}`);
|
|
323
|
+
const parsedUpperBound = parseIntStrict(`${upperBound}`);
|
|
333
324
|
return Math.floor(Math.random() * (parsedUpperBound - parsedLowerBound + 1) + parsedLowerBound);
|
|
334
325
|
}
|
|
335
|
-
var getRandomNumber_default = getRandomNumber;
|
|
336
326
|
|
|
337
327
|
//#endregion
|
|
338
328
|
//#region src/functions/arrayHelpers/randomiseArray.ts
|
|
@@ -351,12 +341,11 @@ function randomiseArray(array) {
|
|
|
351
341
|
const mutableArray = [...array];
|
|
352
342
|
const outputArray = [];
|
|
353
343
|
do {
|
|
354
|
-
const indexToRemove =
|
|
344
|
+
const indexToRemove = getRandomNumber(0, mutableArray.length - 1);
|
|
355
345
|
outputArray.push(mutableArray.splice(indexToRemove, 1)[0]);
|
|
356
346
|
} while (mutableArray.length > 0);
|
|
357
347
|
return outputArray;
|
|
358
348
|
}
|
|
359
|
-
var randomiseArray_default = randomiseArray;
|
|
360
349
|
|
|
361
350
|
//#endregion
|
|
362
351
|
//#region src/functions/arrayHelpers/range.ts
|
|
@@ -389,7 +378,6 @@ function range(start, stop, step = 1) {
|
|
|
389
378
|
}
|
|
390
379
|
return numbers;
|
|
391
380
|
}
|
|
392
|
-
var range_default = range;
|
|
393
381
|
|
|
394
382
|
//#endregion
|
|
395
383
|
//#region src/functions/arrayHelpers/removeDuplicates.ts
|
|
@@ -409,7 +397,6 @@ function removeDuplicates(array) {
|
|
|
409
397
|
for (const item of array) if (!outputArray.includes(item)) outputArray.push(item);
|
|
410
398
|
return outputArray;
|
|
411
399
|
}
|
|
412
|
-
var removeDuplicates_default = removeDuplicates;
|
|
413
400
|
|
|
414
401
|
//#endregion
|
|
415
402
|
//#region src/functions/date/addDaysToDate.ts
|
|
@@ -428,7 +415,6 @@ function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement =
|
|
|
428
415
|
newDate.setDate(newDate.getDate() + dayIncrement);
|
|
429
416
|
return newDate;
|
|
430
417
|
}
|
|
431
|
-
var addDaysToDate_default = addDaysToDate;
|
|
432
418
|
|
|
433
419
|
//#endregion
|
|
434
420
|
//#region src/functions/date/isSameDate.ts
|
|
@@ -445,7 +431,6 @@ var addDaysToDate_default = addDaysToDate;
|
|
|
445
431
|
function isSameDate(firstDate, secondDate) {
|
|
446
432
|
return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth() && firstDate.getFullYear() === secondDate.getFullYear();
|
|
447
433
|
}
|
|
448
|
-
var isSameDate_default = isSameDate;
|
|
449
434
|
|
|
450
435
|
//#endregion
|
|
451
436
|
//#region src/functions/date/formatDateAndTime.ts
|
|
@@ -463,14 +448,13 @@ var isSameDate_default = isSameDate;
|
|
|
463
448
|
* - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
|
|
464
449
|
*/
|
|
465
450
|
function formatDateAndTime(inputDate) {
|
|
466
|
-
const yesterday =
|
|
451
|
+
const yesterday = addDaysToDate(/* @__PURE__ */ new Date(), -1);
|
|
467
452
|
const today = /* @__PURE__ */ new Date();
|
|
468
453
|
const inputTime = `${inputDate.getHours().toString().padStart(2, "0")}:${inputDate.getMinutes().toString().padStart(2, "0")}`;
|
|
469
|
-
if (
|
|
470
|
-
if (
|
|
454
|
+
if (isSameDate(inputDate, yesterday)) return `Yesterday at ${inputTime}`;
|
|
455
|
+
if (isSameDate(inputDate, today)) return `Today at ${inputTime}`;
|
|
471
456
|
return `${inputDate.getDate().toString().padStart(2, "0")}/${(inputDate.getMonth() + 1).toString().padStart(2, "0")}/${inputDate.getFullYear().toString()}, ${inputTime}`;
|
|
472
457
|
}
|
|
473
|
-
var formatDateAndTime_default = formatDateAndTime;
|
|
474
458
|
|
|
475
459
|
//#endregion
|
|
476
460
|
//#region src/functions/date/isLeapYear.ts
|
|
@@ -486,15 +470,14 @@ var formatDateAndTime_default = formatDateAndTime;
|
|
|
486
470
|
* @returns True if the year is a leap year, and false otherwise.
|
|
487
471
|
*/
|
|
488
472
|
function isLeapYear(year) {
|
|
489
|
-
const parsedYear =
|
|
473
|
+
const parsedYear = parseIntStrict(`${year}`);
|
|
490
474
|
return parsedYear % 4 === 0 && parsedYear % 100 !== 0 || parsedYear % 400 === 0;
|
|
491
475
|
}
|
|
492
|
-
var isLeapYear_default = isLeapYear;
|
|
493
476
|
|
|
494
477
|
//#endregion
|
|
495
478
|
//#region src/functions/date/isAnniversary.ts
|
|
496
479
|
function checkLeapYear(firstDate, secondDate) {
|
|
497
|
-
if (
|
|
480
|
+
if (isLeapYear(firstDate.getFullYear()) && firstDate.getMonth() === 1 && secondDate.getMonth() === 1) return firstDate.getDate() === 29 && secondDate.getDate() === 28;
|
|
498
481
|
return false;
|
|
499
482
|
}
|
|
500
483
|
/**
|
|
@@ -511,7 +494,6 @@ function isAnniversary(firstDate, secondDate) {
|
|
|
511
494
|
if (checkLeapYear(firstDate, secondDate) || checkLeapYear(secondDate, firstDate)) return true;
|
|
512
495
|
return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth();
|
|
513
496
|
}
|
|
514
|
-
var isAnniversary_default = isAnniversary;
|
|
515
497
|
|
|
516
498
|
//#endregion
|
|
517
499
|
//#region src/functions/date/isMonthlyMultiple.ts
|
|
@@ -526,7 +508,7 @@ function endOfMonthChecksButNotFebruary(firstDate, secondDate) {
|
|
|
526
508
|
}
|
|
527
509
|
function nonLeapYearFebruaryChecks(firstDate, secondDate) {
|
|
528
510
|
if (firstDate.getMonth() === 1) {
|
|
529
|
-
if (!
|
|
511
|
+
if (!isLeapYear(firstDate.getFullYear()) && firstDate.getDate() === 28) return [
|
|
530
512
|
28,
|
|
531
513
|
29,
|
|
532
514
|
30,
|
|
@@ -537,7 +519,7 @@ function nonLeapYearFebruaryChecks(firstDate, secondDate) {
|
|
|
537
519
|
}
|
|
538
520
|
function leapYearFebruaryChecks(firstDate, secondDate) {
|
|
539
521
|
if (firstDate.getMonth() === 1) {
|
|
540
|
-
if (
|
|
522
|
+
if (isLeapYear(firstDate.getFullYear()) && firstDate.getDate() === 29) return [
|
|
541
523
|
29,
|
|
542
524
|
30,
|
|
543
525
|
31
|
|
@@ -561,7 +543,6 @@ function isMonthlyMultiple(firstDate, secondDate) {
|
|
|
561
543
|
if (leapYearFebruaryChecks(firstDate, secondDate) || leapYearFebruaryChecks(secondDate, firstDate)) return true;
|
|
562
544
|
return firstDate.getDate() === secondDate.getDate();
|
|
563
545
|
}
|
|
564
|
-
var isMonthlyMultiple_default = isMonthlyMultiple;
|
|
565
546
|
|
|
566
547
|
//#endregion
|
|
567
548
|
//#region src/functions/miscellaneous/convertFileToBase64.ts
|
|
@@ -592,7 +573,6 @@ function convertFileToBase64(file) {
|
|
|
592
573
|
};
|
|
593
574
|
});
|
|
594
575
|
}
|
|
595
|
-
var convertFileToBase64_default = convertFileToBase64;
|
|
596
576
|
|
|
597
577
|
//#endregion
|
|
598
578
|
//#region src/functions/miscellaneous/createFormData.ts
|
|
@@ -662,7 +642,6 @@ function createFormData(data, options = {
|
|
|
662
642
|
} else formData.append(String(key), String(value));
|
|
663
643
|
return formData;
|
|
664
644
|
}
|
|
665
|
-
var createFormData_default = createFormData;
|
|
666
645
|
|
|
667
646
|
//#endregion
|
|
668
647
|
//#region src/functions/miscellaneous/isOrdered.ts
|
|
@@ -681,7 +660,385 @@ function isOrdered(array) {
|
|
|
681
660
|
for (const index in newArray) if (newArray[index] !== array[index]) return false;
|
|
682
661
|
return true;
|
|
683
662
|
}
|
|
684
|
-
|
|
663
|
+
|
|
664
|
+
//#endregion
|
|
665
|
+
//#region src/functions/recursive/deepFreeze.ts
|
|
666
|
+
/**
|
|
667
|
+
* Deeply freezes an object or array such that all child objects/arrays are also frozen.
|
|
668
|
+
*
|
|
669
|
+
* Note that this will also freeze the input itself as well.
|
|
670
|
+
* If the intent is to create a newly frozen object with a different reference in memory, pass your object through deepCopy first before passing to deepFreeze.
|
|
671
|
+
*
|
|
672
|
+
* @category Recursive
|
|
673
|
+
*
|
|
674
|
+
* @template ObjectType - The type of the input object.
|
|
675
|
+
*
|
|
676
|
+
* @param object - The object to freeze. May also be an array.
|
|
677
|
+
*
|
|
678
|
+
* @returns The input object completely frozen.
|
|
679
|
+
*/
|
|
680
|
+
function deepFreeze(object) {
|
|
681
|
+
for (const value of Object.values(object)) {
|
|
682
|
+
if (typeof value === "function") continue;
|
|
683
|
+
if (value && typeof value === "object") deepFreeze(value);
|
|
684
|
+
}
|
|
685
|
+
return Object.freeze(object);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
//#endregion
|
|
689
|
+
//#region src/functions/taggedTemplate/createTemplateStringsArray.ts
|
|
690
|
+
/**
|
|
691
|
+
* Creates a template strings array given a regular array of strings
|
|
692
|
+
*
|
|
693
|
+
* @category Tagged Template
|
|
694
|
+
*
|
|
695
|
+
* @param strings - The array of strings.
|
|
696
|
+
*
|
|
697
|
+
* @returns A template strings array that can be passed as the first argument of any tagged template function.
|
|
698
|
+
*/
|
|
699
|
+
function createTemplateStringsArray(strings) {
|
|
700
|
+
return deepFreeze(Object.assign([...strings], { raw: [...strings] }));
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
//#endregion
|
|
704
|
+
//#region src/functions/taggedTemplate/getInterpolations.ts
|
|
705
|
+
/**
|
|
706
|
+
*
|
|
707
|
+
* Gets the strings and interpolations separately from a template string.
|
|
708
|
+
* You can pass a template string directly by doing:
|
|
709
|
+
*
|
|
710
|
+
* ```typescript
|
|
711
|
+
* getInterpolations`Template string here`.
|
|
712
|
+
* ```
|
|
713
|
+
*
|
|
714
|
+
* @category Tagged Template
|
|
715
|
+
*
|
|
716
|
+
* @deprecated Please use `getStringsAndInterpolations` instead.
|
|
717
|
+
*
|
|
718
|
+
* @param strings - The strings from the template to process.
|
|
719
|
+
* @param interpolations - An array of all interpolations from the template.
|
|
720
|
+
*
|
|
721
|
+
* @returns A tuple where the first item is the strings from the template, and the second is the interpolations.
|
|
722
|
+
*/
|
|
723
|
+
function getInterpolations(strings, ...interpolations) {
|
|
724
|
+
return [strings, interpolations];
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
//#endregion
|
|
728
|
+
//#region src/functions/taggedTemplate/getStringsAndInterpolations.ts
|
|
729
|
+
/**
|
|
730
|
+
*
|
|
731
|
+
* Gets the strings and interpolations separately from a template string.
|
|
732
|
+
* You can pass a template string directly by doing:
|
|
733
|
+
*
|
|
734
|
+
* ```typescript
|
|
735
|
+
* getStringsAndInterpolations`Template string here`;
|
|
736
|
+
* ```
|
|
737
|
+
*
|
|
738
|
+
* @category Tagged Template
|
|
739
|
+
*
|
|
740
|
+
* @template InterpolationsType - The type of the interpolations.
|
|
741
|
+
*
|
|
742
|
+
* @param strings - The strings from the template to process.
|
|
743
|
+
* @param interpolations - An array of all interpolations from the template.
|
|
744
|
+
*
|
|
745
|
+
* @returns A tuple where the first item is the strings from the template, and the remaining items are the interpolations.
|
|
746
|
+
*
|
|
747
|
+
* The return of this function may also be spread into any other tagged template function in the following way:
|
|
748
|
+
*
|
|
749
|
+
* ```typescript
|
|
750
|
+
* import { interpolate } from "@alextheman/utility"; // Example function
|
|
751
|
+
*
|
|
752
|
+
* const packageName = "@alextheman/utility";
|
|
753
|
+
* const packageManager = getPackageManager(packageName);
|
|
754
|
+
*
|
|
755
|
+
* interpolate(...getStringsAndInterpolations`The package ${packageName} uses the ${packageManager} package manager.`);
|
|
756
|
+
* ```
|
|
757
|
+
*/
|
|
758
|
+
function getStringsAndInterpolations(strings, ...interpolations) {
|
|
759
|
+
if (strings.length !== interpolations.length + 1) throw new DataError({
|
|
760
|
+
stringsLength: strings.length,
|
|
761
|
+
interpolationsLength: interpolations.length,
|
|
762
|
+
strings,
|
|
763
|
+
interpolations
|
|
764
|
+
}, "INVALID_STRINGS_AND_INTERPOLATIONS_LENGTH", "The length of the strings must be exactly one more than the length of the interpolations.");
|
|
765
|
+
return [createTemplateStringsArray(strings), ...interpolations];
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
//#endregion
|
|
769
|
+
//#region src/functions/taggedTemplate/interpolate.ts
|
|
770
|
+
/**
|
|
771
|
+
* Returns the result of interpolating a template string when given the strings and interpolations separately.
|
|
772
|
+
*
|
|
773
|
+
* You can pass a template string directly by doing:
|
|
774
|
+
*
|
|
775
|
+
* ```
|
|
776
|
+
* interpolate`Template string here`;
|
|
777
|
+
* ```
|
|
778
|
+
*
|
|
779
|
+
* In this case, it will be functionally the same as if you just wrote the template string by itself.
|
|
780
|
+
*
|
|
781
|
+
* @category Tagged Template
|
|
782
|
+
*
|
|
783
|
+
* @template InterpolationsType - The type of the interpolations.
|
|
784
|
+
*
|
|
785
|
+
* @param strings - The strings from the template to process.
|
|
786
|
+
* @param interpolations - An array of all interpolations from the template.
|
|
787
|
+
*
|
|
788
|
+
* @returns A new string with the strings and interpolations from the template applied.
|
|
789
|
+
*/
|
|
790
|
+
function interpolate(strings, ...interpolations) {
|
|
791
|
+
let result = "";
|
|
792
|
+
for (const [string, interpolation = ""] of paralleliseArrays(strings, interpolations)) result += string + interpolation;
|
|
793
|
+
return result;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
//#endregion
|
|
797
|
+
//#region src/functions/taggedTemplate/interpolateObjects.ts
|
|
798
|
+
/**
|
|
799
|
+
* Returns the result of interpolating a template string, also stringifying objects.
|
|
800
|
+
*
|
|
801
|
+
* You can pass a template string directly by doing:
|
|
802
|
+
*
|
|
803
|
+
* ```typescript
|
|
804
|
+
* interpolateObjects`Template string here ${{ my: "object" }}`;
|
|
805
|
+
* ```
|
|
806
|
+
*
|
|
807
|
+
* @category Tagged Template
|
|
808
|
+
*
|
|
809
|
+
* @template InterpolationsType - The type of the interpolations.
|
|
810
|
+
*
|
|
811
|
+
* @param strings - The strings from the template to process.
|
|
812
|
+
* @param interpolations - An array of all interpolations from the template.
|
|
813
|
+
*
|
|
814
|
+
* @returns A new string with the strings and interpolations from the template applied, with objects stringified.
|
|
815
|
+
*/
|
|
816
|
+
function interpolateObjects(strings, ...interpolations) {
|
|
817
|
+
let result = "";
|
|
818
|
+
for (let i = 0; i < strings.length; i++) {
|
|
819
|
+
result += strings[i];
|
|
820
|
+
if (i !== strings.length - 1) result += interpolations[i] && typeof interpolations[i] === "object" ? JSON.stringify(interpolations[i]) : interpolations[i];
|
|
821
|
+
}
|
|
822
|
+
return result;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
//#endregion
|
|
826
|
+
//#region src/functions/taggedTemplate/isTemplateStringsArray.ts
|
|
827
|
+
/**
|
|
828
|
+
* Determines whether or not the input is a valid `TemplateStringsArray`.
|
|
829
|
+
*
|
|
830
|
+
* @category Tagged Template
|
|
831
|
+
*
|
|
832
|
+
* @param input - The input to check
|
|
833
|
+
*
|
|
834
|
+
* @returns `true` if the input is a valid `TemplateStringsArray`, and false otherwise. The type of the input will also be narrowed down to `TemplateStringsArray` if `true`.
|
|
835
|
+
*/
|
|
836
|
+
function isTemplateStringsArray(input) {
|
|
837
|
+
return typeof input === "object" && input !== null && "raw" in input;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
//#endregion
|
|
841
|
+
//#region src/functions/taggedTemplate/normaliseIndents.ts
|
|
842
|
+
function calculateTabSize(line, whitespaceLength) {
|
|
843
|
+
const potentialWhitespacePart = line.slice(0, whitespaceLength);
|
|
844
|
+
const trimmedString = line.trimStart();
|
|
845
|
+
if (potentialWhitespacePart.trim() !== "") return 0;
|
|
846
|
+
const tabSize = line.length - (trimmedString.length + whitespaceLength);
|
|
847
|
+
return tabSize < 0 ? 0 : tabSize;
|
|
848
|
+
}
|
|
849
|
+
function getWhitespaceLength(lines) {
|
|
850
|
+
const [firstNonEmptyLine] = lines.filter((line) => {
|
|
851
|
+
return line.trim() !== "";
|
|
852
|
+
});
|
|
853
|
+
return firstNonEmptyLine.length - firstNonEmptyLine.trimStart().length;
|
|
854
|
+
}
|
|
855
|
+
function reduceLines(lines, { preserveTabs = true }) {
|
|
856
|
+
const slicedLines = lines.slice(1);
|
|
857
|
+
const isFirstLineEmpty = lines[0].trim() === "";
|
|
858
|
+
const whitespaceLength = getWhitespaceLength(isFirstLineEmpty ? lines : slicedLines);
|
|
859
|
+
return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
|
|
860
|
+
const tabSize = calculateTabSize(line, whitespaceLength);
|
|
861
|
+
return (preserveTabs ? fillArray(() => {
|
|
862
|
+
return " ";
|
|
863
|
+
}, tabSize).join("") : "") + line.trimStart();
|
|
864
|
+
}).join("\n");
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Applies any options if provided, then removes any extraneous indents from a multi-line template string.
|
|
868
|
+
*
|
|
869
|
+
* You can pass a template string directly by doing:
|
|
870
|
+
*
|
|
871
|
+
* ```typescript
|
|
872
|
+
* normaliseIndents`Template string here
|
|
873
|
+
* with a new line
|
|
874
|
+
* and another new line`;
|
|
875
|
+
* ```
|
|
876
|
+
*
|
|
877
|
+
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
878
|
+
*
|
|
879
|
+
* ```typescript
|
|
880
|
+
* normaliseIndents({ preserveTabs: false })`Template string here
|
|
881
|
+
* with a new line
|
|
882
|
+
* and another new line`;
|
|
883
|
+
* ```
|
|
884
|
+
*
|
|
885
|
+
* @category Tagged Template
|
|
886
|
+
*
|
|
887
|
+
* @param first - The strings from the template to process, or the options to apply.
|
|
888
|
+
* @param args - An array of all interpolations from the template.
|
|
889
|
+
*
|
|
890
|
+
* @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
891
|
+
*/
|
|
892
|
+
function normaliseIndents(first, ...args) {
|
|
893
|
+
if (typeof first === "object" && first !== null && !Array.isArray(first)) {
|
|
894
|
+
const options = first;
|
|
895
|
+
return (strings, ...interpolations) => {
|
|
896
|
+
return normaliseIndents(strings, ...interpolations, options);
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
const strings = first;
|
|
900
|
+
const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
|
|
901
|
+
return reduceLines(interpolate(strings, ...[...args]).split("\n"), options);
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Applies any options if provided, then removes any extraneous indents from a multi-line template string.
|
|
905
|
+
*
|
|
906
|
+
* You can pass a template string directly by doing:
|
|
907
|
+
*
|
|
908
|
+
* ```typescript
|
|
909
|
+
* normalizeIndents`Template string here
|
|
910
|
+
* with a new line
|
|
911
|
+
* and another new line`.
|
|
912
|
+
* ```
|
|
913
|
+
*
|
|
914
|
+
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
915
|
+
*
|
|
916
|
+
* ```typescript
|
|
917
|
+
* normalizeIndents({ preserveTabs: false })`Template string here
|
|
918
|
+
* with a new line
|
|
919
|
+
* and another new line`.
|
|
920
|
+
* ```
|
|
921
|
+
*
|
|
922
|
+
* @param first - The strings from the template to process, or the options to apply.
|
|
923
|
+
* @param args - An array of all interpolations from the template.
|
|
924
|
+
*
|
|
925
|
+
* @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
926
|
+
*/
|
|
927
|
+
const normalizeIndents = normaliseIndents;
|
|
928
|
+
|
|
929
|
+
//#endregion
|
|
930
|
+
//#region src/functions/miscellaneous/sayHello.ts
|
|
931
|
+
/**
|
|
932
|
+
* Returns a string representing the lyrics to the package's theme song, Commit To You
|
|
933
|
+
*
|
|
934
|
+
* [Pls listen!](https://www.youtube.com/watch?v=mH-Sg-8EnxM)
|
|
935
|
+
*
|
|
936
|
+
* @returns The lyrics string in markdown format.
|
|
937
|
+
*/
|
|
938
|
+
function sayHello() {
|
|
939
|
+
return normaliseIndents`
|
|
940
|
+
# Commit To You
|
|
941
|
+
|
|
942
|
+
### Verse 1
|
|
943
|
+
|
|
944
|
+
I know you've been checking me out,
|
|
945
|
+
Shall we take it to the next level now?
|
|
946
|
+
'Cause I really wanna be there all for you,
|
|
947
|
+
All for you!
|
|
948
|
+
Come on now, let's make a fresh start!
|
|
949
|
+
Pin my number, then you can take me out!
|
|
950
|
+
Can't you see I really do care about you,
|
|
951
|
+
About you!
|
|
952
|
+
|
|
953
|
+
### Pre-chorus 1
|
|
954
|
+
Although our calendars are imperfect, at best,
|
|
955
|
+
I'd like to organise time with you! (with you!).
|
|
956
|
+
Just tell me when and I'll make it clear,
|
|
957
|
+
All clear for you,
|
|
958
|
+
All clear for you!
|
|
959
|
+
(One, two, three, go!)
|
|
960
|
+
|
|
961
|
+
### Chorus
|
|
962
|
+
I wanna be of utility, I'll help you on the run!
|
|
963
|
+
I'll be the one here in the back, while you go have some fun!
|
|
964
|
+
Looking out for you tonight, I'll be the one you can rely on!
|
|
965
|
+
Watch you go and watch me pass by,
|
|
966
|
+
I'll be here!
|
|
967
|
+
I'll commit to you!
|
|
968
|
+
|
|
969
|
+
### Verse 2
|
|
970
|
+
Though sometimes it won't be easy,
|
|
971
|
+
You'll be here to bring out the best in me,
|
|
972
|
+
And I'll hold myself to high standards for you!
|
|
973
|
+
All for you!
|
|
974
|
+
We'll grow as a pair, you and me,
|
|
975
|
+
We'll build up a healthy dependency,
|
|
976
|
+
You can build with me and I'll develop with you!
|
|
977
|
+
I'm with you!
|
|
978
|
+
|
|
979
|
+
### Pre-chorus 2
|
|
980
|
+
I'll be with you when you're up or you're down,
|
|
981
|
+
We'll deal with all our problems together (together!)
|
|
982
|
+
Just tell me what you want, I'll make it clear,
|
|
983
|
+
All clear for you,
|
|
984
|
+
All clear for you!
|
|
985
|
+
(One, three, one, go!)
|
|
986
|
+
|
|
987
|
+
### Chorus
|
|
988
|
+
I wanna be of utility, I'll help you on the run!
|
|
989
|
+
(help you on the run!)
|
|
990
|
+
I'll be the one here in the back, while you go have some fun!
|
|
991
|
+
(you go have some fun!)
|
|
992
|
+
Looking out for you tonight, I'll be the one you can rely on!
|
|
993
|
+
Watch you go and watch me pass by,
|
|
994
|
+
I'll be here!
|
|
995
|
+
I'll commit to you!
|
|
996
|
+
|
|
997
|
+
### Bridge
|
|
998
|
+
Looking into our stack!
|
|
999
|
+
I'll commit to you!
|
|
1000
|
+
We've got a lot to unpack!
|
|
1001
|
+
I'll commit to you!
|
|
1002
|
+
The environment that we're in!
|
|
1003
|
+
I'll commit to you!
|
|
1004
|
+
Delicate as a string!
|
|
1005
|
+
I'll commit to you!
|
|
1006
|
+
|
|
1007
|
+
But I think you're my type!
|
|
1008
|
+
I'll commit to you!
|
|
1009
|
+
Oh, this feels all so right!
|
|
1010
|
+
I'll commit to you!
|
|
1011
|
+
Nothing stopping us now!
|
|
1012
|
+
I'll commit to you!
|
|
1013
|
+
Let's show them what we're about!
|
|
1014
|
+
Two, three, four, go!
|
|
1015
|
+
|
|
1016
|
+
### Final Chorus
|
|
1017
|
+
I wanna be of utility, I'll help you on the run!
|
|
1018
|
+
(help you on the run!)
|
|
1019
|
+
I'll be the one here in the back, while you go have some fun!
|
|
1020
|
+
(you go have some fun!)
|
|
1021
|
+
Looking out for you tonight, I'll be the one you can rely on!
|
|
1022
|
+
Watch you go and watch me pass by,
|
|
1023
|
+
I'll be here!
|
|
1024
|
+
I'll commit to you!
|
|
1025
|
+
|
|
1026
|
+
I wanna be of utility, I'll help you on the run!
|
|
1027
|
+
(I'll commit to you!)
|
|
1028
|
+
I'll be the one here in the back, while you go have some fun!
|
|
1029
|
+
(I'll commit to you!)
|
|
1030
|
+
Looking out for you tonight, I'll be the one you can rely on!
|
|
1031
|
+
(I'll commit to you!)
|
|
1032
|
+
Watch you go and watch me pass by,
|
|
1033
|
+
(I'll commit to you!)
|
|
1034
|
+
I'll be here!
|
|
1035
|
+
|
|
1036
|
+
### Outro
|
|
1037
|
+
I'll commit to you!
|
|
1038
|
+
I'll commit to you!
|
|
1039
|
+
I'll commit to you!
|
|
1040
|
+
`;
|
|
1041
|
+
}
|
|
685
1042
|
|
|
686
1043
|
//#endregion
|
|
687
1044
|
//#region src/functions/miscellaneous/stringifyDotenv.ts
|
|
@@ -698,8 +1055,8 @@ function stringifyDotenv(contents, options) {
|
|
|
698
1055
|
const { quoteStyle = "double" } = options ?? {};
|
|
699
1056
|
let result = "";
|
|
700
1057
|
for (const key in contentsCopy) {
|
|
701
|
-
if (/[ \t\r\n]/.test(key)) throw new
|
|
702
|
-
if (quoteStyle === "none") if (/[ \t\r\n]/.test(contentsCopy[key]) || contentsCopy[key].includes("#") || contentsCopy[key].includes("=") || contentsCopy[key].includes("\\")) throw new
|
|
1058
|
+
if (/[ \t\r\n]/.test(key)) throw new DataError({ [key]: contentsCopy[key] }, "INVALID_KEY", "Environment variables are not allowed to have whitespace.");
|
|
1059
|
+
if (quoteStyle === "none") if (/[ \t\r\n]/.test(contentsCopy[key]) || contentsCopy[key].includes("#") || contentsCopy[key].includes("=") || contentsCopy[key].includes("\\")) throw new DataError({ [key]: contentsCopy[key] }, "INCOMPATIBLE_QUOTE_STYLE", "Cannot use `{ quoteStyle: \"none\" }` when value has whitespace, #, =, or \\");
|
|
703
1060
|
else {
|
|
704
1061
|
result += `${key}=${contentsCopy[key]}\n`;
|
|
705
1062
|
continue;
|
|
@@ -718,7 +1075,6 @@ function stringifyDotenv(contents, options) {
|
|
|
718
1075
|
}
|
|
719
1076
|
return result;
|
|
720
1077
|
}
|
|
721
|
-
var stringifyDotenv_default = stringifyDotenv;
|
|
722
1078
|
|
|
723
1079
|
//#endregion
|
|
724
1080
|
//#region src/functions/miscellaneous/stringListToArray.ts
|
|
@@ -741,7 +1097,6 @@ function stringListToArray(stringList, { separator = ",", trimWhitespace = true
|
|
|
741
1097
|
return item.trim();
|
|
742
1098
|
}) : arrayList;
|
|
743
1099
|
}
|
|
744
|
-
var stringListToArray_default = stringListToArray;
|
|
745
1100
|
|
|
746
1101
|
//#endregion
|
|
747
1102
|
//#region src/functions/miscellaneous/wait.ts
|
|
@@ -761,7 +1116,6 @@ function wait(seconds) {
|
|
|
761
1116
|
}, seconds * 1e3);
|
|
762
1117
|
});
|
|
763
1118
|
}
|
|
764
|
-
var wait_default = wait;
|
|
765
1119
|
|
|
766
1120
|
//#endregion
|
|
767
1121
|
//#region src/functions/objectHelpers/getRecordKeys.ts
|
|
@@ -779,7 +1133,6 @@ var wait_default = wait;
|
|
|
779
1133
|
function getRecordKeys(record) {
|
|
780
1134
|
return Object.keys(record);
|
|
781
1135
|
}
|
|
782
|
-
var getRecordKeys_default = getRecordKeys;
|
|
783
1136
|
|
|
784
1137
|
//#endregion
|
|
785
1138
|
//#region src/functions/objectHelpers/omitProperties.ts
|
|
@@ -803,7 +1156,6 @@ function omitProperties(object, keysToOmit) {
|
|
|
803
1156
|
});
|
|
804
1157
|
return outputObject;
|
|
805
1158
|
}
|
|
806
|
-
var omitProperties_default = omitProperties;
|
|
807
1159
|
|
|
808
1160
|
//#endregion
|
|
809
1161
|
//#region src/functions/objectHelpers/removeUndefinedFromObject.ts
|
|
@@ -819,7 +1171,6 @@ function removeUndefinedFromObject(object) {
|
|
|
819
1171
|
return value !== void 0;
|
|
820
1172
|
}));
|
|
821
1173
|
}
|
|
822
|
-
var removeUndefinedFromObject_default = removeUndefinedFromObject;
|
|
823
1174
|
|
|
824
1175
|
//#endregion
|
|
825
1176
|
//#region src/functions/parsers/parseBoolean.ts
|
|
@@ -836,10 +1187,9 @@ var removeUndefinedFromObject_default = removeUndefinedFromObject;
|
|
|
836
1187
|
*/
|
|
837
1188
|
function parseBoolean(inputString) {
|
|
838
1189
|
const normalisedString = inputString.toLowerCase();
|
|
839
|
-
if (!["true", "false"].includes(normalisedString)) throw new
|
|
1190
|
+
if (!["true", "false"].includes(normalisedString)) throw new DataError(inputString, "INVALID_BOOLEAN_STRING", "The provided boolean string must be one of `true | false`");
|
|
840
1191
|
return normalisedString === "true";
|
|
841
1192
|
}
|
|
842
|
-
var parseBoolean_default = parseBoolean;
|
|
843
1193
|
|
|
844
1194
|
//#endregion
|
|
845
1195
|
//#region src/functions/parsers/zod/_parseZodSchema.ts
|
|
@@ -857,7 +1207,7 @@ function _parseZodSchema(parsedResult, data, onError) {
|
|
|
857
1207
|
const code = issue.code.toUpperCase();
|
|
858
1208
|
allErrorCodes[code] = (allErrorCodes[code] ?? 0) + 1;
|
|
859
1209
|
}
|
|
860
|
-
throw new
|
|
1210
|
+
throw new DataError(data, Object.entries(allErrorCodes).toSorted(([_, firstCount], [__, secondCount]) => {
|
|
861
1211
|
return secondCount - firstCount;
|
|
862
1212
|
}).map(([code, count], _, allErrorCodes) => {
|
|
863
1213
|
return allErrorCodes.length === 1 && count === 1 ? code : `${code}×${count}`;
|
|
@@ -865,7 +1215,6 @@ function _parseZodSchema(parsedResult, data, onError) {
|
|
|
865
1215
|
}
|
|
866
1216
|
return parsedResult.data;
|
|
867
1217
|
}
|
|
868
|
-
var _parseZodSchema_default = _parseZodSchema;
|
|
869
1218
|
|
|
870
1219
|
//#endregion
|
|
871
1220
|
//#region src/functions/parsers/zod/parseZodSchema.ts
|
|
@@ -888,9 +1237,8 @@ var _parseZodSchema_default = _parseZodSchema;
|
|
|
888
1237
|
* @returns The parsed data from the Zod schema.
|
|
889
1238
|
*/
|
|
890
1239
|
function parseZodSchema(schema, data, onError) {
|
|
891
|
-
return
|
|
1240
|
+
return _parseZodSchema(schema.safeParse(data), data, onError);
|
|
892
1241
|
}
|
|
893
|
-
var parseZodSchema_default = parseZodSchema;
|
|
894
1242
|
|
|
895
1243
|
//#endregion
|
|
896
1244
|
//#region src/functions/parsers/parseEnv.ts
|
|
@@ -916,9 +1264,8 @@ const Env = {
|
|
|
916
1264
|
* @returns The specified environment if allowed.
|
|
917
1265
|
*/
|
|
918
1266
|
function parseEnv(data) {
|
|
919
|
-
return
|
|
1267
|
+
return parseZodSchema(z$1.enum(Env), data, new DataError(data, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
|
|
920
1268
|
}
|
|
921
|
-
var parseEnv_default = parseEnv;
|
|
922
1269
|
|
|
923
1270
|
//#endregion
|
|
924
1271
|
//#region src/functions/parsers/parseFilePath.ts
|
|
@@ -934,23 +1281,22 @@ var parseEnv_default = parseEnv;
|
|
|
934
1281
|
* @returns An object representing the different ways the file path can be represented.
|
|
935
1282
|
*/
|
|
936
1283
|
function parseFilePath(filePath) {
|
|
937
|
-
const caughtGroups = filePath.match(RegExp(
|
|
1284
|
+
const caughtGroups = filePath.match(RegExp(FILE_PATH_REGEX));
|
|
938
1285
|
if (!caughtGroups) {
|
|
939
1286
|
if (!(filePath.includes("/") || filePath.includes("\\")) && filePath.includes(".")) return {
|
|
940
1287
|
directory: "",
|
|
941
1288
|
base: filePath,
|
|
942
1289
|
fullPath: filePath
|
|
943
1290
|
};
|
|
944
|
-
throw new
|
|
1291
|
+
throw new DataError({ filePath }, "INVALID_FILE_PATH", "The file path you provided is not valid.");
|
|
945
1292
|
}
|
|
946
|
-
if (!caughtGroups.groups) throw new
|
|
1293
|
+
if (!caughtGroups.groups) throw new DataError({ filePath }, "PARSING_ERROR", "An error occurred while trying to parse the data.");
|
|
947
1294
|
return {
|
|
948
1295
|
directory: caughtGroups.groups.directory,
|
|
949
1296
|
base: caughtGroups.groups.base,
|
|
950
1297
|
fullPath: path.join(caughtGroups.groups.directory.replaceAll("\\", "/"), caughtGroups.groups.base)
|
|
951
1298
|
};
|
|
952
1299
|
}
|
|
953
|
-
var parseFilePath_default = parseFilePath;
|
|
954
1300
|
|
|
955
1301
|
//#endregion
|
|
956
1302
|
//#region src/functions/parsers/parseFormData.ts
|
|
@@ -974,7 +1320,6 @@ function parseFormData(formData, dataParser) {
|
|
|
974
1320
|
if (dataParser) return dataParser(object);
|
|
975
1321
|
return object;
|
|
976
1322
|
}
|
|
977
|
-
var parseFormData_default = parseFormData;
|
|
978
1323
|
|
|
979
1324
|
//#endregion
|
|
980
1325
|
//#region src/functions/parsers/parseVersionType.ts
|
|
@@ -1000,9 +1345,8 @@ const VersionType = {
|
|
|
1000
1345
|
* @returns The given version type if allowed.
|
|
1001
1346
|
*/
|
|
1002
1347
|
function parseVersionType(data) {
|
|
1003
|
-
return
|
|
1348
|
+
return parseZodSchema(z.enum(VersionType), data, new DataError(data, "INVALID_VERSION_TYPE", "The provided version type must be one of `major | minor | patch`"));
|
|
1004
1349
|
}
|
|
1005
|
-
var parseVersionType_default = parseVersionType;
|
|
1006
1350
|
|
|
1007
1351
|
//#endregion
|
|
1008
1352
|
//#region src/functions/parsers/zod/parseZodSchemaAsync.ts
|
|
@@ -1023,9 +1367,8 @@ var parseVersionType_default = parseVersionType;
|
|
|
1023
1367
|
* @returns The parsed data from the Zod schema.
|
|
1024
1368
|
*/
|
|
1025
1369
|
async function parseZodSchemaAsync(schema, data, onError) {
|
|
1026
|
-
return
|
|
1370
|
+
return _parseZodSchema(await schema.safeParseAsync(data), data, onError);
|
|
1027
1371
|
}
|
|
1028
|
-
var parseZodSchemaAsync_default = parseZodSchemaAsync;
|
|
1029
1372
|
|
|
1030
1373
|
//#endregion
|
|
1031
1374
|
//#region src/functions/recursive/deepCopy.ts
|
|
@@ -1054,32 +1397,6 @@ function deepCopy(object) {
|
|
|
1054
1397
|
}
|
|
1055
1398
|
return clonedObject;
|
|
1056
1399
|
}
|
|
1057
|
-
var deepCopy_default = deepCopy;
|
|
1058
|
-
|
|
1059
|
-
//#endregion
|
|
1060
|
-
//#region src/functions/recursive/deepFreeze.ts
|
|
1061
|
-
/**
|
|
1062
|
-
* Deeply freezes an object or array such that all child objects/arrays are also frozen.
|
|
1063
|
-
*
|
|
1064
|
-
* Note that this will also freeze the input itself as well.
|
|
1065
|
-
* If the intent is to create a newly frozen object with a different reference in memory, pass your object through deepCopy first before passing to deepFreeze.
|
|
1066
|
-
*
|
|
1067
|
-
* @category Recursive
|
|
1068
|
-
*
|
|
1069
|
-
* @template ObjectType - The type of the input object.
|
|
1070
|
-
*
|
|
1071
|
-
* @param object - The object to freeze. May also be an array.
|
|
1072
|
-
*
|
|
1073
|
-
* @returns The input object completely frozen.
|
|
1074
|
-
*/
|
|
1075
|
-
function deepFreeze(object) {
|
|
1076
|
-
for (const value of Object.values(object)) {
|
|
1077
|
-
if (typeof value === "function") continue;
|
|
1078
|
-
if (value && typeof value === "object") deepFreeze(value);
|
|
1079
|
-
}
|
|
1080
|
-
return Object.freeze(object);
|
|
1081
|
-
}
|
|
1082
|
-
var deepFreeze_default = deepFreeze;
|
|
1083
1400
|
|
|
1084
1401
|
//#endregion
|
|
1085
1402
|
//#region src/functions/security/encryptWithKey.ts
|
|
@@ -1098,10 +1415,9 @@ async function encryptWithKey(publicKey, plaintextValue) {
|
|
|
1098
1415
|
const encryptedValue = sodium.crypto_box_seal(plaintextValue, base64Key);
|
|
1099
1416
|
return sodium.to_base64(encryptedValue, sodium.base64_variants.ORIGINAL);
|
|
1100
1417
|
} catch {
|
|
1101
|
-
throw new
|
|
1418
|
+
throw new DataError({ publicKey }, "ENCRYPTION_FAILED", "Encryption failed. Please double-check that the given key is a valid base 64 string.");
|
|
1102
1419
|
}
|
|
1103
1420
|
}
|
|
1104
|
-
var encryptWithKey_default = encryptWithKey;
|
|
1105
1421
|
|
|
1106
1422
|
//#endregion
|
|
1107
1423
|
//#region src/functions/security/getPublicAndPrivateKey.ts
|
|
@@ -1119,7 +1435,7 @@ var encryptWithKey_default = encryptWithKey;
|
|
|
1119
1435
|
function getPublicAndPrivateKey(outputFormat) {
|
|
1120
1436
|
const keys = sodium.crypto_box_keypair(outputFormat);
|
|
1121
1437
|
if (outputFormat === "uint8array" || outputFormat === void 0) {
|
|
1122
|
-
if (!(keys?.publicKey instanceof Uint8Array && keys?.privateKey instanceof Uint8Array)) throw new
|
|
1438
|
+
if (!(keys?.publicKey instanceof Uint8Array && keys?.privateKey instanceof Uint8Array)) throw new DataError({
|
|
1123
1439
|
publicKey: `<redacted: ${keys?.publicKey?.constructor?.name ?? typeof keys?.publicKey}>`,
|
|
1124
1440
|
privateKey: `<redacted: ${keys?.privateKey?.constructor?.name ?? typeof keys?.privateKey}>`
|
|
1125
1441
|
}, "INVALID_KEY_TYPES", "Expected Uint8Array keypair from libsodium.");
|
|
@@ -1127,7 +1443,6 @@ function getPublicAndPrivateKey(outputFormat) {
|
|
|
1127
1443
|
}
|
|
1128
1444
|
return keys;
|
|
1129
1445
|
}
|
|
1130
|
-
var getPublicAndPrivateKey_default = getPublicAndPrivateKey;
|
|
1131
1446
|
|
|
1132
1447
|
//#endregion
|
|
1133
1448
|
//#region src/functions/stringHelpers/appendSemicolon.ts
|
|
@@ -1148,7 +1463,6 @@ function appendSemicolon(stringToAppendTo) {
|
|
|
1148
1463
|
if (stringWithNoTrailingWhitespace === "") return "";
|
|
1149
1464
|
return stringWithNoTrailingWhitespace[stringWithNoTrailingWhitespace.length - 1] === ";" ? stringWithNoTrailingWhitespace : `${stringWithNoTrailingWhitespace};`;
|
|
1150
1465
|
}
|
|
1151
|
-
var appendSemicolon_default = appendSemicolon;
|
|
1152
1466
|
|
|
1153
1467
|
//#endregion
|
|
1154
1468
|
//#region src/functions/stringHelpers/camelToKebab.ts
|
|
@@ -1188,7 +1502,6 @@ function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
|
|
|
1188
1502
|
}
|
|
1189
1503
|
return result;
|
|
1190
1504
|
}
|
|
1191
|
-
var camelToKebab_default = camelToKebab;
|
|
1192
1505
|
|
|
1193
1506
|
//#endregion
|
|
1194
1507
|
//#region src/functions/stringHelpers/kebabToCamel.ts
|
|
@@ -1212,7 +1525,7 @@ function kebabToCamel(string, options) {
|
|
|
1212
1525
|
skip = false;
|
|
1213
1526
|
continue;
|
|
1214
1527
|
}
|
|
1215
|
-
const index =
|
|
1528
|
+
const index = parseIntStrict(stringIndex);
|
|
1216
1529
|
if (index === 0 && options?.startWithUpper) {
|
|
1217
1530
|
outputString += string[index].toUpperCase();
|
|
1218
1531
|
continue;
|
|
@@ -1228,7 +1541,6 @@ function kebabToCamel(string, options) {
|
|
|
1228
1541
|
}
|
|
1229
1542
|
return outputString;
|
|
1230
1543
|
}
|
|
1231
|
-
var kebabToCamel_default = kebabToCamel;
|
|
1232
1544
|
|
|
1233
1545
|
//#endregion
|
|
1234
1546
|
//#region src/functions/stringHelpers/normalizeImportPath.ts
|
|
@@ -1266,7 +1578,6 @@ function normalizeImportPath(importPath) {
|
|
|
1266
1578
|
* @returns The import path normalised.
|
|
1267
1579
|
*/
|
|
1268
1580
|
const normaliseImportPath = normalizeImportPath;
|
|
1269
|
-
var normalizeImportPath_default = normalizeImportPath;
|
|
1270
1581
|
|
|
1271
1582
|
//#endregion
|
|
1272
1583
|
//#region src/functions/stringHelpers/truncate.ts
|
|
@@ -1283,190 +1594,6 @@ var normalizeImportPath_default = normalizeImportPath;
|
|
|
1283
1594
|
function truncate(stringToTruncate, maxLength = 5) {
|
|
1284
1595
|
return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
|
|
1285
1596
|
}
|
|
1286
|
-
var truncate_default = truncate;
|
|
1287
|
-
|
|
1288
|
-
//#endregion
|
|
1289
|
-
//#region src/functions/taggedTemplate/createTemplateStringsArray.ts
|
|
1290
|
-
/**
|
|
1291
|
-
* Creates a template strings array given a regular array of strings
|
|
1292
|
-
*
|
|
1293
|
-
* @category Tagged Template
|
|
1294
|
-
*
|
|
1295
|
-
* @param strings - The array of strings.
|
|
1296
|
-
*
|
|
1297
|
-
* @returns A template strings array that can be passed as the first argument of any tagged template function.
|
|
1298
|
-
*/
|
|
1299
|
-
function createTemplateStringsArray(strings) {
|
|
1300
|
-
return deepFreeze_default(Object.assign([...strings], { raw: [...strings] }));
|
|
1301
|
-
}
|
|
1302
|
-
var createTemplateStringsArray_default = createTemplateStringsArray;
|
|
1303
|
-
|
|
1304
|
-
//#endregion
|
|
1305
|
-
//#region src/functions/taggedTemplate/getInterpolations.ts
|
|
1306
|
-
/**
|
|
1307
|
-
* Gets the strings and interpolations separately from a template string.
|
|
1308
|
-
* You can pass a template string directly by doing:
|
|
1309
|
-
*
|
|
1310
|
-
* ```typescript
|
|
1311
|
-
* getInterpolations`Template string here`.
|
|
1312
|
-
* ```
|
|
1313
|
-
*
|
|
1314
|
-
* @category Tagged Template
|
|
1315
|
-
*
|
|
1316
|
-
* @param strings - The strings from the template to process.
|
|
1317
|
-
* @param interpolations - An array of all interpolations from the template.
|
|
1318
|
-
*
|
|
1319
|
-
* @returns A tuple where the first item is the strings from the template, and the second is the interpolations.
|
|
1320
|
-
*/
|
|
1321
|
-
function getInterpolations(strings, ...interpolations) {
|
|
1322
|
-
return [strings, interpolations];
|
|
1323
|
-
}
|
|
1324
|
-
var getInterpolations_default = getInterpolations;
|
|
1325
|
-
|
|
1326
|
-
//#endregion
|
|
1327
|
-
//#region src/functions/taggedTemplate/interpolate.ts
|
|
1328
|
-
/**
|
|
1329
|
-
* Returns the result of interpolating a template string when given the strings and interpolations separately.
|
|
1330
|
-
*
|
|
1331
|
-
* You can pass a template string directly by doing:
|
|
1332
|
-
*
|
|
1333
|
-
* ```
|
|
1334
|
-
* interpolate`Template string here`;
|
|
1335
|
-
* ```
|
|
1336
|
-
*
|
|
1337
|
-
* In this case, it will be functionally the same as if you just wrote the template string by itself.
|
|
1338
|
-
*
|
|
1339
|
-
* @category Tagged Template
|
|
1340
|
-
*
|
|
1341
|
-
* @param strings - The strings from the template to process.
|
|
1342
|
-
* @param interpolations - An array of all interpolations from the template.
|
|
1343
|
-
*
|
|
1344
|
-
* @returns A new string with the strings and interpolations from the template applied.
|
|
1345
|
-
*/
|
|
1346
|
-
function interpolate(strings, ...interpolations) {
|
|
1347
|
-
let result = "";
|
|
1348
|
-
for (const [string, interpolation = ""] of paralleliseArrays_default(strings, interpolations)) result += string + interpolation;
|
|
1349
|
-
return result;
|
|
1350
|
-
}
|
|
1351
|
-
var interpolate_default = interpolate;
|
|
1352
|
-
|
|
1353
|
-
//#endregion
|
|
1354
|
-
//#region src/functions/taggedTemplate/interpolateObjects.ts
|
|
1355
|
-
/**
|
|
1356
|
-
* Returns the result of interpolating a template string, also stringifying objects.
|
|
1357
|
-
*
|
|
1358
|
-
* You can pass a template string directly by doing:
|
|
1359
|
-
*
|
|
1360
|
-
* ```typescript
|
|
1361
|
-
* interpolateObjects`Template string here ${{ my: "object" }}`.
|
|
1362
|
-
* ```
|
|
1363
|
-
*
|
|
1364
|
-
* @category Tagged Template
|
|
1365
|
-
*
|
|
1366
|
-
* @param strings - The strings from the template to process.
|
|
1367
|
-
* @param interpolations - An array of all interpolations from the template.
|
|
1368
|
-
*
|
|
1369
|
-
* @returns A new string with the strings and interpolations from the template applied, with objects stringified.
|
|
1370
|
-
*/
|
|
1371
|
-
function interpolateObjects(strings, ...interpolations) {
|
|
1372
|
-
let result = "";
|
|
1373
|
-
for (let i = 0; i < strings.length; i++) {
|
|
1374
|
-
result += strings[i];
|
|
1375
|
-
if (i !== strings.length - 1) result += interpolations[i] && typeof interpolations[i] === "object" ? JSON.stringify(interpolations[i]) : interpolations[i];
|
|
1376
|
-
}
|
|
1377
|
-
return result;
|
|
1378
|
-
}
|
|
1379
|
-
var interpolateObjects_default = interpolateObjects;
|
|
1380
|
-
|
|
1381
|
-
//#endregion
|
|
1382
|
-
//#region src/functions/taggedTemplate/normaliseIndents.ts
|
|
1383
|
-
function calculateTabSize(line, whitespaceLength) {
|
|
1384
|
-
const potentialWhitespacePart = line.slice(0, whitespaceLength);
|
|
1385
|
-
const trimmedString = line.trimStart();
|
|
1386
|
-
if (potentialWhitespacePart.trim() !== "") return 0;
|
|
1387
|
-
const tabSize = line.length - (trimmedString.length + whitespaceLength);
|
|
1388
|
-
return tabSize < 0 ? 0 : tabSize;
|
|
1389
|
-
}
|
|
1390
|
-
function getWhitespaceLength(lines) {
|
|
1391
|
-
const [firstNonEmptyLine] = lines.filter((line) => {
|
|
1392
|
-
return line.trim() !== "";
|
|
1393
|
-
});
|
|
1394
|
-
return firstNonEmptyLine.length - firstNonEmptyLine.trimStart().length;
|
|
1395
|
-
}
|
|
1396
|
-
function reduceLines(lines, { preserveTabs = true }) {
|
|
1397
|
-
const slicedLines = lines.slice(1);
|
|
1398
|
-
const isFirstLineEmpty = lines[0].trim() === "";
|
|
1399
|
-
const whitespaceLength = getWhitespaceLength(isFirstLineEmpty ? lines : slicedLines);
|
|
1400
|
-
return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
|
|
1401
|
-
const tabSize = calculateTabSize(line, whitespaceLength);
|
|
1402
|
-
return (preserveTabs ? fillArray_default(() => {
|
|
1403
|
-
return " ";
|
|
1404
|
-
}, tabSize).join("") : "") + line.trimStart();
|
|
1405
|
-
}).join("\n");
|
|
1406
|
-
}
|
|
1407
|
-
/**
|
|
1408
|
-
* Applies any options if provided, then removes any extraneous indents from a multi-line template string.
|
|
1409
|
-
*
|
|
1410
|
-
* You can pass a template string directly by doing:
|
|
1411
|
-
*
|
|
1412
|
-
* ```typescript
|
|
1413
|
-
* normaliseIndents`Template string here
|
|
1414
|
-
* with a new line
|
|
1415
|
-
* and another new line`.
|
|
1416
|
-
* ```
|
|
1417
|
-
*
|
|
1418
|
-
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
1419
|
-
*
|
|
1420
|
-
* ```typescript
|
|
1421
|
-
* normaliseIndents({ preserveTabs: false })`Template string here
|
|
1422
|
-
* with a new line
|
|
1423
|
-
* and another new line`.
|
|
1424
|
-
* ```
|
|
1425
|
-
*
|
|
1426
|
-
*@category Tagged Template
|
|
1427
|
-
*
|
|
1428
|
-
* @param first - The strings from the template to process, or the options to apply.
|
|
1429
|
-
* @param args - An array of all interpolations from the template.
|
|
1430
|
-
*
|
|
1431
|
-
* @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
1432
|
-
*/
|
|
1433
|
-
function normaliseIndents(first, ...args) {
|
|
1434
|
-
if (typeof first === "object" && first !== null && !Array.isArray(first)) {
|
|
1435
|
-
const options = first;
|
|
1436
|
-
return (strings, ...interpolations) => {
|
|
1437
|
-
return normaliseIndents(strings, ...interpolations, options);
|
|
1438
|
-
};
|
|
1439
|
-
}
|
|
1440
|
-
const strings = first;
|
|
1441
|
-
const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
|
|
1442
|
-
return reduceLines(interpolate_default(strings, ...[...args]).split("\n"), options);
|
|
1443
|
-
}
|
|
1444
|
-
/**
|
|
1445
|
-
* Applies any options if provided, then removes any extraneous indents from a multi-line template string.
|
|
1446
|
-
*
|
|
1447
|
-
* You can pass a template string directly by doing:
|
|
1448
|
-
*
|
|
1449
|
-
* ```typescript
|
|
1450
|
-
* normalizeIndents`Template string here
|
|
1451
|
-
* with a new line
|
|
1452
|
-
* and another new line`.
|
|
1453
|
-
* ```
|
|
1454
|
-
*
|
|
1455
|
-
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
1456
|
-
*
|
|
1457
|
-
* ```typescript
|
|
1458
|
-
* normalizeIndents({ preserveTabs: false })`Template string here
|
|
1459
|
-
* with a new line
|
|
1460
|
-
* and another new line`.
|
|
1461
|
-
* ```
|
|
1462
|
-
*
|
|
1463
|
-
* @param first - The strings from the template to process, or the options to apply.
|
|
1464
|
-
* @param args - An array of all interpolations from the template.
|
|
1465
|
-
*
|
|
1466
|
-
* @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
1467
|
-
*/
|
|
1468
|
-
const normalizeIndents = normaliseIndents;
|
|
1469
|
-
var normaliseIndents_default = normaliseIndents;
|
|
1470
1597
|
|
|
1471
1598
|
//#endregion
|
|
1472
1599
|
//#region src/functions/versioning/parseVersion.ts
|
|
@@ -1485,11 +1612,10 @@ var normaliseIndents_default = normaliseIndents;
|
|
|
1485
1612
|
* @returns The validated version number, prefixed with `v` if it was not already.
|
|
1486
1613
|
*/
|
|
1487
1614
|
function parseVersion(input, options) {
|
|
1488
|
-
if (!RegExp(
|
|
1615
|
+
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.`);
|
|
1489
1616
|
if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
|
|
1490
1617
|
return input.startsWith("v") ? input : `v${input}`;
|
|
1491
1618
|
}
|
|
1492
|
-
var parseVersion_default = parseVersion;
|
|
1493
1619
|
|
|
1494
1620
|
//#endregion
|
|
1495
1621
|
//#region src/functions/versioning/getIndividualVersionNumbers.ts
|
|
@@ -1508,11 +1634,10 @@ var parseVersion_default = parseVersion;
|
|
|
1508
1634
|
* @returns A tuple of three numbers indicating `[major, minor, patch]`.
|
|
1509
1635
|
*/
|
|
1510
1636
|
function getIndividualVersionNumbers(version) {
|
|
1511
|
-
return
|
|
1512
|
-
return
|
|
1637
|
+
return parseVersion(version, { omitPrefix: true }).split(".").map((versionNumber) => {
|
|
1638
|
+
return parseIntStrict(versionNumber);
|
|
1513
1639
|
});
|
|
1514
1640
|
}
|
|
1515
|
-
var getIndividualVersionNumbers_default = getIndividualVersionNumbers;
|
|
1516
1641
|
|
|
1517
1642
|
//#endregion
|
|
1518
1643
|
//#region src/functions/versioning/determineVersionType.ts
|
|
@@ -1526,12 +1651,11 @@ var getIndividualVersionNumbers_default = getIndividualVersionNumbers;
|
|
|
1526
1651
|
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
1527
1652
|
*/
|
|
1528
1653
|
function determineVersionType(version) {
|
|
1529
|
-
const [_major, minor, patch] =
|
|
1654
|
+
const [_major, minor, patch] = getIndividualVersionNumbers(version);
|
|
1530
1655
|
if (minor === 0 && patch === 0) return "major";
|
|
1531
1656
|
if (patch === 0) return "minor";
|
|
1532
1657
|
return "patch";
|
|
1533
1658
|
}
|
|
1534
|
-
var determineVersionType_default = determineVersionType;
|
|
1535
1659
|
|
|
1536
1660
|
//#endregion
|
|
1537
1661
|
//#region src/functions/versioning/incrementVersion.ts
|
|
@@ -1550,15 +1674,14 @@ var determineVersionType_default = determineVersionType;
|
|
|
1550
1674
|
* @returns A new string representing the version with the increment applied.
|
|
1551
1675
|
*/
|
|
1552
1676
|
function incrementVersion(version, incrementType, options) {
|
|
1553
|
-
const [major, minor, patch] =
|
|
1677
|
+
const [major, minor, patch] = getIndividualVersionNumbers(version);
|
|
1554
1678
|
const newVersion = {
|
|
1555
1679
|
major: `${major + 1}.0.0`,
|
|
1556
1680
|
minor: `${major}.${minor + 1}.0`,
|
|
1557
1681
|
patch: `${major}.${minor}.${patch + 1}`
|
|
1558
1682
|
}[incrementType];
|
|
1559
|
-
return
|
|
1683
|
+
return parseVersion(newVersion, { omitPrefix: options?.omitPrefix });
|
|
1560
1684
|
}
|
|
1561
|
-
var incrementVersion_default = incrementVersion;
|
|
1562
1685
|
|
|
1563
1686
|
//#endregion
|
|
1564
|
-
export {
|
|
1687
|
+
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 };
|