@alextheman/utility 5.23.0 → 5.23.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 +2 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.js +16 -14
- package/dist/internal/index.cjs +43 -43
- package/dist/internal/index.js +43 -43
- package/package.json +14 -14
package/dist/index.cjs
CHANGED
|
@@ -1942,6 +1942,8 @@ function normaliseIndents(first, ...args) {
|
|
|
1942
1942
|
* and another new line`.
|
|
1943
1943
|
* ```
|
|
1944
1944
|
*
|
|
1945
|
+
* @category Tagged Template
|
|
1946
|
+
*
|
|
1945
1947
|
* @param first - The strings from the template to process, or the options to apply.
|
|
1946
1948
|
* @param args - An array of all interpolations from the template.
|
|
1947
1949
|
*
|
package/dist/index.d.cts
CHANGED
|
@@ -1154,6 +1154,8 @@ declare function normaliseIndents(options: NormaliseIndentsOptions): NormaliseIn
|
|
|
1154
1154
|
* and another new line`;
|
|
1155
1155
|
* ```
|
|
1156
1156
|
*
|
|
1157
|
+
* @category Tagged Template
|
|
1158
|
+
*
|
|
1157
1159
|
* @template InterpolationsType - The type of the interpolations.
|
|
1158
1160
|
*
|
|
1159
1161
|
* @param strings - The strings from the template to process.
|
|
@@ -1181,6 +1183,8 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
|
|
|
1181
1183
|
* and another new line`.
|
|
1182
1184
|
* ```
|
|
1183
1185
|
*
|
|
1186
|
+
* @category Tagged Template
|
|
1187
|
+
*
|
|
1184
1188
|
* @param first - The strings from the template to process, or the options to apply.
|
|
1185
1189
|
* @param args - An array of all interpolations from the template.
|
|
1186
1190
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import z
|
|
1
|
+
import z, { ZodCoercedDate, ZodCoercedNumber, ZodError, ZodType, z as z$1 } from "zod";
|
|
2
2
|
import { DotenvParseOutput } from "dotenv";
|
|
3
3
|
|
|
4
4
|
//#region src/root/constants/FILE_PATH_REGEX.d.ts
|
|
@@ -550,7 +550,7 @@ declare class VersionNumber {
|
|
|
550
550
|
*/
|
|
551
551
|
toString(): string;
|
|
552
552
|
}
|
|
553
|
-
declare const zodVersionNumber: z
|
|
553
|
+
declare const zodVersionNumber: z.ZodType<VersionNumber>;
|
|
554
554
|
//#endregion
|
|
555
555
|
//#region src/root/types/ArrayElement.d.ts
|
|
556
556
|
/**
|
|
@@ -1154,6 +1154,8 @@ declare function normaliseIndents(options: NormaliseIndentsOptions): NormaliseIn
|
|
|
1154
1154
|
* and another new line`;
|
|
1155
1155
|
* ```
|
|
1156
1156
|
*
|
|
1157
|
+
* @category Tagged Template
|
|
1158
|
+
*
|
|
1157
1159
|
* @template InterpolationsType - The type of the interpolations.
|
|
1158
1160
|
*
|
|
1159
1161
|
* @param strings - The strings from the template to process.
|
|
@@ -1181,6 +1183,8 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
|
|
|
1181
1183
|
* and another new line`.
|
|
1182
1184
|
* ```
|
|
1183
1185
|
*
|
|
1186
|
+
* @category Tagged Template
|
|
1187
|
+
*
|
|
1184
1188
|
* @param first - The strings from the template to process, or the options to apply.
|
|
1185
1189
|
* @param args - An array of all interpolations from the template.
|
|
1186
1190
|
*
|
|
@@ -1439,7 +1443,7 @@ declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>
|
|
|
1439
1443
|
*
|
|
1440
1444
|
* @returns The parsed data from the Zod schema.
|
|
1441
1445
|
*/
|
|
1442
|
-
declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error = DataError$1>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z.infer<SchemaType>;
|
|
1446
|
+
declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error = DataError$1>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z$1.infer<SchemaType>;
|
|
1443
1447
|
//#endregion
|
|
1444
1448
|
//#region src/root/zod/parseZodSchemaAsync.d.ts
|
|
1445
1449
|
/**
|
|
@@ -1460,10 +1464,10 @@ declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Er
|
|
|
1460
1464
|
*
|
|
1461
1465
|
* @returns The parsed data from the Zod schema.
|
|
1462
1466
|
*/
|
|
1463
|
-
declare function parseZodSchemaAsync<SchemaType extends ZodType, ErrorType extends Error = DataError$1>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): Promise<z.infer<SchemaType>>;
|
|
1467
|
+
declare function parseZodSchemaAsync<SchemaType extends ZodType, ErrorType extends Error = DataError$1>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): Promise<z$1.infer<SchemaType>>;
|
|
1464
1468
|
//#endregion
|
|
1465
1469
|
//#region src/root/zod/zodFieldWrapper.d.ts
|
|
1466
|
-
declare function zodFieldWrapper<SchemaType extends ZodType<unknown, string | null>>(schema: SchemaType): ZodType<z
|
|
1470
|
+
declare function zodFieldWrapper<SchemaType extends ZodType<unknown, string | null>>(schema: SchemaType): ZodType<z.infer<SchemaType>, string>;
|
|
1467
1471
|
//#endregion
|
|
1468
1472
|
//#region src/root/zod/az.d.ts
|
|
1469
1473
|
declare const az: {
|
|
@@ -1472,15 +1476,15 @@ declare const az: {
|
|
|
1472
1476
|
versionNumber: () => ZodType<VersionNumber, unknown>;
|
|
1473
1477
|
fieldDate: () => ZodCoercedDate<string | null>;
|
|
1474
1478
|
with: <SchemaType extends ZodType>(schema: SchemaType) => {
|
|
1475
|
-
parse: <ErrorType extends Error = DataError$1<Record<PropertyKey, unknown>, string>>(input: unknown, error?: ErrorType | ((zodError: z
|
|
1476
|
-
parseAsync: <ErrorType extends Error = DataError$1<Record<PropertyKey, unknown>, string>>(input: unknown, error?: ErrorType | ((zodError: z
|
|
1479
|
+
parse: <ErrorType extends Error = DataError$1<Record<PropertyKey, unknown>, string>>(input: unknown, error?: ErrorType | ((zodError: z.ZodError<unknown>) => void | ErrorType)) => ReturnType<typeof parseZodSchema<SchemaType, ErrorType>>;
|
|
1480
|
+
parseAsync: <ErrorType extends Error = DataError$1<Record<PropertyKey, unknown>, string>>(input: unknown, error?: ErrorType | ((zodError: z.ZodError<unknown>) => void | ErrorType)) => ReturnType<typeof parseZodSchemaAsync<SchemaType, ErrorType>>;
|
|
1477
1481
|
};
|
|
1478
1482
|
};
|
|
1479
1483
|
//#endregion
|
|
1480
1484
|
//#region src/root/zod/_parseZodSchema.d.ts
|
|
1481
1485
|
interface ZodParsingErrorData {
|
|
1482
1486
|
input: unknown;
|
|
1483
|
-
issues: Array<z
|
|
1487
|
+
issues: Array<z.core.$ZodIssue>;
|
|
1484
1488
|
}
|
|
1485
1489
|
//#endregion
|
|
1486
1490
|
export { APIError, type ArrayElement, type CallReturnType, type CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, type KebabToCamelOptions, type NonNull, type NonUndefined, type NormaliseIndentsFunction, type NormaliseIndentsOptions, type NormalizeIndentsFunction, type NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, type ParallelTuple, type RecordKey, type RemoveUndefined, SortDirection, type StringListToArrayOptions, type ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, type ZodParsingErrorData, addDaysToDate, appendSemicolon, assertNotNull, assertNotNullable, assertNotUndefined, az, calculateMonthlyDifference, camelToKebab, containsKeys, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeHTML, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, identity, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isNonNullableObject, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, objectContainsKeys, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, pickProperties, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, sortBy, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import z
|
|
1
|
+
import z, { z as z$1 } from "zod";
|
|
2
2
|
//#region src/root/constants/FILE_PATH_REGEX.ts
|
|
3
3
|
const FILE_PATH_PATTERN = String.raw`(?<directory>.+)[\/\\](?<base>[^\/\\]+)`;
|
|
4
4
|
const FILE_PATH_REGEX = RegExp(`^${FILE_PATH_PATTERN}$`);
|
|
@@ -1300,14 +1300,14 @@ var VersionNumber = class VersionNumber {
|
|
|
1300
1300
|
return VersionNumber.formatString(rawString, { omitPrefix: false });
|
|
1301
1301
|
}
|
|
1302
1302
|
};
|
|
1303
|
-
const zodVersionNumber = z
|
|
1304
|
-
z
|
|
1305
|
-
z
|
|
1306
|
-
z
|
|
1307
|
-
z
|
|
1308
|
-
z
|
|
1303
|
+
const zodVersionNumber = z.union([
|
|
1304
|
+
z.string(),
|
|
1305
|
+
z.tuple([
|
|
1306
|
+
z.number(),
|
|
1307
|
+
z.number(),
|
|
1308
|
+
z.number()
|
|
1309
1309
|
]),
|
|
1310
|
-
z
|
|
1310
|
+
z.instanceof(VersionNumber)
|
|
1311
1311
|
]).transform((rawVersionNumber) => {
|
|
1312
1312
|
return new VersionNumber(rawVersionNumber);
|
|
1313
1313
|
});
|
|
@@ -1325,7 +1325,7 @@ function _parseZodSchema(parsedResult, input, onError) {
|
|
|
1325
1325
|
throw new DataError$1({
|
|
1326
1326
|
input,
|
|
1327
1327
|
issues: parsedResult.error.issues
|
|
1328
|
-
}, "ZOD_ERROR", `\n\n${z
|
|
1328
|
+
}, "ZOD_ERROR", `\n\n${z.prettifyError(parsedResult.error)}\n`);
|
|
1329
1329
|
}
|
|
1330
1330
|
return parsedResult.data;
|
|
1331
1331
|
}
|
|
@@ -1380,7 +1380,7 @@ async function parseZodSchemaAsync(schema, input, onError) {
|
|
|
1380
1380
|
//#endregion
|
|
1381
1381
|
//#region src/root/zod/zodFieldWrapper.ts
|
|
1382
1382
|
function zodFieldWrapper(schema) {
|
|
1383
|
-
return z
|
|
1383
|
+
return z.string().trim().transform((value) => {
|
|
1384
1384
|
return value === "" ? null : value;
|
|
1385
1385
|
}).pipe(schema);
|
|
1386
1386
|
}
|
|
@@ -1389,13 +1389,13 @@ function zodFieldWrapper(schema) {
|
|
|
1389
1389
|
const az = {
|
|
1390
1390
|
field: zodFieldWrapper,
|
|
1391
1391
|
fieldNumber: () => {
|
|
1392
|
-
return z
|
|
1392
|
+
return z.coerce.number();
|
|
1393
1393
|
},
|
|
1394
1394
|
versionNumber: () => {
|
|
1395
1395
|
return zodVersionNumber;
|
|
1396
1396
|
},
|
|
1397
1397
|
fieldDate: () => {
|
|
1398
|
-
return z
|
|
1398
|
+
return z.coerce.date();
|
|
1399
1399
|
},
|
|
1400
1400
|
with: (schema) => {
|
|
1401
1401
|
return {
|
|
@@ -1432,7 +1432,7 @@ const Env = {
|
|
|
1432
1432
|
* @returns The specified environment if allowed.
|
|
1433
1433
|
*/
|
|
1434
1434
|
function parseEnv(input) {
|
|
1435
|
-
return az.with(z.enum(Env)).parse(input, new DataError$1({ input }, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
|
|
1435
|
+
return az.with(z$1.enum(Env)).parse(input, new DataError$1({ input }, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
|
|
1436
1436
|
}
|
|
1437
1437
|
//#endregion
|
|
1438
1438
|
//#region src/root/functions/parsers/parseFormData.ts
|
|
@@ -1498,7 +1498,7 @@ const VersionType = {
|
|
|
1498
1498
|
* @returns The given version type if allowed.
|
|
1499
1499
|
*/
|
|
1500
1500
|
function parseVersionType(input) {
|
|
1501
|
-
return az.with(z
|
|
1501
|
+
return az.with(z.enum(VersionType)).parse(input, new DataError$1({ input }, "INVALID_VERSION_TYPE", "The provided version type must be one of `major | minor | patch`"));
|
|
1502
1502
|
}
|
|
1503
1503
|
//#endregion
|
|
1504
1504
|
//#region src/root/functions/recursive/deepCopy.ts
|
|
@@ -1918,6 +1918,8 @@ function normaliseIndents(first, ...args) {
|
|
|
1918
1918
|
* and another new line`.
|
|
1919
1919
|
* ```
|
|
1920
1920
|
*
|
|
1921
|
+
* @category Tagged Template
|
|
1922
|
+
*
|
|
1921
1923
|
* @param first - The strings from the template to process, or the options to apply.
|
|
1922
1924
|
* @param args - An array of all interpolations from the template.
|
|
1923
1925
|
*
|
package/dist/internal/index.cjs
CHANGED
|
@@ -244,49 +244,6 @@ var DataError = class DataError extends CodeError {
|
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
246
|
//#endregion
|
|
247
|
-
//#region src/root/functions/parsers/parseIntStrict.ts
|
|
248
|
-
/**
|
|
249
|
-
* Converts a string to an integer and throws an error if it cannot be converted.
|
|
250
|
-
*
|
|
251
|
-
* @category Parsers
|
|
252
|
-
*
|
|
253
|
-
* @param string - A string to convert into a number.
|
|
254
|
-
* @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.
|
|
255
|
-
*
|
|
256
|
-
* @throws {DataError} If the provided string cannot safely be converted to an integer.
|
|
257
|
-
*
|
|
258
|
-
* @returns The integer parsed from the input string.
|
|
259
|
-
*/
|
|
260
|
-
function parseIntStrict(string, radix) {
|
|
261
|
-
const trimmedString = string.trim();
|
|
262
|
-
const maxAllowedAlphabeticalCharacter = radix && radix > 10 && radix <= 36 ? String.fromCharCode(87 + radix - 1) : void 0;
|
|
263
|
-
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new DataError(radix ? {
|
|
264
|
-
string,
|
|
265
|
-
radix
|
|
266
|
-
} : { string }, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
|
|
267
|
-
if (radix && radix < 10 && [...trimmedString.replace(/^[+-]/, "")].some((character) => {
|
|
268
|
-
return parseInt(character) >= radix;
|
|
269
|
-
})) throw new DataError({
|
|
270
|
-
string,
|
|
271
|
-
radix
|
|
272
|
-
}, "INTEGER_PARSING_ERROR", "Value contains one or more digits outside of the range of the given radix.");
|
|
273
|
-
const parseIntResult = parseInt(trimmedString, radix);
|
|
274
|
-
if (isNaN(parseIntResult)) throw new DataError({ string }, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
|
|
275
|
-
return parseIntResult;
|
|
276
|
-
}
|
|
277
|
-
//#endregion
|
|
278
|
-
//#region src/root/functions/parsers/parseVersionType.ts
|
|
279
|
-
/**
|
|
280
|
-
* Represents the three common software version types.
|
|
281
|
-
*
|
|
282
|
-
* @category Types
|
|
283
|
-
*/
|
|
284
|
-
const VersionType = {
|
|
285
|
-
MAJOR: "major",
|
|
286
|
-
MINOR: "minor",
|
|
287
|
-
PATCH: "patch"
|
|
288
|
-
};
|
|
289
|
-
//#endregion
|
|
290
247
|
//#region src/root/functions/arrayHelpers/range.ts
|
|
291
248
|
/**
|
|
292
249
|
* Creates an array of numbers within a given range.
|
|
@@ -428,6 +385,49 @@ function paralleliseArrays(firstArray, secondArray) {
|
|
|
428
385
|
return outputArray;
|
|
429
386
|
}
|
|
430
387
|
//#endregion
|
|
388
|
+
//#region src/root/functions/parsers/parseIntStrict.ts
|
|
389
|
+
/**
|
|
390
|
+
* Converts a string to an integer and throws an error if it cannot be converted.
|
|
391
|
+
*
|
|
392
|
+
* @category Parsers
|
|
393
|
+
*
|
|
394
|
+
* @param string - A string to convert into a number.
|
|
395
|
+
* @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.
|
|
396
|
+
*
|
|
397
|
+
* @throws {DataError} If the provided string cannot safely be converted to an integer.
|
|
398
|
+
*
|
|
399
|
+
* @returns The integer parsed from the input string.
|
|
400
|
+
*/
|
|
401
|
+
function parseIntStrict(string, radix) {
|
|
402
|
+
const trimmedString = string.trim();
|
|
403
|
+
const maxAllowedAlphabeticalCharacter = radix && radix > 10 && radix <= 36 ? String.fromCharCode(87 + radix - 1) : void 0;
|
|
404
|
+
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new DataError(radix ? {
|
|
405
|
+
string,
|
|
406
|
+
radix
|
|
407
|
+
} : { string }, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
|
|
408
|
+
if (radix && radix < 10 && [...trimmedString.replace(/^[+-]/, "")].some((character) => {
|
|
409
|
+
return parseInt(character) >= radix;
|
|
410
|
+
})) throw new DataError({
|
|
411
|
+
string,
|
|
412
|
+
radix
|
|
413
|
+
}, "INTEGER_PARSING_ERROR", "Value contains one or more digits outside of the range of the given radix.");
|
|
414
|
+
const parseIntResult = parseInt(trimmedString, radix);
|
|
415
|
+
if (isNaN(parseIntResult)) throw new DataError({ string }, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
|
|
416
|
+
return parseIntResult;
|
|
417
|
+
}
|
|
418
|
+
//#endregion
|
|
419
|
+
//#region src/root/functions/parsers/parseVersionType.ts
|
|
420
|
+
/**
|
|
421
|
+
* Represents the three common software version types.
|
|
422
|
+
*
|
|
423
|
+
* @category Types
|
|
424
|
+
*/
|
|
425
|
+
const VersionType = {
|
|
426
|
+
MAJOR: "major",
|
|
427
|
+
MINOR: "minor",
|
|
428
|
+
PATCH: "patch"
|
|
429
|
+
};
|
|
430
|
+
//#endregion
|
|
431
431
|
//#region src/root/functions/taggedTemplate/interpolate.ts
|
|
432
432
|
/**
|
|
433
433
|
* Returns the result of interpolating a template string when given the strings and interpolations separately.
|
package/dist/internal/index.js
CHANGED
|
@@ -219,49 +219,6 @@ var DataError = class DataError extends CodeError {
|
|
|
219
219
|
}
|
|
220
220
|
};
|
|
221
221
|
//#endregion
|
|
222
|
-
//#region src/root/functions/parsers/parseIntStrict.ts
|
|
223
|
-
/**
|
|
224
|
-
* Converts a string to an integer and throws an error if it cannot be converted.
|
|
225
|
-
*
|
|
226
|
-
* @category Parsers
|
|
227
|
-
*
|
|
228
|
-
* @param string - A string to convert into a number.
|
|
229
|
-
* @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.
|
|
230
|
-
*
|
|
231
|
-
* @throws {DataError} If the provided string cannot safely be converted to an integer.
|
|
232
|
-
*
|
|
233
|
-
* @returns The integer parsed from the input string.
|
|
234
|
-
*/
|
|
235
|
-
function parseIntStrict(string, radix) {
|
|
236
|
-
const trimmedString = string.trim();
|
|
237
|
-
const maxAllowedAlphabeticalCharacter = radix && radix > 10 && radix <= 36 ? String.fromCharCode(87 + radix - 1) : void 0;
|
|
238
|
-
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new DataError(radix ? {
|
|
239
|
-
string,
|
|
240
|
-
radix
|
|
241
|
-
} : { string }, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
|
|
242
|
-
if (radix && radix < 10 && [...trimmedString.replace(/^[+-]/, "")].some((character) => {
|
|
243
|
-
return parseInt(character) >= radix;
|
|
244
|
-
})) throw new DataError({
|
|
245
|
-
string,
|
|
246
|
-
radix
|
|
247
|
-
}, "INTEGER_PARSING_ERROR", "Value contains one or more digits outside of the range of the given radix.");
|
|
248
|
-
const parseIntResult = parseInt(trimmedString, radix);
|
|
249
|
-
if (isNaN(parseIntResult)) throw new DataError({ string }, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
|
|
250
|
-
return parseIntResult;
|
|
251
|
-
}
|
|
252
|
-
//#endregion
|
|
253
|
-
//#region src/root/functions/parsers/parseVersionType.ts
|
|
254
|
-
/**
|
|
255
|
-
* Represents the three common software version types.
|
|
256
|
-
*
|
|
257
|
-
* @category Types
|
|
258
|
-
*/
|
|
259
|
-
const VersionType = {
|
|
260
|
-
MAJOR: "major",
|
|
261
|
-
MINOR: "minor",
|
|
262
|
-
PATCH: "patch"
|
|
263
|
-
};
|
|
264
|
-
//#endregion
|
|
265
222
|
//#region src/root/functions/arrayHelpers/range.ts
|
|
266
223
|
/**
|
|
267
224
|
* Creates an array of numbers within a given range.
|
|
@@ -403,6 +360,49 @@ function paralleliseArrays(firstArray, secondArray) {
|
|
|
403
360
|
return outputArray;
|
|
404
361
|
}
|
|
405
362
|
//#endregion
|
|
363
|
+
//#region src/root/functions/parsers/parseIntStrict.ts
|
|
364
|
+
/**
|
|
365
|
+
* Converts a string to an integer and throws an error if it cannot be converted.
|
|
366
|
+
*
|
|
367
|
+
* @category Parsers
|
|
368
|
+
*
|
|
369
|
+
* @param string - A string to convert into a number.
|
|
370
|
+
* @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.
|
|
371
|
+
*
|
|
372
|
+
* @throws {DataError} If the provided string cannot safely be converted to an integer.
|
|
373
|
+
*
|
|
374
|
+
* @returns The integer parsed from the input string.
|
|
375
|
+
*/
|
|
376
|
+
function parseIntStrict(string, radix) {
|
|
377
|
+
const trimmedString = string.trim();
|
|
378
|
+
const maxAllowedAlphabeticalCharacter = radix && radix > 10 && radix <= 36 ? String.fromCharCode(87 + radix - 1) : void 0;
|
|
379
|
+
if (!(radix && radix > 10 && radix <= 36 ? new RegExp(`^[+-]?[0-9a-${maxAllowedAlphabeticalCharacter}]+$`, "i") : /^[+-]?\d+$/).test(trimmedString)) throw new DataError(radix ? {
|
|
380
|
+
string,
|
|
381
|
+
radix
|
|
382
|
+
} : { string }, "INTEGER_PARSING_ERROR", `Only numeric values${radix && radix > 10 && radix <= 36 ? ` or character${radix !== 11 ? "s" : ""} A${radix !== 11 ? `-${maxAllowedAlphabeticalCharacter?.toUpperCase()} ` : " "}` : " "}are allowed.`);
|
|
383
|
+
if (radix && radix < 10 && [...trimmedString.replace(/^[+-]/, "")].some((character) => {
|
|
384
|
+
return parseInt(character) >= radix;
|
|
385
|
+
})) throw new DataError({
|
|
386
|
+
string,
|
|
387
|
+
radix
|
|
388
|
+
}, "INTEGER_PARSING_ERROR", "Value contains one or more digits outside of the range of the given radix.");
|
|
389
|
+
const parseIntResult = parseInt(trimmedString, radix);
|
|
390
|
+
if (isNaN(parseIntResult)) throw new DataError({ string }, "INTEGER_PARSING_ERROR", "Value is not a valid integer.");
|
|
391
|
+
return parseIntResult;
|
|
392
|
+
}
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region src/root/functions/parsers/parseVersionType.ts
|
|
395
|
+
/**
|
|
396
|
+
* Represents the three common software version types.
|
|
397
|
+
*
|
|
398
|
+
* @category Types
|
|
399
|
+
*/
|
|
400
|
+
const VersionType = {
|
|
401
|
+
MAJOR: "major",
|
|
402
|
+
MINOR: "minor",
|
|
403
|
+
PATCH: "patch"
|
|
404
|
+
};
|
|
405
|
+
//#endregion
|
|
406
406
|
//#region src/root/functions/taggedTemplate/interpolate.ts
|
|
407
407
|
/**
|
|
408
408
|
* Returns the result of interpolating a template string when given the strings and interpolations separately.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "5.23.
|
|
3
|
+
"version": "5.23.2",
|
|
4
4
|
"description": "Helpful utility functions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,27 +40,27 @@
|
|
|
40
40
|
"execa": "9.6.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@alextheman/eslint-plugin": "5.
|
|
44
|
-
"@types/node": "
|
|
45
|
-
"alex-c-line": "2.
|
|
43
|
+
"@alextheman/eslint-plugin": "5.18.0",
|
|
44
|
+
"@types/node": "26.1.0",
|
|
45
|
+
"alex-c-line": "2.11.3",
|
|
46
46
|
"cross-env": "10.1.0",
|
|
47
47
|
"dotenv-cli": "11.0.0",
|
|
48
|
-
"eslint": "10.
|
|
49
|
-
"globals": "17.
|
|
48
|
+
"eslint": "10.6.0",
|
|
49
|
+
"globals": "17.7.0",
|
|
50
50
|
"husky": "9.1.7",
|
|
51
51
|
"jsdom": "29.1.1",
|
|
52
|
-
"markdownlint-cli2": "0.
|
|
53
|
-
"prettier": "3.
|
|
52
|
+
"markdownlint-cli2": "0.23.0",
|
|
53
|
+
"prettier": "3.9.4",
|
|
54
54
|
"tempy": "3.2.0",
|
|
55
|
-
"tsdown": "0.22.
|
|
56
|
-
"tsx": "4.
|
|
55
|
+
"tsdown": "0.22.3",
|
|
56
|
+
"tsx": "4.23.0",
|
|
57
57
|
"typedoc": "0.28.19",
|
|
58
58
|
"typedoc-plugin-markdown": "4.12.0",
|
|
59
59
|
"typedoc-rhineai-theme": "1.2.0",
|
|
60
60
|
"typescript": "6.0.3",
|
|
61
|
-
"typescript-eslint": "8.
|
|
62
|
-
"vite": "8.
|
|
63
|
-
"vitest": "4.1.
|
|
61
|
+
"typescript-eslint": "8.62.1",
|
|
62
|
+
"vite": "8.1.3",
|
|
63
|
+
"vitest": "4.1.9",
|
|
64
64
|
"zod": "4.4.3"
|
|
65
65
|
},
|
|
66
66
|
"engines": {
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"format-prettier-javascript": "prettier --write \"./**/*.js\"",
|
|
83
83
|
"format-prettier-typescript": "prettier --write --parser typescript \"./**/*.ts\"",
|
|
84
84
|
"format-prettier-yml": "prettier --write \"./**/*.{yml,yaml}\"",
|
|
85
|
-
"lint": "pnpm run lint-tsc && pnpm run lint-eslint && pnpm run lint-markdownlint pnpm run lint-prettier && pnpm run lint-pre-release",
|
|
85
|
+
"lint": "pnpm run lint-tsc && pnpm run lint-eslint && pnpm run lint-markdownlint && pnpm run lint-prettier && pnpm run lint-pre-release",
|
|
86
86
|
"lint-eslint": "eslint \"package.json\" \"{src,tests,configs}/**/*.ts\"",
|
|
87
87
|
"lint-markdownlint": "bash -o pipefail -c 'pnpm exec markdownlint-cli2 \"**/*.md\" \"!{node_modules,dist}/**\"| grep -v \"^Finding:\"'",
|
|
88
88
|
"lint-pre-release": "alex-c-line package-json check --rules no-pre-release-dependencies",
|