@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.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -34,17 +35,14 @@ libsodium_wrappers = __toESM(libsodium_wrappers);
|
|
|
34
35
|
|
|
35
36
|
//#region src/constants/FILE_PATH_REGEX.ts
|
|
36
37
|
const FILE_PATH_REGEX = String.raw`^(?<directory>.+)[\/\\](?<base>[^\/\\]+)$`;
|
|
37
|
-
var FILE_PATH_REGEX_default = FILE_PATH_REGEX;
|
|
38
38
|
|
|
39
39
|
//#endregion
|
|
40
40
|
//#region src/constants/NAMESPACE_EXPORT_REGEX.ts
|
|
41
41
|
const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
42
|
-
var NAMESPACE_EXPORT_REGEX_default = NAMESPACE_EXPORT_REGEX;
|
|
43
42
|
|
|
44
43
|
//#endregion
|
|
45
44
|
//#region src/constants/VERSION_NUMBER_REGEX.ts
|
|
46
45
|
const VERSION_NUMBER_REGEX = "^(?:v)?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$";
|
|
47
|
-
var VERSION_NUMBER_REGEX_default = VERSION_NUMBER_REGEX;
|
|
48
46
|
|
|
49
47
|
//#endregion
|
|
50
48
|
//#region src/functions/arrayHelpers/fillArray.ts
|
|
@@ -72,7 +70,6 @@ function fillArray(callback, length = 1) {
|
|
|
72
70
|
})) return Promise.all(outputArray);
|
|
73
71
|
return outputArray;
|
|
74
72
|
}
|
|
75
|
-
var fillArray_default = fillArray;
|
|
76
73
|
|
|
77
74
|
//#endregion
|
|
78
75
|
//#region src/functions/arrayHelpers/paralleliseArrays.ts
|
|
@@ -97,7 +94,6 @@ function paralleliseArrays(firstArray, secondArray) {
|
|
|
97
94
|
for (let i = 0; i < firstArray.length; i++) outputArray.push([firstArray[i], secondArray[i]]);
|
|
98
95
|
return outputArray;
|
|
99
96
|
}
|
|
100
|
-
var paralleliseArrays_default = paralleliseArrays;
|
|
101
97
|
|
|
102
98
|
//#endregion
|
|
103
99
|
//#region src/types/APIError.ts
|
|
@@ -114,7 +110,7 @@ const httpErrorCodeLookup = {
|
|
|
114
110
|
*
|
|
115
111
|
* @category Types
|
|
116
112
|
*/
|
|
117
|
-
var APIError = class extends Error {
|
|
113
|
+
var APIError = class APIError extends Error {
|
|
118
114
|
status;
|
|
119
115
|
/**
|
|
120
116
|
* @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.
|
|
@@ -137,11 +133,11 @@ var APIError = class extends Error {
|
|
|
137
133
|
* @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`.
|
|
138
134
|
*/
|
|
139
135
|
static check(input) {
|
|
136
|
+
if (input instanceof APIError) return true;
|
|
140
137
|
const data = input;
|
|
141
138
|
return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
|
|
142
139
|
}
|
|
143
140
|
};
|
|
144
|
-
var APIError_default = APIError;
|
|
145
141
|
|
|
146
142
|
//#endregion
|
|
147
143
|
//#region src/types/DataError.ts
|
|
@@ -150,7 +146,7 @@ var APIError_default = APIError;
|
|
|
150
146
|
*
|
|
151
147
|
* @category Types
|
|
152
148
|
*/
|
|
153
|
-
var DataError = class extends Error {
|
|
149
|
+
var DataError = class DataError extends Error {
|
|
154
150
|
code;
|
|
155
151
|
data;
|
|
156
152
|
/**
|
|
@@ -176,11 +172,11 @@ var DataError = class extends Error {
|
|
|
176
172
|
* @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`.
|
|
177
173
|
*/
|
|
178
174
|
static check(input) {
|
|
175
|
+
if (input instanceof DataError) return true;
|
|
179
176
|
const data = input;
|
|
180
177
|
return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
|
|
181
178
|
}
|
|
182
179
|
};
|
|
183
|
-
var DataError_default = DataError;
|
|
184
180
|
|
|
185
181
|
//#endregion
|
|
186
182
|
//#region src/types/VersionNumber.ts
|
|
@@ -206,18 +202,18 @@ var VersionNumber = class VersionNumber {
|
|
|
206
202
|
this.minor = input.minor;
|
|
207
203
|
this.patch = input.patch;
|
|
208
204
|
} else if (typeof input === "string") {
|
|
209
|
-
if (!RegExp(
|
|
205
|
+
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.`);
|
|
210
206
|
const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
|
|
211
|
-
return
|
|
207
|
+
return parseIntStrict(number);
|
|
212
208
|
});
|
|
213
209
|
this.major = major;
|
|
214
210
|
this.minor = minor;
|
|
215
211
|
this.patch = patch;
|
|
216
212
|
} else if (Array.isArray(input)) {
|
|
217
|
-
if (input.length !== 3) throw new
|
|
213
|
+
if (input.length !== 3) throw new DataError(input, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
218
214
|
const [major, minor, patch] = input.map((number) => {
|
|
219
|
-
const parsedInteger =
|
|
220
|
-
if (parsedInteger < 0) throw new
|
|
215
|
+
const parsedInteger = parseIntStrict(number?.toString());
|
|
216
|
+
if (parsedInteger < 0) throw new DataError(input, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
221
217
|
return parsedInteger;
|
|
222
218
|
});
|
|
223
219
|
this.major = major;
|
|
@@ -287,7 +283,7 @@ var VersionNumber = class VersionNumber {
|
|
|
287
283
|
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
288
284
|
*/
|
|
289
285
|
[Symbol.toPrimitive](hint) {
|
|
290
|
-
if (hint === "number") throw new
|
|
286
|
+
if (hint === "number") throw new DataError(this.toString(), "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
|
|
291
287
|
return this.toString();
|
|
292
288
|
}
|
|
293
289
|
/**
|
|
@@ -310,7 +306,6 @@ var VersionNumber = class VersionNumber {
|
|
|
310
306
|
return VersionNumber.formatString(rawString, options);
|
|
311
307
|
}
|
|
312
308
|
};
|
|
313
|
-
var VersionNumber_default = VersionNumber;
|
|
314
309
|
|
|
315
310
|
//#endregion
|
|
316
311
|
//#region src/functions/parsers/parseIntStrict.ts
|
|
@@ -329,21 +324,20 @@ var VersionNumber_default = VersionNumber;
|
|
|
329
324
|
function parseIntStrict(string, radix) {
|
|
330
325
|
const trimmedString = string.trim();
|
|
331
326
|
const maxAllowedAlphabeticalCharacter = radix && radix > 10 && radix <= 36 ? String.fromCharCode(87 + radix - 1) : void 0;
|
|
332
|
-
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new
|
|
327
|
+
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new DataError(radix ? {
|
|
333
328
|
string,
|
|
334
329
|
radix
|
|
335
330
|
} : string, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
|
|
336
331
|
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
337
332
|
return parseInt(character) >= radix;
|
|
338
|
-
})) throw new
|
|
333
|
+
})) throw new DataError({
|
|
339
334
|
string,
|
|
340
335
|
radix
|
|
341
336
|
}, "INTEGER_PARSING_ERROR", "Value contains one or more digits outside of the range of the given radix.");
|
|
342
337
|
const parseIntResult = parseInt(trimmedString, radix);
|
|
343
|
-
if (isNaN(parseIntResult)) throw new
|
|
338
|
+
if (isNaN(parseIntResult)) throw new DataError(string, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
|
|
344
339
|
return parseIntResult;
|
|
345
340
|
}
|
|
346
|
-
var parseIntStrict_default = parseIntStrict;
|
|
347
341
|
|
|
348
342
|
//#endregion
|
|
349
343
|
//#region src/functions/miscellaneous/getRandomNumber.ts
|
|
@@ -358,11 +352,10 @@ var parseIntStrict_default = parseIntStrict;
|
|
|
358
352
|
* @returns A random number between the provided lower bound and upper bound.
|
|
359
353
|
*/
|
|
360
354
|
function getRandomNumber(lowerBound, upperBound) {
|
|
361
|
-
const parsedLowerBound =
|
|
362
|
-
const parsedUpperBound =
|
|
355
|
+
const parsedLowerBound = parseIntStrict(`${lowerBound}`);
|
|
356
|
+
const parsedUpperBound = parseIntStrict(`${upperBound}`);
|
|
363
357
|
return Math.floor(Math.random() * (parsedUpperBound - parsedLowerBound + 1) + parsedLowerBound);
|
|
364
358
|
}
|
|
365
|
-
var getRandomNumber_default = getRandomNumber;
|
|
366
359
|
|
|
367
360
|
//#endregion
|
|
368
361
|
//#region src/functions/arrayHelpers/randomiseArray.ts
|
|
@@ -381,12 +374,11 @@ function randomiseArray(array) {
|
|
|
381
374
|
const mutableArray = [...array];
|
|
382
375
|
const outputArray = [];
|
|
383
376
|
do {
|
|
384
|
-
const indexToRemove =
|
|
377
|
+
const indexToRemove = getRandomNumber(0, mutableArray.length - 1);
|
|
385
378
|
outputArray.push(mutableArray.splice(indexToRemove, 1)[0]);
|
|
386
379
|
} while (mutableArray.length > 0);
|
|
387
380
|
return outputArray;
|
|
388
381
|
}
|
|
389
|
-
var randomiseArray_default = randomiseArray;
|
|
390
382
|
|
|
391
383
|
//#endregion
|
|
392
384
|
//#region src/functions/arrayHelpers/range.ts
|
|
@@ -419,7 +411,6 @@ function range(start, stop, step = 1) {
|
|
|
419
411
|
}
|
|
420
412
|
return numbers;
|
|
421
413
|
}
|
|
422
|
-
var range_default = range;
|
|
423
414
|
|
|
424
415
|
//#endregion
|
|
425
416
|
//#region src/functions/arrayHelpers/removeDuplicates.ts
|
|
@@ -439,7 +430,6 @@ function removeDuplicates(array) {
|
|
|
439
430
|
for (const item of array) if (!outputArray.includes(item)) outputArray.push(item);
|
|
440
431
|
return outputArray;
|
|
441
432
|
}
|
|
442
|
-
var removeDuplicates_default = removeDuplicates;
|
|
443
433
|
|
|
444
434
|
//#endregion
|
|
445
435
|
//#region src/functions/date/addDaysToDate.ts
|
|
@@ -458,7 +448,6 @@ function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement =
|
|
|
458
448
|
newDate.setDate(newDate.getDate() + dayIncrement);
|
|
459
449
|
return newDate;
|
|
460
450
|
}
|
|
461
|
-
var addDaysToDate_default = addDaysToDate;
|
|
462
451
|
|
|
463
452
|
//#endregion
|
|
464
453
|
//#region src/functions/date/isSameDate.ts
|
|
@@ -475,7 +464,6 @@ var addDaysToDate_default = addDaysToDate;
|
|
|
475
464
|
function isSameDate(firstDate, secondDate) {
|
|
476
465
|
return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth() && firstDate.getFullYear() === secondDate.getFullYear();
|
|
477
466
|
}
|
|
478
|
-
var isSameDate_default = isSameDate;
|
|
479
467
|
|
|
480
468
|
//#endregion
|
|
481
469
|
//#region src/functions/date/formatDateAndTime.ts
|
|
@@ -493,14 +481,13 @@ var isSameDate_default = isSameDate;
|
|
|
493
481
|
* - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
|
|
494
482
|
*/
|
|
495
483
|
function formatDateAndTime(inputDate) {
|
|
496
|
-
const yesterday =
|
|
484
|
+
const yesterday = addDaysToDate(/* @__PURE__ */ new Date(), -1);
|
|
497
485
|
const today = /* @__PURE__ */ new Date();
|
|
498
486
|
const inputTime = `${inputDate.getHours().toString().padStart(2, "0")}:${inputDate.getMinutes().toString().padStart(2, "0")}`;
|
|
499
|
-
if (
|
|
500
|
-
if (
|
|
487
|
+
if (isSameDate(inputDate, yesterday)) return `Yesterday at ${inputTime}`;
|
|
488
|
+
if (isSameDate(inputDate, today)) return `Today at ${inputTime}`;
|
|
501
489
|
return `${inputDate.getDate().toString().padStart(2, "0")}/${(inputDate.getMonth() + 1).toString().padStart(2, "0")}/${inputDate.getFullYear().toString()}, ${inputTime}`;
|
|
502
490
|
}
|
|
503
|
-
var formatDateAndTime_default = formatDateAndTime;
|
|
504
491
|
|
|
505
492
|
//#endregion
|
|
506
493
|
//#region src/functions/date/isLeapYear.ts
|
|
@@ -516,15 +503,14 @@ var formatDateAndTime_default = formatDateAndTime;
|
|
|
516
503
|
* @returns True if the year is a leap year, and false otherwise.
|
|
517
504
|
*/
|
|
518
505
|
function isLeapYear(year) {
|
|
519
|
-
const parsedYear =
|
|
506
|
+
const parsedYear = parseIntStrict(`${year}`);
|
|
520
507
|
return parsedYear % 4 === 0 && parsedYear % 100 !== 0 || parsedYear % 400 === 0;
|
|
521
508
|
}
|
|
522
|
-
var isLeapYear_default = isLeapYear;
|
|
523
509
|
|
|
524
510
|
//#endregion
|
|
525
511
|
//#region src/functions/date/isAnniversary.ts
|
|
526
512
|
function checkLeapYear(firstDate, secondDate) {
|
|
527
|
-
if (
|
|
513
|
+
if (isLeapYear(firstDate.getFullYear()) && firstDate.getMonth() === 1 && secondDate.getMonth() === 1) return firstDate.getDate() === 29 && secondDate.getDate() === 28;
|
|
528
514
|
return false;
|
|
529
515
|
}
|
|
530
516
|
/**
|
|
@@ -541,7 +527,6 @@ function isAnniversary(firstDate, secondDate) {
|
|
|
541
527
|
if (checkLeapYear(firstDate, secondDate) || checkLeapYear(secondDate, firstDate)) return true;
|
|
542
528
|
return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth();
|
|
543
529
|
}
|
|
544
|
-
var isAnniversary_default = isAnniversary;
|
|
545
530
|
|
|
546
531
|
//#endregion
|
|
547
532
|
//#region src/functions/date/isMonthlyMultiple.ts
|
|
@@ -556,7 +541,7 @@ function endOfMonthChecksButNotFebruary(firstDate, secondDate) {
|
|
|
556
541
|
}
|
|
557
542
|
function nonLeapYearFebruaryChecks(firstDate, secondDate) {
|
|
558
543
|
if (firstDate.getMonth() === 1) {
|
|
559
|
-
if (!
|
|
544
|
+
if (!isLeapYear(firstDate.getFullYear()) && firstDate.getDate() === 28) return [
|
|
560
545
|
28,
|
|
561
546
|
29,
|
|
562
547
|
30,
|
|
@@ -567,7 +552,7 @@ function nonLeapYearFebruaryChecks(firstDate, secondDate) {
|
|
|
567
552
|
}
|
|
568
553
|
function leapYearFebruaryChecks(firstDate, secondDate) {
|
|
569
554
|
if (firstDate.getMonth() === 1) {
|
|
570
|
-
if (
|
|
555
|
+
if (isLeapYear(firstDate.getFullYear()) && firstDate.getDate() === 29) return [
|
|
571
556
|
29,
|
|
572
557
|
30,
|
|
573
558
|
31
|
|
@@ -591,7 +576,6 @@ function isMonthlyMultiple(firstDate, secondDate) {
|
|
|
591
576
|
if (leapYearFebruaryChecks(firstDate, secondDate) || leapYearFebruaryChecks(secondDate, firstDate)) return true;
|
|
592
577
|
return firstDate.getDate() === secondDate.getDate();
|
|
593
578
|
}
|
|
594
|
-
var isMonthlyMultiple_default = isMonthlyMultiple;
|
|
595
579
|
|
|
596
580
|
//#endregion
|
|
597
581
|
//#region src/functions/miscellaneous/convertFileToBase64.ts
|
|
@@ -622,7 +606,6 @@ function convertFileToBase64(file) {
|
|
|
622
606
|
};
|
|
623
607
|
});
|
|
624
608
|
}
|
|
625
|
-
var convertFileToBase64_default = convertFileToBase64;
|
|
626
609
|
|
|
627
610
|
//#endregion
|
|
628
611
|
//#region src/functions/miscellaneous/createFormData.ts
|
|
@@ -692,7 +675,6 @@ function createFormData(data, options = {
|
|
|
692
675
|
} else formData.append(String(key), String(value));
|
|
693
676
|
return formData;
|
|
694
677
|
}
|
|
695
|
-
var createFormData_default = createFormData;
|
|
696
678
|
|
|
697
679
|
//#endregion
|
|
698
680
|
//#region src/functions/miscellaneous/isOrdered.ts
|
|
@@ -711,7 +693,6 @@ function isOrdered(array) {
|
|
|
711
693
|
for (const index in newArray) if (newArray[index] !== array[index]) return false;
|
|
712
694
|
return true;
|
|
713
695
|
}
|
|
714
|
-
var isOrdered_default = isOrdered;
|
|
715
696
|
|
|
716
697
|
//#endregion
|
|
717
698
|
//#region src/functions/recursive/deepFreeze.ts
|
|
@@ -736,7 +717,6 @@ function deepFreeze(object) {
|
|
|
736
717
|
}
|
|
737
718
|
return Object.freeze(object);
|
|
738
719
|
}
|
|
739
|
-
var deepFreeze_default = deepFreeze;
|
|
740
720
|
|
|
741
721
|
//#endregion
|
|
742
722
|
//#region src/functions/taggedTemplate/createTemplateStringsArray.ts
|
|
@@ -750,13 +730,13 @@ var deepFreeze_default = deepFreeze;
|
|
|
750
730
|
* @returns A template strings array that can be passed as the first argument of any tagged template function.
|
|
751
731
|
*/
|
|
752
732
|
function createTemplateStringsArray(strings) {
|
|
753
|
-
return
|
|
733
|
+
return deepFreeze(Object.assign([...strings], { raw: [...strings] }));
|
|
754
734
|
}
|
|
755
|
-
var createTemplateStringsArray_default = createTemplateStringsArray;
|
|
756
735
|
|
|
757
736
|
//#endregion
|
|
758
737
|
//#region src/functions/taggedTemplate/getInterpolations.ts
|
|
759
738
|
/**
|
|
739
|
+
*
|
|
760
740
|
* Gets the strings and interpolations separately from a template string.
|
|
761
741
|
* You can pass a template string directly by doing:
|
|
762
742
|
*
|
|
@@ -766,6 +746,8 @@ var createTemplateStringsArray_default = createTemplateStringsArray;
|
|
|
766
746
|
*
|
|
767
747
|
* @category Tagged Template
|
|
768
748
|
*
|
|
749
|
+
* @deprecated Please use `getStringsAndInterpolations` instead.
|
|
750
|
+
*
|
|
769
751
|
* @param strings - The strings from the template to process.
|
|
770
752
|
* @param interpolations - An array of all interpolations from the template.
|
|
771
753
|
*
|
|
@@ -774,7 +756,47 @@ var createTemplateStringsArray_default = createTemplateStringsArray;
|
|
|
774
756
|
function getInterpolations(strings, ...interpolations) {
|
|
775
757
|
return [strings, interpolations];
|
|
776
758
|
}
|
|
777
|
-
|
|
759
|
+
|
|
760
|
+
//#endregion
|
|
761
|
+
//#region src/functions/taggedTemplate/getStringsAndInterpolations.ts
|
|
762
|
+
/**
|
|
763
|
+
*
|
|
764
|
+
* Gets the strings and interpolations separately from a template string.
|
|
765
|
+
* You can pass a template string directly by doing:
|
|
766
|
+
*
|
|
767
|
+
* ```typescript
|
|
768
|
+
* getStringsAndInterpolations`Template string here`;
|
|
769
|
+
* ```
|
|
770
|
+
*
|
|
771
|
+
* @category Tagged Template
|
|
772
|
+
*
|
|
773
|
+
* @template InterpolationsType - The type of the interpolations.
|
|
774
|
+
*
|
|
775
|
+
* @param strings - The strings from the template to process.
|
|
776
|
+
* @param interpolations - An array of all interpolations from the template.
|
|
777
|
+
*
|
|
778
|
+
* @returns A tuple where the first item is the strings from the template, and the remaining items are the interpolations.
|
|
779
|
+
*
|
|
780
|
+
* The return of this function may also be spread into any other tagged template function in the following way:
|
|
781
|
+
*
|
|
782
|
+
* ```typescript
|
|
783
|
+
* import { interpolate } from "@alextheman/utility"; // Example function
|
|
784
|
+
*
|
|
785
|
+
* const packageName = "@alextheman/utility";
|
|
786
|
+
* const packageManager = getPackageManager(packageName);
|
|
787
|
+
*
|
|
788
|
+
* interpolate(...getStringsAndInterpolations`The package ${packageName} uses the ${packageManager} package manager.`);
|
|
789
|
+
* ```
|
|
790
|
+
*/
|
|
791
|
+
function getStringsAndInterpolations(strings, ...interpolations) {
|
|
792
|
+
if (strings.length !== interpolations.length + 1) throw new DataError({
|
|
793
|
+
stringsLength: strings.length,
|
|
794
|
+
interpolationsLength: interpolations.length,
|
|
795
|
+
strings,
|
|
796
|
+
interpolations
|
|
797
|
+
}, "INVALID_STRINGS_AND_INTERPOLATIONS_LENGTH", "The length of the strings must be exactly one more than the length of the interpolations.");
|
|
798
|
+
return [createTemplateStringsArray(strings), ...interpolations];
|
|
799
|
+
}
|
|
778
800
|
|
|
779
801
|
//#endregion
|
|
780
802
|
//#region src/functions/taggedTemplate/interpolate.ts
|
|
@@ -791,6 +813,8 @@ var getInterpolations_default = getInterpolations;
|
|
|
791
813
|
*
|
|
792
814
|
* @category Tagged Template
|
|
793
815
|
*
|
|
816
|
+
* @template InterpolationsType - The type of the interpolations.
|
|
817
|
+
*
|
|
794
818
|
* @param strings - The strings from the template to process.
|
|
795
819
|
* @param interpolations - An array of all interpolations from the template.
|
|
796
820
|
*
|
|
@@ -798,10 +822,9 @@ var getInterpolations_default = getInterpolations;
|
|
|
798
822
|
*/
|
|
799
823
|
function interpolate(strings, ...interpolations) {
|
|
800
824
|
let result = "";
|
|
801
|
-
for (const [string, interpolation = ""] of
|
|
825
|
+
for (const [string, interpolation = ""] of paralleliseArrays(strings, interpolations)) result += string + interpolation;
|
|
802
826
|
return result;
|
|
803
827
|
}
|
|
804
|
-
var interpolate_default = interpolate;
|
|
805
828
|
|
|
806
829
|
//#endregion
|
|
807
830
|
//#region src/functions/taggedTemplate/interpolateObjects.ts
|
|
@@ -811,11 +834,13 @@ var interpolate_default = interpolate;
|
|
|
811
834
|
* You can pass a template string directly by doing:
|
|
812
835
|
*
|
|
813
836
|
* ```typescript
|
|
814
|
-
* interpolateObjects`Template string here ${{ my: "object" }}
|
|
837
|
+
* interpolateObjects`Template string here ${{ my: "object" }}`;
|
|
815
838
|
* ```
|
|
816
839
|
*
|
|
817
840
|
* @category Tagged Template
|
|
818
841
|
*
|
|
842
|
+
* @template InterpolationsType - The type of the interpolations.
|
|
843
|
+
*
|
|
819
844
|
* @param strings - The strings from the template to process.
|
|
820
845
|
* @param interpolations - An array of all interpolations from the template.
|
|
821
846
|
*
|
|
@@ -829,7 +854,21 @@ function interpolateObjects(strings, ...interpolations) {
|
|
|
829
854
|
}
|
|
830
855
|
return result;
|
|
831
856
|
}
|
|
832
|
-
|
|
857
|
+
|
|
858
|
+
//#endregion
|
|
859
|
+
//#region src/functions/taggedTemplate/isTemplateStringsArray.ts
|
|
860
|
+
/**
|
|
861
|
+
* Determines whether or not the input is a valid `TemplateStringsArray`.
|
|
862
|
+
*
|
|
863
|
+
* @category Tagged Template
|
|
864
|
+
*
|
|
865
|
+
* @param input - The input to check
|
|
866
|
+
*
|
|
867
|
+
* @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`.
|
|
868
|
+
*/
|
|
869
|
+
function isTemplateStringsArray(input) {
|
|
870
|
+
return typeof input === "object" && input !== null && "raw" in input;
|
|
871
|
+
}
|
|
833
872
|
|
|
834
873
|
//#endregion
|
|
835
874
|
//#region src/functions/taggedTemplate/normaliseIndents.ts
|
|
@@ -852,7 +891,7 @@ function reduceLines(lines, { preserveTabs = true }) {
|
|
|
852
891
|
const whitespaceLength = getWhitespaceLength(isFirstLineEmpty ? lines : slicedLines);
|
|
853
892
|
return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
|
|
854
893
|
const tabSize = calculateTabSize(line, whitespaceLength);
|
|
855
|
-
return (preserveTabs ?
|
|
894
|
+
return (preserveTabs ? fillArray(() => {
|
|
856
895
|
return " ";
|
|
857
896
|
}, tabSize).join("") : "") + line.trimStart();
|
|
858
897
|
}).join("\n");
|
|
@@ -865,7 +904,7 @@ function reduceLines(lines, { preserveTabs = true }) {
|
|
|
865
904
|
* ```typescript
|
|
866
905
|
* normaliseIndents`Template string here
|
|
867
906
|
* with a new line
|
|
868
|
-
* and another new line
|
|
907
|
+
* and another new line`;
|
|
869
908
|
* ```
|
|
870
909
|
*
|
|
871
910
|
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
@@ -873,10 +912,10 @@ function reduceLines(lines, { preserveTabs = true }) {
|
|
|
873
912
|
* ```typescript
|
|
874
913
|
* normaliseIndents({ preserveTabs: false })`Template string here
|
|
875
914
|
* with a new line
|
|
876
|
-
* and another new line
|
|
915
|
+
* and another new line`;
|
|
877
916
|
* ```
|
|
878
917
|
*
|
|
879
|
-
|
|
918
|
+
* @category Tagged Template
|
|
880
919
|
*
|
|
881
920
|
* @param first - The strings from the template to process, or the options to apply.
|
|
882
921
|
* @param args - An array of all interpolations from the template.
|
|
@@ -892,7 +931,7 @@ function normaliseIndents(first, ...args) {
|
|
|
892
931
|
}
|
|
893
932
|
const strings = first;
|
|
894
933
|
const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
|
|
895
|
-
return reduceLines(
|
|
934
|
+
return reduceLines(interpolate(strings, ...[...args]).split("\n"), options);
|
|
896
935
|
}
|
|
897
936
|
/**
|
|
898
937
|
* Applies any options if provided, then removes any extraneous indents from a multi-line template string.
|
|
@@ -919,7 +958,6 @@ function normaliseIndents(first, ...args) {
|
|
|
919
958
|
* @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
920
959
|
*/
|
|
921
960
|
const normalizeIndents = normaliseIndents;
|
|
922
|
-
var normaliseIndents_default = normaliseIndents;
|
|
923
961
|
|
|
924
962
|
//#endregion
|
|
925
963
|
//#region src/functions/miscellaneous/sayHello.ts
|
|
@@ -931,7 +969,7 @@ var normaliseIndents_default = normaliseIndents;
|
|
|
931
969
|
* @returns The lyrics string in markdown format.
|
|
932
970
|
*/
|
|
933
971
|
function sayHello() {
|
|
934
|
-
return
|
|
972
|
+
return normaliseIndents`
|
|
935
973
|
# Commit To You
|
|
936
974
|
|
|
937
975
|
### Verse 1
|
|
@@ -1034,7 +1072,6 @@ function sayHello() {
|
|
|
1034
1072
|
I'll commit to you!
|
|
1035
1073
|
`;
|
|
1036
1074
|
}
|
|
1037
|
-
var sayHello_default = sayHello;
|
|
1038
1075
|
|
|
1039
1076
|
//#endregion
|
|
1040
1077
|
//#region src/functions/miscellaneous/stringifyDotenv.ts
|
|
@@ -1051,8 +1088,8 @@ function stringifyDotenv(contents, options) {
|
|
|
1051
1088
|
const { quoteStyle = "double" } = options ?? {};
|
|
1052
1089
|
let result = "";
|
|
1053
1090
|
for (const key in contentsCopy) {
|
|
1054
|
-
if (/[ \t\r\n]/.test(key)) throw new
|
|
1055
|
-
if (quoteStyle === "none") if (/[ \t\r\n]/.test(contentsCopy[key]) || contentsCopy[key].includes("#") || contentsCopy[key].includes("=") || contentsCopy[key].includes("\\")) throw new
|
|
1091
|
+
if (/[ \t\r\n]/.test(key)) throw new DataError({ [key]: contentsCopy[key] }, "INVALID_KEY", "Environment variables are not allowed to have whitespace.");
|
|
1092
|
+
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 \\");
|
|
1056
1093
|
else {
|
|
1057
1094
|
result += `${key}=${contentsCopy[key]}\n`;
|
|
1058
1095
|
continue;
|
|
@@ -1071,7 +1108,6 @@ function stringifyDotenv(contents, options) {
|
|
|
1071
1108
|
}
|
|
1072
1109
|
return result;
|
|
1073
1110
|
}
|
|
1074
|
-
var stringifyDotenv_default = stringifyDotenv;
|
|
1075
1111
|
|
|
1076
1112
|
//#endregion
|
|
1077
1113
|
//#region src/functions/miscellaneous/stringListToArray.ts
|
|
@@ -1094,7 +1130,6 @@ function stringListToArray(stringList, { separator = ",", trimWhitespace = true
|
|
|
1094
1130
|
return item.trim();
|
|
1095
1131
|
}) : arrayList;
|
|
1096
1132
|
}
|
|
1097
|
-
var stringListToArray_default = stringListToArray;
|
|
1098
1133
|
|
|
1099
1134
|
//#endregion
|
|
1100
1135
|
//#region src/functions/miscellaneous/wait.ts
|
|
@@ -1114,7 +1149,6 @@ function wait(seconds) {
|
|
|
1114
1149
|
}, seconds * 1e3);
|
|
1115
1150
|
});
|
|
1116
1151
|
}
|
|
1117
|
-
var wait_default = wait;
|
|
1118
1152
|
|
|
1119
1153
|
//#endregion
|
|
1120
1154
|
//#region src/functions/objectHelpers/getRecordKeys.ts
|
|
@@ -1132,7 +1166,6 @@ var wait_default = wait;
|
|
|
1132
1166
|
function getRecordKeys(record) {
|
|
1133
1167
|
return Object.keys(record);
|
|
1134
1168
|
}
|
|
1135
|
-
var getRecordKeys_default = getRecordKeys;
|
|
1136
1169
|
|
|
1137
1170
|
//#endregion
|
|
1138
1171
|
//#region src/functions/objectHelpers/omitProperties.ts
|
|
@@ -1156,7 +1189,6 @@ function omitProperties(object, keysToOmit) {
|
|
|
1156
1189
|
});
|
|
1157
1190
|
return outputObject;
|
|
1158
1191
|
}
|
|
1159
|
-
var omitProperties_default = omitProperties;
|
|
1160
1192
|
|
|
1161
1193
|
//#endregion
|
|
1162
1194
|
//#region src/functions/objectHelpers/removeUndefinedFromObject.ts
|
|
@@ -1172,7 +1204,6 @@ function removeUndefinedFromObject(object) {
|
|
|
1172
1204
|
return value !== void 0;
|
|
1173
1205
|
}));
|
|
1174
1206
|
}
|
|
1175
|
-
var removeUndefinedFromObject_default = removeUndefinedFromObject;
|
|
1176
1207
|
|
|
1177
1208
|
//#endregion
|
|
1178
1209
|
//#region src/functions/parsers/parseBoolean.ts
|
|
@@ -1189,10 +1220,9 @@ var removeUndefinedFromObject_default = removeUndefinedFromObject;
|
|
|
1189
1220
|
*/
|
|
1190
1221
|
function parseBoolean(inputString) {
|
|
1191
1222
|
const normalisedString = inputString.toLowerCase();
|
|
1192
|
-
if (!["true", "false"].includes(normalisedString)) throw new
|
|
1223
|
+
if (!["true", "false"].includes(normalisedString)) throw new DataError(inputString, "INVALID_BOOLEAN_STRING", "The provided boolean string must be one of `true | false`");
|
|
1193
1224
|
return normalisedString === "true";
|
|
1194
1225
|
}
|
|
1195
|
-
var parseBoolean_default = parseBoolean;
|
|
1196
1226
|
|
|
1197
1227
|
//#endregion
|
|
1198
1228
|
//#region src/functions/parsers/zod/_parseZodSchema.ts
|
|
@@ -1210,7 +1240,7 @@ function _parseZodSchema(parsedResult, data, onError) {
|
|
|
1210
1240
|
const code = issue.code.toUpperCase();
|
|
1211
1241
|
allErrorCodes[code] = (allErrorCodes[code] ?? 0) + 1;
|
|
1212
1242
|
}
|
|
1213
|
-
throw new
|
|
1243
|
+
throw new DataError(data, Object.entries(allErrorCodes).toSorted(([_, firstCount], [__, secondCount]) => {
|
|
1214
1244
|
return secondCount - firstCount;
|
|
1215
1245
|
}).map(([code, count], _, allErrorCodes) => {
|
|
1216
1246
|
return allErrorCodes.length === 1 && count === 1 ? code : `${code}×${count}`;
|
|
@@ -1218,7 +1248,6 @@ function _parseZodSchema(parsedResult, data, onError) {
|
|
|
1218
1248
|
}
|
|
1219
1249
|
return parsedResult.data;
|
|
1220
1250
|
}
|
|
1221
|
-
var _parseZodSchema_default = _parseZodSchema;
|
|
1222
1251
|
|
|
1223
1252
|
//#endregion
|
|
1224
1253
|
//#region src/functions/parsers/zod/parseZodSchema.ts
|
|
@@ -1241,9 +1270,8 @@ var _parseZodSchema_default = _parseZodSchema;
|
|
|
1241
1270
|
* @returns The parsed data from the Zod schema.
|
|
1242
1271
|
*/
|
|
1243
1272
|
function parseZodSchema(schema, data, onError) {
|
|
1244
|
-
return
|
|
1273
|
+
return _parseZodSchema(schema.safeParse(data), data, onError);
|
|
1245
1274
|
}
|
|
1246
|
-
var parseZodSchema_default = parseZodSchema;
|
|
1247
1275
|
|
|
1248
1276
|
//#endregion
|
|
1249
1277
|
//#region src/functions/parsers/parseEnv.ts
|
|
@@ -1269,9 +1297,8 @@ const Env = {
|
|
|
1269
1297
|
* @returns The specified environment if allowed.
|
|
1270
1298
|
*/
|
|
1271
1299
|
function parseEnv(data) {
|
|
1272
|
-
return
|
|
1300
|
+
return parseZodSchema(zod.z.enum(Env), data, new DataError(data, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
|
|
1273
1301
|
}
|
|
1274
|
-
var parseEnv_default = parseEnv;
|
|
1275
1302
|
|
|
1276
1303
|
//#endregion
|
|
1277
1304
|
//#region src/functions/parsers/parseFilePath.ts
|
|
@@ -1287,23 +1314,22 @@ var parseEnv_default = parseEnv;
|
|
|
1287
1314
|
* @returns An object representing the different ways the file path can be represented.
|
|
1288
1315
|
*/
|
|
1289
1316
|
function parseFilePath(filePath) {
|
|
1290
|
-
const caughtGroups = filePath.match(RegExp(
|
|
1317
|
+
const caughtGroups = filePath.match(RegExp(FILE_PATH_REGEX));
|
|
1291
1318
|
if (!caughtGroups) {
|
|
1292
1319
|
if (!(filePath.includes("/") || filePath.includes("\\")) && filePath.includes(".")) return {
|
|
1293
1320
|
directory: "",
|
|
1294
1321
|
base: filePath,
|
|
1295
1322
|
fullPath: filePath
|
|
1296
1323
|
};
|
|
1297
|
-
throw new
|
|
1324
|
+
throw new DataError({ filePath }, "INVALID_FILE_PATH", "The file path you provided is not valid.");
|
|
1298
1325
|
}
|
|
1299
|
-
if (!caughtGroups.groups) throw new
|
|
1326
|
+
if (!caughtGroups.groups) throw new DataError({ filePath }, "PARSING_ERROR", "An error occurred while trying to parse the data.");
|
|
1300
1327
|
return {
|
|
1301
1328
|
directory: caughtGroups.groups.directory,
|
|
1302
1329
|
base: caughtGroups.groups.base,
|
|
1303
1330
|
fullPath: node_path.default.join(caughtGroups.groups.directory.replaceAll("\\", "/"), caughtGroups.groups.base)
|
|
1304
1331
|
};
|
|
1305
1332
|
}
|
|
1306
|
-
var parseFilePath_default = parseFilePath;
|
|
1307
1333
|
|
|
1308
1334
|
//#endregion
|
|
1309
1335
|
//#region src/functions/parsers/parseFormData.ts
|
|
@@ -1327,7 +1353,6 @@ function parseFormData(formData, dataParser) {
|
|
|
1327
1353
|
if (dataParser) return dataParser(object);
|
|
1328
1354
|
return object;
|
|
1329
1355
|
}
|
|
1330
|
-
var parseFormData_default = parseFormData;
|
|
1331
1356
|
|
|
1332
1357
|
//#endregion
|
|
1333
1358
|
//#region src/functions/parsers/parseVersionType.ts
|
|
@@ -1353,9 +1378,8 @@ const VersionType = {
|
|
|
1353
1378
|
* @returns The given version type if allowed.
|
|
1354
1379
|
*/
|
|
1355
1380
|
function parseVersionType(data) {
|
|
1356
|
-
return
|
|
1381
|
+
return parseZodSchema(zod.default.enum(VersionType), data, new DataError(data, "INVALID_VERSION_TYPE", "The provided version type must be one of `major | minor | patch`"));
|
|
1357
1382
|
}
|
|
1358
|
-
var parseVersionType_default = parseVersionType;
|
|
1359
1383
|
|
|
1360
1384
|
//#endregion
|
|
1361
1385
|
//#region src/functions/parsers/zod/parseZodSchemaAsync.ts
|
|
@@ -1376,9 +1400,8 @@ var parseVersionType_default = parseVersionType;
|
|
|
1376
1400
|
* @returns The parsed data from the Zod schema.
|
|
1377
1401
|
*/
|
|
1378
1402
|
async function parseZodSchemaAsync(schema, data, onError) {
|
|
1379
|
-
return
|
|
1403
|
+
return _parseZodSchema(await schema.safeParseAsync(data), data, onError);
|
|
1380
1404
|
}
|
|
1381
|
-
var parseZodSchemaAsync_default = parseZodSchemaAsync;
|
|
1382
1405
|
|
|
1383
1406
|
//#endregion
|
|
1384
1407
|
//#region src/functions/recursive/deepCopy.ts
|
|
@@ -1407,7 +1430,6 @@ function deepCopy(object) {
|
|
|
1407
1430
|
}
|
|
1408
1431
|
return clonedObject;
|
|
1409
1432
|
}
|
|
1410
|
-
var deepCopy_default = deepCopy;
|
|
1411
1433
|
|
|
1412
1434
|
//#endregion
|
|
1413
1435
|
//#region src/functions/security/encryptWithKey.ts
|
|
@@ -1426,10 +1448,9 @@ async function encryptWithKey(publicKey, plaintextValue) {
|
|
|
1426
1448
|
const encryptedValue = libsodium_wrappers.default.crypto_box_seal(plaintextValue, base64Key);
|
|
1427
1449
|
return libsodium_wrappers.default.to_base64(encryptedValue, libsodium_wrappers.default.base64_variants.ORIGINAL);
|
|
1428
1450
|
} catch {
|
|
1429
|
-
throw new
|
|
1451
|
+
throw new DataError({ publicKey }, "ENCRYPTION_FAILED", "Encryption failed. Please double-check that the given key is a valid base 64 string.");
|
|
1430
1452
|
}
|
|
1431
1453
|
}
|
|
1432
|
-
var encryptWithKey_default = encryptWithKey;
|
|
1433
1454
|
|
|
1434
1455
|
//#endregion
|
|
1435
1456
|
//#region src/functions/security/getPublicAndPrivateKey.ts
|
|
@@ -1447,7 +1468,7 @@ var encryptWithKey_default = encryptWithKey;
|
|
|
1447
1468
|
function getPublicAndPrivateKey(outputFormat) {
|
|
1448
1469
|
const keys = libsodium_wrappers.default.crypto_box_keypair(outputFormat);
|
|
1449
1470
|
if (outputFormat === "uint8array" || outputFormat === void 0) {
|
|
1450
|
-
if (!(keys?.publicKey instanceof Uint8Array && keys?.privateKey instanceof Uint8Array)) throw new
|
|
1471
|
+
if (!(keys?.publicKey instanceof Uint8Array && keys?.privateKey instanceof Uint8Array)) throw new DataError({
|
|
1451
1472
|
publicKey: `<redacted: ${keys?.publicKey?.constructor?.name ?? typeof keys?.publicKey}>`,
|
|
1452
1473
|
privateKey: `<redacted: ${keys?.privateKey?.constructor?.name ?? typeof keys?.privateKey}>`
|
|
1453
1474
|
}, "INVALID_KEY_TYPES", "Expected Uint8Array keypair from libsodium.");
|
|
@@ -1455,7 +1476,6 @@ function getPublicAndPrivateKey(outputFormat) {
|
|
|
1455
1476
|
}
|
|
1456
1477
|
return keys;
|
|
1457
1478
|
}
|
|
1458
|
-
var getPublicAndPrivateKey_default = getPublicAndPrivateKey;
|
|
1459
1479
|
|
|
1460
1480
|
//#endregion
|
|
1461
1481
|
//#region src/functions/stringHelpers/appendSemicolon.ts
|
|
@@ -1476,7 +1496,6 @@ function appendSemicolon(stringToAppendTo) {
|
|
|
1476
1496
|
if (stringWithNoTrailingWhitespace === "") return "";
|
|
1477
1497
|
return stringWithNoTrailingWhitespace[stringWithNoTrailingWhitespace.length - 1] === ";" ? stringWithNoTrailingWhitespace : `${stringWithNoTrailingWhitespace};`;
|
|
1478
1498
|
}
|
|
1479
|
-
var appendSemicolon_default = appendSemicolon;
|
|
1480
1499
|
|
|
1481
1500
|
//#endregion
|
|
1482
1501
|
//#region src/functions/stringHelpers/camelToKebab.ts
|
|
@@ -1516,7 +1535,6 @@ function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
|
|
|
1516
1535
|
}
|
|
1517
1536
|
return result;
|
|
1518
1537
|
}
|
|
1519
|
-
var camelToKebab_default = camelToKebab;
|
|
1520
1538
|
|
|
1521
1539
|
//#endregion
|
|
1522
1540
|
//#region src/functions/stringHelpers/kebabToCamel.ts
|
|
@@ -1540,7 +1558,7 @@ function kebabToCamel(string, options) {
|
|
|
1540
1558
|
skip = false;
|
|
1541
1559
|
continue;
|
|
1542
1560
|
}
|
|
1543
|
-
const index =
|
|
1561
|
+
const index = parseIntStrict(stringIndex);
|
|
1544
1562
|
if (index === 0 && options?.startWithUpper) {
|
|
1545
1563
|
outputString += string[index].toUpperCase();
|
|
1546
1564
|
continue;
|
|
@@ -1556,7 +1574,6 @@ function kebabToCamel(string, options) {
|
|
|
1556
1574
|
}
|
|
1557
1575
|
return outputString;
|
|
1558
1576
|
}
|
|
1559
|
-
var kebabToCamel_default = kebabToCamel;
|
|
1560
1577
|
|
|
1561
1578
|
//#endregion
|
|
1562
1579
|
//#region src/functions/stringHelpers/normalizeImportPath.ts
|
|
@@ -1594,7 +1611,6 @@ function normalizeImportPath(importPath) {
|
|
|
1594
1611
|
* @returns The import path normalised.
|
|
1595
1612
|
*/
|
|
1596
1613
|
const normaliseImportPath = normalizeImportPath;
|
|
1597
|
-
var normalizeImportPath_default = normalizeImportPath;
|
|
1598
1614
|
|
|
1599
1615
|
//#endregion
|
|
1600
1616
|
//#region src/functions/stringHelpers/truncate.ts
|
|
@@ -1611,7 +1627,6 @@ var normalizeImportPath_default = normalizeImportPath;
|
|
|
1611
1627
|
function truncate(stringToTruncate, maxLength = 5) {
|
|
1612
1628
|
return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
|
|
1613
1629
|
}
|
|
1614
|
-
var truncate_default = truncate;
|
|
1615
1630
|
|
|
1616
1631
|
//#endregion
|
|
1617
1632
|
//#region src/functions/versioning/parseVersion.ts
|
|
@@ -1630,11 +1645,10 @@ var truncate_default = truncate;
|
|
|
1630
1645
|
* @returns The validated version number, prefixed with `v` if it was not already.
|
|
1631
1646
|
*/
|
|
1632
1647
|
function parseVersion(input, options) {
|
|
1633
|
-
if (!RegExp(
|
|
1648
|
+
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.`);
|
|
1634
1649
|
if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
|
|
1635
1650
|
return input.startsWith("v") ? input : `v${input}`;
|
|
1636
1651
|
}
|
|
1637
|
-
var parseVersion_default = parseVersion;
|
|
1638
1652
|
|
|
1639
1653
|
//#endregion
|
|
1640
1654
|
//#region src/functions/versioning/getIndividualVersionNumbers.ts
|
|
@@ -1653,11 +1667,10 @@ var parseVersion_default = parseVersion;
|
|
|
1653
1667
|
* @returns A tuple of three numbers indicating `[major, minor, patch]`.
|
|
1654
1668
|
*/
|
|
1655
1669
|
function getIndividualVersionNumbers(version) {
|
|
1656
|
-
return
|
|
1657
|
-
return
|
|
1670
|
+
return parseVersion(version, { omitPrefix: true }).split(".").map((versionNumber) => {
|
|
1671
|
+
return parseIntStrict(versionNumber);
|
|
1658
1672
|
});
|
|
1659
1673
|
}
|
|
1660
|
-
var getIndividualVersionNumbers_default = getIndividualVersionNumbers;
|
|
1661
1674
|
|
|
1662
1675
|
//#endregion
|
|
1663
1676
|
//#region src/functions/versioning/determineVersionType.ts
|
|
@@ -1671,12 +1684,11 @@ var getIndividualVersionNumbers_default = getIndividualVersionNumbers;
|
|
|
1671
1684
|
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
1672
1685
|
*/
|
|
1673
1686
|
function determineVersionType(version) {
|
|
1674
|
-
const [_major, minor, patch] =
|
|
1687
|
+
const [_major, minor, patch] = getIndividualVersionNumbers(version);
|
|
1675
1688
|
if (minor === 0 && patch === 0) return "major";
|
|
1676
1689
|
if (patch === 0) return "minor";
|
|
1677
1690
|
return "patch";
|
|
1678
1691
|
}
|
|
1679
|
-
var determineVersionType_default = determineVersionType;
|
|
1680
1692
|
|
|
1681
1693
|
//#endregion
|
|
1682
1694
|
//#region src/functions/versioning/incrementVersion.ts
|
|
@@ -1695,73 +1707,74 @@ var determineVersionType_default = determineVersionType;
|
|
|
1695
1707
|
* @returns A new string representing the version with the increment applied.
|
|
1696
1708
|
*/
|
|
1697
1709
|
function incrementVersion(version, incrementType, options) {
|
|
1698
|
-
const [major, minor, patch] =
|
|
1710
|
+
const [major, minor, patch] = getIndividualVersionNumbers(version);
|
|
1699
1711
|
const newVersion = {
|
|
1700
1712
|
major: `${major + 1}.0.0`,
|
|
1701
1713
|
minor: `${major}.${minor + 1}.0`,
|
|
1702
1714
|
patch: `${major}.${minor}.${patch + 1}`
|
|
1703
1715
|
}[incrementType];
|
|
1704
|
-
return
|
|
1716
|
+
return parseVersion(newVersion, { omitPrefix: options?.omitPrefix });
|
|
1705
1717
|
}
|
|
1706
|
-
var incrementVersion_default = incrementVersion;
|
|
1707
1718
|
|
|
1708
1719
|
//#endregion
|
|
1709
|
-
exports.APIError =
|
|
1710
|
-
exports.DataError =
|
|
1720
|
+
exports.APIError = APIError;
|
|
1721
|
+
exports.DataError = DataError;
|
|
1711
1722
|
exports.Env = Env;
|
|
1712
|
-
exports.FILE_PATH_REGEX =
|
|
1713
|
-
exports.NAMESPACE_EXPORT_REGEX =
|
|
1714
|
-
exports.VERSION_NUMBER_REGEX =
|
|
1715
|
-
exports.VersionNumber =
|
|
1723
|
+
exports.FILE_PATH_REGEX = FILE_PATH_REGEX;
|
|
1724
|
+
exports.NAMESPACE_EXPORT_REGEX = NAMESPACE_EXPORT_REGEX;
|
|
1725
|
+
exports.VERSION_NUMBER_REGEX = VERSION_NUMBER_REGEX;
|
|
1726
|
+
exports.VersionNumber = VersionNumber;
|
|
1716
1727
|
exports.VersionType = VersionType;
|
|
1717
|
-
exports.addDaysToDate =
|
|
1718
|
-
exports.appendSemicolon =
|
|
1719
|
-
exports.camelToKebab =
|
|
1720
|
-
exports.convertFileToBase64 =
|
|
1721
|
-
exports.createFormData =
|
|
1722
|
-
exports.createTemplateStringsArray =
|
|
1723
|
-
exports.deepCopy =
|
|
1724
|
-
exports.deepFreeze =
|
|
1725
|
-
exports.determineVersionType =
|
|
1726
|
-
exports.encryptWithKey =
|
|
1727
|
-
exports.fillArray =
|
|
1728
|
-
exports.formatDateAndTime =
|
|
1729
|
-
exports.getIndividualVersionNumbers =
|
|
1730
|
-
exports.getInterpolations =
|
|
1731
|
-
exports.getPublicAndPrivateKey =
|
|
1732
|
-
exports.getRandomNumber =
|
|
1733
|
-
exports.getRecordKeys =
|
|
1728
|
+
exports.addDaysToDate = addDaysToDate;
|
|
1729
|
+
exports.appendSemicolon = appendSemicolon;
|
|
1730
|
+
exports.camelToKebab = camelToKebab;
|
|
1731
|
+
exports.convertFileToBase64 = convertFileToBase64;
|
|
1732
|
+
exports.createFormData = createFormData;
|
|
1733
|
+
exports.createTemplateStringsArray = createTemplateStringsArray;
|
|
1734
|
+
exports.deepCopy = deepCopy;
|
|
1735
|
+
exports.deepFreeze = deepFreeze;
|
|
1736
|
+
exports.determineVersionType = determineVersionType;
|
|
1737
|
+
exports.encryptWithKey = encryptWithKey;
|
|
1738
|
+
exports.fillArray = fillArray;
|
|
1739
|
+
exports.formatDateAndTime = formatDateAndTime;
|
|
1740
|
+
exports.getIndividualVersionNumbers = getIndividualVersionNumbers;
|
|
1741
|
+
exports.getInterpolations = getInterpolations;
|
|
1742
|
+
exports.getPublicAndPrivateKey = getPublicAndPrivateKey;
|
|
1743
|
+
exports.getRandomNumber = getRandomNumber;
|
|
1744
|
+
exports.getRecordKeys = getRecordKeys;
|
|
1745
|
+
exports.getStringsAndInterpolations = getStringsAndInterpolations;
|
|
1734
1746
|
exports.httpErrorCodeLookup = httpErrorCodeLookup;
|
|
1735
|
-
exports.incrementVersion =
|
|
1736
|
-
exports.interpolate =
|
|
1737
|
-
exports.interpolateObjects =
|
|
1738
|
-
exports.isAnniversary =
|
|
1739
|
-
exports.isLeapYear =
|
|
1740
|
-
exports.isMonthlyMultiple =
|
|
1741
|
-
exports.isOrdered =
|
|
1742
|
-
exports.isSameDate =
|
|
1743
|
-
exports.
|
|
1747
|
+
exports.incrementVersion = incrementVersion;
|
|
1748
|
+
exports.interpolate = interpolate;
|
|
1749
|
+
exports.interpolateObjects = interpolateObjects;
|
|
1750
|
+
exports.isAnniversary = isAnniversary;
|
|
1751
|
+
exports.isLeapYear = isLeapYear;
|
|
1752
|
+
exports.isMonthlyMultiple = isMonthlyMultiple;
|
|
1753
|
+
exports.isOrdered = isOrdered;
|
|
1754
|
+
exports.isSameDate = isSameDate;
|
|
1755
|
+
exports.isTemplateStringsArray = isTemplateStringsArray;
|
|
1756
|
+
exports.kebabToCamel = kebabToCamel;
|
|
1744
1757
|
exports.normaliseImportPath = normaliseImportPath;
|
|
1745
|
-
exports.normaliseIndents =
|
|
1746
|
-
exports.normalizeImportPath =
|
|
1758
|
+
exports.normaliseIndents = normaliseIndents;
|
|
1759
|
+
exports.normalizeImportPath = normalizeImportPath;
|
|
1747
1760
|
exports.normalizeIndents = normalizeIndents;
|
|
1748
|
-
exports.omitProperties =
|
|
1749
|
-
exports.paralleliseArrays =
|
|
1750
|
-
exports.parseBoolean =
|
|
1751
|
-
exports.parseEnv =
|
|
1752
|
-
exports.parseFilePath =
|
|
1753
|
-
exports.parseFormData =
|
|
1754
|
-
exports.parseIntStrict =
|
|
1755
|
-
exports.parseVersion =
|
|
1756
|
-
exports.parseVersionType =
|
|
1757
|
-
exports.parseZodSchema =
|
|
1758
|
-
exports.parseZodSchemaAsync =
|
|
1759
|
-
exports.randomiseArray =
|
|
1760
|
-
exports.range =
|
|
1761
|
-
exports.removeDuplicates =
|
|
1762
|
-
exports.removeUndefinedFromObject =
|
|
1763
|
-
exports.sayHello =
|
|
1764
|
-
exports.stringListToArray =
|
|
1765
|
-
exports.stringifyDotenv =
|
|
1766
|
-
exports.truncate =
|
|
1767
|
-
exports.wait =
|
|
1761
|
+
exports.omitProperties = omitProperties;
|
|
1762
|
+
exports.paralleliseArrays = paralleliseArrays;
|
|
1763
|
+
exports.parseBoolean = parseBoolean;
|
|
1764
|
+
exports.parseEnv = parseEnv;
|
|
1765
|
+
exports.parseFilePath = parseFilePath;
|
|
1766
|
+
exports.parseFormData = parseFormData;
|
|
1767
|
+
exports.parseIntStrict = parseIntStrict;
|
|
1768
|
+
exports.parseVersion = parseVersion;
|
|
1769
|
+
exports.parseVersionType = parseVersionType;
|
|
1770
|
+
exports.parseZodSchema = parseZodSchema;
|
|
1771
|
+
exports.parseZodSchemaAsync = parseZodSchemaAsync;
|
|
1772
|
+
exports.randomiseArray = randomiseArray;
|
|
1773
|
+
exports.range = range;
|
|
1774
|
+
exports.removeDuplicates = removeDuplicates;
|
|
1775
|
+
exports.removeUndefinedFromObject = removeUndefinedFromObject;
|
|
1776
|
+
exports.sayHello = sayHello;
|
|
1777
|
+
exports.stringListToArray = stringListToArray;
|
|
1778
|
+
exports.stringifyDotenv = stringifyDotenv;
|
|
1779
|
+
exports.truncate = truncate;
|
|
1780
|
+
exports.wait = wait;
|