@alextheman/utility 5.6.1 → 5.6.2
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 +14 -69
- package/dist/index.d.cts +21 -21
- package/dist/index.d.ts +21 -21
- package/dist/index.js +18 -68
- package/dist/internal/index.cjs +17 -52
- package/dist/internal/index.d.cts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +10 -40
- package/dist/node/index.cjs +16 -41
- package/dist/node/index.js +9 -29
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value:
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -7,16 +7,12 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
20
16
|
}
|
|
21
17
|
return to;
|
|
22
18
|
};
|
|
@@ -24,31 +20,25 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
20
|
value: mod,
|
|
25
21
|
enumerable: true
|
|
26
22
|
}) : target, mod));
|
|
27
|
-
|
|
28
23
|
//#endregion
|
|
29
24
|
let zod = require("zod");
|
|
30
25
|
zod = __toESM(zod);
|
|
31
26
|
let libsodium_wrappers = require("libsodium-wrappers");
|
|
32
27
|
libsodium_wrappers = __toESM(libsodium_wrappers);
|
|
33
|
-
|
|
34
28
|
//#region src/root/constants/FILE_PATH_REGEX.ts
|
|
35
29
|
const FILE_PATH_PATTERN = String.raw`(?<directory>.+)[\/\\](?<base>[^\/\\]+)`;
|
|
36
30
|
const FILE_PATH_REGEX = RegExp(`^${FILE_PATH_PATTERN}$`);
|
|
37
|
-
|
|
38
31
|
//#endregion
|
|
39
32
|
//#region src/root/constants/ONE_DAY_IN_MILLISECONDS.ts
|
|
40
33
|
const ONE_DAY_IN_MILLISECONDS = 1440 * 60 * 1e3;
|
|
41
|
-
|
|
42
34
|
//#endregion
|
|
43
35
|
//#region src/root/constants/UUID_REGEX.ts
|
|
44
36
|
const UUID_PATTERN = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
|
|
45
37
|
const UUID_REGEX = new RegExp(`^${UUID_PATTERN}$`);
|
|
46
|
-
|
|
47
38
|
//#endregion
|
|
48
39
|
//#region src/root/constants/VERSION_NUMBER_REGEX.ts
|
|
49
40
|
const VERSION_NUMBER_PATTERN = String.raw`^(?:v)?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$`;
|
|
50
41
|
const VERSION_NUMBER_REGEX = RegExp(`^${VERSION_NUMBER_PATTERN}$`);
|
|
51
|
-
|
|
52
42
|
//#endregion
|
|
53
43
|
//#region src/root/functions/arrayHelpers/fillArray.ts
|
|
54
44
|
/**
|
|
@@ -75,7 +65,6 @@ function fillArray(callback, length = 1) {
|
|
|
75
65
|
})) return Promise.all(outputArray);
|
|
76
66
|
return outputArray;
|
|
77
67
|
}
|
|
78
|
-
|
|
79
68
|
//#endregion
|
|
80
69
|
//#region src/root/functions/arrayHelpers/paralleliseArrays.ts
|
|
81
70
|
/**
|
|
@@ -99,7 +88,6 @@ function paralleliseArrays(firstArray, secondArray) {
|
|
|
99
88
|
for (let i = 0; i < firstArray.length; i++) outputArray.push([firstArray[i], secondArray[i]]);
|
|
100
89
|
return outputArray;
|
|
101
90
|
}
|
|
102
|
-
|
|
103
91
|
//#endregion
|
|
104
92
|
//#region src/root/types/APIError.ts
|
|
105
93
|
const httpErrorCodeLookup = {
|
|
@@ -143,7 +131,6 @@ var APIError = class APIError extends Error {
|
|
|
143
131
|
return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
|
|
144
132
|
}
|
|
145
133
|
};
|
|
146
|
-
|
|
147
134
|
//#endregion
|
|
148
135
|
//#region src/root/types/DataError.ts
|
|
149
136
|
/**
|
|
@@ -233,7 +220,6 @@ var DataError = class DataError extends Error {
|
|
|
233
220
|
throw new Error("Expected a DataError to be thrown but none was thrown");
|
|
234
221
|
}
|
|
235
222
|
};
|
|
236
|
-
|
|
237
223
|
//#endregion
|
|
238
224
|
//#region src/root/types/VersionNumber.ts
|
|
239
225
|
/**
|
|
@@ -258,7 +244,7 @@ var VersionNumber = class VersionNumber {
|
|
|
258
244
|
this.minor = input.minor;
|
|
259
245
|
this.patch = input.patch;
|
|
260
246
|
} else if (typeof input === "string") {
|
|
261
|
-
if (!
|
|
247
|
+
if (!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.`);
|
|
262
248
|
const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
|
|
263
249
|
return parseIntStrict(number);
|
|
264
250
|
});
|
|
@@ -275,7 +261,10 @@ var VersionNumber = class VersionNumber {
|
|
|
275
261
|
this.major = major;
|
|
276
262
|
this.minor = minor;
|
|
277
263
|
this.patch = patch;
|
|
278
|
-
}
|
|
264
|
+
} else throw new DataError({ input }, "INVALID_INPUT", normaliseIndents`
|
|
265
|
+
The provided input can not be parsed into a valid version number.
|
|
266
|
+
Expected either a string of format X.Y.Z or vX.Y.Z, a tuple of three numbers, or another \`VersionNumber\` instance.
|
|
267
|
+
`);
|
|
279
268
|
}
|
|
280
269
|
/**
|
|
281
270
|
* Gets the current version type of the current instance of `VersionNumber`.
|
|
@@ -398,7 +387,6 @@ const zodVersionNumber = zod.default.union([
|
|
|
398
387
|
]).transform((rawVersionNumber) => {
|
|
399
388
|
return new VersionNumber(rawVersionNumber);
|
|
400
389
|
});
|
|
401
|
-
|
|
402
390
|
//#endregion
|
|
403
391
|
//#region src/root/functions/parsers/parseIntStrict.ts
|
|
404
392
|
/**
|
|
@@ -420,7 +408,7 @@ function parseIntStrict(string, radix) {
|
|
|
420
408
|
string,
|
|
421
409
|
radix
|
|
422
410
|
} : { string }, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
|
|
423
|
-
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
411
|
+
if (radix && radix < 10 && [...trimmedString.replace(/^[+-]/, "")].some((character) => {
|
|
424
412
|
return parseInt(character) >= radix;
|
|
425
413
|
})) throw new DataError({
|
|
426
414
|
string,
|
|
@@ -430,7 +418,6 @@ function parseIntStrict(string, radix) {
|
|
|
430
418
|
if (isNaN(parseIntResult)) throw new DataError({ string }, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
|
|
431
419
|
return parseIntResult;
|
|
432
420
|
}
|
|
433
|
-
|
|
434
421
|
//#endregion
|
|
435
422
|
//#region src/root/functions/miscellaneous/getRandomNumber.ts
|
|
436
423
|
/**
|
|
@@ -448,7 +435,6 @@ function getRandomNumber(lowerBound, upperBound) {
|
|
|
448
435
|
const parsedUpperBound = parseIntStrict(`${upperBound}`);
|
|
449
436
|
return Math.floor(Math.random() * (parsedUpperBound - parsedLowerBound + 1) + parsedLowerBound);
|
|
450
437
|
}
|
|
451
|
-
|
|
452
438
|
//#endregion
|
|
453
439
|
//#region src/root/functions/arrayHelpers/randomiseArray.ts
|
|
454
440
|
/**
|
|
@@ -471,7 +457,6 @@ function randomiseArray(array) {
|
|
|
471
457
|
} while (mutableArray.length > 0);
|
|
472
458
|
return outputArray;
|
|
473
459
|
}
|
|
474
|
-
|
|
475
460
|
//#endregion
|
|
476
461
|
//#region src/root/functions/arrayHelpers/range.ts
|
|
477
462
|
/**
|
|
@@ -511,7 +496,6 @@ function range(start, stop, step = 1) {
|
|
|
511
496
|
}
|
|
512
497
|
return numbers;
|
|
513
498
|
}
|
|
514
|
-
|
|
515
499
|
//#endregion
|
|
516
500
|
//#region src/root/functions/arrayHelpers/removeDuplicates.ts
|
|
517
501
|
/**
|
|
@@ -530,7 +514,6 @@ function removeDuplicates(array) {
|
|
|
530
514
|
for (const item of array) if (!outputArray.includes(item)) outputArray.push(item);
|
|
531
515
|
return outputArray;
|
|
532
516
|
}
|
|
533
|
-
|
|
534
517
|
//#endregion
|
|
535
518
|
//#region src/root/functions/date/addDaysToDate.ts
|
|
536
519
|
/**
|
|
@@ -548,7 +531,6 @@ function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement =
|
|
|
548
531
|
newDate.setDate(newDate.getDate() + dayIncrement);
|
|
549
532
|
return newDate;
|
|
550
533
|
}
|
|
551
|
-
|
|
552
534
|
//#endregion
|
|
553
535
|
//#region src/root/functions/date/calculateMonthlyDifference.ts
|
|
554
536
|
/**
|
|
@@ -563,7 +545,6 @@ function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement =
|
|
|
563
545
|
function calculateMonthlyDifference(firstDate, secondDate) {
|
|
564
546
|
return firstDate.getMonth() - secondDate.getMonth();
|
|
565
547
|
}
|
|
566
|
-
|
|
567
548
|
//#endregion
|
|
568
549
|
//#region src/root/functions/date/isSameDate.ts
|
|
569
550
|
/**
|
|
@@ -579,7 +560,6 @@ function calculateMonthlyDifference(firstDate, secondDate) {
|
|
|
579
560
|
function isSameDate(firstDate, secondDate) {
|
|
580
561
|
return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth() && firstDate.getFullYear() === secondDate.getFullYear();
|
|
581
562
|
}
|
|
582
|
-
|
|
583
563
|
//#endregion
|
|
584
564
|
//#region src/root/functions/date/formatDateAndTime.ts
|
|
585
565
|
/**
|
|
@@ -603,7 +583,6 @@ function formatDateAndTime(inputDate) {
|
|
|
603
583
|
if (isSameDate(inputDate, today)) return `Today at ${inputTime}`;
|
|
604
584
|
return `${inputDate.getDate().toString().padStart(2, "0")}/${(inputDate.getMonth() + 1).toString().padStart(2, "0")}/${inputDate.getFullYear().toString()}, ${inputTime}`;
|
|
605
585
|
}
|
|
606
|
-
|
|
607
586
|
//#endregion
|
|
608
587
|
//#region src/root/functions/date/isLeapYear.ts
|
|
609
588
|
/**
|
|
@@ -621,7 +600,6 @@ function isLeapYear(year) {
|
|
|
621
600
|
const parsedYear = parseIntStrict(`${year}`);
|
|
622
601
|
return parsedYear % 4 === 0 && parsedYear % 100 !== 0 || parsedYear % 400 === 0;
|
|
623
602
|
}
|
|
624
|
-
|
|
625
603
|
//#endregion
|
|
626
604
|
//#region src/root/functions/date/isAnniversary.ts
|
|
627
605
|
function checkLeapYear(firstDate, secondDate) {
|
|
@@ -642,7 +620,6 @@ function isAnniversary(firstDate, secondDate) {
|
|
|
642
620
|
if (checkLeapYear(firstDate, secondDate) || checkLeapYear(secondDate, firstDate)) return true;
|
|
643
621
|
return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth();
|
|
644
622
|
}
|
|
645
|
-
|
|
646
623
|
//#endregion
|
|
647
624
|
//#region src/root/functions/date/isMonthlyMultiple.ts
|
|
648
625
|
function endOfMonthChecksButNotFebruary(firstDate, secondDate) {
|
|
@@ -691,7 +668,6 @@ function isMonthlyMultiple(firstDate, secondDate) {
|
|
|
691
668
|
if (leapYearFebruaryChecks(firstDate, secondDate) || leapYearFebruaryChecks(secondDate, firstDate)) return true;
|
|
692
669
|
return firstDate.getDate() === secondDate.getDate();
|
|
693
670
|
}
|
|
694
|
-
|
|
695
671
|
//#endregion
|
|
696
672
|
//#region src/root/functions/miscellaneous/convertFileToBase64.ts
|
|
697
673
|
/**
|
|
@@ -721,7 +697,6 @@ function convertFileToBase64(file) {
|
|
|
721
697
|
};
|
|
722
698
|
});
|
|
723
699
|
}
|
|
724
|
-
|
|
725
700
|
//#endregion
|
|
726
701
|
//#region src/root/functions/miscellaneous/createFormData.ts
|
|
727
702
|
function getNullableResolutionStrategy(key, strategy) {
|
|
@@ -793,7 +768,6 @@ function createFormData(data, options = {
|
|
|
793
768
|
} else formData.append(String(key), String(value));
|
|
794
769
|
return formData;
|
|
795
770
|
}
|
|
796
|
-
|
|
797
771
|
//#endregion
|
|
798
772
|
//#region src/root/functions/miscellaneous/isOrdered.ts
|
|
799
773
|
/**
|
|
@@ -811,7 +785,6 @@ function isOrdered(array) {
|
|
|
811
785
|
for (const index in newArray) if (newArray[index] !== array[index]) return false;
|
|
812
786
|
return true;
|
|
813
787
|
}
|
|
814
|
-
|
|
815
788
|
//#endregion
|
|
816
789
|
//#region src/root/functions/recursive/deepFreeze.ts
|
|
817
790
|
/**
|
|
@@ -835,7 +808,6 @@ function deepFreeze(object) {
|
|
|
835
808
|
}
|
|
836
809
|
return Object.freeze(object);
|
|
837
810
|
}
|
|
838
|
-
|
|
839
811
|
//#endregion
|
|
840
812
|
//#region src/root/functions/taggedTemplate/createTemplateStringsArray.ts
|
|
841
813
|
/**
|
|
@@ -850,7 +822,6 @@ function deepFreeze(object) {
|
|
|
850
822
|
function createTemplateStringsArray(strings) {
|
|
851
823
|
return deepFreeze(Object.assign([...strings], { raw: [...strings] }));
|
|
852
824
|
}
|
|
853
|
-
|
|
854
825
|
//#endregion
|
|
855
826
|
//#region src/root/functions/taggedTemplate/getStringsAndInterpolations.ts
|
|
856
827
|
/**
|
|
@@ -891,7 +862,6 @@ function getStringsAndInterpolations(strings, ...interpolations) {
|
|
|
891
862
|
}, "INVALID_STRINGS_AND_INTERPOLATIONS_LENGTH", "The length of the strings must be exactly one more than the length of the interpolations.");
|
|
892
863
|
return [createTemplateStringsArray(strings), ...interpolations];
|
|
893
864
|
}
|
|
894
|
-
|
|
895
865
|
//#endregion
|
|
896
866
|
//#region src/root/functions/taggedTemplate/interpolate.ts
|
|
897
867
|
/**
|
|
@@ -919,7 +889,6 @@ function interpolate(strings, ...interpolations) {
|
|
|
919
889
|
for (const [string, interpolation = ""] of paralleliseArrays(strings, interpolations)) result += string + interpolation;
|
|
920
890
|
return result;
|
|
921
891
|
}
|
|
922
|
-
|
|
923
892
|
//#endregion
|
|
924
893
|
//#region src/root/functions/taggedTemplate/interpolateObjects.ts
|
|
925
894
|
/**
|
|
@@ -948,7 +917,6 @@ function interpolateObjects(strings, ...interpolations) {
|
|
|
948
917
|
}
|
|
949
918
|
return result;
|
|
950
919
|
}
|
|
951
|
-
|
|
952
920
|
//#endregion
|
|
953
921
|
//#region src/root/functions/taggedTemplate/isTemplateStringsArray.ts
|
|
954
922
|
/**
|
|
@@ -963,7 +931,6 @@ function interpolateObjects(strings, ...interpolations) {
|
|
|
963
931
|
function isTemplateStringsArray(input) {
|
|
964
932
|
return typeof input === "object" && input !== null && "raw" in input;
|
|
965
933
|
}
|
|
966
|
-
|
|
967
934
|
//#endregion
|
|
968
935
|
//#region src/root/functions/taggedTemplate/normaliseIndents.ts
|
|
969
936
|
function calculateTabSize(line, whitespaceLength) {
|
|
@@ -1052,7 +1019,6 @@ function normaliseIndents(first, ...args) {
|
|
|
1052
1019
|
* @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
1053
1020
|
*/
|
|
1054
1021
|
const normalizeIndents = normaliseIndents;
|
|
1055
|
-
|
|
1056
1022
|
//#endregion
|
|
1057
1023
|
//#region src/root/functions/miscellaneous/sayHello.ts
|
|
1058
1024
|
/**
|
|
@@ -1166,7 +1132,6 @@ function sayHello() {
|
|
|
1166
1132
|
I'll commit to you!
|
|
1167
1133
|
`;
|
|
1168
1134
|
}
|
|
1169
|
-
|
|
1170
1135
|
//#endregion
|
|
1171
1136
|
//#region src/root/functions/miscellaneous/stringifyDotenv.ts
|
|
1172
1137
|
/**
|
|
@@ -1202,7 +1167,6 @@ function stringifyDotenv(contents, options) {
|
|
|
1202
1167
|
}
|
|
1203
1168
|
return result;
|
|
1204
1169
|
}
|
|
1205
|
-
|
|
1206
1170
|
//#endregion
|
|
1207
1171
|
//#region src/root/functions/miscellaneous/stringListToArray.ts
|
|
1208
1172
|
/**
|
|
@@ -1224,7 +1188,6 @@ function stringListToArray(stringList, { separator = ",", trimWhitespace = true
|
|
|
1224
1188
|
return item.trim();
|
|
1225
1189
|
}) : arrayList;
|
|
1226
1190
|
}
|
|
1227
|
-
|
|
1228
1191
|
//#endregion
|
|
1229
1192
|
//#region src/root/functions/miscellaneous/wait.ts
|
|
1230
1193
|
/**
|
|
@@ -1243,7 +1206,6 @@ function wait(seconds) {
|
|
|
1243
1206
|
}, seconds * 1e3);
|
|
1244
1207
|
});
|
|
1245
1208
|
}
|
|
1246
|
-
|
|
1247
1209
|
//#endregion
|
|
1248
1210
|
//#region src/root/functions/objectHelpers/getRecordKeys.ts
|
|
1249
1211
|
/**
|
|
@@ -1260,7 +1222,6 @@ function wait(seconds) {
|
|
|
1260
1222
|
function getRecordKeys(record) {
|
|
1261
1223
|
return Object.keys(record);
|
|
1262
1224
|
}
|
|
1263
|
-
|
|
1264
1225
|
//#endregion
|
|
1265
1226
|
//#region src/root/functions/objectHelpers/omitProperties.ts
|
|
1266
1227
|
/**
|
|
@@ -1283,7 +1244,6 @@ function omitProperties(object, keysToOmit) {
|
|
|
1283
1244
|
});
|
|
1284
1245
|
return outputObject;
|
|
1285
1246
|
}
|
|
1286
|
-
|
|
1287
1247
|
//#endregion
|
|
1288
1248
|
//#region src/root/functions/objectHelpers/removeUndefinedFromObject.ts
|
|
1289
1249
|
/**
|
|
@@ -1298,7 +1258,6 @@ function removeUndefinedFromObject(object) {
|
|
|
1298
1258
|
return value !== void 0;
|
|
1299
1259
|
}));
|
|
1300
1260
|
}
|
|
1301
|
-
|
|
1302
1261
|
//#endregion
|
|
1303
1262
|
//#region src/root/functions/parsers/parseBoolean.ts
|
|
1304
1263
|
/**
|
|
@@ -1317,7 +1276,6 @@ function parseBoolean(inputString) {
|
|
|
1317
1276
|
if (!["true", "false"].includes(normalisedString)) throw new DataError({ inputString }, "INVALID_BOOLEAN_STRING", "The provided boolean string must be one of `true | false`");
|
|
1318
1277
|
return normalisedString === "true";
|
|
1319
1278
|
}
|
|
1320
|
-
|
|
1321
1279
|
//#endregion
|
|
1322
1280
|
//#region src/root/functions/parsers/zod/_parseZodSchema.ts
|
|
1323
1281
|
function _parseZodSchema(parsedResult, input, onError) {
|
|
@@ -1342,7 +1300,6 @@ function _parseZodSchema(parsedResult, input, onError) {
|
|
|
1342
1300
|
}
|
|
1343
1301
|
return parsedResult.data;
|
|
1344
1302
|
}
|
|
1345
|
-
|
|
1346
1303
|
//#endregion
|
|
1347
1304
|
//#region src/root/functions/parsers/zod/parseZodSchema.ts
|
|
1348
1305
|
/**
|
|
@@ -1366,7 +1323,6 @@ function _parseZodSchema(parsedResult, input, onError) {
|
|
|
1366
1323
|
function parseZodSchema(schema, input, onError) {
|
|
1367
1324
|
return _parseZodSchema(schema.safeParse(input), input, onError);
|
|
1368
1325
|
}
|
|
1369
|
-
|
|
1370
1326
|
//#endregion
|
|
1371
1327
|
//#region src/root/functions/parsers/parseEnv.ts
|
|
1372
1328
|
/**
|
|
@@ -1393,7 +1349,6 @@ const Env = {
|
|
|
1393
1349
|
function parseEnv(input) {
|
|
1394
1350
|
return parseZodSchema(zod.z.enum(Env), input, new DataError({ input }, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
|
|
1395
1351
|
}
|
|
1396
|
-
|
|
1397
1352
|
//#endregion
|
|
1398
1353
|
//#region src/root/functions/parsers/parseFormData.ts
|
|
1399
1354
|
/**
|
|
@@ -1416,7 +1371,6 @@ function parseFormData(formData, dataParser) {
|
|
|
1416
1371
|
if (dataParser) return dataParser(object);
|
|
1417
1372
|
return object;
|
|
1418
1373
|
}
|
|
1419
|
-
|
|
1420
1374
|
//#endregion
|
|
1421
1375
|
//#region src/root/functions/parsers/parseUUID.ts
|
|
1422
1376
|
/**
|
|
@@ -1435,7 +1389,6 @@ function parseUUID(input) {
|
|
|
1435
1389
|
if (!UUID_REGEX.test(input)) throw new DataError({ input }, "INVALID_UUID", "The provided input does not match the expected shape for a UUID.");
|
|
1436
1390
|
return input;
|
|
1437
1391
|
}
|
|
1438
|
-
|
|
1439
1392
|
//#endregion
|
|
1440
1393
|
//#region src/root/functions/parsers/parseVersionType.ts
|
|
1441
1394
|
/**
|
|
@@ -1462,7 +1415,6 @@ const VersionType = {
|
|
|
1462
1415
|
function parseVersionType(input) {
|
|
1463
1416
|
return parseZodSchema(zod.default.enum(VersionType), input, new DataError({ input }, "INVALID_VERSION_TYPE", "The provided version type must be one of `major | minor | patch`"));
|
|
1464
1417
|
}
|
|
1465
|
-
|
|
1466
1418
|
//#endregion
|
|
1467
1419
|
//#region src/root/functions/parsers/zod/parseZodSchemaAsync.ts
|
|
1468
1420
|
/**
|
|
@@ -1484,7 +1436,6 @@ function parseVersionType(input) {
|
|
|
1484
1436
|
async function parseZodSchemaAsync(schema, input, onError) {
|
|
1485
1437
|
return _parseZodSchema(await schema.safeParseAsync(input), input, onError);
|
|
1486
1438
|
}
|
|
1487
|
-
|
|
1488
1439
|
//#endregion
|
|
1489
1440
|
//#region src/root/functions/recursive/deepCopy.ts
|
|
1490
1441
|
function callDeepCopy(input) {
|
|
@@ -1512,7 +1463,6 @@ function deepCopy(object) {
|
|
|
1512
1463
|
}
|
|
1513
1464
|
return clonedObject;
|
|
1514
1465
|
}
|
|
1515
|
-
|
|
1516
1466
|
//#endregion
|
|
1517
1467
|
//#region src/root/functions/security/encryptWithKey.ts
|
|
1518
1468
|
/**
|
|
@@ -1533,7 +1483,6 @@ async function encryptWithKey(publicKey, plaintextValue) {
|
|
|
1533
1483
|
throw new DataError({ publicKey }, "ENCRYPTION_FAILED", "Encryption failed. Please double-check that the given key is a valid base 64 string.");
|
|
1534
1484
|
}
|
|
1535
1485
|
}
|
|
1536
|
-
|
|
1537
1486
|
//#endregion
|
|
1538
1487
|
//#region src/root/functions/stringHelpers/appendSemicolon.ts
|
|
1539
1488
|
/**
|
|
@@ -1553,7 +1502,6 @@ function appendSemicolon(stringToAppendTo) {
|
|
|
1553
1502
|
if (stringWithNoTrailingWhitespace === "") return "";
|
|
1554
1503
|
return stringWithNoTrailingWhitespace[stringWithNoTrailingWhitespace.length - 1] === ";" ? stringWithNoTrailingWhitespace : `${stringWithNoTrailingWhitespace};`;
|
|
1555
1504
|
}
|
|
1556
|
-
|
|
1557
1505
|
//#endregion
|
|
1558
1506
|
//#region src/root/functions/stringHelpers/camelToKebab.ts
|
|
1559
1507
|
/**
|
|
@@ -1592,7 +1540,6 @@ function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
|
|
|
1592
1540
|
}
|
|
1593
1541
|
return result;
|
|
1594
1542
|
}
|
|
1595
|
-
|
|
1596
1543
|
//#endregion
|
|
1597
1544
|
//#region src/root/functions/stringHelpers/kebabToCamel.ts
|
|
1598
1545
|
/**
|
|
@@ -1632,7 +1579,6 @@ function kebabToCamel(input, options) {
|
|
|
1632
1579
|
}
|
|
1633
1580
|
return outputString;
|
|
1634
1581
|
}
|
|
1635
|
-
|
|
1636
1582
|
//#endregion
|
|
1637
1583
|
//#region src/root/functions/stringHelpers/truncate.ts
|
|
1638
1584
|
/**
|
|
@@ -1648,7 +1594,6 @@ function kebabToCamel(input, options) {
|
|
|
1648
1594
|
function truncate(stringToTruncate, maxLength = 5) {
|
|
1649
1595
|
return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
|
|
1650
1596
|
}
|
|
1651
|
-
|
|
1652
1597
|
//#endregion
|
|
1653
1598
|
exports.APIError = APIError;
|
|
1654
1599
|
exports.DataError = DataError;
|
|
@@ -1708,4 +1653,4 @@ exports.stringListToArray = stringListToArray;
|
|
|
1708
1653
|
exports.stringifyDotenv = stringifyDotenv;
|
|
1709
1654
|
exports.truncate = truncate;
|
|
1710
1655
|
exports.wait = wait;
|
|
1711
|
-
exports.zodVersionNumber = zodVersionNumber;
|
|
1656
|
+
exports.zodVersionNumber = zodVersionNumber;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import z, { ZodError, ZodType, z
|
|
1
|
+
import z$1, { ZodError, ZodType, z } from "zod";
|
|
2
2
|
import { DotenvParseOutput } from "dotenv";
|
|
3
3
|
|
|
4
4
|
//#region src/root/constants/FILE_PATH_REGEX.d.ts
|
|
@@ -30,7 +30,7 @@ declare const VERSION_NUMBER_REGEX: RegExp;
|
|
|
30
30
|
*
|
|
31
31
|
* @returns A Promise resolving to an array of the callback results.
|
|
32
32
|
*/
|
|
33
|
-
declare function fillArray<ItemType>(callback: (index: number) => Promise<ItemType>, length?: number): Promise<ItemType
|
|
33
|
+
declare function fillArray<ItemType>(callback: (index: number) => Promise<ItemType>, length?: number): Promise<Array<ItemType>>;
|
|
34
34
|
/**
|
|
35
35
|
* Creates a new array where each element is the result of the provided synchronous callback.
|
|
36
36
|
*
|
|
@@ -44,7 +44,7 @@ declare function fillArray<ItemType>(callback: (index: number) => Promise<ItemTy
|
|
|
44
44
|
*
|
|
45
45
|
* @returns An array of the callback results.
|
|
46
46
|
*/
|
|
47
|
-
declare function fillArray<ItemType>(callback: (index: number) => ItemType, length?: number): ItemType
|
|
47
|
+
declare function fillArray<ItemType>(callback: (index: number) => ItemType, length?: number): Array<ItemType>;
|
|
48
48
|
//#endregion
|
|
49
49
|
//#region src/root/functions/arrayHelpers/paralleliseArrays.d.ts
|
|
50
50
|
type ParallelTuple<A, B> = [A, B | undefined];
|
|
@@ -64,7 +64,7 @@ type ParallelTuple<A, B> = [A, B | undefined];
|
|
|
64
64
|
*
|
|
65
65
|
* @returns An array of `[firstItem, secondItem]` tuples for each index in `firstArray`.
|
|
66
66
|
*/
|
|
67
|
-
declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray:
|
|
67
|
+
declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray: ReadonlyArray<FirstArrayItem>, secondArray: ReadonlyArray<SecondArrayItem>): Array<ParallelTuple<FirstArrayItem, SecondArrayItem>>;
|
|
68
68
|
//#endregion
|
|
69
69
|
//#region src/root/functions/arrayHelpers/randomiseArray.d.ts
|
|
70
70
|
/**
|
|
@@ -78,7 +78,7 @@ declare function paralleliseArrays<FirstArrayItem, SecondArrayItem>(firstArray:
|
|
|
78
78
|
*
|
|
79
79
|
* @returns A new array with the items randomised.
|
|
80
80
|
*/
|
|
81
|
-
declare function randomiseArray<ItemType>(array: ItemType
|
|
81
|
+
declare function randomiseArray<ItemType>(array: Array<ItemType>): Array<ItemType>;
|
|
82
82
|
//#endregion
|
|
83
83
|
//#region src/root/functions/arrayHelpers/range.d.ts
|
|
84
84
|
/**
|
|
@@ -98,7 +98,7 @@ declare function randomiseArray<ItemType>(array: ItemType[]): ItemType[];
|
|
|
98
98
|
*
|
|
99
99
|
* @returns An array of numbers satisfying the range provided.
|
|
100
100
|
*/
|
|
101
|
-
declare function range(start: number, stop: number, step?: number): number
|
|
101
|
+
declare function range(start: number, stop: number, step?: number): Array<number>;
|
|
102
102
|
//#endregion
|
|
103
103
|
//#region src/root/functions/arrayHelpers/removeDuplicates.d.ts
|
|
104
104
|
/**
|
|
@@ -112,7 +112,7 @@ declare function range(start: number, stop: number, step?: number): number[];
|
|
|
112
112
|
*
|
|
113
113
|
* @returns A new array with a different reference in memory, with the duplicates removed.
|
|
114
114
|
*/
|
|
115
|
-
declare function removeDuplicates<ItemType>(array: ItemType
|
|
115
|
+
declare function removeDuplicates<ItemType>(array: Array<ItemType> | ReadonlyArray<ItemType>): Array<ItemType>;
|
|
116
116
|
//#endregion
|
|
117
117
|
//#region src/root/functions/date/addDaysToDate.d.ts
|
|
118
118
|
/**
|
|
@@ -409,7 +409,7 @@ declare class VersionNumber {
|
|
|
409
409
|
*/
|
|
410
410
|
toString(): string;
|
|
411
411
|
}
|
|
412
|
-
declare const zodVersionNumber: z.ZodType<VersionNumber>;
|
|
412
|
+
declare const zodVersionNumber: z$1.ZodType<VersionNumber>;
|
|
413
413
|
//#endregion
|
|
414
414
|
//#region src/root/types/ArrayElement.d.ts
|
|
415
415
|
/**
|
|
@@ -419,7 +419,7 @@ declare const zodVersionNumber: z.ZodType<VersionNumber>;
|
|
|
419
419
|
*
|
|
420
420
|
* @template ArrayType - The type of the array itself.
|
|
421
421
|
*/
|
|
422
|
-
type ArrayElement<ArrayType extends
|
|
422
|
+
type ArrayElement<ArrayType extends ReadonlyArray<unknown>> = ArrayType extends ReadonlyArray<infer ElementType> ? ElementType : never;
|
|
423
423
|
//#endregion
|
|
424
424
|
//#region src/root/types/CallReturnType.d.ts
|
|
425
425
|
type CallReturnType<Function, Arguments> = Function extends ((arg: Arguments) => infer Return) ? Return : never;
|
|
@@ -578,7 +578,7 @@ declare function getRandomNumber(lowerBound: number, upperBound: number): number
|
|
|
578
578
|
*
|
|
579
579
|
* @returns `true` if the array is sorted in ascending order, and `false` otherwise.
|
|
580
580
|
*/
|
|
581
|
-
declare function isOrdered(array:
|
|
581
|
+
declare function isOrdered(array: ReadonlyArray<number>): boolean;
|
|
582
582
|
//#endregion
|
|
583
583
|
//#region src/root/functions/miscellaneous/sayHello.d.ts
|
|
584
584
|
/**
|
|
@@ -633,7 +633,7 @@ interface StringListToArrayOptions {
|
|
|
633
633
|
declare function stringListToArray(stringList: string, {
|
|
634
634
|
separator,
|
|
635
635
|
trimWhitespace
|
|
636
|
-
}?: StringListToArrayOptions): string
|
|
636
|
+
}?: StringListToArrayOptions): Array<string>;
|
|
637
637
|
//#endregion
|
|
638
638
|
//#region src/root/functions/miscellaneous/wait.d.ts
|
|
639
639
|
/**
|
|
@@ -659,7 +659,7 @@ declare function wait(seconds: number): Promise<void>;
|
|
|
659
659
|
*
|
|
660
660
|
* @returns An array with all the keys of the input object in string form, but properly typed as `keyof InputRecordType`.
|
|
661
661
|
*/
|
|
662
|
-
declare function getRecordKeys<InputRecordType extends Record<RecordKey, unknown>>(record: InputRecordType & object):
|
|
662
|
+
declare function getRecordKeys<InputRecordType extends Record<RecordKey, unknown>>(record: InputRecordType & object): Array<keyof InputRecordType>;
|
|
663
663
|
//#endregion
|
|
664
664
|
//#region src/root/functions/objectHelpers/omitProperties.d.ts
|
|
665
665
|
/**
|
|
@@ -675,7 +675,7 @@ declare function getRecordKeys<InputRecordType extends Record<RecordKey, unknown
|
|
|
675
675
|
*
|
|
676
676
|
* @returns An object with a new reference in memory, with the properties omitted.
|
|
677
677
|
*/
|
|
678
|
-
declare function omitProperties<ObjectType extends Record<string, unknown> | Readonly<Record<string, unknown>>, KeysToOmit extends keyof ObjectType>(object: ObjectType, keysToOmit: KeysToOmit |
|
|
678
|
+
declare function omitProperties<ObjectType extends Record<string, unknown> | Readonly<Record<string, unknown>>, KeysToOmit extends keyof ObjectType>(object: ObjectType, keysToOmit: KeysToOmit | ReadonlyArray<KeysToOmit>): Omit<ObjectType, KeysToOmit>;
|
|
679
679
|
//#endregion
|
|
680
680
|
//#region src/root/functions/objectHelpers/removeUndefinedFromObject.d.ts
|
|
681
681
|
type RemoveUndefined<RecordType extends Record<RecordKey, unknown>> = { [Key in keyof RecordType]: Exclude<RecordType[Key], undefined> };
|
|
@@ -821,7 +821,7 @@ declare function parseVersionType(input: unknown): VersionType;
|
|
|
821
821
|
*
|
|
822
822
|
* @returns The parsed data from the Zod schema.
|
|
823
823
|
*/
|
|
824
|
-
declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error = DataError>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z
|
|
824
|
+
declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error = DataError>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z.infer<SchemaType>;
|
|
825
825
|
//#endregion
|
|
826
826
|
//#region src/root/functions/parsers/zod/parseZodSchemaAsync.d.ts
|
|
827
827
|
/**
|
|
@@ -840,7 +840,7 @@ declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Er
|
|
|
840
840
|
*
|
|
841
841
|
* @returns The parsed data from the Zod schema.
|
|
842
842
|
*/
|
|
843
|
-
declare function parseZodSchemaAsync<SchemaType extends ZodType, ErrorType extends Error = DataError>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): Promise<z
|
|
843
|
+
declare function parseZodSchemaAsync<SchemaType extends ZodType, ErrorType extends Error = DataError>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): Promise<z.infer<SchemaType>>;
|
|
844
844
|
//#endregion
|
|
845
845
|
//#region src/root/functions/recursive/deepCopy.d.ts
|
|
846
846
|
/**
|
|
@@ -965,7 +965,7 @@ declare function truncate(stringToTruncate: string, maxLength?: number): string;
|
|
|
965
965
|
*
|
|
966
966
|
* @returns A template strings array that can be passed as the first argument of any tagged template function.
|
|
967
967
|
*/
|
|
968
|
-
declare function createTemplateStringsArray(strings:
|
|
968
|
+
declare function createTemplateStringsArray(strings: ReadonlyArray<string>): TemplateStringsArray;
|
|
969
969
|
//#endregion
|
|
970
970
|
//#region src/root/functions/taggedTemplate/getStringsAndInterpolations.d.ts
|
|
971
971
|
/**
|
|
@@ -997,7 +997,7 @@ declare function createTemplateStringsArray(strings: readonly string[]): Templat
|
|
|
997
997
|
* interpolate(...getStringsAndInterpolations`The package ${packageName} uses the ${packageManager} package manager.`);
|
|
998
998
|
* ```
|
|
999
999
|
*/
|
|
1000
|
-
declare function getStringsAndInterpolations<const InterpolationsType extends
|
|
1000
|
+
declare function getStringsAndInterpolations<const InterpolationsType extends ReadonlyArray<unknown>>(strings: TemplateStringsArray, ...interpolations: InterpolationsType): [TemplateStringsArray, ...InterpolationsType];
|
|
1001
1001
|
//#endregion
|
|
1002
1002
|
//#region src/root/functions/taggedTemplate/interpolate.d.ts
|
|
1003
1003
|
/**
|
|
@@ -1020,7 +1020,7 @@ declare function getStringsAndInterpolations<const InterpolationsType extends re
|
|
|
1020
1020
|
*
|
|
1021
1021
|
* @returns A new string with the strings and interpolations from the template applied.
|
|
1022
1022
|
*/
|
|
1023
|
-
declare function interpolate<const InterpolationsType extends
|
|
1023
|
+
declare function interpolate<const InterpolationsType extends ReadonlyArray<unknown>>(strings: TemplateStringsArray, ...interpolations: InterpolationsType): string;
|
|
1024
1024
|
//#endregion
|
|
1025
1025
|
//#region src/root/functions/taggedTemplate/interpolateObjects.d.ts
|
|
1026
1026
|
/**
|
|
@@ -1041,7 +1041,7 @@ declare function interpolate<const InterpolationsType extends readonly unknown[]
|
|
|
1041
1041
|
*
|
|
1042
1042
|
* @returns A new string with the strings and interpolations from the template applied, with objects stringified.
|
|
1043
1043
|
*/
|
|
1044
|
-
declare function interpolateObjects<const InterpolationsType extends
|
|
1044
|
+
declare function interpolateObjects<const InterpolationsType extends ReadonlyArray<unknown>>(strings: TemplateStringsArray, ...interpolations: InterpolationsType): string;
|
|
1045
1045
|
//#endregion
|
|
1046
1046
|
//#region src/root/functions/taggedTemplate/isTemplateStringsArray.d.ts
|
|
1047
1047
|
/**
|
|
@@ -1066,7 +1066,7 @@ interface NormaliseIndentsOptions {
|
|
|
1066
1066
|
preserveTabs?: boolean;
|
|
1067
1067
|
}
|
|
1068
1068
|
type NormalizeIndentsOptions = NormaliseIndentsOptions;
|
|
1069
|
-
type NormaliseIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown
|
|
1069
|
+
type NormaliseIndentsFunction = (strings: TemplateStringsArray, ...interpolations: Array<unknown>) => string;
|
|
1070
1070
|
type NormalizeIndentsFunction = NormaliseIndentsFunction;
|
|
1071
1071
|
/**
|
|
1072
1072
|
* Provides a new function that removes any extraneous indents from a multi-line template string, with the given options applied.
|
|
@@ -1096,7 +1096,7 @@ declare function normaliseIndents(options: NormaliseIndentsOptions): NormaliseIn
|
|
|
1096
1096
|
*
|
|
1097
1097
|
* @returns A new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
1098
1098
|
*/
|
|
1099
|
-
declare function normaliseIndents(strings: TemplateStringsArray, ...interpolations: unknown
|
|
1099
|
+
declare function normaliseIndents(strings: TemplateStringsArray, ...interpolations: Array<unknown>): string;
|
|
1100
1100
|
/**
|
|
1101
1101
|
* Applies any options if provided, then removes any extraneous indents from a multi-line template string.
|
|
1102
1102
|
*
|