@alextheman/utility 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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
 
@@ -615,6 +613,25 @@ function isMonthlyMultiple(firstDate, secondDate) {
615
613
  return firstDate.getDate() === secondDate.getDate();
616
614
  }
617
615
 
616
+ //#endregion
617
+ //#region src/internal/getDependenciesFromGroup.ts
618
+ /**
619
+ * Get the dependencies from a given dependency group in `package.json`.
620
+ *
621
+ * @category Miscellaneous
622
+ *
623
+ * @param packageInfo - The data coming from `package.json`.
624
+ * @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
625
+ *
626
+ * @returns A record consisting of the package names and version ranges from the given dependency group.
627
+ */
628
+ function getDependenciesFromGroup(packageInfo, dependencyGroup) {
629
+ return {
630
+ dependencies: parseZodSchema(zod.default.record(zod.default.string(), zod.default.string()), packageInfo.dependencies ?? {}),
631
+ devDependencies: parseZodSchema(zod.default.record(zod.default.string(), zod.default.string()), packageInfo.devDependencies ?? {})
632
+ }[dependencyGroup];
633
+ }
634
+
618
635
  //#endregion
619
636
  //#region src/root/functions/miscellaneous/convertFileToBase64.ts
620
637
  /**
@@ -714,25 +731,6 @@ function createFormData(data, options = {
714
731
  return formData;
715
732
  }
716
733
 
717
- //#endregion
718
- //#region src/root/functions/miscellaneous/getDependenciesFromGroup.ts
719
- /**
720
- * Get the dependencies from a given dependency group in `package.json`.
721
- *
722
- * @category Miscellaneous
723
- *
724
- * @param packageInfo - The data coming from `package.json`.
725
- * @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
726
- *
727
- * @returns A record consisting of the package names and version ranges from the given dependency group.
728
- */
729
- function getDependenciesFromGroup(packageInfo, dependencyGroup) {
730
- return {
731
- dependencies: parseZodSchema(zod.default.record(zod.default.string(), zod.default.string()), packageInfo.dependencies ?? {}),
732
- devDependencies: parseZodSchema(zod.default.record(zod.default.string(), zod.default.string()), packageInfo.devDependencies ?? {})
733
- }[dependencyGroup];
734
- }
735
-
736
734
  //#endregion
737
735
  //#region src/root/functions/miscellaneous/isOrdered.ts
738
736
  /**
@@ -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
@@ -190,6 +190,26 @@ declare function isMonthlyMultiple(firstDate: Date, secondDate: Date): boolean;
190
190
  */
191
191
  declare function isSameDate(firstDate: Date, secondDate: Date): boolean;
192
192
  //#endregion
193
+ //#region src/internal/DependencyGroup.d.ts
194
+ declare const DependencyGroup: {
195
+ readonly DEPENDENCIES: "dependencies";
196
+ readonly DEV_DEPENDENCIES: "devDependencies";
197
+ };
198
+ type DependencyGroup = CreateEnumType<typeof DependencyGroup>;
199
+ //#endregion
200
+ //#region src/internal/getDependenciesFromGroup.d.ts
201
+ /**
202
+ * Get the dependencies from a given dependency group in `package.json`.
203
+ *
204
+ * @category Miscellaneous
205
+ *
206
+ * @param packageInfo - The data coming from `package.json`.
207
+ * @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
208
+ *
209
+ * @returns A record consisting of the package names and version ranges from the given dependency group.
210
+ */
211
+ declare function getDependenciesFromGroup(packageInfo: Record<string, unknown>, dependencyGroup: DependencyGroup): Record<string, string>;
212
+ //#endregion
193
213
  //#region src/root/functions/miscellaneous/convertFileToBase64.d.ts
194
214
  /**
195
215
  * Asynchronously converts a file to a base 64 string
@@ -498,24 +518,6 @@ type CreateFormDataOptions<Key extends RecordKey> = CreateFormDataOptionsUndefin
498
518
  */
499
519
  declare function createFormData<DataType extends Record<RecordKey, unknown>>(data: DataType, options?: CreateFormDataOptions<keyof DataType>): FormData;
500
520
  //#endregion
501
- //#region src/root/functions/miscellaneous/getDependenciesFromGroup.d.ts
502
- declare const DependencyGroup: {
503
- readonly DEPENDENCIES: "dependencies";
504
- readonly DEV_DEPENDENCIES: "devDependencies";
505
- };
506
- type DependencyGroup = CreateEnumType<typeof DependencyGroup>;
507
- /**
508
- * Get the dependencies from a given dependency group in `package.json`.
509
- *
510
- * @category Miscellaneous
511
- *
512
- * @param packageInfo - The data coming from `package.json`.
513
- * @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
514
- *
515
- * @returns A record consisting of the package names and version ranges from the given dependency group.
516
- */
517
- declare function getDependenciesFromGroup(packageInfo: Record<string, unknown>, dependencyGroup: DependencyGroup): Record<string, string>;
518
- //#endregion
519
521
  //#region src/root/functions/miscellaneous/getRandomNumber.d.ts
520
522
  /**
521
523
  * Gets a random number between the given bounds.
@@ -688,28 +690,6 @@ type Env = CreateEnumType<typeof Env>;
688
690
  */
689
691
  declare function parseEnv(input: unknown): Env;
690
692
  //#endregion
691
- //#region src/root/functions/parsers/parseFilePath.d.ts
692
- interface FilePathData {
693
- /** The file path without the final part. */
694
- directory: string;
695
- /** The final part of the file path. */
696
- base: string;
697
- /** The full file path, normalised. */
698
- fullPath: string;
699
- }
700
- /**
701
- * Takes a file path string and parses it into the directory part, the base part, and the full path.
702
- *
703
- * @category Parsers
704
- *
705
- * @param filePath - The file path to parse.
706
- *
707
- * @throws {DataError} If the file path is invalid.
708
- *
709
- * @returns An object representing the different ways the file path can be represented.
710
- */
711
- declare function parseFilePath(filePath: string): FilePathData;
712
- //#endregion
713
693
  //#region src/root/functions/parsers/parseFormData.d.ts
714
694
  /**
715
695
  * Returns a parsed object given FormData and a data parser function to call on the resulting object.
@@ -1092,4 +1072,4 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
1092
1072
  */
1093
1073
  declare const normalizeIndents: typeof normaliseIndents;
1094
1074
  //#endregion
1095
- 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, parseFilePath, parseFormData, parseIntStrict, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
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
@@ -190,6 +190,26 @@ declare function isMonthlyMultiple(firstDate: Date, secondDate: Date): boolean;
190
190
  */
191
191
  declare function isSameDate(firstDate: Date, secondDate: Date): boolean;
192
192
  //#endregion
193
+ //#region src/internal/DependencyGroup.d.ts
194
+ declare const DependencyGroup: {
195
+ readonly DEPENDENCIES: "dependencies";
196
+ readonly DEV_DEPENDENCIES: "devDependencies";
197
+ };
198
+ type DependencyGroup = CreateEnumType<typeof DependencyGroup>;
199
+ //#endregion
200
+ //#region src/internal/getDependenciesFromGroup.d.ts
201
+ /**
202
+ * Get the dependencies from a given dependency group in `package.json`.
203
+ *
204
+ * @category Miscellaneous
205
+ *
206
+ * @param packageInfo - The data coming from `package.json`.
207
+ * @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
208
+ *
209
+ * @returns A record consisting of the package names and version ranges from the given dependency group.
210
+ */
211
+ declare function getDependenciesFromGroup(packageInfo: Record<string, unknown>, dependencyGroup: DependencyGroup): Record<string, string>;
212
+ //#endregion
193
213
  //#region src/root/functions/miscellaneous/convertFileToBase64.d.ts
194
214
  /**
195
215
  * Asynchronously converts a file to a base 64 string
@@ -498,24 +518,6 @@ type CreateFormDataOptions<Key extends RecordKey> = CreateFormDataOptionsUndefin
498
518
  */
499
519
  declare function createFormData<DataType extends Record<RecordKey, unknown>>(data: DataType, options?: CreateFormDataOptions<keyof DataType>): FormData;
500
520
  //#endregion
501
- //#region src/root/functions/miscellaneous/getDependenciesFromGroup.d.ts
502
- declare const DependencyGroup: {
503
- readonly DEPENDENCIES: "dependencies";
504
- readonly DEV_DEPENDENCIES: "devDependencies";
505
- };
506
- type DependencyGroup = CreateEnumType<typeof DependencyGroup>;
507
- /**
508
- * Get the dependencies from a given dependency group in `package.json`.
509
- *
510
- * @category Miscellaneous
511
- *
512
- * @param packageInfo - The data coming from `package.json`.
513
- * @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
514
- *
515
- * @returns A record consisting of the package names and version ranges from the given dependency group.
516
- */
517
- declare function getDependenciesFromGroup(packageInfo: Record<string, unknown>, dependencyGroup: DependencyGroup): Record<string, string>;
518
- //#endregion
519
521
  //#region src/root/functions/miscellaneous/getRandomNumber.d.ts
520
522
  /**
521
523
  * Gets a random number between the given bounds.
@@ -688,28 +690,6 @@ type Env = CreateEnumType<typeof Env>;
688
690
  */
689
691
  declare function parseEnv(input: unknown): Env;
690
692
  //#endregion
691
- //#region src/root/functions/parsers/parseFilePath.d.ts
692
- interface FilePathData {
693
- /** The file path without the final part. */
694
- directory: string;
695
- /** The final part of the file path. */
696
- base: string;
697
- /** The full file path, normalised. */
698
- fullPath: string;
699
- }
700
- /**
701
- * Takes a file path string and parses it into the directory part, the base part, and the full path.
702
- *
703
- * @category Parsers
704
- *
705
- * @param filePath - The file path to parse.
706
- *
707
- * @throws {DataError} If the file path is invalid.
708
- *
709
- * @returns An object representing the different ways the file path can be represented.
710
- */
711
- declare function parseFilePath(filePath: string): FilePathData;
712
- //#endregion
713
693
  //#region src/root/functions/parsers/parseFormData.d.ts
714
694
  /**
715
695
  * Returns a parsed object given FormData and a data parser function to call on the resulting object.
@@ -1092,4 +1072,4 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
1092
1072
  */
1093
1073
  declare const normalizeIndents: typeof normaliseIndents;
1094
1074
  //#endregion
1095
- 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, parseFilePath, parseFormData, parseIntStrict, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
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
@@ -584,6 +583,25 @@ function isMonthlyMultiple(firstDate, secondDate) {
584
583
  return firstDate.getDate() === secondDate.getDate();
585
584
  }
586
585
 
586
+ //#endregion
587
+ //#region src/internal/getDependenciesFromGroup.ts
588
+ /**
589
+ * Get the dependencies from a given dependency group in `package.json`.
590
+ *
591
+ * @category Miscellaneous
592
+ *
593
+ * @param packageInfo - The data coming from `package.json`.
594
+ * @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
595
+ *
596
+ * @returns A record consisting of the package names and version ranges from the given dependency group.
597
+ */
598
+ function getDependenciesFromGroup(packageInfo, dependencyGroup) {
599
+ return {
600
+ dependencies: parseZodSchema(z.record(z.string(), z.string()), packageInfo.dependencies ?? {}),
601
+ devDependencies: parseZodSchema(z.record(z.string(), z.string()), packageInfo.devDependencies ?? {})
602
+ }[dependencyGroup];
603
+ }
604
+
587
605
  //#endregion
588
606
  //#region src/root/functions/miscellaneous/convertFileToBase64.ts
589
607
  /**
@@ -683,25 +701,6 @@ function createFormData(data, options = {
683
701
  return formData;
684
702
  }
685
703
 
686
- //#endregion
687
- //#region src/root/functions/miscellaneous/getDependenciesFromGroup.ts
688
- /**
689
- * Get the dependencies from a given dependency group in `package.json`.
690
- *
691
- * @category Miscellaneous
692
- *
693
- * @param packageInfo - The data coming from `package.json`.
694
- * @param dependencyGroup - The group to get dependency information about (can be `dependencies` or `devDependencies`).
695
- *
696
- * @returns A record consisting of the package names and version ranges from the given dependency group.
697
- */
698
- function getDependenciesFromGroup(packageInfo, dependencyGroup) {
699
- return {
700
- dependencies: parseZodSchema(z.record(z.string(), z.string()), packageInfo.dependencies ?? {}),
701
- devDependencies: parseZodSchema(z.record(z.string(), z.string()), packageInfo.devDependencies ?? {})
702
- }[dependencyGroup];
703
- }
704
-
705
704
  //#endregion
706
705
  //#region src/root/functions/miscellaneous/isOrdered.ts
707
706
  /**
@@ -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, parseFilePath, parseFormData, parseIntStrict, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
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 };
@@ -29,11 +29,18 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  let execa = require("execa");
30
30
  let zod = require("zod");
31
31
  zod = __toESM(zod);
32
- let node_path = require("node:path");
33
- node_path = __toESM(node_path);
34
32
  require("libsodium-wrappers");
35
33
  let node_fs_promises = require("node:fs/promises");
34
+ let node_path = require("node:path");
35
+ node_path = __toESM(node_path);
36
+
37
+ //#region src/internal/DependencyGroup.ts
38
+ const DependencyGroup = {
39
+ DEPENDENCIES: "dependencies",
40
+ DEV_DEPENDENCIES: "devDependencies"
41
+ };
36
42
 
43
+ //#endregion
37
44
  //#region src/root/functions/arrayHelpers/fillArray.ts
38
45
  /**
39
46
  * Creates a new array where each element is the result of the provided callback.
@@ -626,6 +633,27 @@ async function getPackageJsonContents(directory) {
626
633
  }
627
634
  }
628
635
 
636
+ //#endregion
637
+ //#region src/internal/ModuleType.ts
638
+ const ModuleType = {
639
+ COMMON_JS: "commonjs",
640
+ ES_MODULES: "module",
641
+ TYPESCRIPT: "typescript"
642
+ };
643
+
644
+ //#endregion
645
+ //#region src/internal/packageJsonNotFoundError.ts
646
+ function packageJsonNotFoundError(packagePath) {
647
+ return new DataError({ packagePath: getPackageJsonPath(packagePath) }, "PACKAGE_JSON_NOT_FOUND", "Could not find package.json in directory.");
648
+ }
649
+
650
+ //#endregion
651
+ //#region src/internal/PackageManager.ts
652
+ const PackageManager = {
653
+ NPM: "npm",
654
+ PNPM: "pnpm"
655
+ };
656
+
629
657
  //#endregion
630
658
  //#region src/internal/parseJsonFromStdout.ts
631
659
  function parseJsonFromStdout(stdout) {
@@ -643,8 +671,30 @@ function parseJsonFromStdout(stdout) {
643
671
  var sayHello_default = sayHello;
644
672
 
645
673
  //#endregion
674
+ //#region src/internal/setupPackageEndToEnd.ts
675
+ async function setupPackageEndToEnd(temporaryPath, packageManager, moduleType, options) {
676
+ const { dependencyGroup = "dependencies" } = options ?? {};
677
+ await (0, execa.execa)({ cwd: process.cwd() })`${packageManager} pack --pack-destination ${temporaryPath}`;
678
+ const tgzFileName = await getExpectedTgzName(process.cwd(), packageManager);
679
+ const runCommandInTempDirectory = (0, execa.execa)({ cwd: temporaryPath });
680
+ if (packageManager === PackageManager.NPM) await runCommandInTempDirectory`npm init -y`;
681
+ else await runCommandInTempDirectory`pnpm init`;
682
+ const packageInfo = await getPackageJsonContents(temporaryPath);
683
+ if (packageInfo === null) throw packageJsonNotFoundError(temporaryPath);
684
+ packageInfo.type = moduleType === ModuleType.TYPESCRIPT ? ModuleType.ES_MODULES : moduleType;
685
+ await (0, node_fs_promises.writeFile)(node_path.default.join(temporaryPath, "package.json"), JSON.stringify(packageInfo, null, 2));
686
+ await runCommandInTempDirectory`${packageManager} install ${dependencyGroup === "devDependencies" ? "--save-dev" : "--save-prod"} ${node_path.default.join(temporaryPath, tgzFileName)}`;
687
+ return runCommandInTempDirectory;
688
+ }
689
+
690
+ //#endregion
691
+ exports.DependencyGroup = DependencyGroup;
692
+ exports.ModuleType = ModuleType;
693
+ exports.PackageManager = PackageManager;
646
694
  exports.getExpectedTgzName = getExpectedTgzName;
647
695
  exports.getPackageJsonContents = getPackageJsonContents;
648
696
  exports.getPackageJsonPath = getPackageJsonPath;
697
+ exports.packageJsonNotFoundError = packageJsonNotFoundError;
649
698
  exports.parseJsonFromStdout = parseJsonFromStdout;
650
- exports.sayHello = sayHello_default;
699
+ exports.sayHello = sayHello_default;
700
+ exports.setupPackageEndToEnd = setupPackageEndToEnd;
@@ -1,14 +1,50 @@
1
- //#region src/internal/getExpectedTgzName.d.ts
2
- declare function getExpectedTgzName(packagePath: string, packageManager: string): Promise<string>;
3
- //#endregion
4
- //#region src/internal/getPackageJsonContents.d.ts
5
- declare function getPackageJsonContents(directory: string): Promise<Record<string, any> | null>;
1
+ import { ExecaMethod } from "execa";
2
+
3
+ //#region src/root/types/RecordKey.d.ts
4
+ /**
5
+ * Represents the native Record's possible key type.
6
+ *
7
+ * @category Types
8
+ */
9
+ type RecordKey = string | number | symbol;
6
10
  //#endregion
7
- //#region src/internal/getPackageJsonPath.d.ts
8
- declare function getPackageJsonPath(directory: string): string;
11
+ //#region src/root/types/DataError.d.ts
12
+ /**
13
+ * Represents errors you may get that may've been caused by a specific piece of data.
14
+ *
15
+ * @category Types
16
+ *
17
+ * @template DataType - The type of the data that caused the error.
18
+ */
19
+ declare class DataError<DataType extends Record<RecordKey, unknown> = Record<RecordKey, unknown>> extends Error {
20
+ code: string;
21
+ data: DataType;
22
+ /**
23
+ * @param data - The data that caused the error.
24
+ * @param code - A standardised code (e.g. UNEXPECTED_DATA).
25
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
26
+ * @param options - Extra options to pass to super Error constructor.
27
+ */
28
+ constructor(data: DataType, code?: string, message?: string, options?: ErrorOptions);
29
+ /**
30
+ * Checks whether the given input may have been caused by a DataError.
31
+ *
32
+ * @param input - The input to check.
33
+ *
34
+ * @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`.
35
+ */
36
+ static check<DataType extends Record<RecordKey, unknown> = Record<RecordKey, unknown>>(input: unknown): input is DataError<DataType>;
37
+ }
9
38
  //#endregion
10
- //#region src/internal/parseJsonFromStdout.d.ts
11
- declare function parseJsonFromStdout(stdout: string): Record<string, unknown>;
39
+ //#region src/root/types/CreateEnumType.d.ts
40
+ /**
41
+ * Get the value types from a const object so the object can behave similarly to an enum.
42
+ *
43
+ * @category Types
44
+ *
45
+ * @template ObjectType - The type of the object to get the value types for.
46
+ */
47
+ type CreateEnumType<ObjectType extends Record<RecordKey, unknown>> = ObjectType[keyof ObjectType];
12
48
  //#endregion
13
49
  //#region src/root/types/IsTypeArgumentString.d.ts
14
50
  type IsTypeArgumentString<Argument extends string> = Argument;
@@ -23,4 +59,49 @@ type IsTypeArgumentString<Argument extends string> = Argument;
23
59
  */
24
60
  declare function sayHello(): string;
25
61
  //#endregion
26
- export { type IsTypeArgumentString, getExpectedTgzName, getPackageJsonContents, getPackageJsonPath, parseJsonFromStdout, sayHello };
62
+ //#region src/internal/DependencyGroup.d.ts
63
+ declare const DependencyGroup: {
64
+ readonly DEPENDENCIES: "dependencies";
65
+ readonly DEV_DEPENDENCIES: "devDependencies";
66
+ };
67
+ type DependencyGroup = CreateEnumType<typeof DependencyGroup>;
68
+ //#endregion
69
+ //#region src/internal/getExpectedTgzName.d.ts
70
+ declare function getExpectedTgzName(packagePath: string, packageManager: string): Promise<string>;
71
+ //#endregion
72
+ //#region src/internal/getPackageJsonContents.d.ts
73
+ declare function getPackageJsonContents(directory: string): Promise<Record<string, any> | null>;
74
+ //#endregion
75
+ //#region src/internal/getPackageJsonPath.d.ts
76
+ declare function getPackageJsonPath(directory: string): string;
77
+ //#endregion
78
+ //#region src/internal/ModuleType.d.ts
79
+ declare const ModuleType: {
80
+ readonly COMMON_JS: "commonjs";
81
+ readonly ES_MODULES: "module";
82
+ readonly TYPESCRIPT: "typescript";
83
+ };
84
+ type ModuleType = CreateEnumType<typeof ModuleType>;
85
+ //#endregion
86
+ //#region src/internal/packageJsonNotFoundError.d.ts
87
+ declare function packageJsonNotFoundError(packagePath: string): DataError;
88
+ //#endregion
89
+ //#region src/internal/PackageManager.d.ts
90
+ declare const PackageManager: {
91
+ readonly NPM: "npm";
92
+ readonly PNPM: "pnpm";
93
+ };
94
+ type PackageManager = CreateEnumType<typeof PackageManager>;
95
+ //#endregion
96
+ //#region src/internal/parseJsonFromStdout.d.ts
97
+ declare function parseJsonFromStdout(stdout: string): Record<string, unknown>;
98
+ //#endregion
99
+ //#region src/internal/setupPackageEndToEnd.d.ts
100
+ interface SetupPackageEndToEndOptions {
101
+ dependencyGroup?: DependencyGroup;
102
+ }
103
+ declare function setupPackageEndToEnd(temporaryPath: string, packageManager: PackageManager, moduleType: ModuleType, options?: SetupPackageEndToEndOptions): Promise<ExecaMethod<{
104
+ cwd: string;
105
+ }>>;
106
+ //#endregion
107
+ export { DependencyGroup, type IsTypeArgumentString, ModuleType, PackageManager, getExpectedTgzName, getPackageJsonContents, getPackageJsonPath, packageJsonNotFoundError, parseJsonFromStdout, sayHello, setupPackageEndToEnd };