@alextheman/utility 4.16.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +134 -269
- package/dist/index.d.cts +124 -259
- package/dist/index.d.ts +124 -259
- package/dist/index.js +134 -262
- 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.cjs
CHANGED
|
@@ -33,19 +33,19 @@ node_path = __toESM(node_path);
|
|
|
33
33
|
let libsodium_wrappers = require("libsodium-wrappers");
|
|
34
34
|
libsodium_wrappers = __toESM(libsodium_wrappers);
|
|
35
35
|
|
|
36
|
-
//#region src/constants/FILE_PATH_REGEX.ts
|
|
36
|
+
//#region src/root/constants/FILE_PATH_REGEX.ts
|
|
37
37
|
const FILE_PATH_REGEX = String.raw`^(?<directory>.+)[\/\\](?<base>[^\/\\]+)$`;
|
|
38
38
|
|
|
39
39
|
//#endregion
|
|
40
|
-
//#region src/constants/NAMESPACE_EXPORT_REGEX.ts
|
|
40
|
+
//#region src/root/constants/NAMESPACE_EXPORT_REGEX.ts
|
|
41
41
|
const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
42
42
|
|
|
43
43
|
//#endregion
|
|
44
|
-
//#region src/constants/VERSION_NUMBER_REGEX.ts
|
|
44
|
+
//#region src/root/constants/VERSION_NUMBER_REGEX.ts
|
|
45
45
|
const VERSION_NUMBER_REGEX = "^(?:v)?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$";
|
|
46
46
|
|
|
47
47
|
//#endregion
|
|
48
|
-
//#region src/functions/arrayHelpers/fillArray.ts
|
|
48
|
+
//#region src/root/functions/arrayHelpers/fillArray.ts
|
|
49
49
|
/**
|
|
50
50
|
* Creates a new array where each element is the result of the provided callback.
|
|
51
51
|
*
|
|
@@ -72,7 +72,7 @@ function fillArray(callback, length = 1) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
//#endregion
|
|
75
|
-
//#region src/functions/arrayHelpers/paralleliseArrays.ts
|
|
75
|
+
//#region src/root/functions/arrayHelpers/paralleliseArrays.ts
|
|
76
76
|
/**
|
|
77
77
|
* Creates a new array of tuples, each containing the item at the given index from both arrays.
|
|
78
78
|
*
|
|
@@ -96,7 +96,7 @@ function paralleliseArrays(firstArray, secondArray) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
//#endregion
|
|
99
|
-
//#region src/types/APIError.ts
|
|
99
|
+
//#region src/root/types/APIError.ts
|
|
100
100
|
const httpErrorCodeLookup = {
|
|
101
101
|
400: "BAD_REQUEST",
|
|
102
102
|
401: "UNAUTHORISED",
|
|
@@ -140,11 +140,13 @@ var APIError = class APIError extends Error {
|
|
|
140
140
|
};
|
|
141
141
|
|
|
142
142
|
//#endregion
|
|
143
|
-
//#region src/types/DataError.ts
|
|
143
|
+
//#region src/root/types/DataError.ts
|
|
144
144
|
/**
|
|
145
145
|
* Represents errors you may get that may've been caused by a specific piece of data.
|
|
146
146
|
*
|
|
147
147
|
* @category Types
|
|
148
|
+
*
|
|
149
|
+
* @template DataType - The type of the data that caused the error.
|
|
148
150
|
*/
|
|
149
151
|
var DataError = class DataError extends Error {
|
|
150
152
|
code;
|
|
@@ -179,7 +181,7 @@ var DataError = class DataError extends Error {
|
|
|
179
181
|
};
|
|
180
182
|
|
|
181
183
|
//#endregion
|
|
182
|
-
//#region src/types/VersionNumber.ts
|
|
184
|
+
//#region src/root/types/VersionNumber.ts
|
|
183
185
|
/**
|
|
184
186
|
* Represents a software version number, considered to be made up of a major, minor, and patch part.
|
|
185
187
|
*
|
|
@@ -202,7 +204,7 @@ var VersionNumber = class VersionNumber {
|
|
|
202
204
|
this.minor = input.minor;
|
|
203
205
|
this.patch = input.patch;
|
|
204
206
|
} else if (typeof input === "string") {
|
|
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.`);
|
|
207
|
+
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.`);
|
|
206
208
|
const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
|
|
207
209
|
return parseIntStrict(number);
|
|
208
210
|
});
|
|
@@ -210,10 +212,10 @@ var VersionNumber = class VersionNumber {
|
|
|
210
212
|
this.minor = minor;
|
|
211
213
|
this.patch = patch;
|
|
212
214
|
} else if (Array.isArray(input)) {
|
|
213
|
-
if (input.length !== 3) throw new DataError(input, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
215
|
+
if (input.length !== 3) throw new DataError({ input }, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
214
216
|
const [major, minor, patch] = input.map((number) => {
|
|
215
217
|
const parsedInteger = parseIntStrict(number?.toString());
|
|
216
|
-
if (parsedInteger < 0) throw new DataError(input, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
218
|
+
if (parsedInteger < 0) throw new DataError({ input }, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
217
219
|
return parsedInteger;
|
|
218
220
|
});
|
|
219
221
|
this.major = major;
|
|
@@ -247,33 +249,60 @@ var VersionNumber = class VersionNumber {
|
|
|
247
249
|
return firstVersion.major === secondVersion.major && firstVersion.minor === secondVersion.minor && firstVersion.patch === secondVersion.patch;
|
|
248
250
|
}
|
|
249
251
|
/**
|
|
252
|
+
* Get a formatted string representation of the current version number
|
|
253
|
+
*
|
|
254
|
+
* @param options - Options to apply to the string formatting.
|
|
255
|
+
*
|
|
256
|
+
* @returns A formatted string representation of the current version number with the options applied.
|
|
257
|
+
*/
|
|
258
|
+
format(options) {
|
|
259
|
+
let baseOutput = `${this.major}`;
|
|
260
|
+
if (!options?.omitMinor) {
|
|
261
|
+
baseOutput += `.${this.minor}`;
|
|
262
|
+
if (!options?.omitPatch) baseOutput += `.${this.patch}`;
|
|
263
|
+
}
|
|
264
|
+
return VersionNumber.formatString(baseOutput, { omitPrefix: options?.omitPrefix });
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
250
267
|
* Increments the current version number by the given increment type, returning the result as a new reference in memory.
|
|
251
268
|
*
|
|
252
269
|
* @param incrementType - The type of increment. Can be one of the following:
|
|
253
270
|
* - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
|
|
254
271
|
* - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
|
|
255
272
|
* - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
|
|
273
|
+
* @param incrementAmount - The amount to increment by (defaults to 1).
|
|
256
274
|
*
|
|
257
275
|
* @returns A new instance of `VersionNumber` with the increment applied.
|
|
258
276
|
*/
|
|
259
|
-
increment(incrementType) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
277
|
+
increment(incrementType, incrementAmount = 1) {
|
|
278
|
+
const incrementBy = parseIntStrict(String(incrementAmount));
|
|
279
|
+
const calculatedRawVersion = {
|
|
280
|
+
major: [
|
|
281
|
+
this.major + incrementBy,
|
|
263
282
|
0,
|
|
264
283
|
0
|
|
265
|
-
]
|
|
266
|
-
minor:
|
|
284
|
+
],
|
|
285
|
+
minor: [
|
|
267
286
|
this.major,
|
|
268
|
-
this.minor +
|
|
287
|
+
this.minor + incrementBy,
|
|
269
288
|
0
|
|
270
|
-
]
|
|
271
|
-
patch:
|
|
289
|
+
],
|
|
290
|
+
patch: [
|
|
272
291
|
this.major,
|
|
273
292
|
this.minor,
|
|
274
|
-
this.patch +
|
|
275
|
-
]
|
|
293
|
+
this.patch + incrementBy
|
|
294
|
+
]
|
|
276
295
|
}[incrementType];
|
|
296
|
+
try {
|
|
297
|
+
return new VersionNumber(calculatedRawVersion);
|
|
298
|
+
} catch (error) {
|
|
299
|
+
if (DataError.check(error) && error.code === "NEGATIVE_INPUTS") throw new DataError({
|
|
300
|
+
currentVersion: this.toString(),
|
|
301
|
+
calculatedRawVersion: `v${calculatedRawVersion.join(".")}`,
|
|
302
|
+
incrementAmount
|
|
303
|
+
}, "NEGATIVE_VERSION", "Cannot apply this increment amount as it would lead to a negative version number.");
|
|
304
|
+
else throw error;
|
|
305
|
+
}
|
|
277
306
|
}
|
|
278
307
|
/**
|
|
279
308
|
* Ensures that the VersionNumber behaves correctly when attempted to be coerced to a string.
|
|
@@ -283,7 +312,7 @@ var VersionNumber = class VersionNumber {
|
|
|
283
312
|
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
284
313
|
*/
|
|
285
314
|
[Symbol.toPrimitive](hint) {
|
|
286
|
-
if (hint === "number") throw new DataError(this.toString(), "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
|
|
315
|
+
if (hint === "number") throw new DataError({ thisVersion: this.toString() }, "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
|
|
287
316
|
return this.toString();
|
|
288
317
|
}
|
|
289
318
|
/**
|
|
@@ -297,13 +326,11 @@ var VersionNumber = class VersionNumber {
|
|
|
297
326
|
/**
|
|
298
327
|
* Get a string representation of the current version number.
|
|
299
328
|
*
|
|
300
|
-
* @
|
|
301
|
-
*
|
|
302
|
-
* @returns A stringified representation of the current version number, leaving out the prefix if `omitPrefix` option was set to true.
|
|
329
|
+
* @returns A stringified representation of the current version number with the prefix.
|
|
303
330
|
*/
|
|
304
|
-
toString(
|
|
331
|
+
toString() {
|
|
305
332
|
const rawString = `${this.major}.${this.minor}.${this.patch}`;
|
|
306
|
-
return VersionNumber.formatString(rawString,
|
|
333
|
+
return VersionNumber.formatString(rawString, { omitPrefix: false });
|
|
307
334
|
}
|
|
308
335
|
};
|
|
309
336
|
const zodVersionNumber = zod.default.union([
|
|
@@ -319,7 +346,7 @@ const zodVersionNumber = zod.default.union([
|
|
|
319
346
|
});
|
|
320
347
|
|
|
321
348
|
//#endregion
|
|
322
|
-
//#region src/functions/parsers/parseIntStrict.ts
|
|
349
|
+
//#region src/root/functions/parsers/parseIntStrict.ts
|
|
323
350
|
/**
|
|
324
351
|
* Converts a string to an integer and throws an error if it cannot be converted.
|
|
325
352
|
*
|
|
@@ -338,7 +365,7 @@ function parseIntStrict(string, radix) {
|
|
|
338
365
|
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new DataError(radix ? {
|
|
339
366
|
string,
|
|
340
367
|
radix
|
|
341
|
-
} : string, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
|
|
368
|
+
} : { string }, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
|
|
342
369
|
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
343
370
|
return parseInt(character) >= radix;
|
|
344
371
|
})) throw new DataError({
|
|
@@ -346,12 +373,12 @@ function parseIntStrict(string, radix) {
|
|
|
346
373
|
radix
|
|
347
374
|
}, "INTEGER_PARSING_ERROR", "Value contains one or more digits outside of the range of the given radix.");
|
|
348
375
|
const parseIntResult = parseInt(trimmedString, radix);
|
|
349
|
-
if (isNaN(parseIntResult)) throw new DataError(string, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
|
|
376
|
+
if (isNaN(parseIntResult)) throw new DataError({ string }, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
|
|
350
377
|
return parseIntResult;
|
|
351
378
|
}
|
|
352
379
|
|
|
353
380
|
//#endregion
|
|
354
|
-
//#region src/functions/miscellaneous/getRandomNumber.ts
|
|
381
|
+
//#region src/root/functions/miscellaneous/getRandomNumber.ts
|
|
355
382
|
/**
|
|
356
383
|
* Gets a random number between the given bounds.
|
|
357
384
|
*
|
|
@@ -369,7 +396,7 @@ function getRandomNumber(lowerBound, upperBound) {
|
|
|
369
396
|
}
|
|
370
397
|
|
|
371
398
|
//#endregion
|
|
372
|
-
//#region src/functions/arrayHelpers/randomiseArray.ts
|
|
399
|
+
//#region src/root/functions/arrayHelpers/randomiseArray.ts
|
|
373
400
|
/**
|
|
374
401
|
* Randomises the order of a given array and returns the result in a new array without mutating the original.
|
|
375
402
|
*
|
|
@@ -392,7 +419,7 @@ function randomiseArray(array) {
|
|
|
392
419
|
}
|
|
393
420
|
|
|
394
421
|
//#endregion
|
|
395
|
-
//#region src/functions/arrayHelpers/range.ts
|
|
422
|
+
//#region src/root/functions/arrayHelpers/range.ts
|
|
396
423
|
/**
|
|
397
424
|
* Creates an array of numbers within a given range.
|
|
398
425
|
*
|
|
@@ -424,7 +451,7 @@ function range(start, stop, step = 1) {
|
|
|
424
451
|
}
|
|
425
452
|
|
|
426
453
|
//#endregion
|
|
427
|
-
//#region src/functions/arrayHelpers/removeDuplicates.ts
|
|
454
|
+
//#region src/root/functions/arrayHelpers/removeDuplicates.ts
|
|
428
455
|
/**
|
|
429
456
|
* Removes duplicate values from an array.
|
|
430
457
|
*
|
|
@@ -443,7 +470,7 @@ function removeDuplicates(array) {
|
|
|
443
470
|
}
|
|
444
471
|
|
|
445
472
|
//#endregion
|
|
446
|
-
//#region src/functions/date/addDaysToDate.ts
|
|
473
|
+
//#region src/root/functions/date/addDaysToDate.ts
|
|
447
474
|
/**
|
|
448
475
|
* Adds a given number of days to the provided date, returning the result as a new instance of Date.
|
|
449
476
|
*
|
|
@@ -461,7 +488,7 @@ function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement =
|
|
|
461
488
|
}
|
|
462
489
|
|
|
463
490
|
//#endregion
|
|
464
|
-
//#region src/functions/date/isSameDate.ts
|
|
491
|
+
//#region src/root/functions/date/isSameDate.ts
|
|
465
492
|
/**
|
|
466
493
|
* Checks if the provided dates happen on the exact same day, month, and year.
|
|
467
494
|
*
|
|
@@ -477,7 +504,7 @@ function isSameDate(firstDate, secondDate) {
|
|
|
477
504
|
}
|
|
478
505
|
|
|
479
506
|
//#endregion
|
|
480
|
-
//#region src/functions/date/formatDateAndTime.ts
|
|
507
|
+
//#region src/root/functions/date/formatDateAndTime.ts
|
|
481
508
|
/**
|
|
482
509
|
* Creates a human-readable string with information about the input date.
|
|
483
510
|
*
|
|
@@ -501,7 +528,7 @@ function formatDateAndTime(inputDate) {
|
|
|
501
528
|
}
|
|
502
529
|
|
|
503
530
|
//#endregion
|
|
504
|
-
//#region src/functions/date/isLeapYear.ts
|
|
531
|
+
//#region src/root/functions/date/isLeapYear.ts
|
|
505
532
|
/**
|
|
506
533
|
* Checks if the provided year is a leap year.
|
|
507
534
|
*
|
|
@@ -519,7 +546,7 @@ function isLeapYear(year) {
|
|
|
519
546
|
}
|
|
520
547
|
|
|
521
548
|
//#endregion
|
|
522
|
-
//#region src/functions/date/isAnniversary.ts
|
|
549
|
+
//#region src/root/functions/date/isAnniversary.ts
|
|
523
550
|
function checkLeapYear(firstDate, secondDate) {
|
|
524
551
|
if (isLeapYear(firstDate.getFullYear()) && firstDate.getMonth() === 1 && secondDate.getMonth() === 1) return firstDate.getDate() === 29 && secondDate.getDate() === 28;
|
|
525
552
|
return false;
|
|
@@ -540,7 +567,7 @@ function isAnniversary(firstDate, secondDate) {
|
|
|
540
567
|
}
|
|
541
568
|
|
|
542
569
|
//#endregion
|
|
543
|
-
//#region src/functions/date/isMonthlyMultiple.ts
|
|
570
|
+
//#region src/root/functions/date/isMonthlyMultiple.ts
|
|
544
571
|
function endOfMonthChecksButNotFebruary(firstDate, secondDate) {
|
|
545
572
|
if ([
|
|
546
573
|
3,
|
|
@@ -589,7 +616,7 @@ function isMonthlyMultiple(firstDate, secondDate) {
|
|
|
589
616
|
}
|
|
590
617
|
|
|
591
618
|
//#endregion
|
|
592
|
-
//#region src/functions/miscellaneous/convertFileToBase64.ts
|
|
619
|
+
//#region src/root/functions/miscellaneous/convertFileToBase64.ts
|
|
593
620
|
/**
|
|
594
621
|
* Asynchronously converts a file to a base 64 string
|
|
595
622
|
*
|
|
@@ -619,7 +646,7 @@ function convertFileToBase64(file) {
|
|
|
619
646
|
}
|
|
620
647
|
|
|
621
648
|
//#endregion
|
|
622
|
-
//#region src/functions/miscellaneous/createFormData.ts
|
|
649
|
+
//#region src/root/functions/miscellaneous/createFormData.ts
|
|
623
650
|
function getNullableResolutionStrategy(key, strategy) {
|
|
624
651
|
return (typeof strategy === "object" ? strategy[key] : strategy) ?? "empty";
|
|
625
652
|
}
|
|
@@ -688,7 +715,26 @@ function createFormData(data, options = {
|
|
|
688
715
|
}
|
|
689
716
|
|
|
690
717
|
//#endregion
|
|
691
|
-
//#region src/functions/miscellaneous/
|
|
718
|
+
//#region src/root/functions/miscellaneous/getDependenciesFromGroup.ts
|
|
719
|
+
/**
|
|
720
|
+
* Get the dependencies from a given dependency group in `package.json`.
|
|
721
|
+
*
|
|
722
|
+
* @category Miscellaneous
|
|
723
|
+
*
|
|
724
|
+
* @param packageInfo - The data coming from `package.json`.
|
|
725
|
+
* @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
|
|
726
|
+
*
|
|
727
|
+
* @returns A record consisting of the package names and version ranges from the given dependency group.
|
|
728
|
+
*/
|
|
729
|
+
function getDependenciesFromGroup(packageInfo, dependencyGroup) {
|
|
730
|
+
return {
|
|
731
|
+
dependencies: parseZodSchema(zod.default.record(zod.default.string(), zod.default.string()), packageInfo.dependencies ?? {}),
|
|
732
|
+
devDependencies: parseZodSchema(zod.default.record(zod.default.string(), zod.default.string()), packageInfo.devDependencies ?? {})
|
|
733
|
+
}[dependencyGroup];
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
//#endregion
|
|
737
|
+
//#region src/root/functions/miscellaneous/isOrdered.ts
|
|
692
738
|
/**
|
|
693
739
|
* Checks to see if the given array is sorted in ascending order.
|
|
694
740
|
*
|
|
@@ -706,7 +752,7 @@ function isOrdered(array) {
|
|
|
706
752
|
}
|
|
707
753
|
|
|
708
754
|
//#endregion
|
|
709
|
-
//#region src/functions/recursive/deepFreeze.ts
|
|
755
|
+
//#region src/root/functions/recursive/deepFreeze.ts
|
|
710
756
|
/**
|
|
711
757
|
* Deeply freezes an object or array such that all child objects/arrays are also frozen.
|
|
712
758
|
*
|
|
@@ -730,7 +776,7 @@ function deepFreeze(object) {
|
|
|
730
776
|
}
|
|
731
777
|
|
|
732
778
|
//#endregion
|
|
733
|
-
//#region src/functions/taggedTemplate/createTemplateStringsArray.ts
|
|
779
|
+
//#region src/root/functions/taggedTemplate/createTemplateStringsArray.ts
|
|
734
780
|
/**
|
|
735
781
|
* Creates a template strings array given a regular array of strings
|
|
736
782
|
*
|
|
@@ -745,31 +791,7 @@ function createTemplateStringsArray(strings) {
|
|
|
745
791
|
}
|
|
746
792
|
|
|
747
793
|
//#endregion
|
|
748
|
-
//#region src/functions/taggedTemplate/
|
|
749
|
-
/**
|
|
750
|
-
*
|
|
751
|
-
* Gets the strings and interpolations separately from a template string.
|
|
752
|
-
* You can pass a template string directly by doing:
|
|
753
|
-
*
|
|
754
|
-
* ```typescript
|
|
755
|
-
* getInterpolations`Template string here`.
|
|
756
|
-
* ```
|
|
757
|
-
*
|
|
758
|
-
* @category Tagged Template
|
|
759
|
-
*
|
|
760
|
-
* @deprecated Please use `getStringsAndInterpolations` instead.
|
|
761
|
-
*
|
|
762
|
-
* @param strings - The strings from the template to process.
|
|
763
|
-
* @param interpolations - An array of all interpolations from the template.
|
|
764
|
-
*
|
|
765
|
-
* @returns A tuple where the first item is the strings from the template, and the second is the interpolations.
|
|
766
|
-
*/
|
|
767
|
-
function getInterpolations(strings, ...interpolations) {
|
|
768
|
-
return [strings, interpolations];
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
//#endregion
|
|
772
|
-
//#region src/functions/taggedTemplate/getStringsAndInterpolations.ts
|
|
794
|
+
//#region src/root/functions/taggedTemplate/getStringsAndInterpolations.ts
|
|
773
795
|
/**
|
|
774
796
|
*
|
|
775
797
|
* Gets the strings and interpolations separately from a template string.
|
|
@@ -810,7 +832,7 @@ function getStringsAndInterpolations(strings, ...interpolations) {
|
|
|
810
832
|
}
|
|
811
833
|
|
|
812
834
|
//#endregion
|
|
813
|
-
//#region src/functions/taggedTemplate/interpolate.ts
|
|
835
|
+
//#region src/root/functions/taggedTemplate/interpolate.ts
|
|
814
836
|
/**
|
|
815
837
|
* Returns the result of interpolating a template string when given the strings and interpolations separately.
|
|
816
838
|
*
|
|
@@ -838,7 +860,7 @@ function interpolate(strings, ...interpolations) {
|
|
|
838
860
|
}
|
|
839
861
|
|
|
840
862
|
//#endregion
|
|
841
|
-
//#region src/functions/taggedTemplate/interpolateObjects.ts
|
|
863
|
+
//#region src/root/functions/taggedTemplate/interpolateObjects.ts
|
|
842
864
|
/**
|
|
843
865
|
* Returns the result of interpolating a template string, also stringifying objects.
|
|
844
866
|
*
|
|
@@ -867,7 +889,7 @@ function interpolateObjects(strings, ...interpolations) {
|
|
|
867
889
|
}
|
|
868
890
|
|
|
869
891
|
//#endregion
|
|
870
|
-
//#region src/functions/taggedTemplate/isTemplateStringsArray.ts
|
|
892
|
+
//#region src/root/functions/taggedTemplate/isTemplateStringsArray.ts
|
|
871
893
|
/**
|
|
872
894
|
* Determines whether or not the input is a valid `TemplateStringsArray`.
|
|
873
895
|
*
|
|
@@ -882,7 +904,7 @@ function isTemplateStringsArray(input) {
|
|
|
882
904
|
}
|
|
883
905
|
|
|
884
906
|
//#endregion
|
|
885
|
-
//#region src/functions/taggedTemplate/normaliseIndents.ts
|
|
907
|
+
//#region src/root/functions/taggedTemplate/normaliseIndents.ts
|
|
886
908
|
function calculateTabSize(line, whitespaceLength) {
|
|
887
909
|
const potentialWhitespacePart = line.slice(0, whitespaceLength);
|
|
888
910
|
const trimmedString = line.trimStart();
|
|
@@ -971,7 +993,7 @@ function normaliseIndents(first, ...args) {
|
|
|
971
993
|
const normalizeIndents = normaliseIndents;
|
|
972
994
|
|
|
973
995
|
//#endregion
|
|
974
|
-
//#region src/functions/miscellaneous/sayHello.ts
|
|
996
|
+
//#region src/root/functions/miscellaneous/sayHello.ts
|
|
975
997
|
/**
|
|
976
998
|
* Returns a string representing the lyrics to the package's theme song, Commit To You
|
|
977
999
|
*
|
|
@@ -1085,7 +1107,7 @@ function sayHello() {
|
|
|
1085
1107
|
}
|
|
1086
1108
|
|
|
1087
1109
|
//#endregion
|
|
1088
|
-
//#region src/functions/miscellaneous/stringifyDotenv.ts
|
|
1110
|
+
//#region src/root/functions/miscellaneous/stringifyDotenv.ts
|
|
1089
1111
|
/**
|
|
1090
1112
|
* Converts an object into a string in .env file format.
|
|
1091
1113
|
*
|
|
@@ -1121,7 +1143,7 @@ function stringifyDotenv(contents, options) {
|
|
|
1121
1143
|
}
|
|
1122
1144
|
|
|
1123
1145
|
//#endregion
|
|
1124
|
-
//#region src/functions/miscellaneous/stringListToArray.ts
|
|
1146
|
+
//#region src/root/functions/miscellaneous/stringListToArray.ts
|
|
1125
1147
|
/**
|
|
1126
1148
|
* Converts a stringly-typed list to a proper array.
|
|
1127
1149
|
*
|
|
@@ -1143,7 +1165,7 @@ function stringListToArray(stringList, { separator = ",", trimWhitespace = true
|
|
|
1143
1165
|
}
|
|
1144
1166
|
|
|
1145
1167
|
//#endregion
|
|
1146
|
-
//#region src/functions/miscellaneous/wait.ts
|
|
1168
|
+
//#region src/root/functions/miscellaneous/wait.ts
|
|
1147
1169
|
/**
|
|
1148
1170
|
* Waits for the given number of seconds
|
|
1149
1171
|
*
|
|
@@ -1162,7 +1184,7 @@ function wait(seconds) {
|
|
|
1162
1184
|
}
|
|
1163
1185
|
|
|
1164
1186
|
//#endregion
|
|
1165
|
-
//#region src/functions/objectHelpers/getRecordKeys.ts
|
|
1187
|
+
//#region src/root/functions/objectHelpers/getRecordKeys.ts
|
|
1166
1188
|
/**
|
|
1167
1189
|
* Gets the keys from a given record object, properly typed to be an array of the key of the input object's type.
|
|
1168
1190
|
*
|
|
@@ -1179,7 +1201,7 @@ function getRecordKeys(record) {
|
|
|
1179
1201
|
}
|
|
1180
1202
|
|
|
1181
1203
|
//#endregion
|
|
1182
|
-
//#region src/functions/objectHelpers/omitProperties.ts
|
|
1204
|
+
//#region src/root/functions/objectHelpers/omitProperties.ts
|
|
1183
1205
|
/**
|
|
1184
1206
|
* Omits properties from a given object.
|
|
1185
1207
|
*
|
|
@@ -1202,7 +1224,7 @@ function omitProperties(object, keysToOmit) {
|
|
|
1202
1224
|
}
|
|
1203
1225
|
|
|
1204
1226
|
//#endregion
|
|
1205
|
-
//#region src/functions/objectHelpers/removeUndefinedFromObject.ts
|
|
1227
|
+
//#region src/root/functions/objectHelpers/removeUndefinedFromObject.ts
|
|
1206
1228
|
/**
|
|
1207
1229
|
* Removes entries whose values are `undefined` from a given object (not including null etc.).
|
|
1208
1230
|
*
|
|
@@ -1217,7 +1239,7 @@ function removeUndefinedFromObject(object) {
|
|
|
1217
1239
|
}
|
|
1218
1240
|
|
|
1219
1241
|
//#endregion
|
|
1220
|
-
//#region src/functions/parsers/parseBoolean.ts
|
|
1242
|
+
//#region src/root/functions/parsers/parseBoolean.ts
|
|
1221
1243
|
/**
|
|
1222
1244
|
* Takes a stringly-typed boolean and converts it to an actual boolean type.
|
|
1223
1245
|
*
|
|
@@ -1231,13 +1253,13 @@ function removeUndefinedFromObject(object) {
|
|
|
1231
1253
|
*/
|
|
1232
1254
|
function parseBoolean(inputString) {
|
|
1233
1255
|
const normalisedString = inputString.toLowerCase();
|
|
1234
|
-
if (!["true", "false"].includes(normalisedString)) throw new DataError(inputString, "INVALID_BOOLEAN_STRING", "The provided boolean string must be one of `true | false`");
|
|
1256
|
+
if (!["true", "false"].includes(normalisedString)) throw new DataError({ inputString }, "INVALID_BOOLEAN_STRING", "The provided boolean string must be one of `true | false`");
|
|
1235
1257
|
return normalisedString === "true";
|
|
1236
1258
|
}
|
|
1237
1259
|
|
|
1238
1260
|
//#endregion
|
|
1239
|
-
//#region src/functions/parsers/zod/_parseZodSchema.ts
|
|
1240
|
-
function _parseZodSchema(parsedResult,
|
|
1261
|
+
//#region src/root/functions/parsers/zod/_parseZodSchema.ts
|
|
1262
|
+
function _parseZodSchema(parsedResult, input, onError) {
|
|
1241
1263
|
if (!parsedResult.success) {
|
|
1242
1264
|
if (onError) {
|
|
1243
1265
|
if (onError instanceof Error) throw onError;
|
|
@@ -1251,7 +1273,7 @@ function _parseZodSchema(parsedResult, data, onError) {
|
|
|
1251
1273
|
const code = issue.code.toUpperCase();
|
|
1252
1274
|
allErrorCodes[code] = (allErrorCodes[code] ?? 0) + 1;
|
|
1253
1275
|
}
|
|
1254
|
-
throw new DataError(
|
|
1276
|
+
throw new DataError({ input }, Object.entries(allErrorCodes).toSorted(([_, firstCount], [__, secondCount]) => {
|
|
1255
1277
|
return secondCount - firstCount;
|
|
1256
1278
|
}).map(([code, count], _, allErrorCodes) => {
|
|
1257
1279
|
return allErrorCodes.length === 1 && count === 1 ? code : `${code}×${count}`;
|
|
@@ -1261,7 +1283,7 @@ function _parseZodSchema(parsedResult, data, onError) {
|
|
|
1261
1283
|
}
|
|
1262
1284
|
|
|
1263
1285
|
//#endregion
|
|
1264
|
-
//#region src/functions/parsers/zod/parseZodSchema.ts
|
|
1286
|
+
//#region src/root/functions/parsers/zod/parseZodSchema.ts
|
|
1265
1287
|
/**
|
|
1266
1288
|
* An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
|
|
1267
1289
|
*
|
|
@@ -1273,19 +1295,19 @@ function _parseZodSchema(parsedResult, data, onError) {
|
|
|
1273
1295
|
* @template ErrorType - The type of error to throw on invalid data.
|
|
1274
1296
|
*
|
|
1275
1297
|
* @param schema - The Zod schema to use in parsing.
|
|
1276
|
-
* @param
|
|
1298
|
+
* @param input - The data to parse.
|
|
1277
1299
|
* @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.
|
|
1278
1300
|
*
|
|
1279
1301
|
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
1280
1302
|
*
|
|
1281
1303
|
* @returns The parsed data from the Zod schema.
|
|
1282
1304
|
*/
|
|
1283
|
-
function parseZodSchema(schema,
|
|
1284
|
-
return _parseZodSchema(schema.safeParse(
|
|
1305
|
+
function parseZodSchema(schema, input, onError) {
|
|
1306
|
+
return _parseZodSchema(schema.safeParse(input), input, onError);
|
|
1285
1307
|
}
|
|
1286
1308
|
|
|
1287
1309
|
//#endregion
|
|
1288
|
-
//#region src/functions/parsers/parseEnv.ts
|
|
1310
|
+
//#region src/root/functions/parsers/parseEnv.ts
|
|
1289
1311
|
/**
|
|
1290
1312
|
* Represents the three common development environments.
|
|
1291
1313
|
*
|
|
@@ -1301,18 +1323,18 @@ const Env = {
|
|
|
1301
1323
|
*
|
|
1302
1324
|
* @category Parsers
|
|
1303
1325
|
*
|
|
1304
|
-
* @param
|
|
1326
|
+
* @param input - The data to parse.
|
|
1305
1327
|
*
|
|
1306
1328
|
* @throws {DataError} If the data does not match one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
1307
1329
|
*
|
|
1308
1330
|
* @returns The specified environment if allowed.
|
|
1309
1331
|
*/
|
|
1310
|
-
function parseEnv(
|
|
1311
|
-
return parseZodSchema(zod.z.enum(Env),
|
|
1332
|
+
function parseEnv(input) {
|
|
1333
|
+
return parseZodSchema(zod.z.enum(Env), input, new DataError({ input }, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
|
|
1312
1334
|
}
|
|
1313
1335
|
|
|
1314
1336
|
//#endregion
|
|
1315
|
-
//#region src/functions/parsers/parseFilePath.ts
|
|
1337
|
+
//#region src/root/functions/parsers/parseFilePath.ts
|
|
1316
1338
|
/**
|
|
1317
1339
|
* Takes a file path string and parses it into the directory part, the base part, and the full path.
|
|
1318
1340
|
*
|
|
@@ -1343,7 +1365,7 @@ function parseFilePath(filePath) {
|
|
|
1343
1365
|
}
|
|
1344
1366
|
|
|
1345
1367
|
//#endregion
|
|
1346
|
-
//#region src/functions/parsers/parseFormData.ts
|
|
1368
|
+
//#region src/root/functions/parsers/parseFormData.ts
|
|
1347
1369
|
/**
|
|
1348
1370
|
* Returns an object given FormData and an optional data parser function to call on the resulting object.
|
|
1349
1371
|
*
|
|
@@ -1366,7 +1388,7 @@ function parseFormData(formData, dataParser) {
|
|
|
1366
1388
|
}
|
|
1367
1389
|
|
|
1368
1390
|
//#endregion
|
|
1369
|
-
//#region src/functions/parsers/parseVersionType.ts
|
|
1391
|
+
//#region src/root/functions/parsers/parseVersionType.ts
|
|
1370
1392
|
/**
|
|
1371
1393
|
* Represents the three common software version types.
|
|
1372
1394
|
*
|
|
@@ -1382,18 +1404,18 @@ const VersionType = {
|
|
|
1382
1404
|
*
|
|
1383
1405
|
* @category Parsers
|
|
1384
1406
|
*
|
|
1385
|
-
* @param
|
|
1407
|
+
* @param input - The data to parse.
|
|
1386
1408
|
*
|
|
1387
1409
|
* @throws {DataError} If the data does not match one of the allowed version types (`"major" | "minor" | "patch"`).
|
|
1388
1410
|
*
|
|
1389
1411
|
* @returns The given version type if allowed.
|
|
1390
1412
|
*/
|
|
1391
|
-
function parseVersionType(
|
|
1392
|
-
return parseZodSchema(zod.default.enum(VersionType),
|
|
1413
|
+
function parseVersionType(input) {
|
|
1414
|
+
return parseZodSchema(zod.default.enum(VersionType), input, new DataError({ input }, "INVALID_VERSION_TYPE", "The provided version type must be one of `major | minor | patch`"));
|
|
1393
1415
|
}
|
|
1394
1416
|
|
|
1395
1417
|
//#endregion
|
|
1396
|
-
//#region src/functions/parsers/zod/parseZodSchemaAsync.ts
|
|
1418
|
+
//#region src/root/functions/parsers/zod/parseZodSchemaAsync.ts
|
|
1397
1419
|
/**
|
|
1398
1420
|
* An alternative function to zodSchema.parseAsync() that can be used to strictly parse asynchronous Zod schemas.
|
|
1399
1421
|
*
|
|
@@ -1403,19 +1425,19 @@ function parseVersionType(data) {
|
|
|
1403
1425
|
* @template ErrorType - The type of error to throw on invalid data.
|
|
1404
1426
|
*
|
|
1405
1427
|
* @param schema - The Zod schema to use in parsing.
|
|
1406
|
-
* @param
|
|
1428
|
+
* @param input - The data to parse.
|
|
1407
1429
|
* @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.
|
|
1408
1430
|
*
|
|
1409
1431
|
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
1410
1432
|
*
|
|
1411
1433
|
* @returns The parsed data from the Zod schema.
|
|
1412
1434
|
*/
|
|
1413
|
-
async function parseZodSchemaAsync(schema,
|
|
1414
|
-
return _parseZodSchema(await schema.safeParseAsync(
|
|
1435
|
+
async function parseZodSchemaAsync(schema, input, onError) {
|
|
1436
|
+
return _parseZodSchema(await schema.safeParseAsync(input), input, onError);
|
|
1415
1437
|
}
|
|
1416
1438
|
|
|
1417
1439
|
//#endregion
|
|
1418
|
-
//#region src/functions/recursive/deepCopy.ts
|
|
1440
|
+
//#region src/root/functions/recursive/deepCopy.ts
|
|
1419
1441
|
function callDeepCopy(input) {
|
|
1420
1442
|
return typeof input === "object" && input !== null ? deepCopy(input) : input;
|
|
1421
1443
|
}
|
|
@@ -1443,7 +1465,7 @@ function deepCopy(object) {
|
|
|
1443
1465
|
}
|
|
1444
1466
|
|
|
1445
1467
|
//#endregion
|
|
1446
|
-
//#region src/functions/security/encryptWithKey.ts
|
|
1468
|
+
//#region src/root/functions/security/encryptWithKey.ts
|
|
1447
1469
|
/**
|
|
1448
1470
|
* Encrypt a secret given the public base64 key and the thing you want to encrypt.
|
|
1449
1471
|
*
|
|
@@ -1464,32 +1486,7 @@ async function encryptWithKey(publicKey, plaintextValue) {
|
|
|
1464
1486
|
}
|
|
1465
1487
|
|
|
1466
1488
|
//#endregion
|
|
1467
|
-
//#region src/functions/
|
|
1468
|
-
/**
|
|
1469
|
-
* Returns the public key and private key, properly narrowing down types depending on the provided `outputFormat`.
|
|
1470
|
-
*
|
|
1471
|
-
* @deprecated Please use `sodium.crypto_box_keypair` from `libsodium-wrappers` instead.
|
|
1472
|
-
*
|
|
1473
|
-
* 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
|
|
1474
|
-
*
|
|
1475
|
-
* @param outputFormat - The format of the resulting publicKey and privateKey you would like to use.
|
|
1476
|
-
*
|
|
1477
|
-
* @returns An object containing both the publicKey and privateKey, along with a keyType.
|
|
1478
|
-
*/
|
|
1479
|
-
function getPublicAndPrivateKey(outputFormat) {
|
|
1480
|
-
const keys = libsodium_wrappers.default.crypto_box_keypair(outputFormat);
|
|
1481
|
-
if (outputFormat === "uint8array" || outputFormat === void 0) {
|
|
1482
|
-
if (!(keys?.publicKey instanceof Uint8Array && keys?.privateKey instanceof Uint8Array)) throw new DataError({
|
|
1483
|
-
publicKey: `<redacted: ${keys?.publicKey?.constructor?.name ?? typeof keys?.publicKey}>`,
|
|
1484
|
-
privateKey: `<redacted: ${keys?.privateKey?.constructor?.name ?? typeof keys?.privateKey}>`
|
|
1485
|
-
}, "INVALID_KEY_TYPES", "Expected Uint8Array keypair from libsodium.");
|
|
1486
|
-
return keys;
|
|
1487
|
-
}
|
|
1488
|
-
return keys;
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
//#endregion
|
|
1492
|
-
//#region src/functions/stringHelpers/appendSemicolon.ts
|
|
1489
|
+
//#region src/root/functions/stringHelpers/appendSemicolon.ts
|
|
1493
1490
|
/**
|
|
1494
1491
|
* Appends a semicolon to the end of a string, trimming where necessary first.
|
|
1495
1492
|
*
|
|
@@ -1509,7 +1506,7 @@ function appendSemicolon(stringToAppendTo) {
|
|
|
1509
1506
|
}
|
|
1510
1507
|
|
|
1511
1508
|
//#endregion
|
|
1512
|
-
//#region src/functions/stringHelpers/camelToKebab.ts
|
|
1509
|
+
//#region src/root/functions/stringHelpers/camelToKebab.ts
|
|
1513
1510
|
/**
|
|
1514
1511
|
* Converts a string from camelCase to kebab-case
|
|
1515
1512
|
*
|
|
@@ -1548,7 +1545,7 @@ function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
|
|
|
1548
1545
|
}
|
|
1549
1546
|
|
|
1550
1547
|
//#endregion
|
|
1551
|
-
//#region src/functions/stringHelpers/kebabToCamel.ts
|
|
1548
|
+
//#region src/root/functions/stringHelpers/kebabToCamel.ts
|
|
1552
1549
|
/**
|
|
1553
1550
|
* Converts a string from kebab-case to camelCase
|
|
1554
1551
|
*
|
|
@@ -1587,44 +1584,7 @@ function kebabToCamel(string, options) {
|
|
|
1587
1584
|
}
|
|
1588
1585
|
|
|
1589
1586
|
//#endregion
|
|
1590
|
-
//#region src/functions/stringHelpers/
|
|
1591
|
-
/**
|
|
1592
|
-
* Normalizes 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 normalize.
|
|
1602
|
-
*
|
|
1603
|
-
* @returns The import path normalized.
|
|
1604
|
-
*/
|
|
1605
|
-
function normalizeImportPath(importPath) {
|
|
1606
|
-
const normalizedPath = node_path.default.posix.normalize(importPath);
|
|
1607
|
-
if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) return `./${normalizedPath}`;
|
|
1608
|
-
return normalizedPath;
|
|
1609
|
-
}
|
|
1610
|
-
/**
|
|
1611
|
-
* Normalises an import path meant for use in an import statement in JavaScript.
|
|
1612
|
-
* 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.
|
|
1613
|
-
*
|
|
1614
|
-
* If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
|
|
1615
|
-
*
|
|
1616
|
-
* Helpful for custom linter rules that need to check (or fix) import paths.
|
|
1617
|
-
*
|
|
1618
|
-
* @category String Helpers
|
|
1619
|
-
*
|
|
1620
|
-
* @param importPath - The import path to normalise.
|
|
1621
|
-
*
|
|
1622
|
-
* @returns The import path normalised.
|
|
1623
|
-
*/
|
|
1624
|
-
const normaliseImportPath = normalizeImportPath;
|
|
1625
|
-
|
|
1626
|
-
//#endregion
|
|
1627
|
-
//#region src/functions/stringHelpers/truncate.ts
|
|
1587
|
+
//#region src/root/functions/stringHelpers/truncate.ts
|
|
1628
1588
|
/**
|
|
1629
1589
|
* Truncates a string and appends `...` to the end of it
|
|
1630
1590
|
*
|
|
@@ -1639,94 +1599,6 @@ function truncate(stringToTruncate, maxLength = 5) {
|
|
|
1639
1599
|
return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
|
|
1640
1600
|
}
|
|
1641
1601
|
|
|
1642
|
-
//#endregion
|
|
1643
|
-
//#region src/functions/versioning/parseVersion.ts
|
|
1644
|
-
/**
|
|
1645
|
-
* Parses a string and verifies it is a valid package version number.
|
|
1646
|
-
*
|
|
1647
|
-
* Valid formats: `X.Y.Z` or `vX.Y.Z`, where X, Y, and Z are non-negative integers.
|
|
1648
|
-
*
|
|
1649
|
-
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(input)` instead.
|
|
1650
|
-
*
|
|
1651
|
-
* @param input - The version string to parse.
|
|
1652
|
-
* @param options - Extra options to apply.
|
|
1653
|
-
*
|
|
1654
|
-
* @throws {DataError} If the input is not a valid version number.
|
|
1655
|
-
*
|
|
1656
|
-
* @returns The validated version number, prefixed with `v` if it was not already.
|
|
1657
|
-
*/
|
|
1658
|
-
function parseVersion(input, options) {
|
|
1659
|
-
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.`);
|
|
1660
|
-
if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
|
|
1661
|
-
return input.startsWith("v") ? input : `v${input}`;
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
|
-
//#endregion
|
|
1665
|
-
//#region src/functions/versioning/getIndividualVersionNumbers.ts
|
|
1666
|
-
/**
|
|
1667
|
-
* Gets the individual version numbers from a given version number as a tuple of numbers.
|
|
1668
|
-
*
|
|
1669
|
-
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use one of the following instead:
|
|
1670
|
-
* ```typescript
|
|
1671
|
-
* new VersionNumber(version).major
|
|
1672
|
-
* new VersionNumber(version).minor
|
|
1673
|
-
* new VersionNumber(version).patch
|
|
1674
|
-
* ```
|
|
1675
|
-
*
|
|
1676
|
-
* @param version - The version number.
|
|
1677
|
-
*
|
|
1678
|
-
* @returns A tuple of three numbers indicating `[major, minor, patch]`.
|
|
1679
|
-
*/
|
|
1680
|
-
function getIndividualVersionNumbers(version) {
|
|
1681
|
-
return parseVersion(version, { omitPrefix: true }).split(".").map((versionNumber) => {
|
|
1682
|
-
return parseIntStrict(versionNumber);
|
|
1683
|
-
});
|
|
1684
|
-
}
|
|
1685
|
-
|
|
1686
|
-
//#endregion
|
|
1687
|
-
//#region src/functions/versioning/determineVersionType.ts
|
|
1688
|
-
/**
|
|
1689
|
-
* Determines whether the given version is a major, minor, or patch version.
|
|
1690
|
-
*
|
|
1691
|
-
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).type` instead.
|
|
1692
|
-
*
|
|
1693
|
-
* @param version - The version number.
|
|
1694
|
-
*
|
|
1695
|
-
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
1696
|
-
*/
|
|
1697
|
-
function determineVersionType(version) {
|
|
1698
|
-
const [_major, minor, patch] = getIndividualVersionNumbers(version);
|
|
1699
|
-
if (minor === 0 && patch === 0) return "major";
|
|
1700
|
-
if (patch === 0) return "minor";
|
|
1701
|
-
return "patch";
|
|
1702
|
-
}
|
|
1703
|
-
|
|
1704
|
-
//#endregion
|
|
1705
|
-
//#region src/functions/versioning/incrementVersion.ts
|
|
1706
|
-
/**
|
|
1707
|
-
* Increments the given input version depending on the given increment type.
|
|
1708
|
-
*
|
|
1709
|
-
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).increment(incrementType)` instead.
|
|
1710
|
-
*
|
|
1711
|
-
* @param version - The version to increment
|
|
1712
|
-
* @param incrementType - The type of increment. Can be one of the following:
|
|
1713
|
-
* - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
|
|
1714
|
-
* - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
|
|
1715
|
-
* - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
|
|
1716
|
-
* @param options - Extra options to apply.
|
|
1717
|
-
*
|
|
1718
|
-
* @returns A new string representing the version with the increment applied.
|
|
1719
|
-
*/
|
|
1720
|
-
function incrementVersion(version, incrementType, options) {
|
|
1721
|
-
const [major, minor, patch] = getIndividualVersionNumbers(version);
|
|
1722
|
-
const newVersion = {
|
|
1723
|
-
major: `${major + 1}.0.0`,
|
|
1724
|
-
minor: `${major}.${minor + 1}.0`,
|
|
1725
|
-
patch: `${major}.${minor}.${patch + 1}`
|
|
1726
|
-
}[incrementType];
|
|
1727
|
-
return parseVersion(newVersion, { omitPrefix: options?.omitPrefix });
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1730
1602
|
//#endregion
|
|
1731
1603
|
exports.APIError = APIError;
|
|
1732
1604
|
exports.DataError = DataError;
|
|
@@ -1744,18 +1616,14 @@ exports.createFormData = createFormData;
|
|
|
1744
1616
|
exports.createTemplateStringsArray = createTemplateStringsArray;
|
|
1745
1617
|
exports.deepCopy = deepCopy;
|
|
1746
1618
|
exports.deepFreeze = deepFreeze;
|
|
1747
|
-
exports.determineVersionType = determineVersionType;
|
|
1748
1619
|
exports.encryptWithKey = encryptWithKey;
|
|
1749
1620
|
exports.fillArray = fillArray;
|
|
1750
1621
|
exports.formatDateAndTime = formatDateAndTime;
|
|
1751
|
-
exports.
|
|
1752
|
-
exports.getInterpolations = getInterpolations;
|
|
1753
|
-
exports.getPublicAndPrivateKey = getPublicAndPrivateKey;
|
|
1622
|
+
exports.getDependenciesFromGroup = getDependenciesFromGroup;
|
|
1754
1623
|
exports.getRandomNumber = getRandomNumber;
|
|
1755
1624
|
exports.getRecordKeys = getRecordKeys;
|
|
1756
1625
|
exports.getStringsAndInterpolations = getStringsAndInterpolations;
|
|
1757
1626
|
exports.httpErrorCodeLookup = httpErrorCodeLookup;
|
|
1758
|
-
exports.incrementVersion = incrementVersion;
|
|
1759
1627
|
exports.interpolate = interpolate;
|
|
1760
1628
|
exports.interpolateObjects = interpolateObjects;
|
|
1761
1629
|
exports.isAnniversary = isAnniversary;
|
|
@@ -1765,9 +1633,7 @@ exports.isOrdered = isOrdered;
|
|
|
1765
1633
|
exports.isSameDate = isSameDate;
|
|
1766
1634
|
exports.isTemplateStringsArray = isTemplateStringsArray;
|
|
1767
1635
|
exports.kebabToCamel = kebabToCamel;
|
|
1768
|
-
exports.normaliseImportPath = normaliseImportPath;
|
|
1769
1636
|
exports.normaliseIndents = normaliseIndents;
|
|
1770
|
-
exports.normalizeImportPath = normalizeImportPath;
|
|
1771
1637
|
exports.normalizeIndents = normalizeIndents;
|
|
1772
1638
|
exports.omitProperties = omitProperties;
|
|
1773
1639
|
exports.paralleliseArrays = paralleliseArrays;
|
|
@@ -1776,7 +1642,6 @@ exports.parseEnv = parseEnv;
|
|
|
1776
1642
|
exports.parseFilePath = parseFilePath;
|
|
1777
1643
|
exports.parseFormData = parseFormData;
|
|
1778
1644
|
exports.parseIntStrict = parseIntStrict;
|
|
1779
|
-
exports.parseVersion = parseVersion;
|
|
1780
1645
|
exports.parseVersionType = parseVersionType;
|
|
1781
1646
|
exports.parseZodSchema = parseZodSchema;
|
|
1782
1647
|
exports.parseZodSchemaAsync = parseZodSchemaAsync;
|