@alextheman/utility 3.10.1 → 4.1.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/LICENSE +21 -0
- package/dist/index.cjs +152 -183
- package/dist/index.d.cts +19 -49
- package/dist/index.d.ts +19 -49
- package/dist/index.js +151 -178
- package/package.json +11 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License Copyright (c) 2025 AlexMan123456
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free
|
|
4
|
+
of charge, to any person obtaining a copy of this software and associated
|
|
5
|
+
documentation files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use, copy, modify, merge,
|
|
7
|
+
publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice
|
|
12
|
+
(including the next paragraph) shall be included in all copies or substantial
|
|
13
|
+
portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
16
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
18
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
19
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/dist/index.cjs
CHANGED
|
@@ -27,8 +27,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
//#endregion
|
|
28
28
|
let zod = require("zod");
|
|
29
29
|
zod = __toESM(zod);
|
|
30
|
-
let
|
|
31
|
-
|
|
30
|
+
let node_path = require("node:path");
|
|
31
|
+
node_path = __toESM(node_path);
|
|
32
32
|
|
|
33
33
|
//#region src/constants/NAMESPACE_EXPORT_REGEX.ts
|
|
34
34
|
const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
@@ -88,27 +88,108 @@ function paralleliseArrays(firstArray, secondArray) {
|
|
|
88
88
|
}
|
|
89
89
|
var paralleliseArrays_default = paralleliseArrays;
|
|
90
90
|
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/types/APIError.ts
|
|
93
|
+
const httpErrorCodeLookup = {
|
|
94
|
+
400: "BAD_REQUEST",
|
|
95
|
+
401: "UNAUTHORISED",
|
|
96
|
+
403: "FORBIDDEN",
|
|
97
|
+
404: "NOT_FOUND",
|
|
98
|
+
418: "I_AM_A_TEAPOT",
|
|
99
|
+
500: "INTERNAL_SERVER_ERROR"
|
|
100
|
+
};
|
|
101
|
+
/** Represents common errors you may get from a HTTP API request. */
|
|
102
|
+
var APIError = class extends Error {
|
|
103
|
+
status;
|
|
104
|
+
/**
|
|
105
|
+
* @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.
|
|
106
|
+
* @param message - An error message to display alongside the status code.
|
|
107
|
+
* @param options - Extra options to be passed to super Error constructor.
|
|
108
|
+
*/
|
|
109
|
+
constructor(status = 500, message, options) {
|
|
110
|
+
super(message, options);
|
|
111
|
+
this.status = status;
|
|
112
|
+
if (message) this.message = message;
|
|
113
|
+
else this.message = httpErrorCodeLookup[this.status] ?? "API_ERROR";
|
|
114
|
+
Object.defineProperty(this, "message", { enumerable: true });
|
|
115
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Checks whether the given input may have been caused by an APIError.
|
|
119
|
+
*
|
|
120
|
+
* @param input - The input to check.
|
|
121
|
+
*
|
|
122
|
+
* @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`.
|
|
123
|
+
*/
|
|
124
|
+
static check(input) {
|
|
125
|
+
const data = input;
|
|
126
|
+
return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
var APIError_default = APIError;
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/types/DataError.ts
|
|
133
|
+
/** Represents errors you may get that may've been caused by a specific piece of data. */
|
|
134
|
+
var DataError = class extends Error {
|
|
135
|
+
data;
|
|
136
|
+
code;
|
|
137
|
+
/**
|
|
138
|
+
* @param data - The data that caused the error.
|
|
139
|
+
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
140
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
141
|
+
* @param options - Extra options to pass to super Error constructor.
|
|
142
|
+
*/
|
|
143
|
+
constructor(data, code = "INVALID_DATA", message = "The data provided is invalid", options) {
|
|
144
|
+
super(message, options);
|
|
145
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
|
|
146
|
+
this.name = new.target.name;
|
|
147
|
+
this.code = code;
|
|
148
|
+
this.data = data;
|
|
149
|
+
Object.defineProperty(this, "message", { enumerable: true });
|
|
150
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Checks whether the given input may have been caused by a DataError.
|
|
154
|
+
*
|
|
155
|
+
* @param input - The input to check.
|
|
156
|
+
*
|
|
157
|
+
* @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`.
|
|
158
|
+
*/
|
|
159
|
+
static check(input) {
|
|
160
|
+
const data = input;
|
|
161
|
+
return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
var DataError_default = DataError;
|
|
165
|
+
|
|
91
166
|
//#endregion
|
|
92
167
|
//#region src/functions/parsers/parseIntStrict.ts
|
|
93
|
-
const IntegerParsingError = /* @__PURE__ */ new TypeError("INTEGER_PARSING_ERROR");
|
|
94
168
|
/**
|
|
95
169
|
* Converts a string to an integer and throws an error if it cannot be converted.
|
|
96
170
|
*
|
|
97
171
|
* @param string - A string to convert into a number.
|
|
98
172
|
* @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.
|
|
99
173
|
*
|
|
100
|
-
* @throws {
|
|
174
|
+
* @throws {DataError} If the provided string cannot safely be converted to an integer.
|
|
101
175
|
*
|
|
102
176
|
* @returns The integer parsed from the input string.
|
|
103
177
|
*/
|
|
104
178
|
function parseIntStrict(string, radix) {
|
|
105
179
|
const trimmedString = string.trim();
|
|
106
|
-
|
|
180
|
+
const maxAllowedAlphabeticalCharacter = radix && radix > 10 && radix <= 36 ? String.fromCharCode(87 + radix - 1) : void 0;
|
|
181
|
+
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new DataError_default(radix ? {
|
|
182
|
+
string,
|
|
183
|
+
radix
|
|
184
|
+
} : string, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
|
|
107
185
|
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
108
186
|
return parseInt(character) >= radix;
|
|
109
|
-
})) throw
|
|
187
|
+
})) throw new DataError_default({
|
|
188
|
+
string,
|
|
189
|
+
radix
|
|
190
|
+
}, "INTEGER_PARSING_ERROR", "Value contains one or more digits outside of the range of the given radix.");
|
|
110
191
|
const parseIntResult = parseInt(trimmedString, radix);
|
|
111
|
-
if (isNaN(parseIntResult)) throw
|
|
192
|
+
if (isNaN(parseIntResult)) throw new DataError_default(string, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
|
|
112
193
|
return parseIntResult;
|
|
113
194
|
}
|
|
114
195
|
var parseIntStrict_default = parseIntStrict;
|
|
@@ -539,19 +620,42 @@ var omitProperties_default = omitProperties;
|
|
|
539
620
|
*
|
|
540
621
|
* @param inputString - The string to parse.
|
|
541
622
|
*
|
|
542
|
-
* @throws {
|
|
623
|
+
* @throws {DataError} If the string is not either `true` or `false` (case insensitive).
|
|
543
624
|
*
|
|
544
625
|
* @returns The string parsed as an actual boolean.
|
|
545
626
|
*/
|
|
546
627
|
function parseBoolean(inputString) {
|
|
547
628
|
const normalisedString = inputString.toLowerCase();
|
|
548
|
-
if (!["true", "false"].includes(normalisedString)) throw new
|
|
629
|
+
if (!["true", "false"].includes(normalisedString)) throw new DataError_default(inputString, "INVALID_BOOLEAN_STRING", "The provided boolean string must be one of `true | false`");
|
|
549
630
|
return normalisedString === "true";
|
|
550
631
|
}
|
|
551
|
-
/** @deprecated This function has been renamed to parseBoolean. */
|
|
552
|
-
const stringToBoolean = parseBoolean;
|
|
553
632
|
var parseBoolean_default = parseBoolean;
|
|
554
633
|
|
|
634
|
+
//#endregion
|
|
635
|
+
//#region src/functions/parsers/parseZodSchema.ts
|
|
636
|
+
/**
|
|
637
|
+
* An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
|
|
638
|
+
*
|
|
639
|
+
* @template Output - The Zod output type.
|
|
640
|
+
* @template Input - The Zod input type.
|
|
641
|
+
* @template Internals - The Zod internal types based on the output and input types.
|
|
642
|
+
* @template ErrorType - The type of error to throw on invalid data.
|
|
643
|
+
*
|
|
644
|
+
* @param schema - The Zod schema to use in parsing.
|
|
645
|
+
* @param data - The data to parse.
|
|
646
|
+
* @param error - A custom error to throw on invalid data (defaults to `DataError`).
|
|
647
|
+
*
|
|
648
|
+
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
649
|
+
*
|
|
650
|
+
* @returns The parsed data from the Zod schema.
|
|
651
|
+
*/
|
|
652
|
+
function parseZodSchema(schema, data, error) {
|
|
653
|
+
const parsedResult = schema.safeParse(data);
|
|
654
|
+
if (!parsedResult.success) throw error ?? new DataError_default(data);
|
|
655
|
+
return parsedResult.data;
|
|
656
|
+
}
|
|
657
|
+
var parseZodSchema_default = parseZodSchema;
|
|
658
|
+
|
|
555
659
|
//#endregion
|
|
556
660
|
//#region src/functions/parsers/parseEnv.ts
|
|
557
661
|
const envSchema = zod.z.enum([
|
|
@@ -564,12 +668,12 @@ const envSchema = zod.z.enum([
|
|
|
564
668
|
*
|
|
565
669
|
* @param data - The data to parse.
|
|
566
670
|
*
|
|
567
|
-
* @throws {
|
|
671
|
+
* @throws {DataError} If the data does not match one of the environments allowed by the Env types ("test" | "development" | "production").
|
|
568
672
|
*
|
|
569
673
|
* @returns The specified environment if allowed.
|
|
570
674
|
*/
|
|
571
675
|
function parseEnv(data) {
|
|
572
|
-
return envSchema
|
|
676
|
+
return parseZodSchema_default(envSchema, data, new DataError_default(data, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
|
|
573
677
|
}
|
|
574
678
|
var parseEnv_default = parseEnv;
|
|
575
679
|
|
|
@@ -595,122 +699,6 @@ function parseFormData(formData, dataParser) {
|
|
|
595
699
|
}
|
|
596
700
|
var parseFormData_default = parseFormData;
|
|
597
701
|
|
|
598
|
-
//#endregion
|
|
599
|
-
//#region src/types/APIError.ts
|
|
600
|
-
const httpErrorCodeLookup = {
|
|
601
|
-
400: "BAD_REQUEST",
|
|
602
|
-
401: "UNAUTHORISED",
|
|
603
|
-
403: "FORBIDDEN",
|
|
604
|
-
404: "NOT_FOUND",
|
|
605
|
-
418: "I_AM_A_TEAPOT",
|
|
606
|
-
500: "INTERNAL_SERVER_ERROR"
|
|
607
|
-
};
|
|
608
|
-
/** Represents common errors you may get from a HTTP API request. */
|
|
609
|
-
var APIError = class extends Error {
|
|
610
|
-
status;
|
|
611
|
-
/**
|
|
612
|
-
* @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.
|
|
613
|
-
* @param message - An error message to display alongside the status code.
|
|
614
|
-
* @param options - Extra options to be passed to super Error constructor.
|
|
615
|
-
*/
|
|
616
|
-
constructor(status = 500, message, options) {
|
|
617
|
-
super(message, options);
|
|
618
|
-
this.status = status;
|
|
619
|
-
if (message) this.message = message;
|
|
620
|
-
else this.message = httpErrorCodeLookup[this.status] ?? "API_ERROR";
|
|
621
|
-
Object.defineProperty(this, "message", { enumerable: true });
|
|
622
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
* Checks whether the given input may have been caused by an APIError.
|
|
626
|
-
*
|
|
627
|
-
* @param input - The input to check.
|
|
628
|
-
*
|
|
629
|
-
* @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`.
|
|
630
|
-
*/
|
|
631
|
-
static check(input) {
|
|
632
|
-
const data = input;
|
|
633
|
-
return typeof data === "object" && data !== null && typeof data?.status === "number" && typeof data?.message === "string";
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
var APIError_default = APIError;
|
|
637
|
-
|
|
638
|
-
//#endregion
|
|
639
|
-
//#region src/types/DataError.ts
|
|
640
|
-
/** Represents errors you may get that may've been caused by a specific piece of data. */
|
|
641
|
-
var DataError = class extends Error {
|
|
642
|
-
data;
|
|
643
|
-
code;
|
|
644
|
-
/**
|
|
645
|
-
* @param data - The data that caused the error.
|
|
646
|
-
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
647
|
-
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
648
|
-
* @param options - Extra options to pass to super Error constructor.
|
|
649
|
-
*/
|
|
650
|
-
constructor(data, message = "The data provided is invalid", code = "INVALID_DATA", options) {
|
|
651
|
-
super(message, options);
|
|
652
|
-
if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
|
|
653
|
-
this.name = new.target.name;
|
|
654
|
-
this.code = code;
|
|
655
|
-
this.data = data;
|
|
656
|
-
Object.defineProperty(this, "message", { enumerable: true });
|
|
657
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
658
|
-
}
|
|
659
|
-
/**
|
|
660
|
-
* Checks whether the given input may have been caused by a DataError.
|
|
661
|
-
*
|
|
662
|
-
* @param input - The input to check.
|
|
663
|
-
*
|
|
664
|
-
* @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`.
|
|
665
|
-
*/
|
|
666
|
-
static check(input) {
|
|
667
|
-
const data = input;
|
|
668
|
-
return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
|
|
669
|
-
}
|
|
670
|
-
};
|
|
671
|
-
var DataError_default = DataError;
|
|
672
|
-
|
|
673
|
-
//#endregion
|
|
674
|
-
//#region src/types/Email.ts
|
|
675
|
-
const emailSchema = zod.default.email().brand();
|
|
676
|
-
/** @deprecated Please use `z.email().parse() from Zod instead.`*/
|
|
677
|
-
function parseEmail(data) {
|
|
678
|
-
return emailSchema.parse(data);
|
|
679
|
-
}
|
|
680
|
-
var Email_default = parseEmail;
|
|
681
|
-
|
|
682
|
-
//#endregion
|
|
683
|
-
//#region src/types/UUID.ts
|
|
684
|
-
const uuidSchema = zod.default.uuid().brand();
|
|
685
|
-
/** @deprecated Please use `z.uuid().parse() from Zod instead.`*/
|
|
686
|
-
function parseUUID(UUID) {
|
|
687
|
-
return uuidSchema.parse(UUID);
|
|
688
|
-
}
|
|
689
|
-
var UUID_default = parseUUID;
|
|
690
|
-
|
|
691
|
-
//#endregion
|
|
692
|
-
//#region src/functions/parsers/parseZodSchema.ts
|
|
693
|
-
/**
|
|
694
|
-
* An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
|
|
695
|
-
*
|
|
696
|
-
* @template Output - The Zod output type.
|
|
697
|
-
* @template Input - The Zod input type.
|
|
698
|
-
* @template Internals - The Zod internal types based on the output and input types.
|
|
699
|
-
*
|
|
700
|
-
* @param schema - The Zod schema to use in parsing.
|
|
701
|
-
* @param data - The data to parse.
|
|
702
|
-
*
|
|
703
|
-
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
704
|
-
*
|
|
705
|
-
* @returns The parsed data from the Zod schema.
|
|
706
|
-
*/
|
|
707
|
-
function parseZodSchema(schema, data) {
|
|
708
|
-
const parsedResult = schema.safeParse(data);
|
|
709
|
-
if (!parsedResult.success) throw new DataError_default(data);
|
|
710
|
-
return parsedResult.data;
|
|
711
|
-
}
|
|
712
|
-
var parseZodSchema_default = parseZodSchema;
|
|
713
|
-
|
|
714
702
|
//#endregion
|
|
715
703
|
//#region src/functions/parsers/parseVersionType.ts
|
|
716
704
|
const versionTypeSchema = zod.default.enum([
|
|
@@ -728,7 +716,7 @@ const versionTypeSchema = zod.default.enum([
|
|
|
728
716
|
* @returns The given version type if allowed.
|
|
729
717
|
*/
|
|
730
718
|
function parseVersionType(data) {
|
|
731
|
-
return parseZodSchema_default(versionTypeSchema, data);
|
|
719
|
+
return parseZodSchema_default(versionTypeSchema, data, new DataError_default(data, "INVALID_VERSION_TYPE", "The provided version type must be one of `major | minor | patch`"));
|
|
732
720
|
}
|
|
733
721
|
var parseVersionType_default = parseVersionType;
|
|
734
722
|
|
|
@@ -807,11 +795,35 @@ var appendSemicolon_default = appendSemicolon;
|
|
|
807
795
|
* Converts a string from camelCase to kebab-case
|
|
808
796
|
*
|
|
809
797
|
* @param string - The string to convert.
|
|
798
|
+
* @param options - Options to apply to the conversion.
|
|
810
799
|
*
|
|
811
800
|
* @returns The string converted to kebab-case.
|
|
812
801
|
*/
|
|
813
|
-
function camelToKebab(string) {
|
|
814
|
-
|
|
802
|
+
function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
|
|
803
|
+
let result = "";
|
|
804
|
+
let outerIndex = 0;
|
|
805
|
+
while (outerIndex < string.length) {
|
|
806
|
+
const character = string[outerIndex];
|
|
807
|
+
if (/[A-Z]/.test(character)) {
|
|
808
|
+
let innerIndex = outerIndex + 1;
|
|
809
|
+
while (innerIndex < string.length && /[A-Z]/.test(string[innerIndex]) && (options.preserveConsecutiveCapitals ? innerIndex + 1 < string.length && /[a-z]/.test(string[innerIndex + 1]) ? false : true : true)) innerIndex++;
|
|
810
|
+
const sequenceOfCapitals = string.slice(outerIndex, innerIndex);
|
|
811
|
+
if (options.preserveConsecutiveCapitals) {
|
|
812
|
+
if (result) result += "-";
|
|
813
|
+
result += sequenceOfCapitals.toLowerCase();
|
|
814
|
+
} else {
|
|
815
|
+
if (result) result += "-";
|
|
816
|
+
result += sequenceOfCapitals.split("").map((character$1) => {
|
|
817
|
+
return character$1.toLowerCase();
|
|
818
|
+
}).join("-");
|
|
819
|
+
}
|
|
820
|
+
outerIndex = innerIndex;
|
|
821
|
+
} else {
|
|
822
|
+
result += character;
|
|
823
|
+
outerIndex++;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return result;
|
|
815
827
|
}
|
|
816
828
|
var camelToKebab_default = camelToKebab;
|
|
817
829
|
|
|
@@ -869,7 +881,7 @@ var kebabToCamel_default = kebabToCamel;
|
|
|
869
881
|
* @returns The import path normalized.
|
|
870
882
|
*/
|
|
871
883
|
function normalizeImportPath(importPath) {
|
|
872
|
-
const normalizedPath =
|
|
884
|
+
const normalizedPath = node_path.default.posix.normalize(importPath);
|
|
873
885
|
if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) return `./${normalizedPath}`;
|
|
874
886
|
return normalizedPath;
|
|
875
887
|
}
|
|
@@ -967,25 +979,25 @@ var interpolateObjects_default = interpolateObjects;
|
|
|
967
979
|
|
|
968
980
|
//#endregion
|
|
969
981
|
//#region src/functions/taggedTemplate/normaliseIndents.ts
|
|
970
|
-
function calculateTabSize
|
|
982
|
+
function calculateTabSize(line, whitespaceLength) {
|
|
971
983
|
const potentialWhitespacePart = line.slice(0, whitespaceLength);
|
|
972
984
|
const trimmedString = line.trimStart();
|
|
973
985
|
if (potentialWhitespacePart.trim() !== "") return 0;
|
|
974
986
|
const tabSize = line.length - (trimmedString.length + whitespaceLength);
|
|
975
987
|
return tabSize < 0 ? 0 : tabSize;
|
|
976
988
|
}
|
|
977
|
-
function getWhitespaceLength
|
|
989
|
+
function getWhitespaceLength(lines) {
|
|
978
990
|
const [firstNonEmptyLine] = lines.filter((line) => {
|
|
979
991
|
return line.trim() !== "";
|
|
980
992
|
});
|
|
981
993
|
return firstNonEmptyLine.length - firstNonEmptyLine.trimStart().length;
|
|
982
994
|
}
|
|
983
|
-
function reduceLines
|
|
995
|
+
function reduceLines(lines, { preserveTabs = true }) {
|
|
984
996
|
const slicedLines = lines.slice(1);
|
|
985
997
|
const isFirstLineEmpty = lines[0].trim() === "";
|
|
986
|
-
const whitespaceLength = getWhitespaceLength
|
|
998
|
+
const whitespaceLength = getWhitespaceLength(isFirstLineEmpty ? lines : slicedLines);
|
|
987
999
|
return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
|
|
988
|
-
const tabSize = calculateTabSize
|
|
1000
|
+
const tabSize = calculateTabSize(line, whitespaceLength);
|
|
989
1001
|
return (preserveTabs ? fillArray_default(() => {
|
|
990
1002
|
return " ";
|
|
991
1003
|
}, tabSize).join("") : "") + line.trimStart();
|
|
@@ -1020,7 +1032,7 @@ function normaliseIndents(first, ...args) {
|
|
|
1020
1032
|
}
|
|
1021
1033
|
const strings = first;
|
|
1022
1034
|
const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
|
|
1023
|
-
return reduceLines
|
|
1035
|
+
return reduceLines(interpolate_default(strings, ...[...args]).split("\n"), options);
|
|
1024
1036
|
}
|
|
1025
1037
|
/**
|
|
1026
1038
|
* Applies any options if provided, then removes any extraneous indents from a multi-line template string.
|
|
@@ -1045,45 +1057,6 @@ function normaliseIndents(first, ...args) {
|
|
|
1045
1057
|
const normalizeIndents = normaliseIndents;
|
|
1046
1058
|
var normaliseIndents_default = normaliseIndents;
|
|
1047
1059
|
|
|
1048
|
-
//#endregion
|
|
1049
|
-
//#region src/functions/taggedTemplate/removeIndents.ts
|
|
1050
|
-
function calculateTabSize(line, whitespaceLength) {
|
|
1051
|
-
const potentialWhitespacePart = line.slice(0, whitespaceLength);
|
|
1052
|
-
const trimmedString = line.trimStart();
|
|
1053
|
-
if (potentialWhitespacePart.trim() !== "") return 0;
|
|
1054
|
-
const tabSize = line.length - (trimmedString.length + whitespaceLength);
|
|
1055
|
-
return tabSize < 0 ? 0 : tabSize;
|
|
1056
|
-
}
|
|
1057
|
-
function getWhitespaceLength(lines) {
|
|
1058
|
-
const [firstNonEmptyLine] = lines.filter((line) => {
|
|
1059
|
-
return line.trim() !== "";
|
|
1060
|
-
});
|
|
1061
|
-
return firstNonEmptyLine.length - firstNonEmptyLine.trimStart().length;
|
|
1062
|
-
}
|
|
1063
|
-
function reduceLines(lines, { preserveTabs = true }) {
|
|
1064
|
-
const slicedLines = lines.slice(1);
|
|
1065
|
-
const isFirstLineEmpty = lines[0].trim() === "";
|
|
1066
|
-
const whitespaceLength = getWhitespaceLength(isFirstLineEmpty ? lines : slicedLines);
|
|
1067
|
-
return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
|
|
1068
|
-
const tabSize = calculateTabSize(line, whitespaceLength);
|
|
1069
|
-
return (preserveTabs ? fillArray_default(() => {
|
|
1070
|
-
return " ";
|
|
1071
|
-
}, tabSize).join("") : "") + line.trimStart();
|
|
1072
|
-
}).join("\n");
|
|
1073
|
-
}
|
|
1074
|
-
function removeIndents(first, ...args) {
|
|
1075
|
-
if (typeof first === "object" && first !== null && !Array.isArray(first)) {
|
|
1076
|
-
const options$1 = first;
|
|
1077
|
-
return (strings$1, ...interpolations) => {
|
|
1078
|
-
return removeIndents(strings$1, ...interpolations, options$1);
|
|
1079
|
-
};
|
|
1080
|
-
}
|
|
1081
|
-
const strings = first;
|
|
1082
|
-
const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
|
|
1083
|
-
return reduceLines(interpolate_default(strings, ...[...args]).split("\n"), options);
|
|
1084
|
-
}
|
|
1085
|
-
var removeIndents_default = removeIndents;
|
|
1086
|
-
|
|
1087
1060
|
//#endregion
|
|
1088
1061
|
//#region src/functions/versioning/parseVersion.ts
|
|
1089
1062
|
/**
|
|
@@ -1099,7 +1072,7 @@ var removeIndents_default = removeIndents;
|
|
|
1099
1072
|
* @returns The validated version number, prefixed with `v` if it was not already.
|
|
1100
1073
|
*/
|
|
1101
1074
|
function parseVersion(input, options) {
|
|
1102
|
-
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
|
|
1075
|
+
if (!RegExp(VERSION_NUMBER_REGEX_default).test(input)) throw new DataError_default(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.`);
|
|
1103
1076
|
if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
|
|
1104
1077
|
return input.startsWith("v") ? input : `v${input}`;
|
|
1105
1078
|
}
|
|
@@ -1199,19 +1172,15 @@ exports.normalizeIndents = normalizeIndents;
|
|
|
1199
1172
|
exports.omitProperties = omitProperties_default;
|
|
1200
1173
|
exports.paralleliseArrays = paralleliseArrays_default;
|
|
1201
1174
|
exports.parseBoolean = parseBoolean_default;
|
|
1202
|
-
exports.parseEmail = Email_default;
|
|
1203
1175
|
exports.parseEnv = parseEnv_default;
|
|
1204
1176
|
exports.parseFormData = parseFormData_default;
|
|
1205
1177
|
exports.parseIntStrict = parseIntStrict_default;
|
|
1206
|
-
exports.parseUUID = UUID_default;
|
|
1207
1178
|
exports.parseVersion = parseVersion_default;
|
|
1208
1179
|
exports.parseVersionType = parseVersionType_default;
|
|
1209
1180
|
exports.parseZodSchema = parseZodSchema_default;
|
|
1210
1181
|
exports.randomiseArray = randomiseArray_default;
|
|
1211
1182
|
exports.range = range_default;
|
|
1212
1183
|
exports.removeDuplicates = removeDuplicates_default;
|
|
1213
|
-
exports.removeIndents = removeIndents_default;
|
|
1214
1184
|
exports.stringListToArray = stringListToArray_default;
|
|
1215
|
-
exports.stringToBoolean = stringToBoolean;
|
|
1216
1185
|
exports.truncate = truncate_default;
|
|
1217
1186
|
exports.wait = wait_default;
|