@alextheman/utility 3.6.0 → 3.8.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 +566 -198
- package/dist/index.d.cts +506 -111
- package/dist/index.d.ts +506 -111
- package/dist/index.js +558 -194
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import path from "path";
|
|
2
1
|
import z, { z as z$1 } from "zod";
|
|
2
|
+
import path from "path";
|
|
3
3
|
|
|
4
4
|
//#region src/constants/NAMESPACE_EXPORT_REGEX.ts
|
|
5
5
|
const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
6
6
|
var NAMESPACE_EXPORT_REGEX_default = NAMESPACE_EXPORT_REGEX;
|
|
7
7
|
|
|
8
8
|
//#endregion
|
|
9
|
-
//#region src/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const stringWithNoTrailingWhitespace = stringToAppendTo.trimEnd();
|
|
13
|
-
if (stringWithNoTrailingWhitespace === "") return "";
|
|
14
|
-
return stringWithNoTrailingWhitespace[stringWithNoTrailingWhitespace.length - 1] === ";" ? stringWithNoTrailingWhitespace : `${stringWithNoTrailingWhitespace};`;
|
|
15
|
-
}
|
|
16
|
-
var appendSemicolon_default = appendSemicolon;
|
|
9
|
+
//#region src/constants/VERSION_NUMBER_REGEX.ts
|
|
10
|
+
const VERSION_NUMBER_REGEX = "^(?:v)?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$";
|
|
11
|
+
var VERSION_NUMBER_REGEX_default = VERSION_NUMBER_REGEX;
|
|
17
12
|
|
|
18
13
|
//#endregion
|
|
19
14
|
//#region src/functions/arrayHelpers/fillArray.ts
|
|
@@ -67,7 +62,17 @@ var paralleliseArrays_default = paralleliseArrays;
|
|
|
67
62
|
//#endregion
|
|
68
63
|
//#region src/functions/parsers/parseIntStrict.ts
|
|
69
64
|
const IntegerParsingError = /* @__PURE__ */ new TypeError("INTEGER_PARSING_ERROR");
|
|
70
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Converts a string to an integer and throws an error if it cannot be converted.
|
|
67
|
+
*
|
|
68
|
+
* @param string — A string to convert into a number.
|
|
69
|
+
* @param radix - A value between 2 and 36 that specifies the base of the number in string. If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal. All other strings are considered decimal.
|
|
70
|
+
*
|
|
71
|
+
* @throws {TypeError} If the provided string cannot safely be converted to an integer.
|
|
72
|
+
*
|
|
73
|
+
* @returns The integer parsed from the input string.
|
|
74
|
+
*/
|
|
75
|
+
function parseIntStrict(string, radix) {
|
|
71
76
|
const trimmedString = string.trim();
|
|
72
77
|
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${String.fromCharCode(87 + radix - 1)}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw IntegerParsingError;
|
|
73
78
|
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
@@ -80,7 +85,15 @@ function parseIntStrict(...[string, radix]) {
|
|
|
80
85
|
var parseIntStrict_default = parseIntStrict;
|
|
81
86
|
|
|
82
87
|
//#endregion
|
|
83
|
-
//#region src/functions/getRandomNumber.ts
|
|
88
|
+
//#region src/functions/miscellaneous/getRandomNumber.ts
|
|
89
|
+
/**
|
|
90
|
+
* Gets a random number between the given bounds.
|
|
91
|
+
*
|
|
92
|
+
* @param lowerBound - The lowest number that can be chosen.
|
|
93
|
+
* @param upperBound - The highest number that can be chosen.
|
|
94
|
+
*
|
|
95
|
+
* @returns A random number between the provided lower bound and upper bound.
|
|
96
|
+
*/
|
|
84
97
|
function getRandomNumber(lowerBound, upperBound) {
|
|
85
98
|
const parsedLowerBound = parseIntStrict_default(`${lowerBound}`);
|
|
86
99
|
const parsedUpperBound = parseIntStrict_default(`${upperBound}`);
|
|
@@ -115,8 +128,8 @@ var randomiseArray_default = randomiseArray;
|
|
|
115
128
|
/**
|
|
116
129
|
* Creates an array of numbers within a given range.
|
|
117
130
|
*
|
|
118
|
-
* The range is inclusive of `start` and exclusive of `stop`.
|
|
119
|
-
* The sign of `step` must match the direction of the range.
|
|
131
|
+
* - The range is inclusive of `start` and exclusive of `stop`.
|
|
132
|
+
* - The sign of `step` must match the direction of the range.
|
|
120
133
|
*
|
|
121
134
|
* @param start - The number to start at (inclusive).
|
|
122
135
|
* @param stop - The number to stop at (exclusive).
|
|
@@ -142,96 +155,22 @@ function range(start, stop, step = 1) {
|
|
|
142
155
|
var range_default = range;
|
|
143
156
|
|
|
144
157
|
//#endregion
|
|
145
|
-
//#region src/functions/
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
reject(/* @__PURE__ */ new Error("FILE_CONVERSION_ERROR"));
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
resolve(reader.result);
|
|
163
|
-
};
|
|
164
|
-
reader.onerror = () => {
|
|
165
|
-
reject(/* @__PURE__ */ new Error("FILE_READER_ERROR"));
|
|
166
|
-
};
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
var convertFileToBase64_default = convertFileToBase64;
|
|
170
|
-
|
|
171
|
-
//#endregion
|
|
172
|
-
//#region src/functions/createFormData.ts
|
|
173
|
-
function getNullableResolutionStrategy(key, strategy) {
|
|
174
|
-
return (typeof strategy === "object" ? strategy[key] : strategy) ?? "empty";
|
|
175
|
-
}
|
|
176
|
-
function createFormData(data, options = {
|
|
177
|
-
arrayResolution: "stringify",
|
|
178
|
-
nullableResolution: "empty"
|
|
179
|
-
}) {
|
|
180
|
-
const formData = new FormData();
|
|
181
|
-
function resolveNullablesByStrategy(key, value, resolutionStrategy) {
|
|
182
|
-
switch (resolutionStrategy) {
|
|
183
|
-
case "empty":
|
|
184
|
-
formData.append(String(key), "");
|
|
185
|
-
break;
|
|
186
|
-
case "stringify":
|
|
187
|
-
formData.append(String(key), JSON.stringify(value));
|
|
188
|
-
break;
|
|
189
|
-
case "omit": break;
|
|
190
|
-
default: throw new TypeError("SLOPPY_PURE_JAVASCRIPT_USER_ERROR");
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
function resolveNullables(key, value, options$1) {
|
|
194
|
-
if (options$1.nullableResolution) {
|
|
195
|
-
resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.nullableResolution));
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
if (options$1.undefinedResolution || options$1.nullResolution) {
|
|
199
|
-
if (data[key] === void 0 && options$1.undefinedResolution) {
|
|
200
|
-
resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.undefinedResolution));
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
if (data[key] === null && options$1.nullResolution) resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.nullResolution));
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
const entries = Object.entries(data);
|
|
207
|
-
for (const [key, value] of entries) if (value instanceof Blob) formData.append(String(key), value);
|
|
208
|
-
else if (value === void 0 || value === null) resolveNullables(key, value, options);
|
|
209
|
-
else if (typeof value === "object") {
|
|
210
|
-
if (Array.isArray(value)) {
|
|
211
|
-
if (value.some((item) => {
|
|
212
|
-
return item instanceof Blob;
|
|
213
|
-
}) && (options.arrayResolution === "stringify" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "stringify")) throw new TypeError("CANNOT_STRINGIFY_BLOB");
|
|
214
|
-
if (options.arrayResolution === "multiple" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "multiple") {
|
|
215
|
-
for (const item of value) {
|
|
216
|
-
if ((typeof item === "object" || !item) && !(item instanceof Blob)) throw new TypeError("NON_PRIMITIVE_ARRAY_ITEMS_FOUND");
|
|
217
|
-
if (item instanceof Blob) formData.append(String(key), item);
|
|
218
|
-
else formData.append(String(key), String(item));
|
|
219
|
-
}
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
formData.append(String(key), JSON.stringify(value));
|
|
224
|
-
} else formData.append(String(key), String(value));
|
|
225
|
-
return formData;
|
|
226
|
-
}
|
|
227
|
-
var createFormData_default = createFormData;
|
|
228
|
-
|
|
229
|
-
//#endregion
|
|
230
|
-
//#region src/functions/createTemplateStringsArray.ts
|
|
231
|
-
function createTemplateStringsArray(strings) {
|
|
232
|
-
return Object.assign([...strings], { raw: [...strings] });
|
|
158
|
+
//#region src/functions/arrayHelpers/removeDuplicates.ts
|
|
159
|
+
/**
|
|
160
|
+
* Removes duplicate values from an array.
|
|
161
|
+
*
|
|
162
|
+
* @template ItemType - The type of the array items.
|
|
163
|
+
*
|
|
164
|
+
* @param array - The array to remove duplicates from.
|
|
165
|
+
*
|
|
166
|
+
* @returns A new array with a different reference in memory, with the duplicates removed.
|
|
167
|
+
*/
|
|
168
|
+
function removeDuplicates(array) {
|
|
169
|
+
const outputArray = [];
|
|
170
|
+
for (const item of array) if (!outputArray.includes(item)) outputArray.push(item);
|
|
171
|
+
return outputArray;
|
|
233
172
|
}
|
|
234
|
-
var
|
|
173
|
+
var removeDuplicates_default = removeDuplicates;
|
|
235
174
|
|
|
236
175
|
//#endregion
|
|
237
176
|
//#region src/functions/date/addDaysToDate.ts
|
|
@@ -374,43 +313,111 @@ function isMonthlyMultiple(firstDate, secondDate) {
|
|
|
374
313
|
var isMonthlyMultiple_default = isMonthlyMultiple;
|
|
375
314
|
|
|
376
315
|
//#endregion
|
|
377
|
-
//#region src/functions/
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
316
|
+
//#region src/functions/miscellaneous/convertFileToBase64.ts
|
|
317
|
+
/**
|
|
318
|
+
* Asynchronously converts a file to a base 64 string
|
|
319
|
+
*
|
|
320
|
+
* @param file - The file to convert.
|
|
321
|
+
*
|
|
322
|
+
* @throws {Error} If the file reader gives an error.
|
|
323
|
+
*
|
|
324
|
+
* @returns A promise that resolves to the encoded base 64 string.
|
|
325
|
+
*/
|
|
326
|
+
function convertFileToBase64(file) {
|
|
327
|
+
return new Promise((resolve, reject) => {
|
|
328
|
+
const reader = new FileReader();
|
|
329
|
+
reader.readAsDataURL(file);
|
|
330
|
+
reader.onload = () => {
|
|
331
|
+
if (reader.result === null) {
|
|
332
|
+
reject(/* @__PURE__ */ new Error("FILE_CONVERSION_ERROR"));
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
resolve(reader.result);
|
|
336
|
+
};
|
|
337
|
+
reader.onerror = () => {
|
|
338
|
+
reject(/* @__PURE__ */ new Error("FILE_READER_ERROR"));
|
|
339
|
+
};
|
|
384
340
|
});
|
|
385
|
-
const clonedObject = { ...object };
|
|
386
|
-
for (const key in clonedObject) {
|
|
387
|
-
const value = clonedObject[key];
|
|
388
|
-
clonedObject[key] = callDeepCopy(value);
|
|
389
|
-
}
|
|
390
|
-
return clonedObject;
|
|
391
341
|
}
|
|
392
|
-
var
|
|
342
|
+
var convertFileToBase64_default = convertFileToBase64;
|
|
393
343
|
|
|
394
344
|
//#endregion
|
|
395
|
-
//#region src/functions/
|
|
396
|
-
function
|
|
397
|
-
|
|
398
|
-
if (typeof value === "function") continue;
|
|
399
|
-
if (value && typeof value === "object") deepFreeze(value);
|
|
400
|
-
}
|
|
401
|
-
return Object.freeze(object);
|
|
345
|
+
//#region src/functions/miscellaneous/createFormData.ts
|
|
346
|
+
function getNullableResolutionStrategy(key, strategy) {
|
|
347
|
+
return (typeof strategy === "object" ? strategy[key] : strategy) ?? "empty";
|
|
402
348
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
349
|
+
/**
|
|
350
|
+
* Creates FormData from a given object, resolving non-string types as appropriate.
|
|
351
|
+
*
|
|
352
|
+
* @template DataType - The type of the given data.
|
|
353
|
+
*
|
|
354
|
+
* @param data - The data to create FormData from.
|
|
355
|
+
* @param options - Options to apply to the conversion.
|
|
356
|
+
*
|
|
357
|
+
* @returns A FormData object with the data applied.
|
|
358
|
+
*/
|
|
359
|
+
function createFormData(data, options = {
|
|
360
|
+
arrayResolution: "stringify",
|
|
361
|
+
nullableResolution: "empty"
|
|
362
|
+
}) {
|
|
363
|
+
const formData = new FormData();
|
|
364
|
+
function resolveNullablesByStrategy(key, value, resolutionStrategy) {
|
|
365
|
+
switch (resolutionStrategy) {
|
|
366
|
+
case "empty":
|
|
367
|
+
formData.append(String(key), "");
|
|
368
|
+
break;
|
|
369
|
+
case "stringify":
|
|
370
|
+
formData.append(String(key), JSON.stringify(value));
|
|
371
|
+
break;
|
|
372
|
+
case "omit": break;
|
|
373
|
+
default: throw new TypeError("SLOPPY_PURE_JAVASCRIPT_USER_ERROR");
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
function resolveNullables(key, value, options$1) {
|
|
377
|
+
if (options$1.nullableResolution) {
|
|
378
|
+
resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.nullableResolution));
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
if (options$1.undefinedResolution || options$1.nullResolution) {
|
|
382
|
+
if (data[key] === void 0 && options$1.undefinedResolution) {
|
|
383
|
+
resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.undefinedResolution));
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (data[key] === null && options$1.nullResolution) resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.nullResolution));
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
const entries = Object.entries(data);
|
|
390
|
+
for (const [key, value] of entries) if (value instanceof Blob) formData.append(String(key), value);
|
|
391
|
+
else if (value === void 0 || value === null) resolveNullables(key, value, options);
|
|
392
|
+
else if (typeof value === "object") {
|
|
393
|
+
if (Array.isArray(value)) {
|
|
394
|
+
if (value.some((item) => {
|
|
395
|
+
return item instanceof Blob;
|
|
396
|
+
}) && (options.arrayResolution === "stringify" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "stringify")) throw new TypeError("CANNOT_STRINGIFY_BLOB");
|
|
397
|
+
if (options.arrayResolution === "multiple" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "multiple") {
|
|
398
|
+
for (const item of value) {
|
|
399
|
+
if ((typeof item === "object" || !item) && !(item instanceof Blob)) throw new TypeError("NON_PRIMITIVE_ARRAY_ITEMS_FOUND");
|
|
400
|
+
if (item instanceof Blob) formData.append(String(key), item);
|
|
401
|
+
else formData.append(String(key), String(item));
|
|
402
|
+
}
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
formData.append(String(key), JSON.stringify(value));
|
|
407
|
+
} else formData.append(String(key), String(value));
|
|
408
|
+
return formData;
|
|
409
409
|
}
|
|
410
|
-
var
|
|
410
|
+
var createFormData_default = createFormData;
|
|
411
411
|
|
|
412
412
|
//#endregion
|
|
413
|
-
//#region src/functions/isOrdered.ts
|
|
413
|
+
//#region src/functions/miscellaneous/isOrdered.ts
|
|
414
|
+
/**
|
|
415
|
+
* Checks to see if the given array is sorted in ascending order.
|
|
416
|
+
*
|
|
417
|
+
* @param array - The array to check.
|
|
418
|
+
*
|
|
419
|
+
* @returns `true` if the array is sorted in ascending order, and `false` otherwise.
|
|
420
|
+
*/
|
|
414
421
|
function isOrdered(array) {
|
|
415
422
|
const newArray = [...array];
|
|
416
423
|
newArray.sort();
|
|
@@ -420,47 +427,73 @@ function isOrdered(array) {
|
|
|
420
427
|
var isOrdered_default = isOrdered;
|
|
421
428
|
|
|
422
429
|
//#endregion
|
|
423
|
-
//#region src/functions/
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
outputString += string[index];
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
if (string[index] === "-" && /^[a-zA-Z]+$/.test(string[index + 1])) {
|
|
444
|
-
outputString += string[index + 1].toUpperCase();
|
|
445
|
-
skip = true;
|
|
446
|
-
} else outputString += string[index];
|
|
447
|
-
}
|
|
448
|
-
return outputString;
|
|
430
|
+
//#region src/functions/miscellaneous/stringListToArray.ts
|
|
431
|
+
/**
|
|
432
|
+
* Converts a stringly-typed list to a proper array.
|
|
433
|
+
*
|
|
434
|
+
* @param stringList - The stringly-typed list to convert.
|
|
435
|
+
* @param options - The options to apply to the conversion.
|
|
436
|
+
* @param options.separator - What each item in the list is separated by.
|
|
437
|
+
* @param options.trimWhitespace - An option to trim any extra whitespace.
|
|
438
|
+
*
|
|
439
|
+
* @returns A new array with each item being an item from the given list.
|
|
440
|
+
*/
|
|
441
|
+
function stringListToArray(stringList, { separator = ",", trimWhitespace = true } = {}) {
|
|
442
|
+
if (trimWhitespace && stringList.trim() === "") return [];
|
|
443
|
+
const arrayList = stringList.split(separator ?? "");
|
|
444
|
+
return trimWhitespace ? arrayList.map((item) => {
|
|
445
|
+
return item.trim();
|
|
446
|
+
}) : arrayList;
|
|
449
447
|
}
|
|
450
|
-
var
|
|
448
|
+
var stringListToArray_default = stringListToArray;
|
|
451
449
|
|
|
452
450
|
//#endregion
|
|
453
|
-
//#region src/functions/
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
451
|
+
//#region src/functions/miscellaneous/wait.ts
|
|
452
|
+
/**
|
|
453
|
+
* Waits for the given number of seconds
|
|
454
|
+
*
|
|
455
|
+
* @param seconds - The number of seconds to wait.
|
|
456
|
+
*
|
|
457
|
+
* @returns A Promise that resolves after the given number of seconds.
|
|
458
|
+
*/
|
|
459
|
+
function wait(seconds) {
|
|
460
|
+
return new Promise((resolve, _) => {
|
|
461
|
+
setTimeout(() => {
|
|
462
|
+
resolve();
|
|
463
|
+
}, seconds * 1e3);
|
|
464
|
+
});
|
|
458
465
|
}
|
|
459
|
-
|
|
460
|
-
|
|
466
|
+
var wait_default = wait;
|
|
467
|
+
|
|
468
|
+
//#endregion
|
|
469
|
+
//#region src/functions/objectHelpers/getRecordKeys.ts
|
|
470
|
+
/**
|
|
471
|
+
* Gets the keys from a given record object, properly typed to be an array of the key of the input object's type.
|
|
472
|
+
*
|
|
473
|
+
* @template InputRecordType - The type of the input object.
|
|
474
|
+
*
|
|
475
|
+
* @param record - The record to get the keys from.
|
|
476
|
+
*
|
|
477
|
+
* @returns An array with all the keys of the input object in string form, but properly typed as `keyof InputRecordType`.
|
|
478
|
+
*/
|
|
479
|
+
function getRecordKeys(record) {
|
|
480
|
+
return Object.keys(record);
|
|
481
|
+
}
|
|
482
|
+
var getRecordKeys_default = getRecordKeys;
|
|
461
483
|
|
|
462
484
|
//#endregion
|
|
463
|
-
//#region src/functions/omitProperties.ts
|
|
485
|
+
//#region src/functions/objectHelpers/omitProperties.ts
|
|
486
|
+
/**
|
|
487
|
+
* Omits properties from a given object.
|
|
488
|
+
*
|
|
489
|
+
* @template ObjectType - The type of the input object.
|
|
490
|
+
* @template KeysToOmit - A type representing the keys to omit from the object.
|
|
491
|
+
*
|
|
492
|
+
* @param object - The object to omit properties from.
|
|
493
|
+
* @param keysToOmit - The keys to omit from the object. Can either be a single string to omit one, or an array to omit multiple.
|
|
494
|
+
*
|
|
495
|
+
* @returns An object with a new reference in memory, with the properties omitted.
|
|
496
|
+
*/
|
|
464
497
|
function omitProperties(object, keysToOmit) {
|
|
465
498
|
const outputObject = { ...object };
|
|
466
499
|
(Array.isArray(keysToOmit) ? keysToOmit : [keysToOmit]).forEach((key) => {
|
|
@@ -472,6 +505,15 @@ var omitProperties_default = omitProperties;
|
|
|
472
505
|
|
|
473
506
|
//#endregion
|
|
474
507
|
//#region src/functions/parsers/parseBoolean.ts
|
|
508
|
+
/**
|
|
509
|
+
* Takes a stringly-typed boolean and converts it to an actual boolean type.
|
|
510
|
+
*
|
|
511
|
+
* @param inputString - The string to parse.
|
|
512
|
+
*
|
|
513
|
+
* @throws {TypeError} If the string is not either `true` or `false` (case insensitive).
|
|
514
|
+
*
|
|
515
|
+
* @returns The string parsed as an actual boolean.
|
|
516
|
+
*/
|
|
475
517
|
function parseBoolean(inputString) {
|
|
476
518
|
const normalisedString = inputString.toLowerCase();
|
|
477
519
|
if (!["true", "false"].includes(normalisedString)) throw new TypeError("INVALID_BOOLEAN_STRING");
|
|
@@ -488,6 +530,15 @@ const envSchema = z$1.enum([
|
|
|
488
530
|
"development",
|
|
489
531
|
"production"
|
|
490
532
|
]);
|
|
533
|
+
/**
|
|
534
|
+
* Parses the input and verifies it matches one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
535
|
+
*
|
|
536
|
+
* @param data - The data to parse.
|
|
537
|
+
*
|
|
538
|
+
* @throws {ZodError} If the data does not match one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
539
|
+
*
|
|
540
|
+
* @returns The specified environment if allowed.
|
|
541
|
+
*/
|
|
491
542
|
function parseEnv(data) {
|
|
492
543
|
return envSchema.parse(data);
|
|
493
544
|
}
|
|
@@ -495,6 +546,16 @@ var parseEnv_default = parseEnv;
|
|
|
495
546
|
|
|
496
547
|
//#endregion
|
|
497
548
|
//#region src/functions/parsers/parseFormData.ts
|
|
549
|
+
/**
|
|
550
|
+
* Returns an object given FormData and an optional data parser function to call on the resulting object.
|
|
551
|
+
*
|
|
552
|
+
* @template DataType - The type of the resulting object when called from the dataParser.
|
|
553
|
+
*
|
|
554
|
+
* @param formData - The FormData to parse.
|
|
555
|
+
* @param dataParser - An optional parser to call on the object before it gets returned.
|
|
556
|
+
*
|
|
557
|
+
* @returns A parsed object based on the contents of the input formData and the result of parsing with the data parser if provided.
|
|
558
|
+
*/
|
|
498
559
|
function parseFormData(formData, dataParser) {
|
|
499
560
|
const object = {};
|
|
500
561
|
formData.forEach((value, key) => {
|
|
@@ -515,8 +576,14 @@ const httpErrorCodeLookup = {
|
|
|
515
576
|
418: "I_AM_A_TEAPOT",
|
|
516
577
|
500: "INTERNAL_SERVER_ERROR"
|
|
517
578
|
};
|
|
579
|
+
/** Represents common errors you may get from a HTTP API request. */
|
|
518
580
|
var APIError = class extends Error {
|
|
519
581
|
status;
|
|
582
|
+
/**
|
|
583
|
+
* @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.
|
|
584
|
+
* @param message - An error message to display alongside the status code.
|
|
585
|
+
* @param options - Extra options to be passed to super Error constructor.
|
|
586
|
+
*/
|
|
520
587
|
constructor(status = 500, message, options) {
|
|
521
588
|
super(message, options);
|
|
522
589
|
this.status = status;
|
|
@@ -525,6 +592,13 @@ var APIError = class extends Error {
|
|
|
525
592
|
Object.defineProperty(this, "message", { enumerable: true });
|
|
526
593
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
527
594
|
}
|
|
595
|
+
/**
|
|
596
|
+
* Checks whether the given input may have been caused by an APIError.
|
|
597
|
+
*
|
|
598
|
+
* @param input - The input to check.
|
|
599
|
+
*
|
|
600
|
+
* @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`.
|
|
601
|
+
*/
|
|
528
602
|
static check(input) {
|
|
529
603
|
const data = input;
|
|
530
604
|
return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
|
|
@@ -534,6 +608,7 @@ var APIError_default = APIError;
|
|
|
534
608
|
|
|
535
609
|
//#endregion
|
|
536
610
|
//#region src/types/DataError.ts
|
|
611
|
+
/** Represents errors you may get that may've been caused by a specific piece of data. */
|
|
537
612
|
var DataError = class extends Error {
|
|
538
613
|
data;
|
|
539
614
|
code;
|
|
@@ -552,6 +627,13 @@ var DataError = class extends Error {
|
|
|
552
627
|
Object.defineProperty(this, "message", { enumerable: true });
|
|
553
628
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
554
629
|
}
|
|
630
|
+
/**
|
|
631
|
+
* Checks whether the given input may have been caused by a DataError.
|
|
632
|
+
*
|
|
633
|
+
* @param input - The input to check.
|
|
634
|
+
*
|
|
635
|
+
* @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`.
|
|
636
|
+
*/
|
|
555
637
|
static check(input) {
|
|
556
638
|
const data = input;
|
|
557
639
|
return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
|
|
@@ -579,6 +661,20 @@ var UUID_default = parseUUID;
|
|
|
579
661
|
|
|
580
662
|
//#endregion
|
|
581
663
|
//#region src/functions/parsers/parseZodSchema.ts
|
|
664
|
+
/**
|
|
665
|
+
* An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
|
|
666
|
+
*
|
|
667
|
+
* @template Output - The Zod output type.
|
|
668
|
+
* @template Input - The Zod input type.
|
|
669
|
+
* @template Internals - The Zod internal types based on the output and input types.
|
|
670
|
+
*
|
|
671
|
+
* @param schema - The Zod schema to use in parsing.
|
|
672
|
+
* @param data - The data to parse.
|
|
673
|
+
*
|
|
674
|
+
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
675
|
+
*
|
|
676
|
+
* @returns The parsed data from the Zod schema.
|
|
677
|
+
*/
|
|
582
678
|
function parseZodSchema(schema, data) {
|
|
583
679
|
const parsedResult = schema.safeParse(data);
|
|
584
680
|
if (!parsedResult.success) throw new DataError_default(data);
|
|
@@ -587,27 +683,207 @@ function parseZodSchema(schema, data) {
|
|
|
587
683
|
var parseZodSchema_default = parseZodSchema;
|
|
588
684
|
|
|
589
685
|
//#endregion
|
|
590
|
-
//#region src/functions/
|
|
591
|
-
function
|
|
592
|
-
|
|
593
|
-
for (const item of array) if (!outputArray.includes(item)) outputArray.push(item);
|
|
594
|
-
return outputArray;
|
|
686
|
+
//#region src/functions/recursive/deepCopy.ts
|
|
687
|
+
function callDeepCopy(input) {
|
|
688
|
+
return typeof input === "object" && input !== null ? deepCopy(input) : input;
|
|
595
689
|
}
|
|
596
|
-
|
|
690
|
+
/**
|
|
691
|
+
* Deeply copies an object or array such that all child objects/arrays are also copied.
|
|
692
|
+
*
|
|
693
|
+
* @template ObjectType - The type of the input object.
|
|
694
|
+
*
|
|
695
|
+
* @param object - The object to copy. May also be an array.
|
|
696
|
+
*
|
|
697
|
+
* @returns An identical object with a new reference in memory.
|
|
698
|
+
*/
|
|
699
|
+
function deepCopy(object) {
|
|
700
|
+
if (Array.isArray(object)) return object.map((item) => {
|
|
701
|
+
return callDeepCopy(item);
|
|
702
|
+
});
|
|
703
|
+
const clonedObject = { ...object };
|
|
704
|
+
for (const key in clonedObject) {
|
|
705
|
+
const value = clonedObject[key];
|
|
706
|
+
clonedObject[key] = callDeepCopy(value);
|
|
707
|
+
}
|
|
708
|
+
return clonedObject;
|
|
709
|
+
}
|
|
710
|
+
var deepCopy_default = deepCopy;
|
|
597
711
|
|
|
598
712
|
//#endregion
|
|
599
|
-
//#region src/functions/
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
713
|
+
//#region src/functions/recursive/deepFreeze.ts
|
|
714
|
+
/**
|
|
715
|
+
* Deeply freezes an object or array such that all child objects/arrays are also frozen.
|
|
716
|
+
*
|
|
717
|
+
* Note that this will also freeze the input itself as well.
|
|
718
|
+
* If the intent is to create a newly frozen object with a different reference in memory, pass your object through deepCopy first before passing to deepFreeze.
|
|
719
|
+
*
|
|
720
|
+
* @template ObjectType - The type of the input object.
|
|
721
|
+
*
|
|
722
|
+
* @param object - The object to freeze. May also be an array.
|
|
723
|
+
*
|
|
724
|
+
* @returns The input object completely frozen.
|
|
725
|
+
*/
|
|
726
|
+
function deepFreeze(object) {
|
|
727
|
+
for (const value of Object.values(object)) {
|
|
728
|
+
if (typeof value === "function") continue;
|
|
729
|
+
if (value && typeof value === "object") deepFreeze(value);
|
|
730
|
+
}
|
|
731
|
+
return Object.freeze(object);
|
|
606
732
|
}
|
|
607
|
-
var
|
|
733
|
+
var deepFreeze_default = deepFreeze;
|
|
734
|
+
|
|
735
|
+
//#endregion
|
|
736
|
+
//#region src/functions/stringHelpers/appendSemicolon.ts
|
|
737
|
+
/**
|
|
738
|
+
* Appends a semicolon to the end of a string, trimming where necessary first.
|
|
739
|
+
*
|
|
740
|
+
* @param stringToAppendTo - The string to append a semicolon to.
|
|
741
|
+
*
|
|
742
|
+
* @throws {Error} If the string contains multiple lines.
|
|
743
|
+
*
|
|
744
|
+
* @returns A string with the semicolon appended.
|
|
745
|
+
*/
|
|
746
|
+
function appendSemicolon(stringToAppendTo) {
|
|
747
|
+
if (stringToAppendTo.includes("\n")) throw new Error("MULTIPLE_LINE_ERROR");
|
|
748
|
+
const stringWithNoTrailingWhitespace = stringToAppendTo.trimEnd();
|
|
749
|
+
if (stringWithNoTrailingWhitespace === "") return "";
|
|
750
|
+
return stringWithNoTrailingWhitespace[stringWithNoTrailingWhitespace.length - 1] === ";" ? stringWithNoTrailingWhitespace : `${stringWithNoTrailingWhitespace};`;
|
|
751
|
+
}
|
|
752
|
+
var appendSemicolon_default = appendSemicolon;
|
|
753
|
+
|
|
754
|
+
//#endregion
|
|
755
|
+
//#region src/functions/stringHelpers/camelToKebab.ts
|
|
756
|
+
/**
|
|
757
|
+
* Converts a string from camelCase to kebab-case
|
|
758
|
+
*
|
|
759
|
+
* @param string - The string to convert.
|
|
760
|
+
*
|
|
761
|
+
* @returns The string converted to kebab-case.
|
|
762
|
+
*/
|
|
763
|
+
function camelToKebab(string) {
|
|
764
|
+
return string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").toLowerCase();
|
|
765
|
+
}
|
|
766
|
+
var camelToKebab_default = camelToKebab;
|
|
767
|
+
|
|
768
|
+
//#endregion
|
|
769
|
+
//#region src/functions/stringHelpers/kebabToCamel.ts
|
|
770
|
+
/**
|
|
771
|
+
* Converts a string from kebab-case to camelCase
|
|
772
|
+
*
|
|
773
|
+
* @param string - The string to convert.
|
|
774
|
+
* @param options - Options to apply to the conversion.
|
|
775
|
+
*
|
|
776
|
+
* @returns The string converted to camelCase.
|
|
777
|
+
*/
|
|
778
|
+
function kebabToCamel(string, options) {
|
|
779
|
+
if (string !== string.toLowerCase()) throw new Error("INVALID_KEBAB_CASE_INPUT");
|
|
780
|
+
if (string.startsWith("-") || string.endsWith("-") || string.includes("--")) throw new Error("INVALID_KEBAB_CASE_INPUT");
|
|
781
|
+
let outputString = "";
|
|
782
|
+
let skip = false;
|
|
783
|
+
for (const stringIndex in [...string]) {
|
|
784
|
+
if (skip) {
|
|
785
|
+
skip = false;
|
|
786
|
+
continue;
|
|
787
|
+
}
|
|
788
|
+
const index = parseIntStrict_default(stringIndex);
|
|
789
|
+
if (index === 0 && options?.startWithUpper) {
|
|
790
|
+
outputString += string[index].toUpperCase();
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
if (index === string.length - 1) {
|
|
794
|
+
outputString += string[index];
|
|
795
|
+
break;
|
|
796
|
+
}
|
|
797
|
+
if (string[index] === "-" && /^[a-zA-Z]+$/.test(string[index + 1])) {
|
|
798
|
+
outputString += string[index + 1].toUpperCase();
|
|
799
|
+
skip = true;
|
|
800
|
+
} else outputString += string[index];
|
|
801
|
+
}
|
|
802
|
+
return outputString;
|
|
803
|
+
}
|
|
804
|
+
var kebabToCamel_default = kebabToCamel;
|
|
805
|
+
|
|
806
|
+
//#endregion
|
|
807
|
+
//#region src/functions/stringHelpers/normalizeImportPath.ts
|
|
808
|
+
/**
|
|
809
|
+
* Normalizes an import path meant for use in an import statement in JavaScript.
|
|
810
|
+
*
|
|
811
|
+
* 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.
|
|
812
|
+
*
|
|
813
|
+
* If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
|
|
814
|
+
*
|
|
815
|
+
* Helpful for custom linter rules that need to check (or fix) import paths.
|
|
816
|
+
*
|
|
817
|
+
* @param importPath - The import path to normalize.
|
|
818
|
+
*
|
|
819
|
+
* @returns The import path normalized.
|
|
820
|
+
*/
|
|
821
|
+
function normalizeImportPath(importPath) {
|
|
822
|
+
const normalizedPath = path.posix.normalize(importPath);
|
|
823
|
+
if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) return `./${normalizedPath}`;
|
|
824
|
+
return normalizedPath;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Normalises an import path meant for use in an import statement in JavaScript.
|
|
828
|
+
*
|
|
829
|
+
* 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.
|
|
830
|
+
*
|
|
831
|
+
* If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
|
|
832
|
+
*
|
|
833
|
+
* Helpful for custom linter rules that need to check (or fix) import paths.
|
|
834
|
+
*
|
|
835
|
+
* @param importPath - The import path to normalise.
|
|
836
|
+
*
|
|
837
|
+
* @returns The import path normalised.
|
|
838
|
+
*/
|
|
839
|
+
const normaliseImportPath = normalizeImportPath;
|
|
840
|
+
var normalizeImportPath_default = normalizeImportPath;
|
|
841
|
+
|
|
842
|
+
//#endregion
|
|
843
|
+
//#region src/functions/stringHelpers/truncate.ts
|
|
844
|
+
/**
|
|
845
|
+
* Truncates a string and appends `...` to the end of it
|
|
846
|
+
*
|
|
847
|
+
* @param stringToTruncate - The string to truncate.
|
|
848
|
+
* @param maxLength - The length at which to start truncating. Note that this does not include the `...` part that would be appended.
|
|
849
|
+
*
|
|
850
|
+
* @returns A new string that has been truncated based on the length provided.
|
|
851
|
+
*/
|
|
852
|
+
function truncate(stringToTruncate, maxLength = 5) {
|
|
853
|
+
return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
|
|
854
|
+
}
|
|
855
|
+
var truncate_default = truncate;
|
|
856
|
+
|
|
857
|
+
//#endregion
|
|
858
|
+
//#region src/functions/taggedTemplate/createTemplateStringsArray.ts
|
|
859
|
+
/**
|
|
860
|
+
* Creates a template strings array given a regular array of strings
|
|
861
|
+
*
|
|
862
|
+
* @param strings - The array of strings.
|
|
863
|
+
*
|
|
864
|
+
* @returns A template strings array that can be passed as the first argument of any tagged template function.
|
|
865
|
+
*/
|
|
866
|
+
function createTemplateStringsArray(strings) {
|
|
867
|
+
return deepFreeze_default(Object.assign([...strings], { raw: [...strings] }));
|
|
868
|
+
}
|
|
869
|
+
var createTemplateStringsArray_default = createTemplateStringsArray;
|
|
608
870
|
|
|
609
871
|
//#endregion
|
|
610
872
|
//#region src/functions/taggedTemplate/interpolate.ts
|
|
873
|
+
/**
|
|
874
|
+
* Returns the result of interpolating a template string when given the strings and interpolations separately.
|
|
875
|
+
*
|
|
876
|
+
* You can pass a template string directly by doing:
|
|
877
|
+
*
|
|
878
|
+
* interpolate`Template string here`.
|
|
879
|
+
*
|
|
880
|
+
* In this case, it will be functionally the same as if you just wrote the template string by itself.
|
|
881
|
+
*
|
|
882
|
+
* @param strings - The strings from the template to process.
|
|
883
|
+
* @param interpolations - An array of all interpolations from the template.
|
|
884
|
+
*
|
|
885
|
+
* @returns A new string with the strings and interpolations from the template applied.
|
|
886
|
+
*/
|
|
611
887
|
function interpolate(strings, ...interpolations) {
|
|
612
888
|
let result = "";
|
|
613
889
|
for (const [string, interpolation = ""] of paralleliseArrays_default(strings, interpolations)) result += string + interpolation;
|
|
@@ -617,11 +893,23 @@ var interpolate_default = interpolate;
|
|
|
617
893
|
|
|
618
894
|
//#endregion
|
|
619
895
|
//#region src/functions/taggedTemplate/interpolateObjects.ts
|
|
620
|
-
|
|
896
|
+
/**
|
|
897
|
+
* Returns the result of interpolating a template string, also stringifying objects.
|
|
898
|
+
*
|
|
899
|
+
* You can pass a template string directly by doing:
|
|
900
|
+
*
|
|
901
|
+
* interpolateObjects`Template string here ${{ my: "object" }}`.
|
|
902
|
+
*
|
|
903
|
+
* @param strings - The strings from the template to process.
|
|
904
|
+
* @param interpolations - An array of all interpolations from the template.
|
|
905
|
+
*
|
|
906
|
+
* @returns A new string with the strings and interpolations from the template applied, with objects stringified.
|
|
907
|
+
*/
|
|
908
|
+
function interpolateObjects(strings, ...interpolations) {
|
|
621
909
|
let result = "";
|
|
622
910
|
for (let i = 0; i < strings.length; i++) {
|
|
623
911
|
result += strings[i];
|
|
624
|
-
if (i !== strings.length - 1) result +=
|
|
912
|
+
if (i !== strings.length - 1) result += interpolations[i] && typeof interpolations[i] === "object" ? JSON.stringify(interpolations[i]) : interpolations[i];
|
|
625
913
|
}
|
|
626
914
|
return result;
|
|
627
915
|
}
|
|
@@ -653,6 +941,26 @@ function reduceLines$1(lines, { preserveTabs = true }) {
|
|
|
653
941
|
}, tabSize).join("") : "") + line.trimStart();
|
|
654
942
|
}).join("\n");
|
|
655
943
|
}
|
|
944
|
+
/**
|
|
945
|
+
* Applies any options if provided, then removes any extraneous indents from a multi-line template string.
|
|
946
|
+
*
|
|
947
|
+
* You can pass a template string directly by doing:
|
|
948
|
+
*
|
|
949
|
+
* normaliseIndents`Template string here
|
|
950
|
+
* with a new line
|
|
951
|
+
* and another new line`.
|
|
952
|
+
*
|
|
953
|
+
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
954
|
+
*
|
|
955
|
+
* normaliseIndents({ preserveTabs: false })`Template string here
|
|
956
|
+
* with a new line
|
|
957
|
+
* and another new line`.
|
|
958
|
+
*
|
|
959
|
+
* @param first - The strings from the template to process, or the options to apply.
|
|
960
|
+
* @param args - An array of all interpolations from the template.
|
|
961
|
+
*
|
|
962
|
+
* @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
963
|
+
*/
|
|
656
964
|
function normaliseIndents(first, ...args) {
|
|
657
965
|
if (typeof first === "object" && first !== null && !Array.isArray(first)) {
|
|
658
966
|
const options$1 = first;
|
|
@@ -664,6 +972,26 @@ function normaliseIndents(first, ...args) {
|
|
|
664
972
|
const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
|
|
665
973
|
return reduceLines$1(interpolate_default(strings, ...[...args]).split("\n"), options);
|
|
666
974
|
}
|
|
975
|
+
/**
|
|
976
|
+
* Applies any options if provided, then removes any extraneous indents from a multi-line template string.
|
|
977
|
+
*
|
|
978
|
+
* You can pass a template string directly by doing:
|
|
979
|
+
*
|
|
980
|
+
* normalizeIndents`Template string here
|
|
981
|
+
* with a new line
|
|
982
|
+
* and another new line`.
|
|
983
|
+
*
|
|
984
|
+
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
985
|
+
*
|
|
986
|
+
* normalizeIndents({ preserveTabs: false })`Template string here
|
|
987
|
+
* with a new line
|
|
988
|
+
* and another new line`.
|
|
989
|
+
*
|
|
990
|
+
* @param first - The strings from the template to process, or the options to apply.
|
|
991
|
+
* @param args - An array of all interpolations from the template.
|
|
992
|
+
*
|
|
993
|
+
* @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
994
|
+
*/
|
|
667
995
|
const normalizeIndents = normaliseIndents;
|
|
668
996
|
var normaliseIndents_default = normaliseIndents;
|
|
669
997
|
|
|
@@ -707,22 +1035,58 @@ function removeIndents(first, ...args) {
|
|
|
707
1035
|
var removeIndents_default = removeIndents;
|
|
708
1036
|
|
|
709
1037
|
//#endregion
|
|
710
|
-
//#region src/functions/
|
|
711
|
-
|
|
712
|
-
|
|
1038
|
+
//#region src/functions/versioning/parseVersion.ts
|
|
1039
|
+
/**
|
|
1040
|
+
* Parses a string and verifies it is a valid package version number.
|
|
1041
|
+
*
|
|
1042
|
+
* Valid formats: `X.Y.Z` or `vX.Y.Z`, where X, Y, and Z are non-negative integers.
|
|
1043
|
+
*
|
|
1044
|
+
* @param input - The version string to parse.
|
|
1045
|
+
* @param options - Extra options to apply.
|
|
1046
|
+
*
|
|
1047
|
+
* @throws {DataError} If the input is not a valid version number.
|
|
1048
|
+
*
|
|
1049
|
+
* @returns The validated version number, prefixed with `v` if it was not already.
|
|
1050
|
+
*/
|
|
1051
|
+
function parseVersion(input, options) {
|
|
1052
|
+
if (!RegExp(VERSION_NUMBER_REGEX_default).test(input)) throw new DataError_default(input, `"${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.`, "INVALID_VERSION");
|
|
1053
|
+
if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
|
|
1054
|
+
return input.startsWith("v") ? input : `v${input}`;
|
|
713
1055
|
}
|
|
714
|
-
var
|
|
1056
|
+
var parseVersion_default = parseVersion;
|
|
715
1057
|
|
|
716
1058
|
//#endregion
|
|
717
|
-
//#region src/functions/
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
1059
|
+
//#region src/functions/versioning/getIndividualVersionNumbers.ts
|
|
1060
|
+
/**
|
|
1061
|
+
* Gets the individual version numbers from a given version number as a tuple of numbers.
|
|
1062
|
+
*
|
|
1063
|
+
* @param version - The version number.
|
|
1064
|
+
*
|
|
1065
|
+
* @returns A tuple of three numbers indicating `[major, minor, patch]`.
|
|
1066
|
+
*/
|
|
1067
|
+
function getIndividualVersionNumbers(version) {
|
|
1068
|
+
return parseVersion_default(version, { omitPrefix: true }).split(".").map((versionNumber) => {
|
|
1069
|
+
return parseIntStrict_default(versionNumber);
|
|
723
1070
|
});
|
|
724
1071
|
}
|
|
725
|
-
var
|
|
1072
|
+
var getIndividualVersionNumbers_default = getIndividualVersionNumbers;
|
|
1073
|
+
|
|
1074
|
+
//#endregion
|
|
1075
|
+
//#region src/functions/versioning/determineVersionType.ts
|
|
1076
|
+
/**
|
|
1077
|
+
* Determines whether the given version is a major, minor, or patch version.
|
|
1078
|
+
*
|
|
1079
|
+
* @param version - The version number.
|
|
1080
|
+
*
|
|
1081
|
+
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
1082
|
+
*/
|
|
1083
|
+
function determineVersionType(version) {
|
|
1084
|
+
const [_major, minor, patch] = getIndividualVersionNumbers_default(version);
|
|
1085
|
+
if (minor === 0 && patch === 0) return "major";
|
|
1086
|
+
if (patch === 0) return "minor";
|
|
1087
|
+
return "patch";
|
|
1088
|
+
}
|
|
1089
|
+
var determineVersionType_default = determineVersionType;
|
|
726
1090
|
|
|
727
1091
|
//#endregion
|
|
728
|
-
export { APIError_default as APIError, DataError_default as DataError, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, Email_default as parseEmail, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, UUID_default as parseUUID, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, removeIndents_default as removeIndents, stringListToArray_default as stringListToArray, stringToBoolean, truncate_default as truncate, wait_default as wait };
|
|
1092
|
+
export { APIError_default as APIError, DataError_default as DataError, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX_default as VERSION_NUMBER_REGEX, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, determineVersionType_default as determineVersionType, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getIndividualVersionNumbers_default as getIndividualVersionNumbers, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, Email_default as parseEmail, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, UUID_default as parseUUID, parseVersion_default as parseVersion, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, removeIndents_default as removeIndents, stringListToArray_default as stringListToArray, stringToBoolean, truncate_default as truncate, wait_default as wait };
|