@alextheman/utility 4.17.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +111 -258
- package/dist/index.d.cts +122 -258
- package/dist/index.d.ts +122 -258
- package/dist/index.js +111 -251
- package/dist/internal/index.cjs +650 -0
- package/dist/internal/index.d.cts +26 -0
- package/dist/internal/index.d.ts +28 -0
- package/dist/internal/index.js +616 -0
- package/dist/node/index.cjs +594 -0
- package/dist/node/index.d.cts +46 -0
- package/dist/node/index.d.ts +48 -0
- package/dist/node/index.js +562 -0
- package/package.json +13 -3
package/dist/index.js
CHANGED
|
@@ -2,19 +2,19 @@ import z, { z as z$1 } from "zod";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import sodium from "libsodium-wrappers";
|
|
4
4
|
|
|
5
|
-
//#region src/constants/FILE_PATH_REGEX.ts
|
|
5
|
+
//#region src/root/constants/FILE_PATH_REGEX.ts
|
|
6
6
|
const FILE_PATH_REGEX = String.raw`^(?<directory>.+)[\/\\](?<base>[^\/\\]+)$`;
|
|
7
7
|
|
|
8
8
|
//#endregion
|
|
9
|
-
//#region src/constants/NAMESPACE_EXPORT_REGEX.ts
|
|
9
|
+
//#region src/root/constants/NAMESPACE_EXPORT_REGEX.ts
|
|
10
10
|
const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
11
11
|
|
|
12
12
|
//#endregion
|
|
13
|
-
//#region src/constants/VERSION_NUMBER_REGEX.ts
|
|
13
|
+
//#region src/root/constants/VERSION_NUMBER_REGEX.ts
|
|
14
14
|
const VERSION_NUMBER_REGEX = "^(?:v)?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$";
|
|
15
15
|
|
|
16
16
|
//#endregion
|
|
17
|
-
//#region src/functions/arrayHelpers/fillArray.ts
|
|
17
|
+
//#region src/root/functions/arrayHelpers/fillArray.ts
|
|
18
18
|
/**
|
|
19
19
|
* Creates a new array where each element is the result of the provided callback.
|
|
20
20
|
*
|
|
@@ -41,7 +41,7 @@ function fillArray(callback, length = 1) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
//#endregion
|
|
44
|
-
//#region src/functions/arrayHelpers/paralleliseArrays.ts
|
|
44
|
+
//#region src/root/functions/arrayHelpers/paralleliseArrays.ts
|
|
45
45
|
/**
|
|
46
46
|
* Creates a new array of tuples, each containing the item at the given index from both arrays.
|
|
47
47
|
*
|
|
@@ -65,7 +65,7 @@ function paralleliseArrays(firstArray, secondArray) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
//#endregion
|
|
68
|
-
//#region src/types/APIError.ts
|
|
68
|
+
//#region src/root/types/APIError.ts
|
|
69
69
|
const httpErrorCodeLookup = {
|
|
70
70
|
400: "BAD_REQUEST",
|
|
71
71
|
401: "UNAUTHORISED",
|
|
@@ -109,11 +109,13 @@ var APIError = class APIError extends Error {
|
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
//#endregion
|
|
112
|
-
//#region src/types/DataError.ts
|
|
112
|
+
//#region src/root/types/DataError.ts
|
|
113
113
|
/**
|
|
114
114
|
* Represents errors you may get that may've been caused by a specific piece of data.
|
|
115
115
|
*
|
|
116
116
|
* @category Types
|
|
117
|
+
*
|
|
118
|
+
* @template DataType - The type of the data that caused the error.
|
|
117
119
|
*/
|
|
118
120
|
var DataError = class DataError extends Error {
|
|
119
121
|
code;
|
|
@@ -148,7 +150,7 @@ var DataError = class DataError extends Error {
|
|
|
148
150
|
};
|
|
149
151
|
|
|
150
152
|
//#endregion
|
|
151
|
-
//#region src/types/VersionNumber.ts
|
|
153
|
+
//#region src/root/types/VersionNumber.ts
|
|
152
154
|
/**
|
|
153
155
|
* Represents a software version number, considered to be made up of a major, minor, and patch part.
|
|
154
156
|
*
|
|
@@ -171,7 +173,7 @@ var VersionNumber = class VersionNumber {
|
|
|
171
173
|
this.minor = input.minor;
|
|
172
174
|
this.patch = input.patch;
|
|
173
175
|
} else if (typeof input === "string") {
|
|
174
|
-
if (!RegExp(VERSION_NUMBER_REGEX).test(input)) throw new DataError(input, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
|
|
176
|
+
if (!RegExp(VERSION_NUMBER_REGEX).test(input)) throw new DataError({ input }, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
|
|
175
177
|
const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
|
|
176
178
|
return parseIntStrict(number);
|
|
177
179
|
});
|
|
@@ -179,10 +181,10 @@ var VersionNumber = class VersionNumber {
|
|
|
179
181
|
this.minor = minor;
|
|
180
182
|
this.patch = patch;
|
|
181
183
|
} else if (Array.isArray(input)) {
|
|
182
|
-
if (input.length !== 3) throw new DataError(input, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
184
|
+
if (input.length !== 3) throw new DataError({ input }, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
183
185
|
const [major, minor, patch] = input.map((number) => {
|
|
184
186
|
const parsedInteger = parseIntStrict(number?.toString());
|
|
185
|
-
if (parsedInteger < 0) throw new DataError(input, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
187
|
+
if (parsedInteger < 0) throw new DataError({ input }, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
186
188
|
return parsedInteger;
|
|
187
189
|
});
|
|
188
190
|
this.major = major;
|
|
@@ -216,6 +218,21 @@ var VersionNumber = class VersionNumber {
|
|
|
216
218
|
return firstVersion.major === secondVersion.major && firstVersion.minor === secondVersion.minor && firstVersion.patch === secondVersion.patch;
|
|
217
219
|
}
|
|
218
220
|
/**
|
|
221
|
+
* Get a formatted string representation of the current version number
|
|
222
|
+
*
|
|
223
|
+
* @param options - Options to apply to the string formatting.
|
|
224
|
+
*
|
|
225
|
+
* @returns A formatted string representation of the current version number with the options applied.
|
|
226
|
+
*/
|
|
227
|
+
format(options) {
|
|
228
|
+
let baseOutput = `${this.major}`;
|
|
229
|
+
if (!options?.omitMinor) {
|
|
230
|
+
baseOutput += `.${this.minor}`;
|
|
231
|
+
if (!options?.omitPatch) baseOutput += `.${this.patch}`;
|
|
232
|
+
}
|
|
233
|
+
return VersionNumber.formatString(baseOutput, { omitPrefix: options?.omitPrefix });
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
219
236
|
* Increments the current version number by the given increment type, returning the result as a new reference in memory.
|
|
220
237
|
*
|
|
221
238
|
* @param incrementType - The type of increment. Can be one of the following:
|
|
@@ -264,7 +281,7 @@ var VersionNumber = class VersionNumber {
|
|
|
264
281
|
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
265
282
|
*/
|
|
266
283
|
[Symbol.toPrimitive](hint) {
|
|
267
|
-
if (hint === "number") throw new DataError(this.toString(), "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
|
|
284
|
+
if (hint === "number") throw new DataError({ thisVersion: this.toString() }, "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
|
|
268
285
|
return this.toString();
|
|
269
286
|
}
|
|
270
287
|
/**
|
|
@@ -278,13 +295,11 @@ var VersionNumber = class VersionNumber {
|
|
|
278
295
|
/**
|
|
279
296
|
* Get a string representation of the current version number.
|
|
280
297
|
*
|
|
281
|
-
* @
|
|
282
|
-
*
|
|
283
|
-
* @returns A stringified representation of the current version number, leaving out the prefix if `omitPrefix` option was set to true.
|
|
298
|
+
* @returns A stringified representation of the current version number with the prefix.
|
|
284
299
|
*/
|
|
285
|
-
toString(
|
|
300
|
+
toString() {
|
|
286
301
|
const rawString = `${this.major}.${this.minor}.${this.patch}`;
|
|
287
|
-
return VersionNumber.formatString(rawString,
|
|
302
|
+
return VersionNumber.formatString(rawString, { omitPrefix: false });
|
|
288
303
|
}
|
|
289
304
|
};
|
|
290
305
|
const zodVersionNumber = z.union([
|
|
@@ -300,7 +315,7 @@ const zodVersionNumber = z.union([
|
|
|
300
315
|
});
|
|
301
316
|
|
|
302
317
|
//#endregion
|
|
303
|
-
//#region src/functions/parsers/parseIntStrict.ts
|
|
318
|
+
//#region src/root/functions/parsers/parseIntStrict.ts
|
|
304
319
|
/**
|
|
305
320
|
* Converts a string to an integer and throws an error if it cannot be converted.
|
|
306
321
|
*
|
|
@@ -319,7 +334,7 @@ function parseIntStrict(string, radix) {
|
|
|
319
334
|
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new DataError(radix ? {
|
|
320
335
|
string,
|
|
321
336
|
radix
|
|
322
|
-
} : string, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
|
|
337
|
+
} : { string }, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
|
|
323
338
|
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
324
339
|
return parseInt(character) >= radix;
|
|
325
340
|
})) throw new DataError({
|
|
@@ -327,12 +342,12 @@ function parseIntStrict(string, radix) {
|
|
|
327
342
|
radix
|
|
328
343
|
}, "INTEGER_PARSING_ERROR", "Value contains one or more digits outside of the range of the given radix.");
|
|
329
344
|
const parseIntResult = parseInt(trimmedString, radix);
|
|
330
|
-
if (isNaN(parseIntResult)) throw new DataError(string, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
|
|
345
|
+
if (isNaN(parseIntResult)) throw new DataError({ string }, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
|
|
331
346
|
return parseIntResult;
|
|
332
347
|
}
|
|
333
348
|
|
|
334
349
|
//#endregion
|
|
335
|
-
//#region src/functions/miscellaneous/getRandomNumber.ts
|
|
350
|
+
//#region src/root/functions/miscellaneous/getRandomNumber.ts
|
|
336
351
|
/**
|
|
337
352
|
* Gets a random number between the given bounds.
|
|
338
353
|
*
|
|
@@ -350,7 +365,7 @@ function getRandomNumber(lowerBound, upperBound) {
|
|
|
350
365
|
}
|
|
351
366
|
|
|
352
367
|
//#endregion
|
|
353
|
-
//#region src/functions/arrayHelpers/randomiseArray.ts
|
|
368
|
+
//#region src/root/functions/arrayHelpers/randomiseArray.ts
|
|
354
369
|
/**
|
|
355
370
|
* Randomises the order of a given array and returns the result in a new array without mutating the original.
|
|
356
371
|
*
|
|
@@ -373,7 +388,7 @@ function randomiseArray(array) {
|
|
|
373
388
|
}
|
|
374
389
|
|
|
375
390
|
//#endregion
|
|
376
|
-
//#region src/functions/arrayHelpers/range.ts
|
|
391
|
+
//#region src/root/functions/arrayHelpers/range.ts
|
|
377
392
|
/**
|
|
378
393
|
* Creates an array of numbers within a given range.
|
|
379
394
|
*
|
|
@@ -405,7 +420,7 @@ function range(start, stop, step = 1) {
|
|
|
405
420
|
}
|
|
406
421
|
|
|
407
422
|
//#endregion
|
|
408
|
-
//#region src/functions/arrayHelpers/removeDuplicates.ts
|
|
423
|
+
//#region src/root/functions/arrayHelpers/removeDuplicates.ts
|
|
409
424
|
/**
|
|
410
425
|
* Removes duplicate values from an array.
|
|
411
426
|
*
|
|
@@ -424,7 +439,7 @@ function removeDuplicates(array) {
|
|
|
424
439
|
}
|
|
425
440
|
|
|
426
441
|
//#endregion
|
|
427
|
-
//#region src/functions/date/addDaysToDate.ts
|
|
442
|
+
//#region src/root/functions/date/addDaysToDate.ts
|
|
428
443
|
/**
|
|
429
444
|
* Adds a given number of days to the provided date, returning the result as a new instance of Date.
|
|
430
445
|
*
|
|
@@ -442,7 +457,7 @@ function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement =
|
|
|
442
457
|
}
|
|
443
458
|
|
|
444
459
|
//#endregion
|
|
445
|
-
//#region src/functions/date/isSameDate.ts
|
|
460
|
+
//#region src/root/functions/date/isSameDate.ts
|
|
446
461
|
/**
|
|
447
462
|
* Checks if the provided dates happen on the exact same day, month, and year.
|
|
448
463
|
*
|
|
@@ -458,7 +473,7 @@ function isSameDate(firstDate, secondDate) {
|
|
|
458
473
|
}
|
|
459
474
|
|
|
460
475
|
//#endregion
|
|
461
|
-
//#region src/functions/date/formatDateAndTime.ts
|
|
476
|
+
//#region src/root/functions/date/formatDateAndTime.ts
|
|
462
477
|
/**
|
|
463
478
|
* Creates a human-readable string with information about the input date.
|
|
464
479
|
*
|
|
@@ -482,7 +497,7 @@ function formatDateAndTime(inputDate) {
|
|
|
482
497
|
}
|
|
483
498
|
|
|
484
499
|
//#endregion
|
|
485
|
-
//#region src/functions/date/isLeapYear.ts
|
|
500
|
+
//#region src/root/functions/date/isLeapYear.ts
|
|
486
501
|
/**
|
|
487
502
|
* Checks if the provided year is a leap year.
|
|
488
503
|
*
|
|
@@ -500,7 +515,7 @@ function isLeapYear(year) {
|
|
|
500
515
|
}
|
|
501
516
|
|
|
502
517
|
//#endregion
|
|
503
|
-
//#region src/functions/date/isAnniversary.ts
|
|
518
|
+
//#region src/root/functions/date/isAnniversary.ts
|
|
504
519
|
function checkLeapYear(firstDate, secondDate) {
|
|
505
520
|
if (isLeapYear(firstDate.getFullYear()) && firstDate.getMonth() === 1 && secondDate.getMonth() === 1) return firstDate.getDate() === 29 && secondDate.getDate() === 28;
|
|
506
521
|
return false;
|
|
@@ -521,7 +536,7 @@ function isAnniversary(firstDate, secondDate) {
|
|
|
521
536
|
}
|
|
522
537
|
|
|
523
538
|
//#endregion
|
|
524
|
-
//#region src/functions/date/isMonthlyMultiple.ts
|
|
539
|
+
//#region src/root/functions/date/isMonthlyMultiple.ts
|
|
525
540
|
function endOfMonthChecksButNotFebruary(firstDate, secondDate) {
|
|
526
541
|
if ([
|
|
527
542
|
3,
|
|
@@ -570,7 +585,7 @@ function isMonthlyMultiple(firstDate, secondDate) {
|
|
|
570
585
|
}
|
|
571
586
|
|
|
572
587
|
//#endregion
|
|
573
|
-
//#region src/functions/miscellaneous/convertFileToBase64.ts
|
|
588
|
+
//#region src/root/functions/miscellaneous/convertFileToBase64.ts
|
|
574
589
|
/**
|
|
575
590
|
* Asynchronously converts a file to a base 64 string
|
|
576
591
|
*
|
|
@@ -600,7 +615,7 @@ function convertFileToBase64(file) {
|
|
|
600
615
|
}
|
|
601
616
|
|
|
602
617
|
//#endregion
|
|
603
|
-
//#region src/functions/miscellaneous/createFormData.ts
|
|
618
|
+
//#region src/root/functions/miscellaneous/createFormData.ts
|
|
604
619
|
function getNullableResolutionStrategy(key, strategy) {
|
|
605
620
|
return (typeof strategy === "object" ? strategy[key] : strategy) ?? "empty";
|
|
606
621
|
}
|
|
@@ -669,7 +684,26 @@ function createFormData(data, options = {
|
|
|
669
684
|
}
|
|
670
685
|
|
|
671
686
|
//#endregion
|
|
672
|
-
//#region src/functions/miscellaneous/
|
|
687
|
+
//#region src/root/functions/miscellaneous/getDependenciesFromGroup.ts
|
|
688
|
+
/**
|
|
689
|
+
* Get the dependencies from a given dependency group in `package.json`.
|
|
690
|
+
*
|
|
691
|
+
* @category Miscellaneous
|
|
692
|
+
*
|
|
693
|
+
* @param packageInfo - The data coming from `package.json`.
|
|
694
|
+
* @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
|
|
695
|
+
*
|
|
696
|
+
* @returns A record consisting of the package names and version ranges from the given dependency group.
|
|
697
|
+
*/
|
|
698
|
+
function getDependenciesFromGroup(packageInfo, dependencyGroup) {
|
|
699
|
+
return {
|
|
700
|
+
dependencies: parseZodSchema(z.record(z.string(), z.string()), packageInfo.dependencies ?? {}),
|
|
701
|
+
devDependencies: parseZodSchema(z.record(z.string(), z.string()), packageInfo.devDependencies ?? {})
|
|
702
|
+
}[dependencyGroup];
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
//#endregion
|
|
706
|
+
//#region src/root/functions/miscellaneous/isOrdered.ts
|
|
673
707
|
/**
|
|
674
708
|
* Checks to see if the given array is sorted in ascending order.
|
|
675
709
|
*
|
|
@@ -687,7 +721,7 @@ function isOrdered(array) {
|
|
|
687
721
|
}
|
|
688
722
|
|
|
689
723
|
//#endregion
|
|
690
|
-
//#region src/functions/recursive/deepFreeze.ts
|
|
724
|
+
//#region src/root/functions/recursive/deepFreeze.ts
|
|
691
725
|
/**
|
|
692
726
|
* Deeply freezes an object or array such that all child objects/arrays are also frozen.
|
|
693
727
|
*
|
|
@@ -711,7 +745,7 @@ function deepFreeze(object) {
|
|
|
711
745
|
}
|
|
712
746
|
|
|
713
747
|
//#endregion
|
|
714
|
-
//#region src/functions/taggedTemplate/createTemplateStringsArray.ts
|
|
748
|
+
//#region src/root/functions/taggedTemplate/createTemplateStringsArray.ts
|
|
715
749
|
/**
|
|
716
750
|
* Creates a template strings array given a regular array of strings
|
|
717
751
|
*
|
|
@@ -726,31 +760,7 @@ function createTemplateStringsArray(strings) {
|
|
|
726
760
|
}
|
|
727
761
|
|
|
728
762
|
//#endregion
|
|
729
|
-
//#region src/functions/taggedTemplate/
|
|
730
|
-
/**
|
|
731
|
-
*
|
|
732
|
-
* Gets the strings and interpolations separately from a template string.
|
|
733
|
-
* You can pass a template string directly by doing:
|
|
734
|
-
*
|
|
735
|
-
* ```typescript
|
|
736
|
-
* getInterpolations`Template string here`.
|
|
737
|
-
* ```
|
|
738
|
-
*
|
|
739
|
-
* @category Tagged Template
|
|
740
|
-
*
|
|
741
|
-
* @deprecated Please use `getStringsAndInterpolations` instead.
|
|
742
|
-
*
|
|
743
|
-
* @param strings - The strings from the template to process.
|
|
744
|
-
* @param interpolations - An array of all interpolations from the template.
|
|
745
|
-
*
|
|
746
|
-
* @returns A tuple where the first item is the strings from the template, and the second is the interpolations.
|
|
747
|
-
*/
|
|
748
|
-
function getInterpolations(strings, ...interpolations) {
|
|
749
|
-
return [strings, interpolations];
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
//#endregion
|
|
753
|
-
//#region src/functions/taggedTemplate/getStringsAndInterpolations.ts
|
|
763
|
+
//#region src/root/functions/taggedTemplate/getStringsAndInterpolations.ts
|
|
754
764
|
/**
|
|
755
765
|
*
|
|
756
766
|
* Gets the strings and interpolations separately from a template string.
|
|
@@ -791,7 +801,7 @@ function getStringsAndInterpolations(strings, ...interpolations) {
|
|
|
791
801
|
}
|
|
792
802
|
|
|
793
803
|
//#endregion
|
|
794
|
-
//#region src/functions/taggedTemplate/interpolate.ts
|
|
804
|
+
//#region src/root/functions/taggedTemplate/interpolate.ts
|
|
795
805
|
/**
|
|
796
806
|
* Returns the result of interpolating a template string when given the strings and interpolations separately.
|
|
797
807
|
*
|
|
@@ -819,7 +829,7 @@ function interpolate(strings, ...interpolations) {
|
|
|
819
829
|
}
|
|
820
830
|
|
|
821
831
|
//#endregion
|
|
822
|
-
//#region src/functions/taggedTemplate/interpolateObjects.ts
|
|
832
|
+
//#region src/root/functions/taggedTemplate/interpolateObjects.ts
|
|
823
833
|
/**
|
|
824
834
|
* Returns the result of interpolating a template string, also stringifying objects.
|
|
825
835
|
*
|
|
@@ -848,7 +858,7 @@ function interpolateObjects(strings, ...interpolations) {
|
|
|
848
858
|
}
|
|
849
859
|
|
|
850
860
|
//#endregion
|
|
851
|
-
//#region src/functions/taggedTemplate/isTemplateStringsArray.ts
|
|
861
|
+
//#region src/root/functions/taggedTemplate/isTemplateStringsArray.ts
|
|
852
862
|
/**
|
|
853
863
|
* Determines whether or not the input is a valid `TemplateStringsArray`.
|
|
854
864
|
*
|
|
@@ -863,7 +873,7 @@ function isTemplateStringsArray(input) {
|
|
|
863
873
|
}
|
|
864
874
|
|
|
865
875
|
//#endregion
|
|
866
|
-
//#region src/functions/taggedTemplate/normaliseIndents.ts
|
|
876
|
+
//#region src/root/functions/taggedTemplate/normaliseIndents.ts
|
|
867
877
|
function calculateTabSize(line, whitespaceLength) {
|
|
868
878
|
const potentialWhitespacePart = line.slice(0, whitespaceLength);
|
|
869
879
|
const trimmedString = line.trimStart();
|
|
@@ -952,7 +962,7 @@ function normaliseIndents(first, ...args) {
|
|
|
952
962
|
const normalizeIndents = normaliseIndents;
|
|
953
963
|
|
|
954
964
|
//#endregion
|
|
955
|
-
//#region src/functions/miscellaneous/sayHello.ts
|
|
965
|
+
//#region src/root/functions/miscellaneous/sayHello.ts
|
|
956
966
|
/**
|
|
957
967
|
* Returns a string representing the lyrics to the package's theme song, Commit To You
|
|
958
968
|
*
|
|
@@ -1066,7 +1076,7 @@ function sayHello() {
|
|
|
1066
1076
|
}
|
|
1067
1077
|
|
|
1068
1078
|
//#endregion
|
|
1069
|
-
//#region src/functions/miscellaneous/stringifyDotenv.ts
|
|
1079
|
+
//#region src/root/functions/miscellaneous/stringifyDotenv.ts
|
|
1070
1080
|
/**
|
|
1071
1081
|
* Converts an object into a string in .env file format.
|
|
1072
1082
|
*
|
|
@@ -1102,7 +1112,7 @@ function stringifyDotenv(contents, options) {
|
|
|
1102
1112
|
}
|
|
1103
1113
|
|
|
1104
1114
|
//#endregion
|
|
1105
|
-
//#region src/functions/miscellaneous/stringListToArray.ts
|
|
1115
|
+
//#region src/root/functions/miscellaneous/stringListToArray.ts
|
|
1106
1116
|
/**
|
|
1107
1117
|
* Converts a stringly-typed list to a proper array.
|
|
1108
1118
|
*
|
|
@@ -1124,7 +1134,7 @@ function stringListToArray(stringList, { separator = ",", trimWhitespace = true
|
|
|
1124
1134
|
}
|
|
1125
1135
|
|
|
1126
1136
|
//#endregion
|
|
1127
|
-
//#region src/functions/miscellaneous/wait.ts
|
|
1137
|
+
//#region src/root/functions/miscellaneous/wait.ts
|
|
1128
1138
|
/**
|
|
1129
1139
|
* Waits for the given number of seconds
|
|
1130
1140
|
*
|
|
@@ -1143,7 +1153,7 @@ function wait(seconds) {
|
|
|
1143
1153
|
}
|
|
1144
1154
|
|
|
1145
1155
|
//#endregion
|
|
1146
|
-
//#region src/functions/objectHelpers/getRecordKeys.ts
|
|
1156
|
+
//#region src/root/functions/objectHelpers/getRecordKeys.ts
|
|
1147
1157
|
/**
|
|
1148
1158
|
* Gets the keys from a given record object, properly typed to be an array of the key of the input object's type.
|
|
1149
1159
|
*
|
|
@@ -1160,7 +1170,7 @@ function getRecordKeys(record) {
|
|
|
1160
1170
|
}
|
|
1161
1171
|
|
|
1162
1172
|
//#endregion
|
|
1163
|
-
//#region src/functions/objectHelpers/omitProperties.ts
|
|
1173
|
+
//#region src/root/functions/objectHelpers/omitProperties.ts
|
|
1164
1174
|
/**
|
|
1165
1175
|
* Omits properties from a given object.
|
|
1166
1176
|
*
|
|
@@ -1183,7 +1193,7 @@ function omitProperties(object, keysToOmit) {
|
|
|
1183
1193
|
}
|
|
1184
1194
|
|
|
1185
1195
|
//#endregion
|
|
1186
|
-
//#region src/functions/objectHelpers/removeUndefinedFromObject.ts
|
|
1196
|
+
//#region src/root/functions/objectHelpers/removeUndefinedFromObject.ts
|
|
1187
1197
|
/**
|
|
1188
1198
|
* Removes entries whose values are `undefined` from a given object (not including null etc.).
|
|
1189
1199
|
*
|
|
@@ -1198,7 +1208,7 @@ function removeUndefinedFromObject(object) {
|
|
|
1198
1208
|
}
|
|
1199
1209
|
|
|
1200
1210
|
//#endregion
|
|
1201
|
-
//#region src/functions/parsers/parseBoolean.ts
|
|
1211
|
+
//#region src/root/functions/parsers/parseBoolean.ts
|
|
1202
1212
|
/**
|
|
1203
1213
|
* Takes a stringly-typed boolean and converts it to an actual boolean type.
|
|
1204
1214
|
*
|
|
@@ -1212,13 +1222,13 @@ function removeUndefinedFromObject(object) {
|
|
|
1212
1222
|
*/
|
|
1213
1223
|
function parseBoolean(inputString) {
|
|
1214
1224
|
const normalisedString = inputString.toLowerCase();
|
|
1215
|
-
if (!["true", "false"].includes(normalisedString)) throw new DataError(inputString, "INVALID_BOOLEAN_STRING", "The provided boolean string must be one of `true | false`");
|
|
1225
|
+
if (!["true", "false"].includes(normalisedString)) throw new DataError({ inputString }, "INVALID_BOOLEAN_STRING", "The provided boolean string must be one of `true | false`");
|
|
1216
1226
|
return normalisedString === "true";
|
|
1217
1227
|
}
|
|
1218
1228
|
|
|
1219
1229
|
//#endregion
|
|
1220
|
-
//#region src/functions/parsers/zod/_parseZodSchema.ts
|
|
1221
|
-
function _parseZodSchema(parsedResult,
|
|
1230
|
+
//#region src/root/functions/parsers/zod/_parseZodSchema.ts
|
|
1231
|
+
function _parseZodSchema(parsedResult, input, onError) {
|
|
1222
1232
|
if (!parsedResult.success) {
|
|
1223
1233
|
if (onError) {
|
|
1224
1234
|
if (onError instanceof Error) throw onError;
|
|
@@ -1232,7 +1242,7 @@ function _parseZodSchema(parsedResult, data, onError) {
|
|
|
1232
1242
|
const code = issue.code.toUpperCase();
|
|
1233
1243
|
allErrorCodes[code] = (allErrorCodes[code] ?? 0) + 1;
|
|
1234
1244
|
}
|
|
1235
|
-
throw new DataError(
|
|
1245
|
+
throw new DataError({ input }, Object.entries(allErrorCodes).toSorted(([_, firstCount], [__, secondCount]) => {
|
|
1236
1246
|
return secondCount - firstCount;
|
|
1237
1247
|
}).map(([code, count], _, allErrorCodes) => {
|
|
1238
1248
|
return allErrorCodes.length === 1 && count === 1 ? code : `${code}×${count}`;
|
|
@@ -1242,7 +1252,7 @@ function _parseZodSchema(parsedResult, data, onError) {
|
|
|
1242
1252
|
}
|
|
1243
1253
|
|
|
1244
1254
|
//#endregion
|
|
1245
|
-
//#region src/functions/parsers/zod/parseZodSchema.ts
|
|
1255
|
+
//#region src/root/functions/parsers/zod/parseZodSchema.ts
|
|
1246
1256
|
/**
|
|
1247
1257
|
* An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
|
|
1248
1258
|
*
|
|
@@ -1254,19 +1264,19 @@ function _parseZodSchema(parsedResult, data, onError) {
|
|
|
1254
1264
|
* @template ErrorType - The type of error to throw on invalid data.
|
|
1255
1265
|
*
|
|
1256
1266
|
* @param schema - The Zod schema to use in parsing.
|
|
1257
|
-
* @param
|
|
1267
|
+
* @param input - The data to parse.
|
|
1258
1268
|
* @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
|
|
1259
1269
|
*
|
|
1260
1270
|
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
1261
1271
|
*
|
|
1262
1272
|
* @returns The parsed data from the Zod schema.
|
|
1263
1273
|
*/
|
|
1264
|
-
function parseZodSchema(schema,
|
|
1265
|
-
return _parseZodSchema(schema.safeParse(
|
|
1274
|
+
function parseZodSchema(schema, input, onError) {
|
|
1275
|
+
return _parseZodSchema(schema.safeParse(input), input, onError);
|
|
1266
1276
|
}
|
|
1267
1277
|
|
|
1268
1278
|
//#endregion
|
|
1269
|
-
//#region src/functions/parsers/parseEnv.ts
|
|
1279
|
+
//#region src/root/functions/parsers/parseEnv.ts
|
|
1270
1280
|
/**
|
|
1271
1281
|
* Represents the three common development environments.
|
|
1272
1282
|
*
|
|
@@ -1282,18 +1292,18 @@ const Env = {
|
|
|
1282
1292
|
*
|
|
1283
1293
|
* @category Parsers
|
|
1284
1294
|
*
|
|
1285
|
-
* @param
|
|
1295
|
+
* @param input - The data to parse.
|
|
1286
1296
|
*
|
|
1287
1297
|
* @throws {DataError} If the data does not match one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
1288
1298
|
*
|
|
1289
1299
|
* @returns The specified environment if allowed.
|
|
1290
1300
|
*/
|
|
1291
|
-
function parseEnv(
|
|
1292
|
-
return parseZodSchema(z$1.enum(Env),
|
|
1301
|
+
function parseEnv(input) {
|
|
1302
|
+
return parseZodSchema(z$1.enum(Env), input, new DataError({ input }, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
|
|
1293
1303
|
}
|
|
1294
1304
|
|
|
1295
1305
|
//#endregion
|
|
1296
|
-
//#region src/functions/parsers/parseFilePath.ts
|
|
1306
|
+
//#region src/root/functions/parsers/parseFilePath.ts
|
|
1297
1307
|
/**
|
|
1298
1308
|
* Takes a file path string and parses it into the directory part, the base part, and the full path.
|
|
1299
1309
|
*
|
|
@@ -1324,7 +1334,7 @@ function parseFilePath(filePath) {
|
|
|
1324
1334
|
}
|
|
1325
1335
|
|
|
1326
1336
|
//#endregion
|
|
1327
|
-
//#region src/functions/parsers/parseFormData.ts
|
|
1337
|
+
//#region src/root/functions/parsers/parseFormData.ts
|
|
1328
1338
|
/**
|
|
1329
1339
|
* Returns an object given FormData and an optional data parser function to call on the resulting object.
|
|
1330
1340
|
*
|
|
@@ -1347,7 +1357,7 @@ function parseFormData(formData, dataParser) {
|
|
|
1347
1357
|
}
|
|
1348
1358
|
|
|
1349
1359
|
//#endregion
|
|
1350
|
-
//#region src/functions/parsers/parseVersionType.ts
|
|
1360
|
+
//#region src/root/functions/parsers/parseVersionType.ts
|
|
1351
1361
|
/**
|
|
1352
1362
|
* Represents the three common software version types.
|
|
1353
1363
|
*
|
|
@@ -1363,18 +1373,18 @@ const VersionType = {
|
|
|
1363
1373
|
*
|
|
1364
1374
|
* @category Parsers
|
|
1365
1375
|
*
|
|
1366
|
-
* @param
|
|
1376
|
+
* @param input - The data to parse.
|
|
1367
1377
|
*
|
|
1368
1378
|
* @throws {DataError} If the data does not match one of the allowed version types (`"major" | "minor" | "patch"`).
|
|
1369
1379
|
*
|
|
1370
1380
|
* @returns The given version type if allowed.
|
|
1371
1381
|
*/
|
|
1372
|
-
function parseVersionType(
|
|
1373
|
-
return parseZodSchema(z.enum(VersionType),
|
|
1382
|
+
function parseVersionType(input) {
|
|
1383
|
+
return parseZodSchema(z.enum(VersionType), input, new DataError({ input }, "INVALID_VERSION_TYPE", "The provided version type must be one of `major | minor | patch`"));
|
|
1374
1384
|
}
|
|
1375
1385
|
|
|
1376
1386
|
//#endregion
|
|
1377
|
-
//#region src/functions/parsers/zod/parseZodSchemaAsync.ts
|
|
1387
|
+
//#region src/root/functions/parsers/zod/parseZodSchemaAsync.ts
|
|
1378
1388
|
/**
|
|
1379
1389
|
* An alternative function to zodSchema.parseAsync() that can be used to strictly parse asynchronous Zod schemas.
|
|
1380
1390
|
*
|
|
@@ -1384,19 +1394,19 @@ function parseVersionType(data) {
|
|
|
1384
1394
|
* @template ErrorType - The type of error to throw on invalid data.
|
|
1385
1395
|
*
|
|
1386
1396
|
* @param schema - The Zod schema to use in parsing.
|
|
1387
|
-
* @param
|
|
1397
|
+
* @param input - The data to parse.
|
|
1388
1398
|
* @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
|
|
1389
1399
|
*
|
|
1390
1400
|
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
1391
1401
|
*
|
|
1392
1402
|
* @returns The parsed data from the Zod schema.
|
|
1393
1403
|
*/
|
|
1394
|
-
async function parseZodSchemaAsync(schema,
|
|
1395
|
-
return _parseZodSchema(await schema.safeParseAsync(
|
|
1404
|
+
async function parseZodSchemaAsync(schema, input, onError) {
|
|
1405
|
+
return _parseZodSchema(await schema.safeParseAsync(input), input, onError);
|
|
1396
1406
|
}
|
|
1397
1407
|
|
|
1398
1408
|
//#endregion
|
|
1399
|
-
//#region src/functions/recursive/deepCopy.ts
|
|
1409
|
+
//#region src/root/functions/recursive/deepCopy.ts
|
|
1400
1410
|
function callDeepCopy(input) {
|
|
1401
1411
|
return typeof input === "object" && input !== null ? deepCopy(input) : input;
|
|
1402
1412
|
}
|
|
@@ -1424,7 +1434,7 @@ function deepCopy(object) {
|
|
|
1424
1434
|
}
|
|
1425
1435
|
|
|
1426
1436
|
//#endregion
|
|
1427
|
-
//#region src/functions/security/encryptWithKey.ts
|
|
1437
|
+
//#region src/root/functions/security/encryptWithKey.ts
|
|
1428
1438
|
/**
|
|
1429
1439
|
* Encrypt a secret given the public base64 key and the thing you want to encrypt.
|
|
1430
1440
|
*
|
|
@@ -1445,32 +1455,7 @@ async function encryptWithKey(publicKey, plaintextValue) {
|
|
|
1445
1455
|
}
|
|
1446
1456
|
|
|
1447
1457
|
//#endregion
|
|
1448
|
-
//#region src/functions/
|
|
1449
|
-
/**
|
|
1450
|
-
* Returns the public key and private key, properly narrowing down types depending on the provided `outputFormat`.
|
|
1451
|
-
*
|
|
1452
|
-
* @deprecated Please use `sodium.crypto_box_keypair` from `libsodium-wrappers` instead.
|
|
1453
|
-
*
|
|
1454
|
-
* This function was initially created to deal with a typing issue with the package introduced in v0.8.1 of said package, but this seems to have been fixed in v0.8.2
|
|
1455
|
-
*
|
|
1456
|
-
* @param outputFormat - The format of the resulting publicKey and privateKey you would like to use.
|
|
1457
|
-
*
|
|
1458
|
-
* @returns An object containing both the publicKey and privateKey, along with a keyType.
|
|
1459
|
-
*/
|
|
1460
|
-
function getPublicAndPrivateKey(outputFormat) {
|
|
1461
|
-
const keys = sodium.crypto_box_keypair(outputFormat);
|
|
1462
|
-
if (outputFormat === "uint8array" || outputFormat === void 0) {
|
|
1463
|
-
if (!(keys?.publicKey instanceof Uint8Array && keys?.privateKey instanceof Uint8Array)) throw new DataError({
|
|
1464
|
-
publicKey: `<redacted: ${keys?.publicKey?.constructor?.name ?? typeof keys?.publicKey}>`,
|
|
1465
|
-
privateKey: `<redacted: ${keys?.privateKey?.constructor?.name ?? typeof keys?.privateKey}>`
|
|
1466
|
-
}, "INVALID_KEY_TYPES", "Expected Uint8Array keypair from libsodium.");
|
|
1467
|
-
return keys;
|
|
1468
|
-
}
|
|
1469
|
-
return keys;
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
//#endregion
|
|
1473
|
-
//#region src/functions/stringHelpers/appendSemicolon.ts
|
|
1458
|
+
//#region src/root/functions/stringHelpers/appendSemicolon.ts
|
|
1474
1459
|
/**
|
|
1475
1460
|
* Appends a semicolon to the end of a string, trimming where necessary first.
|
|
1476
1461
|
*
|
|
@@ -1490,7 +1475,7 @@ function appendSemicolon(stringToAppendTo) {
|
|
|
1490
1475
|
}
|
|
1491
1476
|
|
|
1492
1477
|
//#endregion
|
|
1493
|
-
//#region src/functions/stringHelpers/camelToKebab.ts
|
|
1478
|
+
//#region src/root/functions/stringHelpers/camelToKebab.ts
|
|
1494
1479
|
/**
|
|
1495
1480
|
* Converts a string from camelCase to kebab-case
|
|
1496
1481
|
*
|
|
@@ -1529,7 +1514,7 @@ function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
|
|
|
1529
1514
|
}
|
|
1530
1515
|
|
|
1531
1516
|
//#endregion
|
|
1532
|
-
//#region src/functions/stringHelpers/kebabToCamel.ts
|
|
1517
|
+
//#region src/root/functions/stringHelpers/kebabToCamel.ts
|
|
1533
1518
|
/**
|
|
1534
1519
|
* Converts a string from kebab-case to camelCase
|
|
1535
1520
|
*
|
|
@@ -1568,44 +1553,7 @@ function kebabToCamel(string, options) {
|
|
|
1568
1553
|
}
|
|
1569
1554
|
|
|
1570
1555
|
//#endregion
|
|
1571
|
-
//#region src/functions/stringHelpers/
|
|
1572
|
-
/**
|
|
1573
|
-
* Normalizes an import path meant for use in an import statement in JavaScript.
|
|
1574
|
-
* When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. If the path is a zero-length string, '.' is returned, representing the current working directory.
|
|
1575
|
-
*
|
|
1576
|
-
* If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
|
|
1577
|
-
*
|
|
1578
|
-
* Helpful for custom linter rules that need to check (or fix) import paths.
|
|
1579
|
-
*
|
|
1580
|
-
* @category String Helpers
|
|
1581
|
-
*
|
|
1582
|
-
* @param importPath - The import path to normalize.
|
|
1583
|
-
*
|
|
1584
|
-
* @returns The import path normalized.
|
|
1585
|
-
*/
|
|
1586
|
-
function normalizeImportPath(importPath) {
|
|
1587
|
-
const normalizedPath = path.posix.normalize(importPath);
|
|
1588
|
-
if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) return `./${normalizedPath}`;
|
|
1589
|
-
return normalizedPath;
|
|
1590
|
-
}
|
|
1591
|
-
/**
|
|
1592
|
-
* Normalises an import path meant for use in an import statement in JavaScript.
|
|
1593
|
-
* When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. If the path is a zero-length string, '.' is returned, representing the current working directory.
|
|
1594
|
-
*
|
|
1595
|
-
* If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
|
|
1596
|
-
*
|
|
1597
|
-
* Helpful for custom linter rules that need to check (or fix) import paths.
|
|
1598
|
-
*
|
|
1599
|
-
* @category String Helpers
|
|
1600
|
-
*
|
|
1601
|
-
* @param importPath - The import path to normalise.
|
|
1602
|
-
*
|
|
1603
|
-
* @returns The import path normalised.
|
|
1604
|
-
*/
|
|
1605
|
-
const normaliseImportPath = normalizeImportPath;
|
|
1606
|
-
|
|
1607
|
-
//#endregion
|
|
1608
|
-
//#region src/functions/stringHelpers/truncate.ts
|
|
1556
|
+
//#region src/root/functions/stringHelpers/truncate.ts
|
|
1609
1557
|
/**
|
|
1610
1558
|
* Truncates a string and appends `...` to the end of it
|
|
1611
1559
|
*
|
|
@@ -1621,92 +1569,4 @@ function truncate(stringToTruncate, maxLength = 5) {
|
|
|
1621
1569
|
}
|
|
1622
1570
|
|
|
1623
1571
|
//#endregion
|
|
1624
|
-
|
|
1625
|
-
/**
|
|
1626
|
-
* Parses a string and verifies it is a valid package version number.
|
|
1627
|
-
*
|
|
1628
|
-
* Valid formats: `X.Y.Z` or `vX.Y.Z`, where X, Y, and Z are non-negative integers.
|
|
1629
|
-
*
|
|
1630
|
-
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(input)` instead.
|
|
1631
|
-
*
|
|
1632
|
-
* @param input - The version string to parse.
|
|
1633
|
-
* @param options - Extra options to apply.
|
|
1634
|
-
*
|
|
1635
|
-
* @throws {DataError} If the input is not a valid version number.
|
|
1636
|
-
*
|
|
1637
|
-
* @returns The validated version number, prefixed with `v` if it was not already.
|
|
1638
|
-
*/
|
|
1639
|
-
function parseVersion(input, options) {
|
|
1640
|
-
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.`);
|
|
1641
|
-
if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
|
|
1642
|
-
return input.startsWith("v") ? input : `v${input}`;
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
//#endregion
|
|
1646
|
-
//#region src/functions/versioning/getIndividualVersionNumbers.ts
|
|
1647
|
-
/**
|
|
1648
|
-
* Gets the individual version numbers from a given version number as a tuple of numbers.
|
|
1649
|
-
*
|
|
1650
|
-
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use one of the following instead:
|
|
1651
|
-
* ```typescript
|
|
1652
|
-
* new VersionNumber(version).major
|
|
1653
|
-
* new VersionNumber(version).minor
|
|
1654
|
-
* new VersionNumber(version).patch
|
|
1655
|
-
* ```
|
|
1656
|
-
*
|
|
1657
|
-
* @param version - The version number.
|
|
1658
|
-
*
|
|
1659
|
-
* @returns A tuple of three numbers indicating `[major, minor, patch]`.
|
|
1660
|
-
*/
|
|
1661
|
-
function getIndividualVersionNumbers(version) {
|
|
1662
|
-
return parseVersion(version, { omitPrefix: true }).split(".").map((versionNumber) => {
|
|
1663
|
-
return parseIntStrict(versionNumber);
|
|
1664
|
-
});
|
|
1665
|
-
}
|
|
1666
|
-
|
|
1667
|
-
//#endregion
|
|
1668
|
-
//#region src/functions/versioning/determineVersionType.ts
|
|
1669
|
-
/**
|
|
1670
|
-
* Determines whether the given version is a major, minor, or patch version.
|
|
1671
|
-
*
|
|
1672
|
-
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).type` instead.
|
|
1673
|
-
*
|
|
1674
|
-
* @param version - The version number.
|
|
1675
|
-
*
|
|
1676
|
-
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
1677
|
-
*/
|
|
1678
|
-
function determineVersionType(version) {
|
|
1679
|
-
const [_major, minor, patch] = getIndividualVersionNumbers(version);
|
|
1680
|
-
if (minor === 0 && patch === 0) return "major";
|
|
1681
|
-
if (patch === 0) return "minor";
|
|
1682
|
-
return "patch";
|
|
1683
|
-
}
|
|
1684
|
-
|
|
1685
|
-
//#endregion
|
|
1686
|
-
//#region src/functions/versioning/incrementVersion.ts
|
|
1687
|
-
/**
|
|
1688
|
-
* Increments the given input version depending on the given increment type.
|
|
1689
|
-
*
|
|
1690
|
-
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).increment(incrementType)` instead.
|
|
1691
|
-
*
|
|
1692
|
-
* @param version - The version to increment
|
|
1693
|
-
* @param incrementType - The type of increment. Can be one of the following:
|
|
1694
|
-
* - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
|
|
1695
|
-
* - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
|
|
1696
|
-
* - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
|
|
1697
|
-
* @param options - Extra options to apply.
|
|
1698
|
-
*
|
|
1699
|
-
* @returns A new string representing the version with the increment applied.
|
|
1700
|
-
*/
|
|
1701
|
-
function incrementVersion(version, incrementType, options) {
|
|
1702
|
-
const [major, minor, patch] = getIndividualVersionNumbers(version);
|
|
1703
|
-
const newVersion = {
|
|
1704
|
-
major: `${major + 1}.0.0`,
|
|
1705
|
-
minor: `${major}.${minor + 1}.0`,
|
|
1706
|
-
patch: `${major}.${minor}.${patch + 1}`
|
|
1707
|
-
}[incrementType];
|
|
1708
|
-
return parseVersion(newVersion, { omitPrefix: options?.omitPrefix });
|
|
1709
|
-
}
|
|
1710
|
-
|
|
1711
|
-
//#endregion
|
|
1712
|
-
export { APIError, DataError, Env, FILE_PATH_REGEX, NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getPublicAndPrivateKey, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFilePath, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
|
|
1572
|
+
export { APIError, DataError, Env, FILE_PATH_REGEX, NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, encryptWithKey, fillArray, formatDateAndTime, getDependenciesFromGroup, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFilePath, parseFormData, parseIntStrict, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
|