@alextheman/utility 5.0.1 → 5.1.1
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 +0 -34
- package/dist/index.d.cts +1 -23
- package/dist/index.d.ts +1 -23
- package/dist/index.js +1 -33
- package/dist/internal/index.cjs +23 -3
- package/dist/internal/index.d.cts +14 -1
- package/dist/internal/index.d.ts +15 -2
- package/dist/internal/index.js +22 -3
- package/dist/node/index.cjs +238 -206
- package/dist/node/index.d.cts +23 -1
- package/dist/node/index.d.ts +23 -1
- package/dist/node/index.js +238 -207
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -28,8 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
//#endregion
|
|
29
29
|
let zod = require("zod");
|
|
30
30
|
zod = __toESM(zod);
|
|
31
|
-
let node_path = require("node:path");
|
|
32
|
-
node_path = __toESM(node_path);
|
|
33
31
|
let libsodium_wrappers = require("libsodium-wrappers");
|
|
34
32
|
libsodium_wrappers = __toESM(libsodium_wrappers);
|
|
35
33
|
|
|
@@ -1333,37 +1331,6 @@ function parseEnv(input) {
|
|
|
1333
1331
|
return parseZodSchema(zod.z.enum(Env), input, new DataError({ input }, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
|
|
1334
1332
|
}
|
|
1335
1333
|
|
|
1336
|
-
//#endregion
|
|
1337
|
-
//#region src/root/functions/parsers/parseFilePath.ts
|
|
1338
|
-
/**
|
|
1339
|
-
* Takes a file path string and parses it into the directory part, the base part, and the full path.
|
|
1340
|
-
*
|
|
1341
|
-
* @category Parsers
|
|
1342
|
-
*
|
|
1343
|
-
* @param filePath - The file path to parse.
|
|
1344
|
-
*
|
|
1345
|
-
* @throws {DataError} If the file path is invalid.
|
|
1346
|
-
*
|
|
1347
|
-
* @returns An object representing the different ways the file path can be represented.
|
|
1348
|
-
*/
|
|
1349
|
-
function parseFilePath(filePath) {
|
|
1350
|
-
const caughtGroups = filePath.match(RegExp(FILE_PATH_REGEX));
|
|
1351
|
-
if (!caughtGroups) {
|
|
1352
|
-
if (!(filePath.includes("/") || filePath.includes("\\")) && filePath.includes(".")) return {
|
|
1353
|
-
directory: "",
|
|
1354
|
-
base: filePath,
|
|
1355
|
-
fullPath: filePath
|
|
1356
|
-
};
|
|
1357
|
-
throw new DataError({ filePath }, "INVALID_FILE_PATH", "The file path you provided is not valid.");
|
|
1358
|
-
}
|
|
1359
|
-
if (!caughtGroups.groups) throw new DataError({ filePath }, "PARSING_ERROR", "An error occurred while trying to parse the data.");
|
|
1360
|
-
return {
|
|
1361
|
-
directory: caughtGroups.groups.directory,
|
|
1362
|
-
base: caughtGroups.groups.base,
|
|
1363
|
-
fullPath: node_path.default.join(caughtGroups.groups.directory.replaceAll("\\", "/"), caughtGroups.groups.base)
|
|
1364
|
-
};
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
1334
|
//#endregion
|
|
1368
1335
|
//#region src/root/functions/parsers/parseFormData.ts
|
|
1369
1336
|
/**
|
|
@@ -1639,7 +1606,6 @@ exports.omitProperties = omitProperties;
|
|
|
1639
1606
|
exports.paralleliseArrays = paralleliseArrays;
|
|
1640
1607
|
exports.parseBoolean = parseBoolean;
|
|
1641
1608
|
exports.parseEnv = parseEnv;
|
|
1642
|
-
exports.parseFilePath = parseFilePath;
|
|
1643
1609
|
exports.parseFormData = parseFormData;
|
|
1644
1610
|
exports.parseIntStrict = parseIntStrict;
|
|
1645
1611
|
exports.parseVersionType = parseVersionType;
|
package/dist/index.d.cts
CHANGED
|
@@ -690,28 +690,6 @@ type Env = CreateEnumType<typeof Env>;
|
|
|
690
690
|
*/
|
|
691
691
|
declare function parseEnv(input: unknown): Env;
|
|
692
692
|
//#endregion
|
|
693
|
-
//#region src/root/functions/parsers/parseFilePath.d.ts
|
|
694
|
-
interface FilePathData {
|
|
695
|
-
/** The file path without the final part. */
|
|
696
|
-
directory: string;
|
|
697
|
-
/** The final part of the file path. */
|
|
698
|
-
base: string;
|
|
699
|
-
/** The full file path, normalised. */
|
|
700
|
-
fullPath: string;
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
* Takes a file path string and parses it into the directory part, the base part, and the full path.
|
|
704
|
-
*
|
|
705
|
-
* @category Parsers
|
|
706
|
-
*
|
|
707
|
-
* @param filePath - The file path to parse.
|
|
708
|
-
*
|
|
709
|
-
* @throws {DataError} If the file path is invalid.
|
|
710
|
-
*
|
|
711
|
-
* @returns An object representing the different ways the file path can be represented.
|
|
712
|
-
*/
|
|
713
|
-
declare function parseFilePath(filePath: string): FilePathData;
|
|
714
|
-
//#endregion
|
|
715
693
|
//#region src/root/functions/parsers/parseFormData.d.ts
|
|
716
694
|
/**
|
|
717
695
|
* Returns a parsed object given FormData and a data parser function to call on the resulting object.
|
|
@@ -1094,4 +1072,4 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
|
|
|
1094
1072
|
*/
|
|
1095
1073
|
declare const normalizeIndents: typeof normaliseIndents;
|
|
1096
1074
|
//#endregion
|
|
1097
|
-
export { APIError, ArrayElement, CallReturnType, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FILE_PATH_REGEX, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IsTypeArgumentString, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, encryptWithKey, fillArray, formatDateAndTime, getDependenciesFromGroup, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv,
|
|
1075
|
+
export { APIError, ArrayElement, CallReturnType, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FILE_PATH_REGEX, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IsTypeArgumentString, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, encryptWithKey, fillArray, formatDateAndTime, getDependenciesFromGroup, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
|
package/dist/index.d.ts
CHANGED
|
@@ -690,28 +690,6 @@ type Env = CreateEnumType<typeof Env>;
|
|
|
690
690
|
*/
|
|
691
691
|
declare function parseEnv(input: unknown): Env;
|
|
692
692
|
//#endregion
|
|
693
|
-
//#region src/root/functions/parsers/parseFilePath.d.ts
|
|
694
|
-
interface FilePathData {
|
|
695
|
-
/** The file path without the final part. */
|
|
696
|
-
directory: string;
|
|
697
|
-
/** The final part of the file path. */
|
|
698
|
-
base: string;
|
|
699
|
-
/** The full file path, normalised. */
|
|
700
|
-
fullPath: string;
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
* Takes a file path string and parses it into the directory part, the base part, and the full path.
|
|
704
|
-
*
|
|
705
|
-
* @category Parsers
|
|
706
|
-
*
|
|
707
|
-
* @param filePath - The file path to parse.
|
|
708
|
-
*
|
|
709
|
-
* @throws {DataError} If the file path is invalid.
|
|
710
|
-
*
|
|
711
|
-
* @returns An object representing the different ways the file path can be represented.
|
|
712
|
-
*/
|
|
713
|
-
declare function parseFilePath(filePath: string): FilePathData;
|
|
714
|
-
//#endregion
|
|
715
693
|
//#region src/root/functions/parsers/parseFormData.d.ts
|
|
716
694
|
/**
|
|
717
695
|
* Returns a parsed object given FormData and a data parser function to call on the resulting object.
|
|
@@ -1094,4 +1072,4 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
|
|
|
1094
1072
|
*/
|
|
1095
1073
|
declare const normalizeIndents: typeof normaliseIndents;
|
|
1096
1074
|
//#endregion
|
|
1097
|
-
export { APIError, type ArrayElement, type CallReturnType, CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type OptionalOnCondition, ParallelTuple, type RecordKey, type RemoveUndefined, type StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, encryptWithKey, fillArray, formatDateAndTime, getDependenciesFromGroup, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv,
|
|
1075
|
+
export { APIError, type ArrayElement, type CallReturnType, CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type OptionalOnCondition, ParallelTuple, type RecordKey, type RemoveUndefined, type StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, encryptWithKey, fillArray, formatDateAndTime, getDependenciesFromGroup, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import z, { z as z$1 } from "zod";
|
|
2
|
-
import path from "node:path";
|
|
3
2
|
import sodium from "libsodium-wrappers";
|
|
4
3
|
|
|
5
4
|
//#region src/root/constants/FILE_PATH_REGEX.ts
|
|
@@ -1302,37 +1301,6 @@ function parseEnv(input) {
|
|
|
1302
1301
|
return parseZodSchema(z$1.enum(Env), input, new DataError({ input }, "INVALID_ENV", "The provided environment type must be one of `test | development | production`"));
|
|
1303
1302
|
}
|
|
1304
1303
|
|
|
1305
|
-
//#endregion
|
|
1306
|
-
//#region src/root/functions/parsers/parseFilePath.ts
|
|
1307
|
-
/**
|
|
1308
|
-
* Takes a file path string and parses it into the directory part, the base part, and the full path.
|
|
1309
|
-
*
|
|
1310
|
-
* @category Parsers
|
|
1311
|
-
*
|
|
1312
|
-
* @param filePath - The file path to parse.
|
|
1313
|
-
*
|
|
1314
|
-
* @throws {DataError} If the file path is invalid.
|
|
1315
|
-
*
|
|
1316
|
-
* @returns An object representing the different ways the file path can be represented.
|
|
1317
|
-
*/
|
|
1318
|
-
function parseFilePath(filePath) {
|
|
1319
|
-
const caughtGroups = filePath.match(RegExp(FILE_PATH_REGEX));
|
|
1320
|
-
if (!caughtGroups) {
|
|
1321
|
-
if (!(filePath.includes("/") || filePath.includes("\\")) && filePath.includes(".")) return {
|
|
1322
|
-
directory: "",
|
|
1323
|
-
base: filePath,
|
|
1324
|
-
fullPath: filePath
|
|
1325
|
-
};
|
|
1326
|
-
throw new DataError({ filePath }, "INVALID_FILE_PATH", "The file path you provided is not valid.");
|
|
1327
|
-
}
|
|
1328
|
-
if (!caughtGroups.groups) throw new DataError({ filePath }, "PARSING_ERROR", "An error occurred while trying to parse the data.");
|
|
1329
|
-
return {
|
|
1330
|
-
directory: caughtGroups.groups.directory,
|
|
1331
|
-
base: caughtGroups.groups.base,
|
|
1332
|
-
fullPath: path.join(caughtGroups.groups.directory.replaceAll("\\", "/"), caughtGroups.groups.base)
|
|
1333
|
-
};
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
1304
|
//#endregion
|
|
1337
1305
|
//#region src/root/functions/parsers/parseFormData.ts
|
|
1338
1306
|
/**
|
|
@@ -1569,4 +1537,4 @@ function truncate(stringToTruncate, maxLength = 5) {
|
|
|
1569
1537
|
}
|
|
1570
1538
|
|
|
1571
1539
|
//#endregion
|
|
1572
|
-
export { APIError, DataError, Env, FILE_PATH_REGEX, NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, encryptWithKey, fillArray, formatDateAndTime, getDependenciesFromGroup, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv,
|
|
1540
|
+
export { APIError, DataError, Env, FILE_PATH_REGEX, NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, encryptWithKey, fillArray, formatDateAndTime, getDependenciesFromGroup, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
|
package/dist/internal/index.cjs
CHANGED
|
@@ -26,13 +26,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
}) : target, mod));
|
|
27
27
|
|
|
28
28
|
//#endregion
|
|
29
|
-
let execa = require("execa");
|
|
30
29
|
let zod = require("zod");
|
|
31
30
|
zod = __toESM(zod);
|
|
32
|
-
let node_path = require("node:path");
|
|
33
|
-
node_path = __toESM(node_path);
|
|
34
31
|
require("libsodium-wrappers");
|
|
32
|
+
let execa = require("execa");
|
|
35
33
|
let node_fs_promises = require("node:fs/promises");
|
|
34
|
+
let node_path = require("node:path");
|
|
35
|
+
node_path = __toESM(node_path);
|
|
36
36
|
|
|
37
37
|
//#region src/internal/DependencyGroup.ts
|
|
38
38
|
const DependencyGroup = {
|
|
@@ -605,6 +605,25 @@ const VersionType = {
|
|
|
605
605
|
PATCH: "patch"
|
|
606
606
|
};
|
|
607
607
|
|
|
608
|
+
//#endregion
|
|
609
|
+
//#region src/internal/getDependenciesFromGroup.ts
|
|
610
|
+
/**
|
|
611
|
+
* Get the dependencies from a given dependency group in `package.json`.
|
|
612
|
+
*
|
|
613
|
+
* @category Miscellaneous
|
|
614
|
+
*
|
|
615
|
+
* @param packageInfo - The data coming from `package.json`.
|
|
616
|
+
* @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
|
|
617
|
+
*
|
|
618
|
+
* @returns A record consisting of the package names and version ranges from the given dependency group.
|
|
619
|
+
*/
|
|
620
|
+
function getDependenciesFromGroup(packageInfo, dependencyGroup) {
|
|
621
|
+
return {
|
|
622
|
+
dependencies: parseZodSchema(zod.default.record(zod.default.string(), zod.default.string()), packageInfo.dependencies ?? {}),
|
|
623
|
+
devDependencies: parseZodSchema(zod.default.record(zod.default.string(), zod.default.string()), packageInfo.devDependencies ?? {})
|
|
624
|
+
}[dependencyGroup];
|
|
625
|
+
}
|
|
626
|
+
|
|
608
627
|
//#endregion
|
|
609
628
|
//#region src/internal/getExpectedTgzName.ts
|
|
610
629
|
async function getExpectedTgzName(packagePath, packageManager) {
|
|
@@ -691,6 +710,7 @@ async function setupPackageEndToEnd(temporaryPath, packageManager, moduleType, o
|
|
|
691
710
|
exports.DependencyGroup = DependencyGroup;
|
|
692
711
|
exports.ModuleType = ModuleType;
|
|
693
712
|
exports.PackageManager = PackageManager;
|
|
713
|
+
exports.getDependenciesFromGroup = getDependenciesFromGroup;
|
|
694
714
|
exports.getExpectedTgzName = getExpectedTgzName;
|
|
695
715
|
exports.getPackageJsonContents = getPackageJsonContents;
|
|
696
716
|
exports.getPackageJsonPath = getPackageJsonPath;
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { ExecaMethod } from "execa";
|
|
2
2
|
|
|
3
|
+
//#region src/internal/getDependenciesFromGroup.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Get the dependencies from a given dependency group in `package.json`.
|
|
6
|
+
*
|
|
7
|
+
* @category Miscellaneous
|
|
8
|
+
*
|
|
9
|
+
* @param packageInfo - The data coming from `package.json`.
|
|
10
|
+
* @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
|
|
11
|
+
*
|
|
12
|
+
* @returns A record consisting of the package names and version ranges from the given dependency group.
|
|
13
|
+
*/
|
|
14
|
+
declare function getDependenciesFromGroup(packageInfo: Record<string, unknown>, dependencyGroup: DependencyGroup): Record<string, string>;
|
|
15
|
+
//#endregion
|
|
3
16
|
//#region src/root/types/RecordKey.d.ts
|
|
4
17
|
/**
|
|
5
18
|
* Represents the native Record's possible key type.
|
|
@@ -104,4 +117,4 @@ declare function setupPackageEndToEnd(temporaryPath: string, packageManager: Pac
|
|
|
104
117
|
cwd: string;
|
|
105
118
|
}>>;
|
|
106
119
|
//#endregion
|
|
107
|
-
export { DependencyGroup, type IsTypeArgumentString, ModuleType, PackageManager, getExpectedTgzName, getPackageJsonContents, getPackageJsonPath, packageJsonNotFoundError, parseJsonFromStdout, sayHello, setupPackageEndToEnd };
|
|
120
|
+
export { DependencyGroup, type IsTypeArgumentString, ModuleType, PackageManager, getDependenciesFromGroup, getExpectedTgzName, getPackageJsonContents, getPackageJsonPath, packageJsonNotFoundError, parseJsonFromStdout, sayHello, setupPackageEndToEnd };
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
import { ExecaMethod } from "execa";
|
|
2
1
|
import z from "zod";
|
|
2
|
+
import { ExecaMethod } from "execa";
|
|
3
3
|
|
|
4
|
+
//#region src/internal/getDependenciesFromGroup.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Get the dependencies from a given dependency group in `package.json`.
|
|
7
|
+
*
|
|
8
|
+
* @category Miscellaneous
|
|
9
|
+
*
|
|
10
|
+
* @param packageInfo - The data coming from `package.json`.
|
|
11
|
+
* @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
|
|
12
|
+
*
|
|
13
|
+
* @returns A record consisting of the package names and version ranges from the given dependency group.
|
|
14
|
+
*/
|
|
15
|
+
declare function getDependenciesFromGroup(packageInfo: Record<string, unknown>, dependencyGroup: DependencyGroup): Record<string, string>;
|
|
16
|
+
//#endregion
|
|
4
17
|
//#region src/root/types/RecordKey.d.ts
|
|
5
18
|
/**
|
|
6
19
|
* Represents the native Record's possible key type.
|
|
@@ -105,4 +118,4 @@ declare function setupPackageEndToEnd(temporaryPath: string, packageManager: Pac
|
|
|
105
118
|
cwd: string;
|
|
106
119
|
}>>;
|
|
107
120
|
//#endregion
|
|
108
|
-
export { DependencyGroup, type IsTypeArgumentString, ModuleType, PackageManager, getExpectedTgzName, getPackageJsonContents, getPackageJsonPath, packageJsonNotFoundError, parseJsonFromStdout, sayHello, setupPackageEndToEnd };
|
|
121
|
+
export { DependencyGroup, type IsTypeArgumentString, ModuleType, PackageManager, getDependenciesFromGroup, getExpectedTgzName, getPackageJsonContents, getPackageJsonPath, packageJsonNotFoundError, parseJsonFromStdout, sayHello, setupPackageEndToEnd };
|
package/dist/internal/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { execa } from "execa";
|
|
2
1
|
import z from "zod";
|
|
3
|
-
import path from "node:path";
|
|
4
2
|
import "libsodium-wrappers";
|
|
3
|
+
import { execa } from "execa";
|
|
5
4
|
import { readFile, writeFile } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
6
|
|
|
7
7
|
//#region src/internal/DependencyGroup.ts
|
|
8
8
|
const DependencyGroup = {
|
|
@@ -575,6 +575,25 @@ const VersionType = {
|
|
|
575
575
|
PATCH: "patch"
|
|
576
576
|
};
|
|
577
577
|
|
|
578
|
+
//#endregion
|
|
579
|
+
//#region src/internal/getDependenciesFromGroup.ts
|
|
580
|
+
/**
|
|
581
|
+
* Get the dependencies from a given dependency group in `package.json`.
|
|
582
|
+
*
|
|
583
|
+
* @category Miscellaneous
|
|
584
|
+
*
|
|
585
|
+
* @param packageInfo - The data coming from `package.json`.
|
|
586
|
+
* @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
|
|
587
|
+
*
|
|
588
|
+
* @returns A record consisting of the package names and version ranges from the given dependency group.
|
|
589
|
+
*/
|
|
590
|
+
function getDependenciesFromGroup(packageInfo, dependencyGroup) {
|
|
591
|
+
return {
|
|
592
|
+
dependencies: parseZodSchema(z.record(z.string(), z.string()), packageInfo.dependencies ?? {}),
|
|
593
|
+
devDependencies: parseZodSchema(z.record(z.string(), z.string()), packageInfo.devDependencies ?? {})
|
|
594
|
+
}[dependencyGroup];
|
|
595
|
+
}
|
|
596
|
+
|
|
578
597
|
//#endregion
|
|
579
598
|
//#region src/internal/getExpectedTgzName.ts
|
|
580
599
|
async function getExpectedTgzName(packagePath, packageManager) {
|
|
@@ -658,4 +677,4 @@ async function setupPackageEndToEnd(temporaryPath, packageManager, moduleType, o
|
|
|
658
677
|
}
|
|
659
678
|
|
|
660
679
|
//#endregion
|
|
661
|
-
export { DependencyGroup, ModuleType, PackageManager, getExpectedTgzName, getPackageJsonContents, getPackageJsonPath, packageJsonNotFoundError, parseJsonFromStdout, sayHello_default as sayHello, setupPackageEndToEnd };
|
|
680
|
+
export { DependencyGroup, ModuleType, PackageManager, getDependenciesFromGroup, getExpectedTgzName, getPackageJsonContents, getPackageJsonPath, packageJsonNotFoundError, parseJsonFromStdout, sayHello_default as sayHello, setupPackageEndToEnd };
|
package/dist/node/index.cjs
CHANGED
|
@@ -76,6 +76,47 @@ const FILE_PATH_REGEX = String.raw`^(?<directory>.+)[\/\\](?<base>[^\/\\]+)$`;
|
|
|
76
76
|
//#region src/root/constants/VERSION_NUMBER_REGEX.ts
|
|
77
77
|
const VERSION_NUMBER_REGEX = "^(?:v)?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$";
|
|
78
78
|
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/root/types/DataError.ts
|
|
81
|
+
/**
|
|
82
|
+
* Represents errors you may get that may've been caused by a specific piece of data.
|
|
83
|
+
*
|
|
84
|
+
* @category Types
|
|
85
|
+
*
|
|
86
|
+
* @template DataType - The type of the data that caused the error.
|
|
87
|
+
*/
|
|
88
|
+
var DataError = class DataError extends Error {
|
|
89
|
+
code;
|
|
90
|
+
data;
|
|
91
|
+
/**
|
|
92
|
+
* @param data - The data that caused the error.
|
|
93
|
+
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
94
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
95
|
+
* @param options - Extra options to pass to super Error constructor.
|
|
96
|
+
*/
|
|
97
|
+
constructor(data, code = "INVALID_DATA", message = "The data provided is invalid", options) {
|
|
98
|
+
super(message, options);
|
|
99
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
|
|
100
|
+
this.name = new.target.name;
|
|
101
|
+
this.code = code;
|
|
102
|
+
this.data = data;
|
|
103
|
+
Object.defineProperty(this, "message", { enumerable: true });
|
|
104
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Checks whether the given input may have been caused by a DataError.
|
|
108
|
+
*
|
|
109
|
+
* @param input - The input to check.
|
|
110
|
+
*
|
|
111
|
+
* @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`.
|
|
112
|
+
*/
|
|
113
|
+
static check(input) {
|
|
114
|
+
if (input instanceof DataError) return true;
|
|
115
|
+
const data = input;
|
|
116
|
+
return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
79
120
|
//#endregion
|
|
80
121
|
//#region src/root/functions/arrayHelpers/fillArray.ts
|
|
81
122
|
/**
|
|
@@ -127,212 +168,6 @@ function paralleliseArrays(firstArray, secondArray) {
|
|
|
127
168
|
return outputArray;
|
|
128
169
|
}
|
|
129
170
|
|
|
130
|
-
//#endregion
|
|
131
|
-
//#region src/root/types/DataError.ts
|
|
132
|
-
/**
|
|
133
|
-
* Represents errors you may get that may've been caused by a specific piece of data.
|
|
134
|
-
*
|
|
135
|
-
* @category Types
|
|
136
|
-
*
|
|
137
|
-
* @template DataType - The type of the data that caused the error.
|
|
138
|
-
*/
|
|
139
|
-
var DataError = class DataError extends Error {
|
|
140
|
-
code;
|
|
141
|
-
data;
|
|
142
|
-
/**
|
|
143
|
-
* @param data - The data that caused the error.
|
|
144
|
-
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
145
|
-
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
146
|
-
* @param options - Extra options to pass to super Error constructor.
|
|
147
|
-
*/
|
|
148
|
-
constructor(data, code = "INVALID_DATA", message = "The data provided is invalid", options) {
|
|
149
|
-
super(message, options);
|
|
150
|
-
if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
|
|
151
|
-
this.name = new.target.name;
|
|
152
|
-
this.code = code;
|
|
153
|
-
this.data = data;
|
|
154
|
-
Object.defineProperty(this, "message", { enumerable: true });
|
|
155
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Checks whether the given input may have been caused by a DataError.
|
|
159
|
-
*
|
|
160
|
-
* @param input - The input to check.
|
|
161
|
-
*
|
|
162
|
-
* @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`.
|
|
163
|
-
*/
|
|
164
|
-
static check(input) {
|
|
165
|
-
if (input instanceof DataError) return true;
|
|
166
|
-
const data = input;
|
|
167
|
-
return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
//#endregion
|
|
172
|
-
//#region src/root/types/VersionNumber.ts
|
|
173
|
-
/**
|
|
174
|
-
* Represents a software version number, considered to be made up of a major, minor, and patch part.
|
|
175
|
-
*
|
|
176
|
-
* @category Types
|
|
177
|
-
*/
|
|
178
|
-
var VersionNumber = class VersionNumber {
|
|
179
|
-
static NON_NEGATIVE_TUPLE_ERROR = "Input array must be a tuple of three non-negative integers.";
|
|
180
|
-
/** The major number. Increments when a feature is removed or changed in a way that is not backwards-compatible with the previous release. */
|
|
181
|
-
major = 0;
|
|
182
|
-
/** The minor number. Increments when a new feature is added/deprecated and is expected to be backwards-compatible with the previous release. */
|
|
183
|
-
minor = 0;
|
|
184
|
-
/** The patch number. Increments when the next release is fixing a bug or doing a small refactor that should not be noticeable in practice. */
|
|
185
|
-
patch = 0;
|
|
186
|
-
/**
|
|
187
|
-
* @param input - The input to create a new instance of `VersionNumber` from.
|
|
188
|
-
*/
|
|
189
|
-
constructor(input) {
|
|
190
|
-
if (input instanceof VersionNumber) {
|
|
191
|
-
this.major = input.major;
|
|
192
|
-
this.minor = input.minor;
|
|
193
|
-
this.patch = input.patch;
|
|
194
|
-
} else if (typeof input === "string") {
|
|
195
|
-
if (!RegExp(VERSION_NUMBER_REGEX).test(input)) throw new DataError({ input }, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
|
|
196
|
-
const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
|
|
197
|
-
return parseIntStrict(number);
|
|
198
|
-
});
|
|
199
|
-
this.major = major;
|
|
200
|
-
this.minor = minor;
|
|
201
|
-
this.patch = patch;
|
|
202
|
-
} else if (Array.isArray(input)) {
|
|
203
|
-
if (input.length !== 3) throw new DataError({ input }, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
204
|
-
const [major, minor, patch] = input.map((number) => {
|
|
205
|
-
const parsedInteger = parseIntStrict(number?.toString());
|
|
206
|
-
if (parsedInteger < 0) throw new DataError({ input }, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
207
|
-
return parsedInteger;
|
|
208
|
-
});
|
|
209
|
-
this.major = major;
|
|
210
|
-
this.minor = minor;
|
|
211
|
-
this.patch = patch;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Gets the current version type of the current instance of `VersionNumber`.
|
|
216
|
-
*
|
|
217
|
-
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
218
|
-
*/
|
|
219
|
-
get type() {
|
|
220
|
-
if (this.minor === 0 && this.patch === 0) return VersionType.MAJOR;
|
|
221
|
-
if (this.patch === 0) return VersionType.MINOR;
|
|
222
|
-
return VersionType.PATCH;
|
|
223
|
-
}
|
|
224
|
-
static formatString(input, options) {
|
|
225
|
-
if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
|
|
226
|
-
return input.startsWith("v") ? input : `v${input}`;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Checks if the provided version numbers have the exact same major, minor, and patch numbers.
|
|
230
|
-
*
|
|
231
|
-
* @param firstVersion - The first version number to compare.
|
|
232
|
-
* @param secondVersion - The second version number to compare.
|
|
233
|
-
*
|
|
234
|
-
* @returns `true` if the provided version numbers have exactly the same major, minor, and patch numbers, and returns `false` otherwise.
|
|
235
|
-
*/
|
|
236
|
-
static isEqual(firstVersion, secondVersion) {
|
|
237
|
-
return firstVersion.major === secondVersion.major && firstVersion.minor === secondVersion.minor && firstVersion.patch === secondVersion.patch;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Get a formatted string representation of the current version number
|
|
241
|
-
*
|
|
242
|
-
* @param options - Options to apply to the string formatting.
|
|
243
|
-
*
|
|
244
|
-
* @returns A formatted string representation of the current version number with the options applied.
|
|
245
|
-
*/
|
|
246
|
-
format(options) {
|
|
247
|
-
let baseOutput = `${this.major}`;
|
|
248
|
-
if (!options?.omitMinor) {
|
|
249
|
-
baseOutput += `.${this.minor}`;
|
|
250
|
-
if (!options?.omitPatch) baseOutput += `.${this.patch}`;
|
|
251
|
-
}
|
|
252
|
-
return VersionNumber.formatString(baseOutput, { omitPrefix: options?.omitPrefix });
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Increments the current version number by the given increment type, returning the result as a new reference in memory.
|
|
256
|
-
*
|
|
257
|
-
* @param incrementType - The type of increment. Can be one of the following:
|
|
258
|
-
* - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
|
|
259
|
-
* - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
|
|
260
|
-
* - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
|
|
261
|
-
* @param incrementAmount - The amount to increment by (defaults to 1).
|
|
262
|
-
*
|
|
263
|
-
* @returns A new instance of `VersionNumber` with the increment applied.
|
|
264
|
-
*/
|
|
265
|
-
increment(incrementType, incrementAmount = 1) {
|
|
266
|
-
const incrementBy = parseIntStrict(String(incrementAmount));
|
|
267
|
-
const calculatedRawVersion = {
|
|
268
|
-
major: [
|
|
269
|
-
this.major + incrementBy,
|
|
270
|
-
0,
|
|
271
|
-
0
|
|
272
|
-
],
|
|
273
|
-
minor: [
|
|
274
|
-
this.major,
|
|
275
|
-
this.minor + incrementBy,
|
|
276
|
-
0
|
|
277
|
-
],
|
|
278
|
-
patch: [
|
|
279
|
-
this.major,
|
|
280
|
-
this.minor,
|
|
281
|
-
this.patch + incrementBy
|
|
282
|
-
]
|
|
283
|
-
}[incrementType];
|
|
284
|
-
try {
|
|
285
|
-
return new VersionNumber(calculatedRawVersion);
|
|
286
|
-
} catch (error) {
|
|
287
|
-
if (DataError.check(error) && error.code === "NEGATIVE_INPUTS") throw new DataError({
|
|
288
|
-
currentVersion: this.toString(),
|
|
289
|
-
calculatedRawVersion: `v${calculatedRawVersion.join(".")}`,
|
|
290
|
-
incrementAmount
|
|
291
|
-
}, "NEGATIVE_VERSION", "Cannot apply this increment amount as it would lead to a negative version number.");
|
|
292
|
-
else throw error;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Ensures that the VersionNumber behaves correctly when attempted to be coerced to a string.
|
|
297
|
-
*
|
|
298
|
-
* @param hint - Not used as of now, but generally used to help with numeric coercion, I think (which we most likely do not need for version numbers).
|
|
299
|
-
*
|
|
300
|
-
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
301
|
-
*/
|
|
302
|
-
[Symbol.toPrimitive](hint) {
|
|
303
|
-
if (hint === "number") throw new DataError({ thisVersion: this.toString() }, "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
|
|
304
|
-
return this.toString();
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Ensures that the VersionNumber behaves correctly when attempted to be converted to JSON.
|
|
308
|
-
*
|
|
309
|
-
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
310
|
-
*/
|
|
311
|
-
toJSON() {
|
|
312
|
-
return this.toString();
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Get a string representation of the current version number.
|
|
316
|
-
*
|
|
317
|
-
* @returns A stringified representation of the current version number with the prefix.
|
|
318
|
-
*/
|
|
319
|
-
toString() {
|
|
320
|
-
const rawString = `${this.major}.${this.minor}.${this.patch}`;
|
|
321
|
-
return VersionNumber.formatString(rawString, { omitPrefix: false });
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
const zodVersionNumber = zod.default.union([
|
|
325
|
-
zod.default.string(),
|
|
326
|
-
zod.default.tuple([
|
|
327
|
-
zod.default.number(),
|
|
328
|
-
zod.default.number(),
|
|
329
|
-
zod.default.number()
|
|
330
|
-
]),
|
|
331
|
-
zod.default.instanceof(VersionNumber)
|
|
332
|
-
]).transform((rawVersionNumber) => {
|
|
333
|
-
return new VersionNumber(rawVersionNumber);
|
|
334
|
-
});
|
|
335
|
-
|
|
336
171
|
//#endregion
|
|
337
172
|
//#region src/root/functions/parsers/parseIntStrict.ts
|
|
338
173
|
/**
|
|
@@ -584,6 +419,202 @@ const VersionType = {
|
|
|
584
419
|
PATCH: "patch"
|
|
585
420
|
};
|
|
586
421
|
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region src/root/types/VersionNumber.ts
|
|
424
|
+
/**
|
|
425
|
+
* Represents a software version number, considered to be made up of a major, minor, and patch part.
|
|
426
|
+
*
|
|
427
|
+
* @category Types
|
|
428
|
+
*/
|
|
429
|
+
var VersionNumber = class VersionNumber {
|
|
430
|
+
static NON_NEGATIVE_TUPLE_ERROR = "Input array must be a tuple of three non-negative integers.";
|
|
431
|
+
/** The major number. Increments when a feature is removed or changed in a way that is not backwards-compatible with the previous release. */
|
|
432
|
+
major = 0;
|
|
433
|
+
/** The minor number. Increments when a new feature is added/deprecated and is expected to be backwards-compatible with the previous release. */
|
|
434
|
+
minor = 0;
|
|
435
|
+
/** The patch number. Increments when the next release is fixing a bug or doing a small refactor that should not be noticeable in practice. */
|
|
436
|
+
patch = 0;
|
|
437
|
+
/**
|
|
438
|
+
* @param input - The input to create a new instance of `VersionNumber` from.
|
|
439
|
+
*/
|
|
440
|
+
constructor(input) {
|
|
441
|
+
if (input instanceof VersionNumber) {
|
|
442
|
+
this.major = input.major;
|
|
443
|
+
this.minor = input.minor;
|
|
444
|
+
this.patch = input.patch;
|
|
445
|
+
} else if (typeof input === "string") {
|
|
446
|
+
if (!RegExp(VERSION_NUMBER_REGEX).test(input)) throw new DataError({ input }, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
|
|
447
|
+
const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
|
|
448
|
+
return parseIntStrict(number);
|
|
449
|
+
});
|
|
450
|
+
this.major = major;
|
|
451
|
+
this.minor = minor;
|
|
452
|
+
this.patch = patch;
|
|
453
|
+
} else if (Array.isArray(input)) {
|
|
454
|
+
if (input.length !== 3) throw new DataError({ input }, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
455
|
+
const [major, minor, patch] = input.map((number) => {
|
|
456
|
+
const parsedInteger = parseIntStrict(number?.toString());
|
|
457
|
+
if (parsedInteger < 0) throw new DataError({ input }, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
458
|
+
return parsedInteger;
|
|
459
|
+
});
|
|
460
|
+
this.major = major;
|
|
461
|
+
this.minor = minor;
|
|
462
|
+
this.patch = patch;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Gets the current version type of the current instance of `VersionNumber`.
|
|
467
|
+
*
|
|
468
|
+
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
469
|
+
*/
|
|
470
|
+
get type() {
|
|
471
|
+
if (this.minor === 0 && this.patch === 0) return VersionType.MAJOR;
|
|
472
|
+
if (this.patch === 0) return VersionType.MINOR;
|
|
473
|
+
return VersionType.PATCH;
|
|
474
|
+
}
|
|
475
|
+
static formatString(input, options) {
|
|
476
|
+
if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
|
|
477
|
+
return input.startsWith("v") ? input : `v${input}`;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Checks if the provided version numbers have the exact same major, minor, and patch numbers.
|
|
481
|
+
*
|
|
482
|
+
* @param firstVersion - The first version number to compare.
|
|
483
|
+
* @param secondVersion - The second version number to compare.
|
|
484
|
+
*
|
|
485
|
+
* @returns `true` if the provided version numbers have exactly the same major, minor, and patch numbers, and returns `false` otherwise.
|
|
486
|
+
*/
|
|
487
|
+
static isEqual(firstVersion, secondVersion) {
|
|
488
|
+
return firstVersion.major === secondVersion.major && firstVersion.minor === secondVersion.minor && firstVersion.patch === secondVersion.patch;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Get a formatted string representation of the current version number
|
|
492
|
+
*
|
|
493
|
+
* @param options - Options to apply to the string formatting.
|
|
494
|
+
*
|
|
495
|
+
* @returns A formatted string representation of the current version number with the options applied.
|
|
496
|
+
*/
|
|
497
|
+
format(options) {
|
|
498
|
+
let baseOutput = `${this.major}`;
|
|
499
|
+
if (!options?.omitMinor) {
|
|
500
|
+
baseOutput += `.${this.minor}`;
|
|
501
|
+
if (!options?.omitPatch) baseOutput += `.${this.patch}`;
|
|
502
|
+
}
|
|
503
|
+
return VersionNumber.formatString(baseOutput, { omitPrefix: options?.omitPrefix });
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Increments the current version number by the given increment type, returning the result as a new reference in memory.
|
|
507
|
+
*
|
|
508
|
+
* @param incrementType - The type of increment. Can be one of the following:
|
|
509
|
+
* - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
|
|
510
|
+
* - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
|
|
511
|
+
* - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
|
|
512
|
+
* @param incrementAmount - The amount to increment by (defaults to 1).
|
|
513
|
+
*
|
|
514
|
+
* @returns A new instance of `VersionNumber` with the increment applied.
|
|
515
|
+
*/
|
|
516
|
+
increment(incrementType, incrementAmount = 1) {
|
|
517
|
+
const incrementBy = parseIntStrict(String(incrementAmount));
|
|
518
|
+
const calculatedRawVersion = {
|
|
519
|
+
major: [
|
|
520
|
+
this.major + incrementBy,
|
|
521
|
+
0,
|
|
522
|
+
0
|
|
523
|
+
],
|
|
524
|
+
minor: [
|
|
525
|
+
this.major,
|
|
526
|
+
this.minor + incrementBy,
|
|
527
|
+
0
|
|
528
|
+
],
|
|
529
|
+
patch: [
|
|
530
|
+
this.major,
|
|
531
|
+
this.minor,
|
|
532
|
+
this.patch + incrementBy
|
|
533
|
+
]
|
|
534
|
+
}[incrementType];
|
|
535
|
+
try {
|
|
536
|
+
return new VersionNumber(calculatedRawVersion);
|
|
537
|
+
} catch (error) {
|
|
538
|
+
if (DataError.check(error) && error.code === "NEGATIVE_INPUTS") throw new DataError({
|
|
539
|
+
currentVersion: this.toString(),
|
|
540
|
+
calculatedRawVersion: `v${calculatedRawVersion.join(".")}`,
|
|
541
|
+
incrementAmount
|
|
542
|
+
}, "NEGATIVE_VERSION", "Cannot apply this increment amount as it would lead to a negative version number.");
|
|
543
|
+
else throw error;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Ensures that the VersionNumber behaves correctly when attempted to be coerced to a string.
|
|
548
|
+
*
|
|
549
|
+
* @param hint - Not used as of now, but generally used to help with numeric coercion, I think (which we most likely do not need for version numbers).
|
|
550
|
+
*
|
|
551
|
+
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
552
|
+
*/
|
|
553
|
+
[Symbol.toPrimitive](hint) {
|
|
554
|
+
if (hint === "number") throw new DataError({ thisVersion: this.toString() }, "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
|
|
555
|
+
return this.toString();
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Ensures that the VersionNumber behaves correctly when attempted to be converted to JSON.
|
|
559
|
+
*
|
|
560
|
+
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
561
|
+
*/
|
|
562
|
+
toJSON() {
|
|
563
|
+
return this.toString();
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Get a string representation of the current version number.
|
|
567
|
+
*
|
|
568
|
+
* @returns A stringified representation of the current version number with the prefix.
|
|
569
|
+
*/
|
|
570
|
+
toString() {
|
|
571
|
+
const rawString = `${this.major}.${this.minor}.${this.patch}`;
|
|
572
|
+
return VersionNumber.formatString(rawString, { omitPrefix: false });
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
const zodVersionNumber = zod.default.union([
|
|
576
|
+
zod.default.string(),
|
|
577
|
+
zod.default.tuple([
|
|
578
|
+
zod.default.number(),
|
|
579
|
+
zod.default.number(),
|
|
580
|
+
zod.default.number()
|
|
581
|
+
]),
|
|
582
|
+
zod.default.instanceof(VersionNumber)
|
|
583
|
+
]).transform((rawVersionNumber) => {
|
|
584
|
+
return new VersionNumber(rawVersionNumber);
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
//#endregion
|
|
588
|
+
//#region src/node/functions/parseFilePath.ts
|
|
589
|
+
/**
|
|
590
|
+
* Takes a file path string and parses it into the directory part, the base part, and the full path.
|
|
591
|
+
*
|
|
592
|
+
* @category Parsers
|
|
593
|
+
*
|
|
594
|
+
* @param filePath - The file path to parse.
|
|
595
|
+
*
|
|
596
|
+
* @throws {DataError} If the file path is invalid.
|
|
597
|
+
*
|
|
598
|
+
* @returns An object representing the different ways the file path can be represented.
|
|
599
|
+
*/
|
|
600
|
+
function parseFilePath(filePath) {
|
|
601
|
+
const caughtGroups = filePath.match(RegExp(FILE_PATH_REGEX));
|
|
602
|
+
if (!caughtGroups) {
|
|
603
|
+
if (!(filePath.includes("/") || filePath.includes("\\")) && filePath.includes(".")) return {
|
|
604
|
+
directory: "",
|
|
605
|
+
base: filePath,
|
|
606
|
+
fullPath: filePath
|
|
607
|
+
};
|
|
608
|
+
throw new DataError({ filePath }, "INVALID_FILE_PATH", "The file path you provided is not valid.");
|
|
609
|
+
}
|
|
610
|
+
if (!caughtGroups.groups) throw new DataError({ filePath }, "PARSING_ERROR", "An error occurred while trying to parse the data.");
|
|
611
|
+
return {
|
|
612
|
+
directory: caughtGroups.groups.directory,
|
|
613
|
+
base: caughtGroups.groups.base,
|
|
614
|
+
fullPath: node_path.default.join(caughtGroups.groups.directory.replaceAll("\\", "/"), caughtGroups.groups.base)
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
|
|
587
618
|
//#endregion
|
|
588
619
|
//#region src/node/functions/sayHello.ts
|
|
589
620
|
var sayHello_default = sayHello;
|
|
@@ -591,4 +622,5 @@ var sayHello_default = sayHello;
|
|
|
591
622
|
//#endregion
|
|
592
623
|
exports.normaliseImportPath = normaliseImportPath;
|
|
593
624
|
exports.normalizeImportPath = normalizeImportPath;
|
|
625
|
+
exports.parseFilePath = parseFilePath;
|
|
594
626
|
exports.sayHello = sayHello_default;
|
package/dist/node/index.d.cts
CHANGED
|
@@ -30,6 +30,28 @@ declare function normalizeImportPath(importPath: string): string;
|
|
|
30
30
|
*/
|
|
31
31
|
declare const normaliseImportPath: typeof normalizeImportPath;
|
|
32
32
|
//#endregion
|
|
33
|
+
//#region src/node/functions/parseFilePath.d.ts
|
|
34
|
+
interface FilePathData {
|
|
35
|
+
/** The file path without the final part. */
|
|
36
|
+
directory: string;
|
|
37
|
+
/** The final part of the file path. */
|
|
38
|
+
base: string;
|
|
39
|
+
/** The full file path, normalised. */
|
|
40
|
+
fullPath: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Takes a file path string and parses it into the directory part, the base part, and the full path.
|
|
44
|
+
*
|
|
45
|
+
* @category Parsers
|
|
46
|
+
*
|
|
47
|
+
* @param filePath - The file path to parse.
|
|
48
|
+
*
|
|
49
|
+
* @throws {DataError} If the file path is invalid.
|
|
50
|
+
*
|
|
51
|
+
* @returns An object representing the different ways the file path can be represented.
|
|
52
|
+
*/
|
|
53
|
+
declare function parseFilePath(filePath: string): FilePathData;
|
|
54
|
+
//#endregion
|
|
33
55
|
//#region src/root/types/IsTypeArgumentString.d.ts
|
|
34
56
|
type IsTypeArgumentString<Argument extends string> = Argument;
|
|
35
57
|
//#endregion
|
|
@@ -43,4 +65,4 @@ type IsTypeArgumentString<Argument extends string> = Argument;
|
|
|
43
65
|
*/
|
|
44
66
|
declare function sayHello(): string;
|
|
45
67
|
//#endregion
|
|
46
|
-
export { IsTypeArgumentString, normaliseImportPath, normalizeImportPath, sayHello };
|
|
68
|
+
export { IsTypeArgumentString, normaliseImportPath, normalizeImportPath, parseFilePath, sayHello };
|
package/dist/node/index.d.ts
CHANGED
|
@@ -32,6 +32,28 @@ declare function normalizeImportPath(importPath: string): string;
|
|
|
32
32
|
*/
|
|
33
33
|
declare const normaliseImportPath: typeof normalizeImportPath;
|
|
34
34
|
//#endregion
|
|
35
|
+
//#region src/node/functions/parseFilePath.d.ts
|
|
36
|
+
interface FilePathData {
|
|
37
|
+
/** The file path without the final part. */
|
|
38
|
+
directory: string;
|
|
39
|
+
/** The final part of the file path. */
|
|
40
|
+
base: string;
|
|
41
|
+
/** The full file path, normalised. */
|
|
42
|
+
fullPath: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Takes a file path string and parses it into the directory part, the base part, and the full path.
|
|
46
|
+
*
|
|
47
|
+
* @category Parsers
|
|
48
|
+
*
|
|
49
|
+
* @param filePath - The file path to parse.
|
|
50
|
+
*
|
|
51
|
+
* @throws {DataError} If the file path is invalid.
|
|
52
|
+
*
|
|
53
|
+
* @returns An object representing the different ways the file path can be represented.
|
|
54
|
+
*/
|
|
55
|
+
declare function parseFilePath(filePath: string): FilePathData;
|
|
56
|
+
//#endregion
|
|
35
57
|
//#region src/root/types/IsTypeArgumentString.d.ts
|
|
36
58
|
type IsTypeArgumentString<Argument extends string> = Argument;
|
|
37
59
|
//#endregion
|
|
@@ -45,4 +67,4 @@ type IsTypeArgumentString<Argument extends string> = Argument;
|
|
|
45
67
|
*/
|
|
46
68
|
declare function sayHello(): string;
|
|
47
69
|
//#endregion
|
|
48
|
-
export { type IsTypeArgumentString, normaliseImportPath, normalizeImportPath, sayHello };
|
|
70
|
+
export { type IsTypeArgumentString, normaliseImportPath, normalizeImportPath, parseFilePath, sayHello };
|
package/dist/node/index.js
CHANGED
|
@@ -46,6 +46,47 @@ const FILE_PATH_REGEX = String.raw`^(?<directory>.+)[\/\\](?<base>[^\/\\]+)$`;
|
|
|
46
46
|
//#region src/root/constants/VERSION_NUMBER_REGEX.ts
|
|
47
47
|
const VERSION_NUMBER_REGEX = "^(?:v)?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$";
|
|
48
48
|
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/root/types/DataError.ts
|
|
51
|
+
/**
|
|
52
|
+
* Represents errors you may get that may've been caused by a specific piece of data.
|
|
53
|
+
*
|
|
54
|
+
* @category Types
|
|
55
|
+
*
|
|
56
|
+
* @template DataType - The type of the data that caused the error.
|
|
57
|
+
*/
|
|
58
|
+
var DataError = class DataError extends Error {
|
|
59
|
+
code;
|
|
60
|
+
data;
|
|
61
|
+
/**
|
|
62
|
+
* @param data - The data that caused the error.
|
|
63
|
+
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
64
|
+
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
65
|
+
* @param options - Extra options to pass to super Error constructor.
|
|
66
|
+
*/
|
|
67
|
+
constructor(data, code = "INVALID_DATA", message = "The data provided is invalid", options) {
|
|
68
|
+
super(message, options);
|
|
69
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
|
|
70
|
+
this.name = new.target.name;
|
|
71
|
+
this.code = code;
|
|
72
|
+
this.data = data;
|
|
73
|
+
Object.defineProperty(this, "message", { enumerable: true });
|
|
74
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Checks whether the given input may have been caused by a DataError.
|
|
78
|
+
*
|
|
79
|
+
* @param input - The input to check.
|
|
80
|
+
*
|
|
81
|
+
* @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`.
|
|
82
|
+
*/
|
|
83
|
+
static check(input) {
|
|
84
|
+
if (input instanceof DataError) return true;
|
|
85
|
+
const data = input;
|
|
86
|
+
return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
49
90
|
//#endregion
|
|
50
91
|
//#region src/root/functions/arrayHelpers/fillArray.ts
|
|
51
92
|
/**
|
|
@@ -97,212 +138,6 @@ function paralleliseArrays(firstArray, secondArray) {
|
|
|
97
138
|
return outputArray;
|
|
98
139
|
}
|
|
99
140
|
|
|
100
|
-
//#endregion
|
|
101
|
-
//#region src/root/types/DataError.ts
|
|
102
|
-
/**
|
|
103
|
-
* Represents errors you may get that may've been caused by a specific piece of data.
|
|
104
|
-
*
|
|
105
|
-
* @category Types
|
|
106
|
-
*
|
|
107
|
-
* @template DataType - The type of the data that caused the error.
|
|
108
|
-
*/
|
|
109
|
-
var DataError = class DataError extends Error {
|
|
110
|
-
code;
|
|
111
|
-
data;
|
|
112
|
-
/**
|
|
113
|
-
* @param data - The data that caused the error.
|
|
114
|
-
* @param code - A standardised code (e.g. UNEXPECTED_DATA).
|
|
115
|
-
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
116
|
-
* @param options - Extra options to pass to super Error constructor.
|
|
117
|
-
*/
|
|
118
|
-
constructor(data, code = "INVALID_DATA", message = "The data provided is invalid", options) {
|
|
119
|
-
super(message, options);
|
|
120
|
-
if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
|
|
121
|
-
this.name = new.target.name;
|
|
122
|
-
this.code = code;
|
|
123
|
-
this.data = data;
|
|
124
|
-
Object.defineProperty(this, "message", { enumerable: true });
|
|
125
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Checks whether the given input may have been caused by a DataError.
|
|
129
|
-
*
|
|
130
|
-
* @param input - The input to check.
|
|
131
|
-
*
|
|
132
|
-
* @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`.
|
|
133
|
-
*/
|
|
134
|
-
static check(input) {
|
|
135
|
-
if (input instanceof DataError) return true;
|
|
136
|
-
const data = input;
|
|
137
|
-
return typeof data === "object" && data !== null && typeof data.message === "string" && typeof data.code === "string" && "data" in data;
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
//#endregion
|
|
142
|
-
//#region src/root/types/VersionNumber.ts
|
|
143
|
-
/**
|
|
144
|
-
* Represents a software version number, considered to be made up of a major, minor, and patch part.
|
|
145
|
-
*
|
|
146
|
-
* @category Types
|
|
147
|
-
*/
|
|
148
|
-
var VersionNumber = class VersionNumber {
|
|
149
|
-
static NON_NEGATIVE_TUPLE_ERROR = "Input array must be a tuple of three non-negative integers.";
|
|
150
|
-
/** The major number. Increments when a feature is removed or changed in a way that is not backwards-compatible with the previous release. */
|
|
151
|
-
major = 0;
|
|
152
|
-
/** The minor number. Increments when a new feature is added/deprecated and is expected to be backwards-compatible with the previous release. */
|
|
153
|
-
minor = 0;
|
|
154
|
-
/** The patch number. Increments when the next release is fixing a bug or doing a small refactor that should not be noticeable in practice. */
|
|
155
|
-
patch = 0;
|
|
156
|
-
/**
|
|
157
|
-
* @param input - The input to create a new instance of `VersionNumber` from.
|
|
158
|
-
*/
|
|
159
|
-
constructor(input) {
|
|
160
|
-
if (input instanceof VersionNumber) {
|
|
161
|
-
this.major = input.major;
|
|
162
|
-
this.minor = input.minor;
|
|
163
|
-
this.patch = input.patch;
|
|
164
|
-
} else if (typeof input === "string") {
|
|
165
|
-
if (!RegExp(VERSION_NUMBER_REGEX).test(input)) throw new DataError({ input }, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
|
|
166
|
-
const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
|
|
167
|
-
return parseIntStrict(number);
|
|
168
|
-
});
|
|
169
|
-
this.major = major;
|
|
170
|
-
this.minor = minor;
|
|
171
|
-
this.patch = patch;
|
|
172
|
-
} else if (Array.isArray(input)) {
|
|
173
|
-
if (input.length !== 3) throw new DataError({ input }, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
174
|
-
const [major, minor, patch] = input.map((number) => {
|
|
175
|
-
const parsedInteger = parseIntStrict(number?.toString());
|
|
176
|
-
if (parsedInteger < 0) throw new DataError({ input }, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
177
|
-
return parsedInteger;
|
|
178
|
-
});
|
|
179
|
-
this.major = major;
|
|
180
|
-
this.minor = minor;
|
|
181
|
-
this.patch = patch;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Gets the current version type of the current instance of `VersionNumber`.
|
|
186
|
-
*
|
|
187
|
-
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
188
|
-
*/
|
|
189
|
-
get type() {
|
|
190
|
-
if (this.minor === 0 && this.patch === 0) return VersionType.MAJOR;
|
|
191
|
-
if (this.patch === 0) return VersionType.MINOR;
|
|
192
|
-
return VersionType.PATCH;
|
|
193
|
-
}
|
|
194
|
-
static formatString(input, options) {
|
|
195
|
-
if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
|
|
196
|
-
return input.startsWith("v") ? input : `v${input}`;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Checks if the provided version numbers have the exact same major, minor, and patch numbers.
|
|
200
|
-
*
|
|
201
|
-
* @param firstVersion - The first version number to compare.
|
|
202
|
-
* @param secondVersion - The second version number to compare.
|
|
203
|
-
*
|
|
204
|
-
* @returns `true` if the provided version numbers have exactly the same major, minor, and patch numbers, and returns `false` otherwise.
|
|
205
|
-
*/
|
|
206
|
-
static isEqual(firstVersion, secondVersion) {
|
|
207
|
-
return firstVersion.major === secondVersion.major && firstVersion.minor === secondVersion.minor && firstVersion.patch === secondVersion.patch;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Get a formatted string representation of the current version number
|
|
211
|
-
*
|
|
212
|
-
* @param options - Options to apply to the string formatting.
|
|
213
|
-
*
|
|
214
|
-
* @returns A formatted string representation of the current version number with the options applied.
|
|
215
|
-
*/
|
|
216
|
-
format(options) {
|
|
217
|
-
let baseOutput = `${this.major}`;
|
|
218
|
-
if (!options?.omitMinor) {
|
|
219
|
-
baseOutput += `.${this.minor}`;
|
|
220
|
-
if (!options?.omitPatch) baseOutput += `.${this.patch}`;
|
|
221
|
-
}
|
|
222
|
-
return VersionNumber.formatString(baseOutput, { omitPrefix: options?.omitPrefix });
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Increments the current version number by the given increment type, returning the result as a new reference in memory.
|
|
226
|
-
*
|
|
227
|
-
* @param incrementType - The type of increment. Can be one of the following:
|
|
228
|
-
* - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
|
|
229
|
-
* - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
|
|
230
|
-
* - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
|
|
231
|
-
* @param incrementAmount - The amount to increment by (defaults to 1).
|
|
232
|
-
*
|
|
233
|
-
* @returns A new instance of `VersionNumber` with the increment applied.
|
|
234
|
-
*/
|
|
235
|
-
increment(incrementType, incrementAmount = 1) {
|
|
236
|
-
const incrementBy = parseIntStrict(String(incrementAmount));
|
|
237
|
-
const calculatedRawVersion = {
|
|
238
|
-
major: [
|
|
239
|
-
this.major + incrementBy,
|
|
240
|
-
0,
|
|
241
|
-
0
|
|
242
|
-
],
|
|
243
|
-
minor: [
|
|
244
|
-
this.major,
|
|
245
|
-
this.minor + incrementBy,
|
|
246
|
-
0
|
|
247
|
-
],
|
|
248
|
-
patch: [
|
|
249
|
-
this.major,
|
|
250
|
-
this.minor,
|
|
251
|
-
this.patch + incrementBy
|
|
252
|
-
]
|
|
253
|
-
}[incrementType];
|
|
254
|
-
try {
|
|
255
|
-
return new VersionNumber(calculatedRawVersion);
|
|
256
|
-
} catch (error) {
|
|
257
|
-
if (DataError.check(error) && error.code === "NEGATIVE_INPUTS") throw new DataError({
|
|
258
|
-
currentVersion: this.toString(),
|
|
259
|
-
calculatedRawVersion: `v${calculatedRawVersion.join(".")}`,
|
|
260
|
-
incrementAmount
|
|
261
|
-
}, "NEGATIVE_VERSION", "Cannot apply this increment amount as it would lead to a negative version number.");
|
|
262
|
-
else throw error;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Ensures that the VersionNumber behaves correctly when attempted to be coerced to a string.
|
|
267
|
-
*
|
|
268
|
-
* @param hint - Not used as of now, but generally used to help with numeric coercion, I think (which we most likely do not need for version numbers).
|
|
269
|
-
*
|
|
270
|
-
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
271
|
-
*/
|
|
272
|
-
[Symbol.toPrimitive](hint) {
|
|
273
|
-
if (hint === "number") throw new DataError({ thisVersion: this.toString() }, "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
|
|
274
|
-
return this.toString();
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Ensures that the VersionNumber behaves correctly when attempted to be converted to JSON.
|
|
278
|
-
*
|
|
279
|
-
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
280
|
-
*/
|
|
281
|
-
toJSON() {
|
|
282
|
-
return this.toString();
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Get a string representation of the current version number.
|
|
286
|
-
*
|
|
287
|
-
* @returns A stringified representation of the current version number with the prefix.
|
|
288
|
-
*/
|
|
289
|
-
toString() {
|
|
290
|
-
const rawString = `${this.major}.${this.minor}.${this.patch}`;
|
|
291
|
-
return VersionNumber.formatString(rawString, { omitPrefix: false });
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
const zodVersionNumber = z.union([
|
|
295
|
-
z.string(),
|
|
296
|
-
z.tuple([
|
|
297
|
-
z.number(),
|
|
298
|
-
z.number(),
|
|
299
|
-
z.number()
|
|
300
|
-
]),
|
|
301
|
-
z.instanceof(VersionNumber)
|
|
302
|
-
]).transform((rawVersionNumber) => {
|
|
303
|
-
return new VersionNumber(rawVersionNumber);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
141
|
//#endregion
|
|
307
142
|
//#region src/root/functions/parsers/parseIntStrict.ts
|
|
308
143
|
/**
|
|
@@ -554,9 +389,205 @@ const VersionType = {
|
|
|
554
389
|
PATCH: "patch"
|
|
555
390
|
};
|
|
556
391
|
|
|
392
|
+
//#endregion
|
|
393
|
+
//#region src/root/types/VersionNumber.ts
|
|
394
|
+
/**
|
|
395
|
+
* Represents a software version number, considered to be made up of a major, minor, and patch part.
|
|
396
|
+
*
|
|
397
|
+
* @category Types
|
|
398
|
+
*/
|
|
399
|
+
var VersionNumber = class VersionNumber {
|
|
400
|
+
static NON_NEGATIVE_TUPLE_ERROR = "Input array must be a tuple of three non-negative integers.";
|
|
401
|
+
/** The major number. Increments when a feature is removed or changed in a way that is not backwards-compatible with the previous release. */
|
|
402
|
+
major = 0;
|
|
403
|
+
/** The minor number. Increments when a new feature is added/deprecated and is expected to be backwards-compatible with the previous release. */
|
|
404
|
+
minor = 0;
|
|
405
|
+
/** The patch number. Increments when the next release is fixing a bug or doing a small refactor that should not be noticeable in practice. */
|
|
406
|
+
patch = 0;
|
|
407
|
+
/**
|
|
408
|
+
* @param input - The input to create a new instance of `VersionNumber` from.
|
|
409
|
+
*/
|
|
410
|
+
constructor(input) {
|
|
411
|
+
if (input instanceof VersionNumber) {
|
|
412
|
+
this.major = input.major;
|
|
413
|
+
this.minor = input.minor;
|
|
414
|
+
this.patch = input.patch;
|
|
415
|
+
} else if (typeof input === "string") {
|
|
416
|
+
if (!RegExp(VERSION_NUMBER_REGEX).test(input)) throw new DataError({ input }, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
|
|
417
|
+
const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
|
|
418
|
+
return parseIntStrict(number);
|
|
419
|
+
});
|
|
420
|
+
this.major = major;
|
|
421
|
+
this.minor = minor;
|
|
422
|
+
this.patch = patch;
|
|
423
|
+
} else if (Array.isArray(input)) {
|
|
424
|
+
if (input.length !== 3) throw new DataError({ input }, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
425
|
+
const [major, minor, patch] = input.map((number) => {
|
|
426
|
+
const parsedInteger = parseIntStrict(number?.toString());
|
|
427
|
+
if (parsedInteger < 0) throw new DataError({ input }, "NEGATIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
|
|
428
|
+
return parsedInteger;
|
|
429
|
+
});
|
|
430
|
+
this.major = major;
|
|
431
|
+
this.minor = minor;
|
|
432
|
+
this.patch = patch;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Gets the current version type of the current instance of `VersionNumber`.
|
|
437
|
+
*
|
|
438
|
+
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
439
|
+
*/
|
|
440
|
+
get type() {
|
|
441
|
+
if (this.minor === 0 && this.patch === 0) return VersionType.MAJOR;
|
|
442
|
+
if (this.patch === 0) return VersionType.MINOR;
|
|
443
|
+
return VersionType.PATCH;
|
|
444
|
+
}
|
|
445
|
+
static formatString(input, options) {
|
|
446
|
+
if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
|
|
447
|
+
return input.startsWith("v") ? input : `v${input}`;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Checks if the provided version numbers have the exact same major, minor, and patch numbers.
|
|
451
|
+
*
|
|
452
|
+
* @param firstVersion - The first version number to compare.
|
|
453
|
+
* @param secondVersion - The second version number to compare.
|
|
454
|
+
*
|
|
455
|
+
* @returns `true` if the provided version numbers have exactly the same major, minor, and patch numbers, and returns `false` otherwise.
|
|
456
|
+
*/
|
|
457
|
+
static isEqual(firstVersion, secondVersion) {
|
|
458
|
+
return firstVersion.major === secondVersion.major && firstVersion.minor === secondVersion.minor && firstVersion.patch === secondVersion.patch;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Get a formatted string representation of the current version number
|
|
462
|
+
*
|
|
463
|
+
* @param options - Options to apply to the string formatting.
|
|
464
|
+
*
|
|
465
|
+
* @returns A formatted string representation of the current version number with the options applied.
|
|
466
|
+
*/
|
|
467
|
+
format(options) {
|
|
468
|
+
let baseOutput = `${this.major}`;
|
|
469
|
+
if (!options?.omitMinor) {
|
|
470
|
+
baseOutput += `.${this.minor}`;
|
|
471
|
+
if (!options?.omitPatch) baseOutput += `.${this.patch}`;
|
|
472
|
+
}
|
|
473
|
+
return VersionNumber.formatString(baseOutput, { omitPrefix: options?.omitPrefix });
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Increments the current version number by the given increment type, returning the result as a new reference in memory.
|
|
477
|
+
*
|
|
478
|
+
* @param incrementType - The type of increment. Can be one of the following:
|
|
479
|
+
* - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
|
|
480
|
+
* - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
|
|
481
|
+
* - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
|
|
482
|
+
* @param incrementAmount - The amount to increment by (defaults to 1).
|
|
483
|
+
*
|
|
484
|
+
* @returns A new instance of `VersionNumber` with the increment applied.
|
|
485
|
+
*/
|
|
486
|
+
increment(incrementType, incrementAmount = 1) {
|
|
487
|
+
const incrementBy = parseIntStrict(String(incrementAmount));
|
|
488
|
+
const calculatedRawVersion = {
|
|
489
|
+
major: [
|
|
490
|
+
this.major + incrementBy,
|
|
491
|
+
0,
|
|
492
|
+
0
|
|
493
|
+
],
|
|
494
|
+
minor: [
|
|
495
|
+
this.major,
|
|
496
|
+
this.minor + incrementBy,
|
|
497
|
+
0
|
|
498
|
+
],
|
|
499
|
+
patch: [
|
|
500
|
+
this.major,
|
|
501
|
+
this.minor,
|
|
502
|
+
this.patch + incrementBy
|
|
503
|
+
]
|
|
504
|
+
}[incrementType];
|
|
505
|
+
try {
|
|
506
|
+
return new VersionNumber(calculatedRawVersion);
|
|
507
|
+
} catch (error) {
|
|
508
|
+
if (DataError.check(error) && error.code === "NEGATIVE_INPUTS") throw new DataError({
|
|
509
|
+
currentVersion: this.toString(),
|
|
510
|
+
calculatedRawVersion: `v${calculatedRawVersion.join(".")}`,
|
|
511
|
+
incrementAmount
|
|
512
|
+
}, "NEGATIVE_VERSION", "Cannot apply this increment amount as it would lead to a negative version number.");
|
|
513
|
+
else throw error;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Ensures that the VersionNumber behaves correctly when attempted to be coerced to a string.
|
|
518
|
+
*
|
|
519
|
+
* @param hint - Not used as of now, but generally used to help with numeric coercion, I think (which we most likely do not need for version numbers).
|
|
520
|
+
*
|
|
521
|
+
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
522
|
+
*/
|
|
523
|
+
[Symbol.toPrimitive](hint) {
|
|
524
|
+
if (hint === "number") throw new DataError({ thisVersion: this.toString() }, "INVALID_COERCION", "VersionNumber cannot be coerced to a number type.");
|
|
525
|
+
return this.toString();
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Ensures that the VersionNumber behaves correctly when attempted to be converted to JSON.
|
|
529
|
+
*
|
|
530
|
+
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
531
|
+
*/
|
|
532
|
+
toJSON() {
|
|
533
|
+
return this.toString();
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Get a string representation of the current version number.
|
|
537
|
+
*
|
|
538
|
+
* @returns A stringified representation of the current version number with the prefix.
|
|
539
|
+
*/
|
|
540
|
+
toString() {
|
|
541
|
+
const rawString = `${this.major}.${this.minor}.${this.patch}`;
|
|
542
|
+
return VersionNumber.formatString(rawString, { omitPrefix: false });
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
const zodVersionNumber = z.union([
|
|
546
|
+
z.string(),
|
|
547
|
+
z.tuple([
|
|
548
|
+
z.number(),
|
|
549
|
+
z.number(),
|
|
550
|
+
z.number()
|
|
551
|
+
]),
|
|
552
|
+
z.instanceof(VersionNumber)
|
|
553
|
+
]).transform((rawVersionNumber) => {
|
|
554
|
+
return new VersionNumber(rawVersionNumber);
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
//#endregion
|
|
558
|
+
//#region src/node/functions/parseFilePath.ts
|
|
559
|
+
/**
|
|
560
|
+
* Takes a file path string and parses it into the directory part, the base part, and the full path.
|
|
561
|
+
*
|
|
562
|
+
* @category Parsers
|
|
563
|
+
*
|
|
564
|
+
* @param filePath - The file path to parse.
|
|
565
|
+
*
|
|
566
|
+
* @throws {DataError} If the file path is invalid.
|
|
567
|
+
*
|
|
568
|
+
* @returns An object representing the different ways the file path can be represented.
|
|
569
|
+
*/
|
|
570
|
+
function parseFilePath(filePath) {
|
|
571
|
+
const caughtGroups = filePath.match(RegExp(FILE_PATH_REGEX));
|
|
572
|
+
if (!caughtGroups) {
|
|
573
|
+
if (!(filePath.includes("/") || filePath.includes("\\")) && filePath.includes(".")) return {
|
|
574
|
+
directory: "",
|
|
575
|
+
base: filePath,
|
|
576
|
+
fullPath: filePath
|
|
577
|
+
};
|
|
578
|
+
throw new DataError({ filePath }, "INVALID_FILE_PATH", "The file path you provided is not valid.");
|
|
579
|
+
}
|
|
580
|
+
if (!caughtGroups.groups) throw new DataError({ filePath }, "PARSING_ERROR", "An error occurred while trying to parse the data.");
|
|
581
|
+
return {
|
|
582
|
+
directory: caughtGroups.groups.directory,
|
|
583
|
+
base: caughtGroups.groups.base,
|
|
584
|
+
fullPath: path.join(caughtGroups.groups.directory.replaceAll("\\", "/"), caughtGroups.groups.base)
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
|
|
557
588
|
//#endregion
|
|
558
589
|
//#region src/node/functions/sayHello.ts
|
|
559
590
|
var sayHello_default = sayHello;
|
|
560
591
|
|
|
561
592
|
//#endregion
|
|
562
|
-
export { normaliseImportPath, normalizeImportPath, sayHello_default as sayHello };
|
|
593
|
+
export { normaliseImportPath, normalizeImportPath, parseFilePath, sayHello_default as sayHello };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "Helpful utility functions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"zod": "^4.3.6"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@alextheman/eslint-plugin": "^5.7.
|
|
39
|
+
"@alextheman/eslint-plugin": "^5.7.1",
|
|
40
40
|
"@types/node": "^25.2.3",
|
|
41
41
|
"alex-c-line": "^1.26.2",
|
|
42
42
|
"dotenv-cli": "^11.0.0",
|