@alextheman/utility 3.5.10 → 3.7.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 +526 -219
- package/dist/index.d.cts +477 -120
- package/dist/index.d.ts +478 -121
- package/dist/index.js +526 -219
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -25,25 +25,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
|
-
let path = require("path");
|
|
29
|
-
path = __toESM(path);
|
|
30
28
|
let zod = require("zod");
|
|
31
29
|
zod = __toESM(zod);
|
|
30
|
+
let path = require("path");
|
|
31
|
+
path = __toESM(path);
|
|
32
32
|
|
|
33
33
|
//#region src/constants/NAMESPACE_EXPORT_REGEX.ts
|
|
34
34
|
const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
35
35
|
var NAMESPACE_EXPORT_REGEX_default = NAMESPACE_EXPORT_REGEX;
|
|
36
36
|
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region src/functions/appendSemicolon.ts
|
|
39
|
-
function appendSemicolon(stringToAppendTo) {
|
|
40
|
-
if (stringToAppendTo.includes("\n")) throw new Error("MULTIPLE_LINE_ERROR");
|
|
41
|
-
const stringWithNoTrailingWhitespace = stringToAppendTo.trimEnd();
|
|
42
|
-
if (stringWithNoTrailingWhitespace === "") return "";
|
|
43
|
-
return stringWithNoTrailingWhitespace[stringWithNoTrailingWhitespace.length - 1] === ";" ? stringWithNoTrailingWhitespace : `${stringWithNoTrailingWhitespace};`;
|
|
44
|
-
}
|
|
45
|
-
var appendSemicolon_default = appendSemicolon;
|
|
46
|
-
|
|
47
37
|
//#endregion
|
|
48
38
|
//#region src/functions/arrayHelpers/fillArray.ts
|
|
49
39
|
/**
|
|
@@ -96,7 +86,17 @@ var paralleliseArrays_default = paralleliseArrays;
|
|
|
96
86
|
//#endregion
|
|
97
87
|
//#region src/functions/parsers/parseIntStrict.ts
|
|
98
88
|
const IntegerParsingError = /* @__PURE__ */ new TypeError("INTEGER_PARSING_ERROR");
|
|
99
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Converts a string to an integer and throws an error if it cannot be converted.
|
|
91
|
+
*
|
|
92
|
+
* @param string — A string to convert into a number.
|
|
93
|
+
* @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.
|
|
94
|
+
*
|
|
95
|
+
* @throws {TypeError} If the provided string cannot safely be converted to an integer.
|
|
96
|
+
*
|
|
97
|
+
* @returns The integer parsed from the input string.
|
|
98
|
+
*/
|
|
99
|
+
function parseIntStrict(string, radix) {
|
|
100
100
|
const trimmedString = string.trim();
|
|
101
101
|
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${String.fromCharCode(87 + radix - 1)}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw IntegerParsingError;
|
|
102
102
|
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
@@ -109,7 +109,15 @@ function parseIntStrict(...[string, radix]) {
|
|
|
109
109
|
var parseIntStrict_default = parseIntStrict;
|
|
110
110
|
|
|
111
111
|
//#endregion
|
|
112
|
-
//#region src/functions/getRandomNumber.ts
|
|
112
|
+
//#region src/functions/miscellaneous/getRandomNumber.ts
|
|
113
|
+
/**
|
|
114
|
+
* Gets a random number between the given bounds.
|
|
115
|
+
*
|
|
116
|
+
* @param lowerBound - The lowest number that can be chosen.
|
|
117
|
+
* @param upperBound - The highest number that can be chosen.
|
|
118
|
+
*
|
|
119
|
+
* @returns A random number between the provided lower bound and upper bound.
|
|
120
|
+
*/
|
|
113
121
|
function getRandomNumber(lowerBound, upperBound) {
|
|
114
122
|
const parsedLowerBound = parseIntStrict_default(`${lowerBound}`);
|
|
115
123
|
const parsedUpperBound = parseIntStrict_default(`${upperBound}`);
|
|
@@ -144,8 +152,8 @@ var randomiseArray_default = randomiseArray;
|
|
|
144
152
|
/**
|
|
145
153
|
* Creates an array of numbers within a given range.
|
|
146
154
|
*
|
|
147
|
-
* The range is inclusive of `start` and exclusive of `stop`.
|
|
148
|
-
* The sign of `step` must match the direction of the range.
|
|
155
|
+
* - The range is inclusive of `start` and exclusive of `stop`.
|
|
156
|
+
* - The sign of `step` must match the direction of the range.
|
|
149
157
|
*
|
|
150
158
|
* @param start - The number to start at (inclusive).
|
|
151
159
|
* @param stop - The number to stop at (exclusive).
|
|
@@ -171,96 +179,22 @@ function range(start, stop, step = 1) {
|
|
|
171
179
|
var range_default = range;
|
|
172
180
|
|
|
173
181
|
//#endregion
|
|
174
|
-
//#region src/functions/
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
reject(/* @__PURE__ */ new Error("FILE_CONVERSION_ERROR"));
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
resolve(reader.result);
|
|
192
|
-
};
|
|
193
|
-
reader.onerror = () => {
|
|
194
|
-
reject(/* @__PURE__ */ new Error("FILE_READER_ERROR"));
|
|
195
|
-
};
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
var convertFileToBase64_default = convertFileToBase64;
|
|
199
|
-
|
|
200
|
-
//#endregion
|
|
201
|
-
//#region src/functions/createFormData.ts
|
|
202
|
-
function getNullableResolutionStrategy(key, strategy) {
|
|
203
|
-
return (typeof strategy === "object" ? strategy[key] : strategy) ?? "empty";
|
|
204
|
-
}
|
|
205
|
-
function createFormData(data, options = {
|
|
206
|
-
arrayResolution: "stringify",
|
|
207
|
-
nullableResolution: "empty"
|
|
208
|
-
}) {
|
|
209
|
-
const formData = new FormData();
|
|
210
|
-
function resolveNullablesByStrategy(key, value, resolutionStrategy) {
|
|
211
|
-
switch (resolutionStrategy) {
|
|
212
|
-
case "empty":
|
|
213
|
-
formData.append(String(key), "");
|
|
214
|
-
break;
|
|
215
|
-
case "stringify":
|
|
216
|
-
formData.append(String(key), JSON.stringify(value));
|
|
217
|
-
break;
|
|
218
|
-
case "omit": break;
|
|
219
|
-
default: throw new TypeError("SLOPPY_PURE_JAVASCRIPT_USER_ERROR");
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
function resolveNullables(key, value, options$1) {
|
|
223
|
-
if (options$1.nullableResolution) {
|
|
224
|
-
resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.nullableResolution));
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
if (options$1.undefinedResolution || options$1.nullResolution) {
|
|
228
|
-
if (data[key] === void 0 && options$1.undefinedResolution) {
|
|
229
|
-
resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.undefinedResolution));
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
if (data[key] === null && options$1.nullResolution) resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.nullResolution));
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
const entries = Object.entries(data);
|
|
236
|
-
for (const [key, value] of entries) if (value instanceof Blob) formData.append(String(key), value);
|
|
237
|
-
else if (value === void 0 || value === null) resolveNullables(key, value, options);
|
|
238
|
-
else if (typeof value === "object") {
|
|
239
|
-
if (Array.isArray(value)) {
|
|
240
|
-
if (value.some((item) => {
|
|
241
|
-
return item instanceof Blob;
|
|
242
|
-
}) && (options.arrayResolution === "stringify" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "stringify")) throw new TypeError("CANNOT_STRINGIFY_BLOB");
|
|
243
|
-
if (options.arrayResolution === "multiple" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "multiple") {
|
|
244
|
-
for (const item of value) {
|
|
245
|
-
if ((typeof item === "object" || !item) && !(item instanceof Blob)) throw new TypeError("NON_PRIMITIVE_ARRAY_ITEMS_FOUND");
|
|
246
|
-
if (item instanceof Blob) formData.append(String(key), item);
|
|
247
|
-
else formData.append(String(key), String(item));
|
|
248
|
-
}
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
formData.append(String(key), JSON.stringify(value));
|
|
253
|
-
} else formData.append(String(key), String(value));
|
|
254
|
-
return formData;
|
|
255
|
-
}
|
|
256
|
-
var createFormData_default = createFormData;
|
|
257
|
-
|
|
258
|
-
//#endregion
|
|
259
|
-
//#region src/functions/createTemplateStringsArray.ts
|
|
260
|
-
function createTemplateStringsArray(strings) {
|
|
261
|
-
return Object.assign([...strings], { raw: [...strings] });
|
|
182
|
+
//#region src/functions/arrayHelpers/removeDuplicates.ts
|
|
183
|
+
/**
|
|
184
|
+
* Removes duplicate values from an array.
|
|
185
|
+
*
|
|
186
|
+
* @template ItemType - The type of the array items.
|
|
187
|
+
*
|
|
188
|
+
* @param array - The array to remove duplicates from.
|
|
189
|
+
*
|
|
190
|
+
* @returns A new array with a different reference in memory, with the duplicates removed.
|
|
191
|
+
*/
|
|
192
|
+
function removeDuplicates(array) {
|
|
193
|
+
const outputArray = [];
|
|
194
|
+
for (const item of array) if (!outputArray.includes(item)) outputArray.push(item);
|
|
195
|
+
return outputArray;
|
|
262
196
|
}
|
|
263
|
-
var
|
|
197
|
+
var removeDuplicates_default = removeDuplicates;
|
|
264
198
|
|
|
265
199
|
//#endregion
|
|
266
200
|
//#region src/functions/date/addDaysToDate.ts
|
|
@@ -403,43 +337,111 @@ function isMonthlyMultiple(firstDate, secondDate) {
|
|
|
403
337
|
var isMonthlyMultiple_default = isMonthlyMultiple;
|
|
404
338
|
|
|
405
339
|
//#endregion
|
|
406
|
-
//#region src/functions/
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
340
|
+
//#region src/functions/miscellaneous/convertFileToBase64.ts
|
|
341
|
+
/**
|
|
342
|
+
* Asynchronously converts a file to a base 64 string
|
|
343
|
+
*
|
|
344
|
+
* @param file - The file to convert.
|
|
345
|
+
*
|
|
346
|
+
* @throws {Error} If the file reader gives an error.
|
|
347
|
+
*
|
|
348
|
+
* @returns A promise that resolves to the encoded base 64 string.
|
|
349
|
+
*/
|
|
350
|
+
function convertFileToBase64(file) {
|
|
351
|
+
return new Promise((resolve, reject) => {
|
|
352
|
+
const reader = new FileReader();
|
|
353
|
+
reader.readAsDataURL(file);
|
|
354
|
+
reader.onload = () => {
|
|
355
|
+
if (reader.result === null) {
|
|
356
|
+
reject(/* @__PURE__ */ new Error("FILE_CONVERSION_ERROR"));
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
resolve(reader.result);
|
|
360
|
+
};
|
|
361
|
+
reader.onerror = () => {
|
|
362
|
+
reject(/* @__PURE__ */ new Error("FILE_READER_ERROR"));
|
|
363
|
+
};
|
|
413
364
|
});
|
|
414
|
-
const clonedObject = { ...object };
|
|
415
|
-
for (const key in clonedObject) {
|
|
416
|
-
const value = clonedObject[key];
|
|
417
|
-
clonedObject[key] = callDeepCopy(value);
|
|
418
|
-
}
|
|
419
|
-
return clonedObject;
|
|
420
365
|
}
|
|
421
|
-
var
|
|
366
|
+
var convertFileToBase64_default = convertFileToBase64;
|
|
422
367
|
|
|
423
368
|
//#endregion
|
|
424
|
-
//#region src/functions/
|
|
425
|
-
function
|
|
426
|
-
|
|
427
|
-
if (typeof value === "function") continue;
|
|
428
|
-
if (value && typeof value === "object") deepFreeze(value);
|
|
429
|
-
}
|
|
430
|
-
return Object.freeze(object);
|
|
369
|
+
//#region src/functions/miscellaneous/createFormData.ts
|
|
370
|
+
function getNullableResolutionStrategy(key, strategy) {
|
|
371
|
+
return (typeof strategy === "object" ? strategy[key] : strategy) ?? "empty";
|
|
431
372
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
373
|
+
/**
|
|
374
|
+
* Creates FormData from a given object, resolving non-string types as appropriate.
|
|
375
|
+
*
|
|
376
|
+
* @template DataType - The type of the given data.
|
|
377
|
+
*
|
|
378
|
+
* @param data - The data to create FormData from.
|
|
379
|
+
* @param options - Options to apply to the conversion.
|
|
380
|
+
*
|
|
381
|
+
* @returns A FormData object with the data applied.
|
|
382
|
+
*/
|
|
383
|
+
function createFormData(data, options = {
|
|
384
|
+
arrayResolution: "stringify",
|
|
385
|
+
nullableResolution: "empty"
|
|
386
|
+
}) {
|
|
387
|
+
const formData = new FormData();
|
|
388
|
+
function resolveNullablesByStrategy(key, value, resolutionStrategy) {
|
|
389
|
+
switch (resolutionStrategy) {
|
|
390
|
+
case "empty":
|
|
391
|
+
formData.append(String(key), "");
|
|
392
|
+
break;
|
|
393
|
+
case "stringify":
|
|
394
|
+
formData.append(String(key), JSON.stringify(value));
|
|
395
|
+
break;
|
|
396
|
+
case "omit": break;
|
|
397
|
+
default: throw new TypeError("SLOPPY_PURE_JAVASCRIPT_USER_ERROR");
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
function resolveNullables(key, value, options$1) {
|
|
401
|
+
if (options$1.nullableResolution) {
|
|
402
|
+
resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.nullableResolution));
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (options$1.undefinedResolution || options$1.nullResolution) {
|
|
406
|
+
if (data[key] === void 0 && options$1.undefinedResolution) {
|
|
407
|
+
resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.undefinedResolution));
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
if (data[key] === null && options$1.nullResolution) resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.nullResolution));
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
const entries = Object.entries(data);
|
|
414
|
+
for (const [key, value] of entries) if (value instanceof Blob) formData.append(String(key), value);
|
|
415
|
+
else if (value === void 0 || value === null) resolveNullables(key, value, options);
|
|
416
|
+
else if (typeof value === "object") {
|
|
417
|
+
if (Array.isArray(value)) {
|
|
418
|
+
if (value.some((item) => {
|
|
419
|
+
return item instanceof Blob;
|
|
420
|
+
}) && (options.arrayResolution === "stringify" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "stringify")) throw new TypeError("CANNOT_STRINGIFY_BLOB");
|
|
421
|
+
if (options.arrayResolution === "multiple" || typeof options.arrayResolution === "object" && options.arrayResolution[key] === "multiple") {
|
|
422
|
+
for (const item of value) {
|
|
423
|
+
if ((typeof item === "object" || !item) && !(item instanceof Blob)) throw new TypeError("NON_PRIMITIVE_ARRAY_ITEMS_FOUND");
|
|
424
|
+
if (item instanceof Blob) formData.append(String(key), item);
|
|
425
|
+
else formData.append(String(key), String(item));
|
|
426
|
+
}
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
formData.append(String(key), JSON.stringify(value));
|
|
431
|
+
} else formData.append(String(key), String(value));
|
|
432
|
+
return formData;
|
|
438
433
|
}
|
|
439
|
-
var
|
|
434
|
+
var createFormData_default = createFormData;
|
|
440
435
|
|
|
441
436
|
//#endregion
|
|
442
|
-
//#region src/functions/isOrdered.ts
|
|
437
|
+
//#region src/functions/miscellaneous/isOrdered.ts
|
|
438
|
+
/**
|
|
439
|
+
* Checks to see if the given array is sorted in ascending order.
|
|
440
|
+
*
|
|
441
|
+
* @param array - The array to check.
|
|
442
|
+
*
|
|
443
|
+
* @returns `true` if the array is sorted in ascending order, and `false` otherwise.
|
|
444
|
+
*/
|
|
443
445
|
function isOrdered(array) {
|
|
444
446
|
const newArray = [...array];
|
|
445
447
|
newArray.sort();
|
|
@@ -449,47 +451,73 @@ function isOrdered(array) {
|
|
|
449
451
|
var isOrdered_default = isOrdered;
|
|
450
452
|
|
|
451
453
|
//#endregion
|
|
452
|
-
//#region src/functions/
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
outputString += string[index];
|
|
470
|
-
break;
|
|
471
|
-
}
|
|
472
|
-
if (string[index] === "-" && /^[a-zA-Z]+$/.test(string[index + 1])) {
|
|
473
|
-
outputString += string[index + 1].toUpperCase();
|
|
474
|
-
skip = true;
|
|
475
|
-
} else outputString += string[index];
|
|
476
|
-
}
|
|
477
|
-
return outputString;
|
|
478
|
-
}
|
|
479
|
-
var kebabToCamel_default = kebabToCamel;
|
|
480
|
-
|
|
481
|
-
//#endregion
|
|
482
|
-
//#region src/functions/normalizeImportPath.ts
|
|
483
|
-
function normalizeImportPath(importPath) {
|
|
484
|
-
const normalizedPath = path.default.posix.normalize(importPath);
|
|
485
|
-
if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) return `./${normalizedPath}`;
|
|
486
|
-
return normalizedPath;
|
|
454
|
+
//#region src/functions/miscellaneous/stringListToArray.ts
|
|
455
|
+
/**
|
|
456
|
+
* Converts a stringly-typed list to a proper array.
|
|
457
|
+
*
|
|
458
|
+
* @param stringList - The stringly-typed list to convert.
|
|
459
|
+
* @param options - The options to apply to the conversion.
|
|
460
|
+
* @param options.separator - What each item in the list is separated by.
|
|
461
|
+
* @param options.trimWhitespace - An option to trim any extra whitespace.
|
|
462
|
+
*
|
|
463
|
+
* @returns A new array with each item being an item from the given list.
|
|
464
|
+
*/
|
|
465
|
+
function stringListToArray(stringList, { separator = ",", trimWhitespace = true } = {}) {
|
|
466
|
+
if (trimWhitespace && stringList.trim() === "") return [];
|
|
467
|
+
const arrayList = stringList.split(separator ?? "");
|
|
468
|
+
return trimWhitespace ? arrayList.map((item) => {
|
|
469
|
+
return item.trim();
|
|
470
|
+
}) : arrayList;
|
|
487
471
|
}
|
|
488
|
-
|
|
489
|
-
|
|
472
|
+
var stringListToArray_default = stringListToArray;
|
|
473
|
+
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region src/functions/miscellaneous/wait.ts
|
|
476
|
+
/**
|
|
477
|
+
* Waits for the given number of seconds
|
|
478
|
+
*
|
|
479
|
+
* @param seconds - The number of seconds to wait.
|
|
480
|
+
*
|
|
481
|
+
* @returns A Promise that resolves after the given number of seconds.
|
|
482
|
+
*/
|
|
483
|
+
function wait(seconds) {
|
|
484
|
+
return new Promise((resolve, _) => {
|
|
485
|
+
setTimeout(() => {
|
|
486
|
+
resolve();
|
|
487
|
+
}, seconds * 1e3);
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
var wait_default = wait;
|
|
491
|
+
|
|
492
|
+
//#endregion
|
|
493
|
+
//#region src/functions/objectHelpers/getRecordKeys.ts
|
|
494
|
+
/**
|
|
495
|
+
* Gets the keys from a given record object, properly typed to be an array of the key of the input object's type.
|
|
496
|
+
*
|
|
497
|
+
* @template InputRecordType - The type of the input object.
|
|
498
|
+
*
|
|
499
|
+
* @param record - The record to get the keys from.
|
|
500
|
+
*
|
|
501
|
+
* @returns An array with all the keys of the input object in string form, but properly typed as `keyof InputRecordType`.
|
|
502
|
+
*/
|
|
503
|
+
function getRecordKeys(record) {
|
|
504
|
+
return Object.keys(record);
|
|
505
|
+
}
|
|
506
|
+
var getRecordKeys_default = getRecordKeys;
|
|
490
507
|
|
|
491
508
|
//#endregion
|
|
492
|
-
//#region src/functions/omitProperties.ts
|
|
509
|
+
//#region src/functions/objectHelpers/omitProperties.ts
|
|
510
|
+
/**
|
|
511
|
+
* Omits properties from a given object.
|
|
512
|
+
*
|
|
513
|
+
* @template ObjectType - The type of the input object.
|
|
514
|
+
* @template KeysToOmit - A type representing the keys to omit from the object.
|
|
515
|
+
*
|
|
516
|
+
* @param object - The object to omit properties from.
|
|
517
|
+
* @param keysToOmit - The keys to omit from the object. Can either be a single string to omit one, or an array to omit multiple.
|
|
518
|
+
*
|
|
519
|
+
* @returns An object with a new reference in memory, with the properties omitted.
|
|
520
|
+
*/
|
|
493
521
|
function omitProperties(object, keysToOmit) {
|
|
494
522
|
const outputObject = { ...object };
|
|
495
523
|
(Array.isArray(keysToOmit) ? keysToOmit : [keysToOmit]).forEach((key) => {
|
|
@@ -501,6 +529,15 @@ var omitProperties_default = omitProperties;
|
|
|
501
529
|
|
|
502
530
|
//#endregion
|
|
503
531
|
//#region src/functions/parsers/parseBoolean.ts
|
|
532
|
+
/**
|
|
533
|
+
* Takes a stringly-typed boolean and converts it to an actual boolean type.
|
|
534
|
+
*
|
|
535
|
+
* @param inputString - The string to parse.
|
|
536
|
+
*
|
|
537
|
+
* @throws {TypeError} If the string is not either `true` or `false` (case insensitive).
|
|
538
|
+
*
|
|
539
|
+
* @returns The string parsed as an actual boolean.
|
|
540
|
+
*/
|
|
504
541
|
function parseBoolean(inputString) {
|
|
505
542
|
const normalisedString = inputString.toLowerCase();
|
|
506
543
|
if (!["true", "false"].includes(normalisedString)) throw new TypeError("INVALID_BOOLEAN_STRING");
|
|
@@ -510,8 +547,39 @@ function parseBoolean(inputString) {
|
|
|
510
547
|
const stringToBoolean = parseBoolean;
|
|
511
548
|
var parseBoolean_default = parseBoolean;
|
|
512
549
|
|
|
550
|
+
//#endregion
|
|
551
|
+
//#region src/functions/parsers/parseEnv.ts
|
|
552
|
+
const envSchema = zod.z.enum([
|
|
553
|
+
"test",
|
|
554
|
+
"development",
|
|
555
|
+
"production"
|
|
556
|
+
]);
|
|
557
|
+
/**
|
|
558
|
+
* Parses the input and verifies it matches one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
559
|
+
*
|
|
560
|
+
* @param data - The data to parse.
|
|
561
|
+
*
|
|
562
|
+
* @throws {ZodError} If the data does not match one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
563
|
+
*
|
|
564
|
+
* @returns The specified environment if allowed.
|
|
565
|
+
*/
|
|
566
|
+
function parseEnv(data) {
|
|
567
|
+
return envSchema.parse(data);
|
|
568
|
+
}
|
|
569
|
+
var parseEnv_default = parseEnv;
|
|
570
|
+
|
|
513
571
|
//#endregion
|
|
514
572
|
//#region src/functions/parsers/parseFormData.ts
|
|
573
|
+
/**
|
|
574
|
+
* Returns an object given FormData and an optional data parser function to call on the resulting object.
|
|
575
|
+
*
|
|
576
|
+
* @template DataType - The type of the resulting object when called from the dataParser.
|
|
577
|
+
*
|
|
578
|
+
* @param formData - The FormData to parse.
|
|
579
|
+
* @param dataParser - An optional parser to call on the object before it gets returned.
|
|
580
|
+
*
|
|
581
|
+
* @returns A parsed object based on the contents of the input formData and the result of parsing with the data parser if provided.
|
|
582
|
+
*/
|
|
515
583
|
function parseFormData(formData, dataParser) {
|
|
516
584
|
const object = {};
|
|
517
585
|
formData.forEach((value, key) => {
|
|
@@ -532,8 +600,14 @@ const httpErrorCodeLookup = {
|
|
|
532
600
|
418: "I_AM_A_TEAPOT",
|
|
533
601
|
500: "INTERNAL_SERVER_ERROR"
|
|
534
602
|
};
|
|
603
|
+
/** Represents common errors you may get from a HTTP API request. */
|
|
535
604
|
var APIError = class extends Error {
|
|
536
605
|
status;
|
|
606
|
+
/**
|
|
607
|
+
* @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.
|
|
608
|
+
* @param message - An error message to display alongside the status code.
|
|
609
|
+
* @param options - Extra options to be passed to super Error constructor.
|
|
610
|
+
*/
|
|
537
611
|
constructor(status = 500, message, options) {
|
|
538
612
|
super(message, options);
|
|
539
613
|
this.status = status;
|
|
@@ -542,6 +616,13 @@ var APIError = class extends Error {
|
|
|
542
616
|
Object.defineProperty(this, "message", { enumerable: true });
|
|
543
617
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
544
618
|
}
|
|
619
|
+
/**
|
|
620
|
+
* Checks whether the given input may have been caused by an APIError.
|
|
621
|
+
*
|
|
622
|
+
* @param input - The input to check.
|
|
623
|
+
*
|
|
624
|
+
* @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`.
|
|
625
|
+
*/
|
|
545
626
|
static check(input) {
|
|
546
627
|
const data = input;
|
|
547
628
|
return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
|
|
@@ -551,6 +632,7 @@ var APIError_default = APIError;
|
|
|
551
632
|
|
|
552
633
|
//#endregion
|
|
553
634
|
//#region src/types/DataError.ts
|
|
635
|
+
/** Represents errors you may get that may've been caused by a specific piece of data. */
|
|
554
636
|
var DataError = class extends Error {
|
|
555
637
|
data;
|
|
556
638
|
code;
|
|
@@ -569,6 +651,13 @@ var DataError = class extends Error {
|
|
|
569
651
|
Object.defineProperty(this, "message", { enumerable: true });
|
|
570
652
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
571
653
|
}
|
|
654
|
+
/**
|
|
655
|
+
* Checks whether the given input may have been caused by a DataError.
|
|
656
|
+
*
|
|
657
|
+
* @param input - The input to check.
|
|
658
|
+
*
|
|
659
|
+
* @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`.
|
|
660
|
+
*/
|
|
572
661
|
static check(input) {
|
|
573
662
|
const data = input;
|
|
574
663
|
return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
|
|
@@ -579,26 +668,16 @@ var DataError_default = DataError;
|
|
|
579
668
|
//#endregion
|
|
580
669
|
//#region src/types/Email.ts
|
|
581
670
|
const emailSchema = zod.default.email().brand();
|
|
671
|
+
/** @deprecated Please use `z.email().parse() from Zod instead.`*/
|
|
582
672
|
function parseEmail(data) {
|
|
583
673
|
return emailSchema.parse(data);
|
|
584
674
|
}
|
|
585
675
|
var Email_default = parseEmail;
|
|
586
676
|
|
|
587
|
-
//#endregion
|
|
588
|
-
//#region src/types/Env.ts
|
|
589
|
-
const envSchema = zod.z.enum([
|
|
590
|
-
"test",
|
|
591
|
-
"development",
|
|
592
|
-
"production"
|
|
593
|
-
]);
|
|
594
|
-
function parseEnv(data = "development") {
|
|
595
|
-
return envSchema.parse(data);
|
|
596
|
-
}
|
|
597
|
-
var Env_default = parseEnv;
|
|
598
|
-
|
|
599
677
|
//#endregion
|
|
600
678
|
//#region src/types/UUID.ts
|
|
601
679
|
const uuidSchema = zod.default.uuid().brand();
|
|
680
|
+
/** @deprecated Please use `z.uuid().parse() from Zod instead.`*/
|
|
602
681
|
function parseUUID(UUID) {
|
|
603
682
|
return uuidSchema.parse(UUID);
|
|
604
683
|
}
|
|
@@ -606,6 +685,20 @@ var UUID_default = parseUUID;
|
|
|
606
685
|
|
|
607
686
|
//#endregion
|
|
608
687
|
//#region src/functions/parsers/parseZodSchema.ts
|
|
688
|
+
/**
|
|
689
|
+
* An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
|
|
690
|
+
*
|
|
691
|
+
* @template Output - The Zod output type.
|
|
692
|
+
* @template Input - The Zod input type.
|
|
693
|
+
* @template Internals - The Zod internal types based on the output and input types.
|
|
694
|
+
*
|
|
695
|
+
* @param schema - The Zod schema to use in parsing.
|
|
696
|
+
* @param data - The data to parse.
|
|
697
|
+
*
|
|
698
|
+
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
699
|
+
*
|
|
700
|
+
* @returns The parsed data from the Zod schema.
|
|
701
|
+
*/
|
|
609
702
|
function parseZodSchema(schema, data) {
|
|
610
703
|
const parsedResult = schema.safeParse(data);
|
|
611
704
|
if (!parsedResult.success) throw new DataError_default(data);
|
|
@@ -614,27 +707,207 @@ function parseZodSchema(schema, data) {
|
|
|
614
707
|
var parseZodSchema_default = parseZodSchema;
|
|
615
708
|
|
|
616
709
|
//#endregion
|
|
617
|
-
//#region src/functions/
|
|
618
|
-
function
|
|
619
|
-
|
|
620
|
-
for (const item of array) if (!outputArray.includes(item)) outputArray.push(item);
|
|
621
|
-
return outputArray;
|
|
710
|
+
//#region src/functions/recursive/deepCopy.ts
|
|
711
|
+
function callDeepCopy(input) {
|
|
712
|
+
return typeof input === "object" && input !== null ? deepCopy(input) : input;
|
|
622
713
|
}
|
|
623
|
-
|
|
714
|
+
/**
|
|
715
|
+
* Deeply copies an object or array such that all child objects/arrays are also copied.
|
|
716
|
+
*
|
|
717
|
+
* @template ObjectType - The type of the input object.
|
|
718
|
+
*
|
|
719
|
+
* @param object - The object to copy. May also be an array.
|
|
720
|
+
*
|
|
721
|
+
* @returns An identical object with a new reference in memory.
|
|
722
|
+
*/
|
|
723
|
+
function deepCopy(object) {
|
|
724
|
+
if (Array.isArray(object)) return object.map((item) => {
|
|
725
|
+
return callDeepCopy(item);
|
|
726
|
+
});
|
|
727
|
+
const clonedObject = { ...object };
|
|
728
|
+
for (const key in clonedObject) {
|
|
729
|
+
const value = clonedObject[key];
|
|
730
|
+
clonedObject[key] = callDeepCopy(value);
|
|
731
|
+
}
|
|
732
|
+
return clonedObject;
|
|
733
|
+
}
|
|
734
|
+
var deepCopy_default = deepCopy;
|
|
624
735
|
|
|
625
736
|
//#endregion
|
|
626
|
-
//#region src/functions/
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
737
|
+
//#region src/functions/recursive/deepFreeze.ts
|
|
738
|
+
/**
|
|
739
|
+
* Deeply freezes an object or array such that all child objects/arrays are also frozen.
|
|
740
|
+
*
|
|
741
|
+
* Note that this will also freeze the input itself as well.
|
|
742
|
+
* 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.
|
|
743
|
+
*
|
|
744
|
+
* @template ObjectType - The type of the input object.
|
|
745
|
+
*
|
|
746
|
+
* @param object - The object to freeze. May also be an array.
|
|
747
|
+
*
|
|
748
|
+
* @returns The input object completely frozen.
|
|
749
|
+
*/
|
|
750
|
+
function deepFreeze(object) {
|
|
751
|
+
for (const value of Object.values(object)) {
|
|
752
|
+
if (typeof value === "function") continue;
|
|
753
|
+
if (value && typeof value === "object") deepFreeze(value);
|
|
754
|
+
}
|
|
755
|
+
return Object.freeze(object);
|
|
633
756
|
}
|
|
634
|
-
var
|
|
757
|
+
var deepFreeze_default = deepFreeze;
|
|
758
|
+
|
|
759
|
+
//#endregion
|
|
760
|
+
//#region src/functions/stringHelpers/appendSemicolon.ts
|
|
761
|
+
/**
|
|
762
|
+
* Appends a semicolon to the end of a string, trimming where necessary first.
|
|
763
|
+
*
|
|
764
|
+
* @param stringToAppendTo - The string to append a semicolon to.
|
|
765
|
+
*
|
|
766
|
+
* @throws {Error} If the string contains multiple lines.
|
|
767
|
+
*
|
|
768
|
+
* @returns A string with the semicolon appended.
|
|
769
|
+
*/
|
|
770
|
+
function appendSemicolon(stringToAppendTo) {
|
|
771
|
+
if (stringToAppendTo.includes("\n")) throw new Error("MULTIPLE_LINE_ERROR");
|
|
772
|
+
const stringWithNoTrailingWhitespace = stringToAppendTo.trimEnd();
|
|
773
|
+
if (stringWithNoTrailingWhitespace === "") return "";
|
|
774
|
+
return stringWithNoTrailingWhitespace[stringWithNoTrailingWhitespace.length - 1] === ";" ? stringWithNoTrailingWhitespace : `${stringWithNoTrailingWhitespace};`;
|
|
775
|
+
}
|
|
776
|
+
var appendSemicolon_default = appendSemicolon;
|
|
777
|
+
|
|
778
|
+
//#endregion
|
|
779
|
+
//#region src/functions/stringHelpers/camelToKebab.ts
|
|
780
|
+
/**
|
|
781
|
+
* Converts a string from camelCase to kebab-case
|
|
782
|
+
*
|
|
783
|
+
* @param string - The string to convert.
|
|
784
|
+
*
|
|
785
|
+
* @returns The string converted to kebab-case.
|
|
786
|
+
*/
|
|
787
|
+
function camelToKebab(string) {
|
|
788
|
+
return string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").toLowerCase();
|
|
789
|
+
}
|
|
790
|
+
var camelToKebab_default = camelToKebab;
|
|
791
|
+
|
|
792
|
+
//#endregion
|
|
793
|
+
//#region src/functions/stringHelpers/kebabToCamel.ts
|
|
794
|
+
/**
|
|
795
|
+
* Converts a string from kebab-case to camelCase
|
|
796
|
+
*
|
|
797
|
+
* @param string - The string to convert.
|
|
798
|
+
* @param options - Options to apply to the conversion.
|
|
799
|
+
*
|
|
800
|
+
* @returns The string converted to camelCase.
|
|
801
|
+
*/
|
|
802
|
+
function kebabToCamel(string, options) {
|
|
803
|
+
if (string !== string.toLowerCase()) throw new Error("INVALID_KEBAB_CASE_INPUT");
|
|
804
|
+
if (string.startsWith("-") || string.endsWith("-") || string.includes("--")) throw new Error("INVALID_KEBAB_CASE_INPUT");
|
|
805
|
+
let outputString = "";
|
|
806
|
+
let skip = false;
|
|
807
|
+
for (const stringIndex in [...string]) {
|
|
808
|
+
if (skip) {
|
|
809
|
+
skip = false;
|
|
810
|
+
continue;
|
|
811
|
+
}
|
|
812
|
+
const index = parseIntStrict_default(stringIndex);
|
|
813
|
+
if (index === 0 && options?.startWithUpper) {
|
|
814
|
+
outputString += string[index].toUpperCase();
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
if (index === string.length - 1) {
|
|
818
|
+
outputString += string[index];
|
|
819
|
+
break;
|
|
820
|
+
}
|
|
821
|
+
if (string[index] === "-" && /^[a-zA-Z]+$/.test(string[index + 1])) {
|
|
822
|
+
outputString += string[index + 1].toUpperCase();
|
|
823
|
+
skip = true;
|
|
824
|
+
} else outputString += string[index];
|
|
825
|
+
}
|
|
826
|
+
return outputString;
|
|
827
|
+
}
|
|
828
|
+
var kebabToCamel_default = kebabToCamel;
|
|
829
|
+
|
|
830
|
+
//#endregion
|
|
831
|
+
//#region src/functions/stringHelpers/normalizeImportPath.ts
|
|
832
|
+
/**
|
|
833
|
+
* Normalizes an import path meant for use in an import statement in JavaScript.
|
|
834
|
+
*
|
|
835
|
+
* 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.
|
|
836
|
+
*
|
|
837
|
+
* If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
|
|
838
|
+
*
|
|
839
|
+
* Helpful for custom linter rules that need to check (or fix) import paths.
|
|
840
|
+
*
|
|
841
|
+
* @param importPath - The import path to normalize.
|
|
842
|
+
*
|
|
843
|
+
* @returns The import path normalized.
|
|
844
|
+
*/
|
|
845
|
+
function normalizeImportPath(importPath) {
|
|
846
|
+
const normalizedPath = path.default.posix.normalize(importPath);
|
|
847
|
+
if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) return `./${normalizedPath}`;
|
|
848
|
+
return normalizedPath;
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Normalises an import path meant for use in an import statement in JavaScript.
|
|
852
|
+
*
|
|
853
|
+
* 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.
|
|
854
|
+
*
|
|
855
|
+
* If the path starts with ./, it is preserved (unlike what would happen with path.posix.normalize() normally).
|
|
856
|
+
*
|
|
857
|
+
* Helpful for custom linter rules that need to check (or fix) import paths.
|
|
858
|
+
*
|
|
859
|
+
* @param importPath - The import path to normalise.
|
|
860
|
+
*
|
|
861
|
+
* @returns The import path normalised.
|
|
862
|
+
*/
|
|
863
|
+
const normaliseImportPath = normalizeImportPath;
|
|
864
|
+
var normalizeImportPath_default = normalizeImportPath;
|
|
865
|
+
|
|
866
|
+
//#endregion
|
|
867
|
+
//#region src/functions/stringHelpers/truncate.ts
|
|
868
|
+
/**
|
|
869
|
+
* Truncates a string and appends `...` to the end of it
|
|
870
|
+
*
|
|
871
|
+
* @param stringToTruncate - The string to truncate.
|
|
872
|
+
* @param maxLength - The length at which to start truncating. Note that this does not include the `...` part that would be appended.
|
|
873
|
+
*
|
|
874
|
+
* @returns A new string that has been truncated based on the length provided.
|
|
875
|
+
*/
|
|
876
|
+
function truncate(stringToTruncate, maxLength = 5) {
|
|
877
|
+
return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
|
|
878
|
+
}
|
|
879
|
+
var truncate_default = truncate;
|
|
880
|
+
|
|
881
|
+
//#endregion
|
|
882
|
+
//#region src/functions/taggedTemplate/createTemplateStringsArray.ts
|
|
883
|
+
/**
|
|
884
|
+
* Creates a template strings array given a regular array of strings
|
|
885
|
+
*
|
|
886
|
+
* @param strings - The array of strings.
|
|
887
|
+
*
|
|
888
|
+
* @returns A template strings array that can be passed as the first argument of any tagged template function.
|
|
889
|
+
*/
|
|
890
|
+
function createTemplateStringsArray(strings) {
|
|
891
|
+
return deepFreeze_default(Object.assign([...strings], { raw: [...strings] }));
|
|
892
|
+
}
|
|
893
|
+
var createTemplateStringsArray_default = createTemplateStringsArray;
|
|
635
894
|
|
|
636
895
|
//#endregion
|
|
637
896
|
//#region src/functions/taggedTemplate/interpolate.ts
|
|
897
|
+
/**
|
|
898
|
+
* Returns the result of interpolating a template string when given the strings and interpolations separately.
|
|
899
|
+
*
|
|
900
|
+
* You can pass a template string directly by doing:
|
|
901
|
+
*
|
|
902
|
+
* interpolate`Template string here`.
|
|
903
|
+
*
|
|
904
|
+
* In this case, it will be functionally the same as if you just wrote the template string by itself.
|
|
905
|
+
*
|
|
906
|
+
* @param strings - The strings from the template to process.
|
|
907
|
+
* @param interpolations - An array of all interpolations from the template.
|
|
908
|
+
*
|
|
909
|
+
* @returns A new string with the strings and interpolations from the template applied.
|
|
910
|
+
*/
|
|
638
911
|
function interpolate(strings, ...interpolations) {
|
|
639
912
|
let result = "";
|
|
640
913
|
for (const [string, interpolation = ""] of paralleliseArrays_default(strings, interpolations)) result += string + interpolation;
|
|
@@ -644,11 +917,23 @@ var interpolate_default = interpolate;
|
|
|
644
917
|
|
|
645
918
|
//#endregion
|
|
646
919
|
//#region src/functions/taggedTemplate/interpolateObjects.ts
|
|
647
|
-
|
|
920
|
+
/**
|
|
921
|
+
* Returns the result of interpolating a template string, also stringifying objects.
|
|
922
|
+
*
|
|
923
|
+
* You can pass a template string directly by doing:
|
|
924
|
+
*
|
|
925
|
+
* interpolateObjects`Template string here ${{ my: "object" }}`.
|
|
926
|
+
*
|
|
927
|
+
* @param strings - The strings from the template to process.
|
|
928
|
+
* @param interpolations - An array of all interpolations from the template.
|
|
929
|
+
*
|
|
930
|
+
* @returns A new string with the strings and interpolations from the template applied, with objects stringified.
|
|
931
|
+
*/
|
|
932
|
+
function interpolateObjects(strings, ...interpolations) {
|
|
648
933
|
let result = "";
|
|
649
934
|
for (let i = 0; i < strings.length; i++) {
|
|
650
935
|
result += strings[i];
|
|
651
|
-
if (i !== strings.length - 1) result +=
|
|
936
|
+
if (i !== strings.length - 1) result += interpolations[i] && typeof interpolations[i] === "object" ? JSON.stringify(interpolations[i]) : interpolations[i];
|
|
652
937
|
}
|
|
653
938
|
return result;
|
|
654
939
|
}
|
|
@@ -680,6 +965,26 @@ function reduceLines$1(lines, { preserveTabs = true }) {
|
|
|
680
965
|
}, tabSize).join("") : "") + line.trimStart();
|
|
681
966
|
}).join("\n");
|
|
682
967
|
}
|
|
968
|
+
/**
|
|
969
|
+
* Applies any options if provided, then removes any extraneous indents from a multi-line template string.
|
|
970
|
+
*
|
|
971
|
+
* You can pass a template string directly by doing:
|
|
972
|
+
*
|
|
973
|
+
* normaliseIndents`Template string here
|
|
974
|
+
* with a new line
|
|
975
|
+
* and another new line`.
|
|
976
|
+
*
|
|
977
|
+
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
978
|
+
*
|
|
979
|
+
* normaliseIndents({ preserveTabs: false })`Template string here
|
|
980
|
+
* with a new line
|
|
981
|
+
* and another new line`.
|
|
982
|
+
*
|
|
983
|
+
* @param first - The strings from the template to process, or the options to apply.
|
|
984
|
+
* @param args - An array of all interpolations from the template.
|
|
985
|
+
*
|
|
986
|
+
* @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
987
|
+
*/
|
|
683
988
|
function normaliseIndents(first, ...args) {
|
|
684
989
|
if (typeof first === "object" && first !== null && !Array.isArray(first)) {
|
|
685
990
|
const options$1 = first;
|
|
@@ -691,6 +996,26 @@ function normaliseIndents(first, ...args) {
|
|
|
691
996
|
const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
|
|
692
997
|
return reduceLines$1(interpolate_default(strings, ...[...args]).split("\n"), options);
|
|
693
998
|
}
|
|
999
|
+
/**
|
|
1000
|
+
* Applies any options if provided, then removes any extraneous indents from a multi-line template string.
|
|
1001
|
+
*
|
|
1002
|
+
* You can pass a template string directly by doing:
|
|
1003
|
+
*
|
|
1004
|
+
* normalizeIndents`Template string here
|
|
1005
|
+
* with a new line
|
|
1006
|
+
* and another new line`.
|
|
1007
|
+
*
|
|
1008
|
+
* You may also pass the options first, then invoke the resulting function with a template string:
|
|
1009
|
+
*
|
|
1010
|
+
* normalizeIndents({ preserveTabs: false })`Template string here
|
|
1011
|
+
* with a new line
|
|
1012
|
+
* and another new line`.
|
|
1013
|
+
*
|
|
1014
|
+
* @param first - The strings from the template to process, or the options to apply.
|
|
1015
|
+
* @param args - An array of all interpolations from the template.
|
|
1016
|
+
*
|
|
1017
|
+
* @returns An additional function to invoke, or a new string with the strings and interpolations from the template applied, and extraneous indents removed.
|
|
1018
|
+
*/
|
|
694
1019
|
const normalizeIndents = normaliseIndents;
|
|
695
1020
|
var normaliseIndents_default = normaliseIndents;
|
|
696
1021
|
|
|
@@ -733,24 +1058,6 @@ function removeIndents(first, ...args) {
|
|
|
733
1058
|
}
|
|
734
1059
|
var removeIndents_default = removeIndents;
|
|
735
1060
|
|
|
736
|
-
//#endregion
|
|
737
|
-
//#region src/functions/truncate.ts
|
|
738
|
-
function truncate(stringToTruncate, maxLength = 5) {
|
|
739
|
-
return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
|
|
740
|
-
}
|
|
741
|
-
var truncate_default = truncate;
|
|
742
|
-
|
|
743
|
-
//#endregion
|
|
744
|
-
//#region src/functions/wait.ts
|
|
745
|
-
function wait(seconds) {
|
|
746
|
-
return new Promise((resolve, _) => {
|
|
747
|
-
setTimeout(() => {
|
|
748
|
-
resolve();
|
|
749
|
-
}, seconds * 1e3);
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
var wait_default = wait;
|
|
753
|
-
|
|
754
1061
|
//#endregion
|
|
755
1062
|
exports.APIError = APIError_default;
|
|
756
1063
|
exports.DataError = DataError_default;
|
|
@@ -784,7 +1091,7 @@ exports.omitProperties = omitProperties_default;
|
|
|
784
1091
|
exports.paralleliseArrays = paralleliseArrays_default;
|
|
785
1092
|
exports.parseBoolean = parseBoolean_default;
|
|
786
1093
|
exports.parseEmail = Email_default;
|
|
787
|
-
exports.parseEnv =
|
|
1094
|
+
exports.parseEnv = parseEnv_default;
|
|
788
1095
|
exports.parseFormData = parseFormData_default;
|
|
789
1096
|
exports.parseIntStrict = parseIntStrict_default;
|
|
790
1097
|
exports.parseUUID = UUID_default;
|