@alextheman/utility 4.13.0 → 4.14.1
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 +173 -160
- package/dist/index.d.cts +57 -6
- package/dist/index.d.ts +57 -6
- package/dist/index.js +116 -106
- package/package.json +8 -8
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
|
|
@@ -84,7 +79,7 @@ const httpErrorCodeLookup = {
|
|
|
84
79
|
*
|
|
85
80
|
* @category Types
|
|
86
81
|
*/
|
|
87
|
-
var APIError = class extends Error {
|
|
82
|
+
var APIError = class APIError extends Error {
|
|
88
83
|
status;
|
|
89
84
|
/**
|
|
90
85
|
* @param status - A HTTP status code. Can be any number, but numbers between 400 and 600 are encouraged to fit with HTTP status code conventions.
|
|
@@ -107,11 +102,11 @@ var APIError = class extends Error {
|
|
|
107
102
|
* @returns `true` if the input is an APIError, and `false` otherwise. The type of the input will also be narrowed down to APIError if `true`.
|
|
108
103
|
*/
|
|
109
104
|
static check(input) {
|
|
105
|
+
if (input instanceof APIError) return true;
|
|
110
106
|
const data = input;
|
|
111
107
|
return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
|
|
112
108
|
}
|
|
113
109
|
};
|
|
114
|
-
var APIError_default = APIError;
|
|
115
110
|
|
|
116
111
|
//#endregion
|
|
117
112
|
//#region src/types/DataError.ts
|
|
@@ -120,7 +115,7 @@ var APIError_default = APIError;
|
|
|
120
115
|
*
|
|
121
116
|
* @category Types
|
|
122
117
|
*/
|
|
123
|
-
var DataError = class extends Error {
|
|
118
|
+
var DataError = class DataError extends Error {
|
|
124
119
|
code;
|
|
125
120
|
data;
|
|
126
121
|
/**
|
|
@@ -146,11 +141,11 @@ var DataError = class extends Error {
|
|
|
146
141
|
* @returns `true` if the input is a DataError, and `false` otherwise. The type of the input will also be narrowed down to DataError if `true`.
|
|
147
142
|
*/
|
|
148
143
|
static check(input) {
|
|
144
|
+
if (input instanceof DataError) return true;
|
|
149
145
|
const data = input;
|
|
150
146
|
return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
|
|
151
147
|
}
|
|
152
148
|
};
|
|
153
|
-
var DataError_default = DataError;
|
|
154
149
|
|
|
155
150
|
//#endregion
|
|
156
151
|
//#region src/types/VersionNumber.ts
|
|
@@ -176,18 +171,18 @@ var VersionNumber = class VersionNumber {
|
|
|
176
171
|
this.minor = input.minor;
|
|
177
172
|
this.patch = input.patch;
|
|
178
173
|
} else if (typeof input === "string") {
|
|
179
|
-
if (!RegExp(
|
|
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.`);
|
|
180
175
|
const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
|
|
181
|
-
return
|
|
176
|
+
return parseIntStrict(number);
|
|
182
177
|
});
|
|
183
178
|
this.major = major;
|
|
184
179
|
this.minor = minor;
|
|
185
180
|
this.patch = patch;
|
|
186
181
|
} else if (Array.isArray(input)) {
|
|
187
|
-
if (input.length !== 3) throw new
|
|
182
|
+
if (input.length !== 3) throw new DataError(input, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
188
183
|
const [major, minor, patch] = input.map((number) => {
|
|
189
|
-
const parsedInteger =
|
|
190
|
-
if (parsedInteger < 0) throw new
|
|
184
|
+
const parsedInteger = parseIntStrict(number?.toString());
|
|
185
|
+
if (parsedInteger < 0) throw new DataError(input, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
191
186
|
return parsedInteger;
|
|
192
187
|
});
|
|
193
188
|
this.major = major;
|
|
@@ -257,7 +252,7 @@ var VersionNumber = class VersionNumber {
|
|
|
257
252
|
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
258
253
|
*/
|
|
259
254
|
[Symbol.toPrimitive](hint) {
|
|
260
|
-
if (hint === "number") throw new
|
|
255
|
+
if (hint === "number") throw new DataError(this.toString(), "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
|
|
261
256
|
return this.toString();
|
|
262
257
|
}
|
|
263
258
|
/**
|
|
@@ -280,7 +275,6 @@ var VersionNumber = class VersionNumber {
|
|
|
280
275
|
return VersionNumber.formatString(rawString, options);
|
|
281
276
|
}
|
|
282
277
|
};
|
|
283
|
-
var VersionNumber_default = VersionNumber;
|
|
284
278
|
|
|
285
279
|
//#endregion
|
|
286
280
|
//#region src/functions/parsers/parseIntStrict.ts
|
|
@@ -299,21 +293,20 @@ var VersionNumber_default = VersionNumber;
|
|
|
299
293
|
function parseIntStrict(string, radix) {
|
|
300
294
|
const trimmedString = string.trim();
|
|
301
295
|
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
|
|
296
|
+
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new DataError(radix ? {
|
|
303
297
|
string,
|
|
304
298
|
radix
|
|
305
299
|
} : 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
300
|
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
307
301
|
return parseInt(character) >= radix;
|
|
308
|
-
})) throw new
|
|
302
|
+
})) throw new DataError({
|
|
309
303
|
string,
|
|
310
304
|
radix
|
|
311
305
|
}, "INTEGER_PARSING_ERROR", "Value contains one or more digits outside of the range of the given radix.");
|
|
312
306
|
const parseIntResult = parseInt(trimmedString, radix);
|
|
313
|
-
if (isNaN(parseIntResult)) throw new
|
|
307
|
+
if (isNaN(parseIntResult)) throw new DataError(string, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
|
|
314
308
|
return parseIntResult;
|
|
315
309
|
}
|
|
316
|
-
var parseIntStrict_default = parseIntStrict;
|
|
317
310
|
|
|
318
311
|
//#endregion
|
|
319
312
|
//#region src/functions/miscellaneous/getRandomNumber.ts
|
|
@@ -328,11 +321,10 @@ var parseIntStrict_default = parseIntStrict;
|
|
|
328
321
|
* @returns A random number between the provided lower bound and upper bound.
|
|
329
322
|
*/
|
|
330
323
|
function getRandomNumber(lowerBound, upperBound) {
|
|
331
|
-
const parsedLowerBound =
|
|
332
|
-
const parsedUpperBound =
|
|
324
|
+
const parsedLowerBound = parseIntStrict(`${lowerBound}`);
|
|
325
|
+
const parsedUpperBound = parseIntStrict(`${upperBound}`);
|
|
333
326
|
return Math.floor(Math.random() * (parsedUpperBound - parsedLowerBound + 1) + parsedLowerBound);
|
|
334
327
|
}
|
|
335
|
-
var getRandomNumber_default = getRandomNumber;
|
|
336
328
|
|
|
337
329
|
//#endregion
|
|
338
330
|
//#region src/functions/arrayHelpers/randomiseArray.ts
|
|
@@ -351,12 +343,11 @@ function randomiseArray(array) {
|
|
|
351
343
|
const mutableArray = [...array];
|
|
352
344
|
const outputArray = [];
|
|
353
345
|
do {
|
|
354
|
-
const indexToRemove =
|
|
346
|
+
const indexToRemove = getRandomNumber(0, mutableArray.length - 1);
|
|
355
347
|
outputArray.push(mutableArray.splice(indexToRemove, 1)[0]);
|
|
356
348
|
} while (mutableArray.length > 0);
|
|
357
349
|
return outputArray;
|
|
358
350
|
}
|
|
359
|
-
var randomiseArray_default = randomiseArray;
|
|
360
351
|
|
|
361
352
|
//#endregion
|
|
362
353
|
//#region src/functions/arrayHelpers/range.ts
|
|
@@ -389,7 +380,6 @@ function range(start, stop, step = 1) {
|
|
|
389
380
|
}
|
|
390
381
|
return numbers;
|
|
391
382
|
}
|
|
392
|
-
var range_default = range;
|
|
393
383
|
|
|
394
384
|
//#endregion
|
|
395
385
|
//#region src/functions/arrayHelpers/removeDuplicates.ts
|
|
@@ -409,7 +399,6 @@ function removeDuplicates(array) {
|
|
|
409
399
|
for (const item of array) if (!outputArray.includes(item)) outputArray.push(item);
|
|
410
400
|
return outputArray;
|
|
411
401
|
}
|
|
412
|
-
var removeDuplicates_default = removeDuplicates;
|
|
413
402
|
|
|
414
403
|
//#endregion
|
|
415
404
|
//#region src/functions/date/addDaysToDate.ts
|
|
@@ -428,7 +417,6 @@ function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement =
|
|
|
428
417
|
newDate.setDate(newDate.getDate() + dayIncrement);
|
|
429
418
|
return newDate;
|
|
430
419
|
}
|
|
431
|
-
var addDaysToDate_default = addDaysToDate;
|
|
432
420
|
|
|
433
421
|
//#endregion
|
|
434
422
|
//#region src/functions/date/isSameDate.ts
|
|
@@ -445,7 +433,6 @@ var addDaysToDate_default = addDaysToDate;
|
|
|
445
433
|
function isSameDate(firstDate, secondDate) {
|
|
446
434
|
return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth() && firstDate.getFullYear() === secondDate.getFullYear();
|
|
447
435
|
}
|
|
448
|
-
var isSameDate_default = isSameDate;
|
|
449
436
|
|
|
450
437
|
//#endregion
|
|
451
438
|
//#region src/functions/date/formatDateAndTime.ts
|
|
@@ -463,14 +450,13 @@ var isSameDate_default = isSameDate;
|
|
|
463
450
|
* - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
|
|
464
451
|
*/
|
|
465
452
|
function formatDateAndTime(inputDate) {
|
|
466
|
-
const yesterday =
|
|
453
|
+
const yesterday = addDaysToDate(/* @__PURE__ */ new Date(), -1);
|
|
467
454
|
const today = /* @__PURE__ */ new Date();
|
|
468
455
|
const inputTime = `${inputDate.getHours().toString().padStart(2, "0")}:${inputDate.getMinutes().toString().padStart(2, "0")}`;
|
|
469
|
-
if (
|
|
470
|
-
if (
|
|
456
|
+
if (isSameDate(inputDate, yesterday)) return `Yesterday at ${inputTime}`;
|
|
457
|
+
if (isSameDate(inputDate, today)) return `Today at ${inputTime}`;
|
|
471
458
|
return `${inputDate.getDate().toString().padStart(2, "0")}/${(inputDate.getMonth() + 1).toString().padStart(2, "0")}/${inputDate.getFullYear().toString()}, ${inputTime}`;
|
|
472
459
|
}
|
|
473
|
-
var formatDateAndTime_default = formatDateAndTime;
|
|
474
460
|
|
|
475
461
|
//#endregion
|
|
476
462
|
//#region src/functions/date/isLeapYear.ts
|
|
@@ -486,15 +472,14 @@ var formatDateAndTime_default = formatDateAndTime;
|
|
|
486
472
|
* @returns True if the year is a leap year, and false otherwise.
|
|
487
473
|
*/
|
|
488
474
|
function isLeapYear(year) {
|
|
489
|
-
const parsedYear =
|
|
475
|
+
const parsedYear = parseIntStrict(`${year}`);
|
|
490
476
|
return parsedYear % 4 === 0 && parsedYear % 100 !== 0 || parsedYear % 400 === 0;
|
|
491
477
|
}
|
|
492
|
-
var isLeapYear_default = isLeapYear;
|
|
493
478
|
|
|
494
479
|
//#endregion
|
|
495
480
|
//#region src/functions/date/isAnniversary.ts
|
|
496
481
|
function checkLeapYear(firstDate, secondDate) {
|
|
497
|
-
if (
|
|
482
|
+
if (isLeapYear(firstDate.getFullYear()) && firstDate.getMonth() === 1 && secondDate.getMonth() === 1) return firstDate.getDate() === 29 && secondDate.getDate() === 28;
|
|
498
483
|
return false;
|
|
499
484
|
}
|
|
500
485
|
/**
|
|
@@ -511,7 +496,6 @@ function isAnniversary(firstDate, secondDate) {
|
|
|
511
496
|
if (checkLeapYear(firstDate, secondDate) || checkLeapYear(secondDate, firstDate)) return true;
|
|
512
497
|
return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth();
|
|
513
498
|
}
|
|
514
|
-
var isAnniversary_default = isAnniversary;
|
|
515
499
|
|
|
516
500
|
//#endregion
|
|
517
501
|
//#region src/functions/date/isMonthlyMultiple.ts
|
|
@@ -526,7 +510,7 @@ function endOfMonthChecksButNotFebruary(firstDate, secondDate) {
|
|
|
526
510
|
}
|
|
527
511
|
function nonLeapYearFebruaryChecks(firstDate, secondDate) {
|
|
528
512
|
if (firstDate.getMonth() === 1) {
|
|
529
|
-
if (!
|
|
513
|
+
if (!isLeapYear(firstDate.getFullYear()) && firstDate.getDate() === 28) return [
|
|
530
514
|
28,
|
|
531
515
|
29,
|
|
532
516
|
30,
|
|
@@ -537,7 +521,7 @@ function nonLeapYearFebruaryChecks(firstDate, secondDate) {
|
|
|
537
521
|
}
|
|
538
522
|
function leapYearFebruaryChecks(firstDate, secondDate) {
|
|
539
523
|
if (firstDate.getMonth() === 1) {
|
|
540
|
-
if (
|
|
524
|
+
if (isLeapYear(firstDate.getFullYear()) && firstDate.getDate() === 29) return [
|
|
541
525
|
29,
|
|
542
526
|
30,
|
|
543
527
|
31
|
|
@@ -561,7 +545,6 @@ function isMonthlyMultiple(firstDate, secondDate) {
|
|
|
561
545
|
if (leapYearFebruaryChecks(firstDate, secondDate) || leapYearFebruaryChecks(secondDate, firstDate)) return true;
|
|
562
546
|
return firstDate.getDate() === secondDate.getDate();
|
|
563
547
|
}
|
|
564
|
-
var isMonthlyMultiple_default = isMonthlyMultiple;
|
|
565
548
|
|
|
566
549
|
//#endregion
|
|
567
550
|
//#region src/functions/miscellaneous/convertFileToBase64.ts
|
|
@@ -592,7 +575,6 @@ function convertFileToBase64(file) {
|
|
|
592
575
|
};
|
|
593
576
|
});
|
|
594
577
|
}
|
|
595
|
-
var convertFileToBase64_default = convertFileToBase64;
|
|
596
578
|
|
|
597
579
|
//#endregion
|
|
598
580
|
//#region src/functions/miscellaneous/createFormData.ts
|
|
@@ -662,7 +644,6 @@ function createFormData(data, options = {
|
|
|
662
644
|
} else formData.append(String(key), String(value));
|
|
663
645
|
return formData;
|
|
664
646
|
}
|
|
665
|
-
var createFormData_default = createFormData;
|
|
666
647
|
|
|
667
648
|
//#endregion
|
|
668
649
|
//#region src/functions/miscellaneous/isOrdered.ts
|
|
@@ -681,7 +662,6 @@ function isOrdered(array) {
|
|
|
681
662
|
for (const index in newArray) if (newArray[index] !== array[index]) return false;
|
|
682
663
|
return true;
|
|
683
664
|
}
|
|
684
|
-
var isOrdered_default = isOrdered;
|
|
685
665
|
|
|
686
666
|
//#endregion
|
|
687
667
|
//#region src/functions/recursive/deepFreeze.ts
|
|
@@ -706,7 +686,6 @@ function deepFreeze(object) {
|
|
|
706
686
|
}
|
|
707
687
|
return Object.freeze(object);
|
|
708
688
|
}
|
|
709
|
-
var deepFreeze_default = deepFreeze;
|
|
710
689
|
|
|
711
690
|
//#endregion
|
|
712
691
|
//#region src/functions/taggedTemplate/createTemplateStringsArray.ts
|
|
@@ -720,13 +699,13 @@ var deepFreeze_default = deepFreeze;
|
|
|
720
699
|
* @returns A template strings array that can be passed as the first argument of any tagged template function.
|
|
721
700
|
*/
|
|
722
701
|
function createTemplateStringsArray(strings) {
|
|
723
|
-
return
|
|
702
|
+
return deepFreeze(Object.assign([...strings], { raw: [...strings] }));
|
|
724
703
|
}
|
|
725
|
-
var createTemplateStringsArray_default = createTemplateStringsArray;
|
|
726
704
|
|
|
727
705
|
//#endregion
|
|
728
706
|
//#region src/functions/taggedTemplate/getInterpolations.ts
|
|
729
707
|
/**
|
|
708
|
+
*
|
|
730
709
|
* Gets the strings and interpolations separately from a template string.
|
|
731
710
|
* You can pass a template string directly by doing:
|
|
732
711
|
*
|
|
@@ -736,6 +715,8 @@ var createTemplateStringsArray_default = createTemplateStringsArray;
|
|
|
736
715
|
*
|
|
737
716
|
* @category Tagged Template
|
|
738
717
|
*
|
|
718
|
+
* @deprecated Please use `getStringsAndInterpolations` instead.
|
|
719
|
+
*
|
|
739
720
|
* @param strings - The strings from the template to process.
|
|
740
721
|
* @param interpolations - An array of all interpolations from the template.
|
|
741
722
|
*
|
|
@@ -744,7 +725,47 @@ var createTemplateStringsArray_default = createTemplateStringsArray;
|
|
|
744
725
|
function getInterpolations(strings, ...interpolations) {
|
|
745
726
|
return [strings, interpolations];
|
|
746
727
|
}
|
|
747
|
-
|
|
728
|
+
|
|
729
|
+
//#endregion
|
|
730
|
+
//#region src/functions/taggedTemplate/getStringsAndInterpolations.ts
|
|
731
|
+
/**
|
|
732
|
+
*
|
|
733
|
+
* Gets the strings and interpolations separately from a template string.
|
|
734
|
+
* You can pass a template string directly by doing:
|
|
735
|
+
*
|
|
736
|
+
* ```typescript
|
|
737
|
+
* getStringsAndInterpolations`Template string here`;
|
|
738
|
+
* ```
|
|
739
|
+
*
|
|
740
|
+
* @category Tagged Template
|
|
741
|
+
*
|
|
742
|
+
* @template InterpolationsType - The type of the interpolations.
|
|
743
|
+
*
|
|
744
|
+
* @param strings - The strings from the template to process.
|
|
745
|
+
* @param interpolations - An array of all interpolations from the template.
|
|
746
|
+
*
|
|
747
|
+
* @returns A tuple where the first item is the strings from the template, and the remaining items are the interpolations.
|
|
748
|
+
*
|
|
749
|
+
* The return of this function may also be spread into any other tagged template function in the following way:
|
|
750
|
+
*
|
|
751
|
+
* ```typescript
|
|
752
|
+
* import { interpolate } from "@alextheman/utility"; // Example function
|
|
753
|
+
*
|
|
754
|
+
* const packageName = "@alextheman/utility";
|
|
755
|
+
* const packageManager = getPackageManager(packageName);
|
|
756
|
+
*
|
|
757
|
+
* interpolate(...getStringsAndInterpolations`The package ${packageName} uses the ${packageManager} package manager.`);
|
|
758
|
+
* ```
|
|
759
|
+
*/
|
|
760
|
+
function getStringsAndInterpolations(strings, ...interpolations) {
|
|
761
|
+
if (strings.length !== interpolations.length + 1) throw new DataError({
|
|
762
|
+
stringsLength: strings.length,
|
|
763
|
+
interpolationsLength: interpolations.length,
|
|
764
|
+
strings,
|
|
765
|
+
interpolations
|
|
766
|
+
}, "INVALID_STRINGS_AND_INTERPOLATIONS_LENGTH", "The length of the strings must be exactly one more than the length of the interpolations.");
|
|
767
|
+
return [createTemplateStringsArray(strings), ...interpolations];
|
|
768
|
+
}
|
|
748
769
|
|
|
749
770
|
//#endregion
|
|
750
771
|
//#region src/functions/taggedTemplate/interpolate.ts
|
|
@@ -761,6 +782,8 @@ var getInterpolations_default = getInterpolations;
|
|
|
761
782
|
*
|
|
762
783
|
* @category Tagged Template
|
|
763
784
|
*
|
|
785
|
+
* @template InterpolationsType - The type of the interpolations.
|
|
786
|
+
*
|
|
764
787
|
* @param strings - The strings from the template to process.
|
|
765
788
|
* @param interpolations - An array of all interpolations from the template.
|
|
766
789
|
*
|
|
@@ -768,10 +791,9 @@ var getInterpolations_default = getInterpolations;
|
|
|
768
791
|
*/
|
|
769
792
|
function interpolate(strings, ...interpolations) {
|
|
770
793
|
let result = "";
|
|
771
|
-
for (const [string, interpolation = ""] of
|
|
794
|
+
for (const [string, interpolation = ""] of paralleliseArrays(strings, interpolations)) result += string + interpolation;
|
|
772
795
|
return result;
|
|
773
796
|
}
|
|
774
|
-
var interpolate_default = interpolate;
|
|
775
797
|
|
|
776
798
|
//#endregion
|
|
777
799
|
//#region src/functions/taggedTemplate/interpolateObjects.ts
|
|
@@ -781,11 +803,13 @@ var interpolate_default = interpolate;
|
|
|
781
803
|
* You can pass a template string directly by doing:
|
|
782
804
|
*
|
|
783
805
|
* ```typescript
|
|
784
|
-
* interpolateObjects`Template string here ${{ my: "object" }}
|
|
806
|
+
* interpolateObjects`Template string here ${{ my: "object" }}`;
|
|
785
807
|
* ```
|
|
786
808
|
*
|
|
787
809
|
* @category Tagged Template
|
|
788
810
|
*
|
|
811
|
+
* @template InterpolationsType - The type of the interpolations.
|
|
812
|
+
*
|
|
789
813
|
* @param strings - The strings from the template to process.
|
|
790
814
|
* @param interpolations - An array of all interpolations from the template.
|
|
791
815
|
*
|
|
@@ -799,7 +823,21 @@ function interpolateObjects(strings, ...interpolations) {
|
|
|
799
823
|
}
|
|
800
824
|
return result;
|
|
801
825
|
}
|
|
802
|
-
|
|
826
|
+
|
|
827
|
+
//#endregion
|
|
828
|
+
//#region src/functions/taggedTemplate/isTemplateStringsArray.ts
|
|
829
|
+
/**
|
|
830
|
+
* Determines whether or not the input is a valid `TemplateStringsArray`.
|
|
831
|
+
*
|
|
832
|
+
* @category Tagged Template
|
|
833
|
+
*
|
|
834
|
+
* @param input - The input to check
|
|
835
|
+
*
|
|
836
|
+
* @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`.
|
|
837
|
+
*/
|
|
838
|
+
function isTemplateStringsArray(input) {
|
|
839
|
+
return typeof input === "object" && input !== null && "raw" in input;
|
|
840
|
+
}
|
|
803
841
|
|
|
804
842
|
//#endregion
|
|
805
843
|
//#region src/functions/taggedTemplate/normaliseIndents.ts
|
|
@@ -822,7 +860,7 @@ function reduceLines(lines, { preserveTabs = true }) {
|
|
|
822
860
|
const whitespaceLength = getWhitespaceLength(isFirstLineEmpty ? lines : slicedLines);
|
|
823
861
|
return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
|
|
824
862
|
const tabSize = calculateTabSize(line, whitespaceLength);
|
|
825
|
-
return (preserveTabs ?
|
|
863
|
+
return (preserveTabs ? fillArray(() => {
|
|
826
864
|
return " ";
|
|
827
865
|
}, tabSize).join("") : "") + line.trimStart();
|
|
828
866
|
}).join("\n");
|
|
@@ -835,7 +873,7 @@ function reduceLines(lines, { preserveTabs = true }) {
|
|
|
835
873
|
* ```typescript
|
|
836
874
|
* normaliseIndents`Template string here
|
|
837
875
|
* with a new line
|
|
838
|
-
* and another new line
|
|
876
|
+
* and another new line`;
|
|
839
877
|
* ```
|
|
840
878
|
*
|
|
841
879
|
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
@@ -843,10 +881,10 @@ function reduceLines(lines, { preserveTabs = true }) {
|
|
|
843
881
|
* ```typescript
|
|
844
882
|
* normaliseIndents({ preserveTabs: false })`Template string here
|
|
845
883
|
* with a new line
|
|
846
|
-
* and another new line
|
|
884
|
+
* and another new line`;
|
|
847
885
|
* ```
|
|
848
886
|
*
|
|
849
|
-
|
|
887
|
+
* @category Tagged Template
|
|
850
888
|
*
|
|
851
889
|
* @param first - The strings from the template to process, or the options to apply.
|
|
852
890
|
* @param args - An array of all interpolations from the template.
|
|
@@ -862,7 +900,7 @@ function normaliseIndents(first, ...args) {
|
|
|
862
900
|
}
|
|
863
901
|
const strings = first;
|
|
864
902
|
const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
|
|
865
|
-
return reduceLines(
|
|
903
|
+
return reduceLines(interpolate(strings, ...[...args]).split("\n"), options);
|
|
866
904
|
}
|
|
867
905
|
/**
|
|
868
906
|
* Applies any options if provided, then removes any extraneous indents from a multi-line template string.
|
|
@@ -889,7 +927,6 @@ function normaliseIndents(first, ...args) {
|
|
|
889
927
|
* @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
890
928
|
*/
|
|
891
929
|
const normalizeIndents = normaliseIndents;
|
|
892
|
-
var normaliseIndents_default = normaliseIndents;
|
|
893
930
|
|
|
894
931
|
//#endregion
|
|
895
932
|
//#region src/functions/miscellaneous/sayHello.ts
|
|
@@ -901,7 +938,7 @@ var normaliseIndents_default = normaliseIndents;
|
|
|
901
938
|
* @returns The lyrics string in markdown format.
|
|
902
939
|
*/
|
|
903
940
|
function sayHello() {
|
|
904
|
-
return
|
|
941
|
+
return normaliseIndents`
|
|
905
942
|
# Commit To You
|
|
906
943
|
|
|
907
944
|
### Verse 1
|
|
@@ -1004,7 +1041,6 @@ function sayHello() {
|
|
|
1004
1041
|
I'll commit to you!
|
|
1005
1042
|
`;
|
|
1006
1043
|
}
|
|
1007
|
-
var sayHello_default = sayHello;
|
|
1008
1044
|
|
|
1009
1045
|
//#endregion
|
|
1010
1046
|
//#region src/functions/miscellaneous/stringifyDotenv.ts
|
|
@@ -1021,8 +1057,8 @@ function stringifyDotenv(contents, options) {
|
|
|
1021
1057
|
const { quoteStyle = "double" } = options ?? {};
|
|
1022
1058
|
let result = "";
|
|
1023
1059
|
for (const key in contentsCopy) {
|
|
1024
|
-
if (/[ \t\r\n]/.test(key)) throw new
|
|
1025
|
-
if (quoteStyle === "none") if (/[ \t\r\n]/.test(contentsCopy[key]) || contentsCopy[key].includes("#") || contentsCopy[key].includes("=") || contentsCopy[key].includes("\\")) throw new
|
|
1060
|
+
if (/[ \t\r\n]/.test(key)) throw new DataError({ [key]: contentsCopy[key] }, "INVALID_KEY", "Environment variables are not allowed to have whitespace.");
|
|
1061
|
+
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 \\");
|
|
1026
1062
|
else {
|
|
1027
1063
|
result += `${key}=${contentsCopy[key]}\n`;
|
|
1028
1064
|
continue;
|
|
@@ -1041,7 +1077,6 @@ function stringifyDotenv(contents, options) {
|
|
|
1041
1077
|
}
|
|
1042
1078
|
return result;
|
|
1043
1079
|
}
|
|
1044
|
-
var stringifyDotenv_default = stringifyDotenv;
|
|
1045
1080
|
|
|
1046
1081
|
//#endregion
|
|
1047
1082
|
//#region src/functions/miscellaneous/stringListToArray.ts
|
|
@@ -1064,7 +1099,6 @@ function stringListToArray(stringList, { separator = ",", trimWhitespace = true
|
|
|
1064
1099
|
return item.trim();
|
|
1065
1100
|
}) : arrayList;
|
|
1066
1101
|
}
|
|
1067
|
-
var stringListToArray_default = stringListToArray;
|
|
1068
1102
|
|
|
1069
1103
|
//#endregion
|
|
1070
1104
|
//#region src/functions/miscellaneous/wait.ts
|
|
@@ -1084,7 +1118,6 @@ function wait(seconds) {
|
|
|
1084
1118
|
}, seconds * 1e3);
|
|
1085
1119
|
});
|
|
1086
1120
|
}
|
|
1087
|
-
var wait_default = wait;
|
|
1088
1121
|
|
|
1089
1122
|
//#endregion
|
|
1090
1123
|
//#region src/functions/objectHelpers/getRecordKeys.ts
|
|
@@ -1102,7 +1135,6 @@ var wait_default = wait;
|
|
|
1102
1135
|
function getRecordKeys(record) {
|
|
1103
1136
|
return Object.keys(record);
|
|
1104
1137
|
}
|
|
1105
|
-
var getRecordKeys_default = getRecordKeys;
|
|
1106
1138
|
|
|
1107
1139
|
//#endregion
|
|
1108
1140
|
//#region src/functions/objectHelpers/omitProperties.ts
|
|
@@ -1126,7 +1158,6 @@ function omitProperties(object, keysToOmit) {
|
|
|
1126
1158
|
});
|
|
1127
1159
|
return outputObject;
|
|
1128
1160
|
}
|
|
1129
|
-
var omitProperties_default = omitProperties;
|
|
1130
1161
|
|
|
1131
1162
|
//#endregion
|
|
1132
1163
|
//#region src/functions/objectHelpers/removeUndefinedFromObject.ts
|
|
@@ -1142,7 +1173,6 @@ function removeUndefinedFromObject(object) {
|
|
|
1142
1173
|
return value !== void 0;
|
|
1143
1174
|
}));
|
|
1144
1175
|
}
|
|
1145
|
-
var removeUndefinedFromObject_default = removeUndefinedFromObject;
|
|
1146
1176
|
|
|
1147
1177
|
//#endregion
|
|
1148
1178
|
//#region src/functions/parsers/parseBoolean.ts
|
|
@@ -1159,10 +1189,9 @@ var removeUndefinedFromObject_default = removeUndefinedFromObject;
|
|
|
1159
1189
|
*/
|
|
1160
1190
|
function parseBoolean(inputString) {
|
|
1161
1191
|
const normalisedString = inputString.toLowerCase();
|
|
1162
|
-
if (!["true", "false"].includes(normalisedString)) throw new
|
|
1192
|
+
if (!["true", "false"].includes(normalisedString)) throw new DataError(inputString, "INVALID_BOOLEAN_STRING", "The provided boolean string must be one of `true | false`");
|
|
1163
1193
|
return normalisedString === "true";
|
|
1164
1194
|
}
|
|
1165
|
-
var parseBoolean_default = parseBoolean;
|
|
1166
1195
|
|
|
1167
1196
|
//#endregion
|
|
1168
1197
|
//#region src/functions/parsers/zod/_parseZodSchema.ts
|
|
@@ -1180,7 +1209,7 @@ function _parseZodSchema(parsedResult, data, onError) {
|
|
|
1180
1209
|
const code = issue.code.toUpperCase();
|
|
1181
1210
|
allErrorCodes[code] = (allErrorCodes[code] ?? 0) + 1;
|
|
1182
1211
|
}
|
|
1183
|
-
throw new
|
|
1212
|
+
throw new DataError(data, Object.entries(allErrorCodes).toSorted(([_, firstCount], [__, secondCount]) => {
|
|
1184
1213
|
return secondCount - firstCount;
|
|
1185
1214
|
}).map(([code, count], _, allErrorCodes) => {
|
|
1186
1215
|
return allErrorCodes.length === 1 && count === 1 ? code : `${code}×${count}`;
|
|
@@ -1188,7 +1217,6 @@ function _parseZodSchema(parsedResult, data, onError) {
|
|
|
1188
1217
|
}
|
|
1189
1218
|
return parsedResult.data;
|
|
1190
1219
|
}
|
|
1191
|
-
var _parseZodSchema_default = _parseZodSchema;
|
|
1192
1220
|
|
|
1193
1221
|
//#endregion
|
|
1194
1222
|
//#region src/functions/parsers/zod/parseZodSchema.ts
|
|
@@ -1211,9 +1239,8 @@ var _parseZodSchema_default = _parseZodSchema;
|
|
|
1211
1239
|
* @returns The parsed data from the Zod schema.
|
|
1212
1240
|
*/
|
|
1213
1241
|
function parseZodSchema(schema, data, onError) {
|
|
1214
|
-
return
|
|
1242
|
+
return _parseZodSchema(schema.safeParse(data), data, onError);
|
|
1215
1243
|
}
|
|
1216
|
-
var parseZodSchema_default = parseZodSchema;
|
|
1217
1244
|
|
|
1218
1245
|
//#endregion
|
|
1219
1246
|
//#region src/functions/parsers/parseEnv.ts
|
|
@@ -1239,9 +1266,8 @@ const Env = {
|
|
|
1239
1266
|
* @returns The specified environment if allowed.
|
|
1240
1267
|
*/
|
|
1241
1268
|
function parseEnv(data) {
|
|
1242
|
-
return
|
|
1269
|
+
return parseZodSchema(z$1.enum(Env), data, new DataError(data, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
|
|
1243
1270
|
}
|
|
1244
|
-
var parseEnv_default = parseEnv;
|
|
1245
1271
|
|
|
1246
1272
|
//#endregion
|
|
1247
1273
|
//#region src/functions/parsers/parseFilePath.ts
|
|
@@ -1257,23 +1283,22 @@ var parseEnv_default = parseEnv;
|
|
|
1257
1283
|
* @returns An object representing the different ways the file path can be represented.
|
|
1258
1284
|
*/
|
|
1259
1285
|
function parseFilePath(filePath) {
|
|
1260
|
-
const caughtGroups = filePath.match(RegExp(
|
|
1286
|
+
const caughtGroups = filePath.match(RegExp(FILE_PATH_REGEX));
|
|
1261
1287
|
if (!caughtGroups) {
|
|
1262
1288
|
if (!(filePath.includes("/") || filePath.includes("\\")) && filePath.includes(".")) return {
|
|
1263
1289
|
directory: "",
|
|
1264
1290
|
base: filePath,
|
|
1265
1291
|
fullPath: filePath
|
|
1266
1292
|
};
|
|
1267
|
-
throw new
|
|
1293
|
+
throw new DataError({ filePath }, "INVALID_FILE_PATH", "The file path you provided is not valid.");
|
|
1268
1294
|
}
|
|
1269
|
-
if (!caughtGroups.groups) throw new
|
|
1295
|
+
if (!caughtGroups.groups) throw new DataError({ filePath }, "PARSING_ERROR", "An error occurred while trying to parse the data.");
|
|
1270
1296
|
return {
|
|
1271
1297
|
directory: caughtGroups.groups.directory,
|
|
1272
1298
|
base: caughtGroups.groups.base,
|
|
1273
1299
|
fullPath: path.join(caughtGroups.groups.directory.replaceAll("\\", "/"), caughtGroups.groups.base)
|
|
1274
1300
|
};
|
|
1275
1301
|
}
|
|
1276
|
-
var parseFilePath_default = parseFilePath;
|
|
1277
1302
|
|
|
1278
1303
|
//#endregion
|
|
1279
1304
|
//#region src/functions/parsers/parseFormData.ts
|
|
@@ -1297,7 +1322,6 @@ function parseFormData(formData, dataParser) {
|
|
|
1297
1322
|
if (dataParser) return dataParser(object);
|
|
1298
1323
|
return object;
|
|
1299
1324
|
}
|
|
1300
|
-
var parseFormData_default = parseFormData;
|
|
1301
1325
|
|
|
1302
1326
|
//#endregion
|
|
1303
1327
|
//#region src/functions/parsers/parseVersionType.ts
|
|
@@ -1323,9 +1347,8 @@ const VersionType = {
|
|
|
1323
1347
|
* @returns The given version type if allowed.
|
|
1324
1348
|
*/
|
|
1325
1349
|
function parseVersionType(data) {
|
|
1326
|
-
return
|
|
1350
|
+
return parseZodSchema(z.enum(VersionType), data, new DataError(data, "INVALID_VERSION_TYPE", "The provided version type must be one of `major | minor | patch`"));
|
|
1327
1351
|
}
|
|
1328
|
-
var parseVersionType_default = parseVersionType;
|
|
1329
1352
|
|
|
1330
1353
|
//#endregion
|
|
1331
1354
|
//#region src/functions/parsers/zod/parseZodSchemaAsync.ts
|
|
@@ -1346,9 +1369,8 @@ var parseVersionType_default = parseVersionType;
|
|
|
1346
1369
|
* @returns The parsed data from the Zod schema.
|
|
1347
1370
|
*/
|
|
1348
1371
|
async function parseZodSchemaAsync(schema, data, onError) {
|
|
1349
|
-
return
|
|
1372
|
+
return _parseZodSchema(await schema.safeParseAsync(data), data, onError);
|
|
1350
1373
|
}
|
|
1351
|
-
var parseZodSchemaAsync_default = parseZodSchemaAsync;
|
|
1352
1374
|
|
|
1353
1375
|
//#endregion
|
|
1354
1376
|
//#region src/functions/recursive/deepCopy.ts
|
|
@@ -1377,7 +1399,6 @@ function deepCopy(object) {
|
|
|
1377
1399
|
}
|
|
1378
1400
|
return clonedObject;
|
|
1379
1401
|
}
|
|
1380
|
-
var deepCopy_default = deepCopy;
|
|
1381
1402
|
|
|
1382
1403
|
//#endregion
|
|
1383
1404
|
//#region src/functions/security/encryptWithKey.ts
|
|
@@ -1396,10 +1417,9 @@ async function encryptWithKey(publicKey, plaintextValue) {
|
|
|
1396
1417
|
const encryptedValue = sodium.crypto_box_seal(plaintextValue, base64Key);
|
|
1397
1418
|
return sodium.to_base64(encryptedValue, sodium.base64_variants.ORIGINAL);
|
|
1398
1419
|
} catch {
|
|
1399
|
-
throw new
|
|
1420
|
+
throw new DataError({ publicKey }, "ENCRYPTION_FAILED", "Encryption failed. Please double-check that the given key is a valid base 64 string.");
|
|
1400
1421
|
}
|
|
1401
1422
|
}
|
|
1402
|
-
var encryptWithKey_default = encryptWithKey;
|
|
1403
1423
|
|
|
1404
1424
|
//#endregion
|
|
1405
1425
|
//#region src/functions/security/getPublicAndPrivateKey.ts
|
|
@@ -1417,7 +1437,7 @@ var encryptWithKey_default = encryptWithKey;
|
|
|
1417
1437
|
function getPublicAndPrivateKey(outputFormat) {
|
|
1418
1438
|
const keys = sodium.crypto_box_keypair(outputFormat);
|
|
1419
1439
|
if (outputFormat === "uint8array" || outputFormat === void 0) {
|
|
1420
|
-
if (!(keys?.publicKey instanceof Uint8Array && keys?.privateKey instanceof Uint8Array)) throw new
|
|
1440
|
+
if (!(keys?.publicKey instanceof Uint8Array && keys?.privateKey instanceof Uint8Array)) throw new DataError({
|
|
1421
1441
|
publicKey: `<redacted: ${keys?.publicKey?.constructor?.name ?? typeof keys?.publicKey}>`,
|
|
1422
1442
|
privateKey: `<redacted: ${keys?.privateKey?.constructor?.name ?? typeof keys?.privateKey}>`
|
|
1423
1443
|
}, "INVALID_KEY_TYPES", "Expected Uint8Array keypair from libsodium.");
|
|
@@ -1425,7 +1445,6 @@ function getPublicAndPrivateKey(outputFormat) {
|
|
|
1425
1445
|
}
|
|
1426
1446
|
return keys;
|
|
1427
1447
|
}
|
|
1428
|
-
var getPublicAndPrivateKey_default = getPublicAndPrivateKey;
|
|
1429
1448
|
|
|
1430
1449
|
//#endregion
|
|
1431
1450
|
//#region src/functions/stringHelpers/appendSemicolon.ts
|
|
@@ -1446,7 +1465,6 @@ function appendSemicolon(stringToAppendTo) {
|
|
|
1446
1465
|
if (stringWithNoTrailingWhitespace === "") return "";
|
|
1447
1466
|
return stringWithNoTrailingWhitespace[stringWithNoTrailingWhitespace.length - 1] === ";" ? stringWithNoTrailingWhitespace : `${stringWithNoTrailingWhitespace};`;
|
|
1448
1467
|
}
|
|
1449
|
-
var appendSemicolon_default = appendSemicolon;
|
|
1450
1468
|
|
|
1451
1469
|
//#endregion
|
|
1452
1470
|
//#region src/functions/stringHelpers/camelToKebab.ts
|
|
@@ -1486,7 +1504,6 @@ function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
|
|
|
1486
1504
|
}
|
|
1487
1505
|
return result;
|
|
1488
1506
|
}
|
|
1489
|
-
var camelToKebab_default = camelToKebab;
|
|
1490
1507
|
|
|
1491
1508
|
//#endregion
|
|
1492
1509
|
//#region src/functions/stringHelpers/kebabToCamel.ts
|
|
@@ -1510,7 +1527,7 @@ function kebabToCamel(string, options) {
|
|
|
1510
1527
|
skip = false;
|
|
1511
1528
|
continue;
|
|
1512
1529
|
}
|
|
1513
|
-
const index =
|
|
1530
|
+
const index = parseIntStrict(stringIndex);
|
|
1514
1531
|
if (index === 0 && options?.startWithUpper) {
|
|
1515
1532
|
outputString += string[index].toUpperCase();
|
|
1516
1533
|
continue;
|
|
@@ -1526,7 +1543,6 @@ function kebabToCamel(string, options) {
|
|
|
1526
1543
|
}
|
|
1527
1544
|
return outputString;
|
|
1528
1545
|
}
|
|
1529
|
-
var kebabToCamel_default = kebabToCamel;
|
|
1530
1546
|
|
|
1531
1547
|
//#endregion
|
|
1532
1548
|
//#region src/functions/stringHelpers/normalizeImportPath.ts
|
|
@@ -1564,7 +1580,6 @@ function normalizeImportPath(importPath) {
|
|
|
1564
1580
|
* @returns The import path normalised.
|
|
1565
1581
|
*/
|
|
1566
1582
|
const normaliseImportPath = normalizeImportPath;
|
|
1567
|
-
var normalizeImportPath_default = normalizeImportPath;
|
|
1568
1583
|
|
|
1569
1584
|
//#endregion
|
|
1570
1585
|
//#region src/functions/stringHelpers/truncate.ts
|
|
@@ -1581,7 +1596,6 @@ var normalizeImportPath_default = normalizeImportPath;
|
|
|
1581
1596
|
function truncate(stringToTruncate, maxLength = 5) {
|
|
1582
1597
|
return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
|
|
1583
1598
|
}
|
|
1584
|
-
var truncate_default = truncate;
|
|
1585
1599
|
|
|
1586
1600
|
//#endregion
|
|
1587
1601
|
//#region src/functions/versioning/parseVersion.ts
|
|
@@ -1600,11 +1614,10 @@ var truncate_default = truncate;
|
|
|
1600
1614
|
* @returns The validated version number, prefixed with `v` if it was not already.
|
|
1601
1615
|
*/
|
|
1602
1616
|
function parseVersion(input, options) {
|
|
1603
|
-
if (!RegExp(
|
|
1617
|
+
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.`);
|
|
1604
1618
|
if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
|
|
1605
1619
|
return input.startsWith("v") ? input : `v${input}`;
|
|
1606
1620
|
}
|
|
1607
|
-
var parseVersion_default = parseVersion;
|
|
1608
1621
|
|
|
1609
1622
|
//#endregion
|
|
1610
1623
|
//#region src/functions/versioning/getIndividualVersionNumbers.ts
|
|
@@ -1623,11 +1636,10 @@ var parseVersion_default = parseVersion;
|
|
|
1623
1636
|
* @returns A tuple of three numbers indicating `[major, minor, patch]`.
|
|
1624
1637
|
*/
|
|
1625
1638
|
function getIndividualVersionNumbers(version) {
|
|
1626
|
-
return
|
|
1627
|
-
return
|
|
1639
|
+
return parseVersion(version, { omitPrefix: true }).split(".").map((versionNumber) => {
|
|
1640
|
+
return parseIntStrict(versionNumber);
|
|
1628
1641
|
});
|
|
1629
1642
|
}
|
|
1630
|
-
var getIndividualVersionNumbers_default = getIndividualVersionNumbers;
|
|
1631
1643
|
|
|
1632
1644
|
//#endregion
|
|
1633
1645
|
//#region src/functions/versioning/determineVersionType.ts
|
|
@@ -1641,12 +1653,11 @@ var getIndividualVersionNumbers_default = getIndividualVersionNumbers;
|
|
|
1641
1653
|
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
1642
1654
|
*/
|
|
1643
1655
|
function determineVersionType(version) {
|
|
1644
|
-
const [_major, minor, patch] =
|
|
1656
|
+
const [_major, minor, patch] = getIndividualVersionNumbers(version);
|
|
1645
1657
|
if (minor === 0 && patch === 0) return "major";
|
|
1646
1658
|
if (patch === 0) return "minor";
|
|
1647
1659
|
return "patch";
|
|
1648
1660
|
}
|
|
1649
|
-
var determineVersionType_default = determineVersionType;
|
|
1650
1661
|
|
|
1651
1662
|
//#endregion
|
|
1652
1663
|
//#region src/functions/versioning/incrementVersion.ts
|
|
@@ -1665,15 +1676,14 @@ var determineVersionType_default = determineVersionType;
|
|
|
1665
1676
|
* @returns A new string representing the version with the increment applied.
|
|
1666
1677
|
*/
|
|
1667
1678
|
function incrementVersion(version, incrementType, options) {
|
|
1668
|
-
const [major, minor, patch] =
|
|
1679
|
+
const [major, minor, patch] = getIndividualVersionNumbers(version);
|
|
1669
1680
|
const newVersion = {
|
|
1670
1681
|
major: `${major + 1}.0.0`,
|
|
1671
1682
|
minor: `${major}.${minor + 1}.0`,
|
|
1672
1683
|
patch: `${major}.${minor}.${patch + 1}`
|
|
1673
1684
|
}[incrementType];
|
|
1674
|
-
return
|
|
1685
|
+
return parseVersion(newVersion, { omitPrefix: options?.omitPrefix });
|
|
1675
1686
|
}
|
|
1676
|
-
var incrementVersion_default = incrementVersion;
|
|
1677
1687
|
|
|
1678
1688
|
//#endregion
|
|
1679
|
-
export {
|
|
1689
|
+
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 };
|