@alextheman/utility 4.11.0 → 4.12.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
@@ -27,11 +27,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  //#endregion
28
28
  let zod = require("zod");
29
29
  zod = __toESM(zod);
30
- let libsodium_wrappers = require("libsodium-wrappers");
31
- libsodium_wrappers = __toESM(libsodium_wrappers);
32
30
  let node_path = require("node:path");
33
31
  node_path = __toESM(node_path);
32
+ let libsodium_wrappers = require("libsodium-wrappers");
33
+ libsodium_wrappers = __toESM(libsodium_wrappers);
34
+
35
+ //#region src/constants/FILE_PATH_REGEX.ts
36
+ const FILE_PATH_REGEX = String.raw`^(?<directory>.+)[\/\\](?<base>[^\/\\]+)$`;
37
+ var FILE_PATH_REGEX_default = FILE_PATH_REGEX;
34
38
 
39
+ //#endregion
35
40
  //#region src/constants/NAMESPACE_EXPORT_REGEX.ts
36
41
  const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
37
42
  var NAMESPACE_EXPORT_REGEX_default = NAMESPACE_EXPORT_REGEX;
@@ -653,17 +658,17 @@ function createFormData(data, options = {
653
658
  default: throw new TypeError("SLOPPY_PURE_JAVASCRIPT_USER_ERROR");
654
659
  }
655
660
  }
656
- function resolveNullables(key, value, options$1) {
657
- if (options$1.nullableResolution) {
658
- resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.nullableResolution));
661
+ function resolveNullables(key, value, options) {
662
+ if (options.nullableResolution) {
663
+ resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options.nullableResolution));
659
664
  return;
660
665
  }
661
- if (options$1.undefinedResolution || options$1.nullResolution) {
662
- if (data[key] === void 0 && options$1.undefinedResolution) {
663
- resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.undefinedResolution));
666
+ if (options.undefinedResolution || options.nullResolution) {
667
+ if (data[key] === void 0 && options.undefinedResolution) {
668
+ resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options.undefinedResolution));
664
669
  return;
665
670
  }
666
- if (data[key] === null && options$1.nullResolution) resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.nullResolution));
671
+ if (data[key] === null && options.nullResolution) resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options.nullResolution));
667
672
  }
668
673
  }
669
674
  const entries = Object.entries(data);
@@ -884,8 +889,8 @@ function _parseZodSchema(parsedResult, data, onError) {
884
889
  }
885
890
  throw new DataError_default(data, Object.entries(allErrorCodes).toSorted(([_, firstCount], [__, secondCount]) => {
886
891
  return secondCount - firstCount;
887
- }).map(([code, count], _, allErrorCodes$1) => {
888
- return allErrorCodes$1.length === 1 && count === 1 ? code : `${code}×${count}`;
892
+ }).map(([code, count], _, allErrorCodes) => {
893
+ return allErrorCodes.length === 1 && count === 1 ? code : `${code}×${count}`;
889
894
  }).join(","), `\n\n${zod.default.prettifyError(parsedResult.error)}\n`);
890
895
  }
891
896
  return parsedResult.data;
@@ -945,6 +950,38 @@ function parseEnv(data) {
945
950
  }
946
951
  var parseEnv_default = parseEnv;
947
952
 
953
+ //#endregion
954
+ //#region src/functions/parsers/parseFilePath.ts
955
+ /**
956
+ * Takes a file path string and parses it into the directory part, the base part, and the full path.
957
+ *
958
+ * @category Parsers
959
+ *
960
+ * @param filePath - The file path to parse.
961
+ *
962
+ * @throws {DataError} If the file path is invalid.
963
+ *
964
+ * @returns An object representing the different ways the file path can be represented.
965
+ */
966
+ function parseFilePath(filePath) {
967
+ const caughtGroups = filePath.match(RegExp(FILE_PATH_REGEX_default));
968
+ if (!caughtGroups) {
969
+ if (!(filePath.includes("/") || filePath.includes("\\")) && filePath.includes(".")) return {
970
+ directory: "",
971
+ base: filePath,
972
+ fullPath: filePath
973
+ };
974
+ throw new DataError_default({ filePath }, "INVALID_FILE_PATH", "The file path you provided is not valid.");
975
+ }
976
+ if (!caughtGroups.groups) throw new DataError_default({ filePath }, "PARSING_ERROR", "An error occurred while trying to parse the data.");
977
+ return {
978
+ directory: caughtGroups.groups.directory,
979
+ base: caughtGroups.groups.base,
980
+ fullPath: node_path.default.join(caughtGroups.groups.directory.replaceAll("\\", "/"), caughtGroups.groups.base)
981
+ };
982
+ }
983
+ var parseFilePath_default = parseFilePath;
984
+
948
985
  //#endregion
949
986
  //#region src/functions/parsers/parseFormData.ts
950
987
  /**
@@ -1101,6 +1138,10 @@ var encryptWithKey_default = encryptWithKey;
1101
1138
  /**
1102
1139
  * Returns the public key and private key, properly narrowing down types depending on the provided `outputFormat`.
1103
1140
  *
1141
+ * @deprecated Please use `sodium.crypto_box_keypair` from `libsodium-wrappers` instead.
1142
+ *
1143
+ * This function was initially created to deal with a typing issue with the package introduced in v0.8.1 of said package, but this seems to have been fixed in v0.8.2
1144
+ *
1104
1145
  * @param outputFormat - The format of the resulting publicKey and privateKey you would like to use.
1105
1146
  *
1106
1147
  * @returns An object containing both the publicKey and privateKey, along with a keyType.
@@ -1165,8 +1206,8 @@ function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
1165
1206
  result += sequenceOfCapitals.toLowerCase();
1166
1207
  } else {
1167
1208
  if (result) result += "-";
1168
- result += sequenceOfCapitals.split("").map((character$1) => {
1169
- return character$1.toLowerCase();
1209
+ result += sequenceOfCapitals.split("").map((character) => {
1210
+ return character.toLowerCase();
1170
1211
  }).join("-");
1171
1212
  }
1172
1213
  outerIndex = innerIndex;
@@ -1421,9 +1462,9 @@ function reduceLines(lines, { preserveTabs = true }) {
1421
1462
  */
1422
1463
  function normaliseIndents(first, ...args) {
1423
1464
  if (typeof first === "object" && first !== null && !Array.isArray(first)) {
1424
- const options$1 = first;
1425
- return (strings$1, ...interpolations) => {
1426
- return normaliseIndents(strings$1, ...interpolations, options$1);
1465
+ const options = first;
1466
+ return (strings, ...interpolations) => {
1467
+ return normaliseIndents(strings, ...interpolations, options);
1427
1468
  };
1428
1469
  }
1429
1470
  const strings = first;
@@ -1553,6 +1594,7 @@ var incrementVersion_default = incrementVersion;
1553
1594
  exports.APIError = APIError_default;
1554
1595
  exports.DataError = DataError_default;
1555
1596
  exports.Env = Env;
1597
+ exports.FILE_PATH_REGEX = FILE_PATH_REGEX_default;
1556
1598
  exports.NAMESPACE_EXPORT_REGEX = NAMESPACE_EXPORT_REGEX_default;
1557
1599
  exports.VERSION_NUMBER_REGEX = VERSION_NUMBER_REGEX_default;
1558
1600
  exports.VersionNumber = VersionNumber_default;
@@ -1592,6 +1634,7 @@ exports.omitProperties = omitProperties_default;
1592
1634
  exports.paralleliseArrays = paralleliseArrays_default;
1593
1635
  exports.parseBoolean = parseBoolean_default;
1594
1636
  exports.parseEnv = parseEnv_default;
1637
+ exports.parseFilePath = parseFilePath_default;
1595
1638
  exports.parseFormData = parseFormData_default;
1596
1639
  exports.parseIntStrict = parseIntStrict_default;
1597
1640
  exports.parseVersion = parseVersion_default;
package/dist/index.d.cts CHANGED
@@ -2,6 +2,9 @@ import { DotenvParseOutput } from "dotenv";
2
2
  import { ZodError, ZodType, z } from "zod";
3
3
  import sodium from "libsodium-wrappers";
4
4
 
5
+ //#region src/constants/FILE_PATH_REGEX.d.ts
6
+ declare const FILE_PATH_REGEX: string;
7
+ //#endregion
5
8
  //#region src/constants/NAMESPACE_EXPORT_REGEX.d.ts
6
9
  declare const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
7
10
  //#endregion
@@ -414,9 +417,9 @@ type FormDataArrayResolutionStrategy = "stringify" | "multiple";
414
417
  *
415
418
  * @template Key - The type of the key of the input record.
416
419
  */
417
- interface CreateFormDataOptionsBase<Key$1 extends RecordKey> {
420
+ interface CreateFormDataOptionsBase<Key extends RecordKey> {
418
421
  /** How to resolve any arrays provided in the data (can either stringify them or add them multiple times). */
419
- arrayResolution?: FormDataArrayResolutionStrategy | Partial<Record<Key$1, FormDataArrayResolutionStrategy>>;
422
+ arrayResolution?: FormDataArrayResolutionStrategy | Partial<Record<Key, FormDataArrayResolutionStrategy>>;
420
423
  }
421
424
  /**
422
425
  * Options for resolving form data when it may be undefined or null, but not both.
@@ -425,11 +428,11 @@ interface CreateFormDataOptionsBase<Key$1 extends RecordKey> {
425
428
  *
426
429
  * @template Key - The type of the key of the input record.
427
430
  */
428
- interface CreateFormDataOptionsUndefinedOrNullResolution<Key$1 extends RecordKey> extends CreateFormDataOptionsBase<Key$1> {
431
+ interface CreateFormDataOptionsUndefinedOrNullResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
429
432
  /** How to resolve undefined data (May either stringify to 'undefined', resolve to an empty string, or omit entirely). */
430
- undefinedResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key$1, FormDataNullableResolutionStrategy>>;
433
+ undefinedResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
431
434
  /** How to resolve null data (May either stringify to 'null', resolve to an empty string, or omit entirely). */
432
- nullResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key$1, FormDataNullableResolutionStrategy>>;
435
+ nullResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
433
436
  /** @note This must not be provided at the same time as undefinedResolution and/or nullResolution. */
434
437
  nullableResolution?: never;
435
438
  }
@@ -440,13 +443,13 @@ interface CreateFormDataOptionsUndefinedOrNullResolution<Key$1 extends RecordKey
440
443
  *
441
444
  * @template Key - The type of the key of the input record.
442
445
  */
443
- interface CreateFormDataOptionsNullableResolution<Key$1 extends RecordKey> extends CreateFormDataOptionsBase<Key$1> {
446
+ interface CreateFormDataOptionsNullableResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
444
447
  /** @note This must not be provided at the same time as nullableResolution. */
445
448
  undefinedResolution?: never;
446
449
  /** @note This must not be provided at the same time as nullableResolution. */
447
450
  nullResolution?: never;
448
451
  /** How to resolve nullable data (May either stringify to 'undefined | null', resolve to an empty string, or omit entirely). */
449
- nullableResolution: FormDataNullableResolutionStrategy | Partial<Record<Key$1, FormDataNullableResolutionStrategy>>;
452
+ nullableResolution: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
450
453
  }
451
454
  /**
452
455
  * Options for resolving form data.
@@ -455,7 +458,7 @@ interface CreateFormDataOptionsNullableResolution<Key$1 extends RecordKey> exten
455
458
  *
456
459
  * @template Key - The type of the key of the input record.
457
460
  */
458
- type CreateFormDataOptions<Key$1 extends RecordKey> = CreateFormDataOptionsUndefinedOrNullResolution<Key$1> | CreateFormDataOptionsNullableResolution<Key$1>;
461
+ type CreateFormDataOptions<Key extends RecordKey> = CreateFormDataOptionsUndefinedOrNullResolution<Key> | CreateFormDataOptionsNullableResolution<Key>;
459
462
  /**
460
463
  * Creates FormData from a given object, resolving non-string types as appropriate.
461
464
  *
@@ -632,6 +635,28 @@ type Env = CreateEnumType<typeof Env>;
632
635
  */
633
636
  declare function parseEnv(data: unknown): Env;
634
637
  //#endregion
638
+ //#region src/functions/parsers/parseFilePath.d.ts
639
+ interface FilePathData {
640
+ /** The file path without the final part. */
641
+ directory: string;
642
+ /** The final part of the file path. */
643
+ base: string;
644
+ /** The full file path, normalised. */
645
+ fullPath: string;
646
+ }
647
+ /**
648
+ * Takes a file path string and parses it into the directory part, the base part, and the full path.
649
+ *
650
+ * @category Parsers
651
+ *
652
+ * @param filePath - The file path to parse.
653
+ *
654
+ * @throws {DataError} If the file path is invalid.
655
+ *
656
+ * @returns An object representing the different ways the file path can be represented.
657
+ */
658
+ declare function parseFilePath(filePath: string): FilePathData;
659
+ //#endregion
635
660
  //#region src/functions/parsers/parseFormData.d.ts
636
661
  /**
637
662
  * Returns a parsed object given FormData and a data parser function to call on the resulting object.
@@ -787,6 +812,10 @@ interface PublicAndPrivateKey<KeyType extends Uint8Array | string> {
787
812
  /**
788
813
  * Returns the public key and private key, properly narrowing down types depending on the provided `outputFormat`.
789
814
  *
815
+ * @deprecated Please use `sodium.crypto_box_keypair` from `libsodium-wrappers` instead.
816
+ *
817
+ * This function was initially created to deal with a typing issue with the package introduced in v0.8.1 of said package, but this seems to have been fixed in v0.8.2
818
+ *
790
819
  * @returns An object containing both the publicKey and privateKey, along with a keyType.
791
820
  *
792
821
  * Because you have not provided an `outputFormat`, the keys will be typed as `Uint8Array`.
@@ -795,6 +824,10 @@ declare function getPublicAndPrivateKey(): PublicAndPrivateKey<Uint8Array>;
795
824
  /**
796
825
  * Returns the public key and private key, properly narrowing down types depending on the provided `outputFormat`.
797
826
  *
827
+ * @deprecated Please use `sodium.crypto_box_keypair` from `libsodium-wrappers` instead.
828
+ *
829
+ * This function was initially created to deal with a typing issue with the package introduced in v0.8.1 of said package, but this seems to have been fixed in v0.8.2
830
+ *
798
831
  * @param outputFormat - The format of the resulting publicKey and privateKey you would like to use.
799
832
  *
800
833
  * @returns An object containing both the publicKey and privateKey, along with a keyType.
@@ -805,6 +838,10 @@ declare function getPublicAndPrivateKey(outputFormat: "uint8array"): PublicAndPr
805
838
  /**
806
839
  * Returns the public key and private key, properly narrowing down types depending on the provided `outputFormat`.
807
840
  *
841
+ * @deprecated Please use `sodium.crypto_box_keypair` from `libsodium-wrappers` instead.
842
+ *
843
+ * This function was initially created to deal with a typing issue with the package introduced in v0.8.1 of said package, but this seems to have been fixed in v0.8.2
844
+ *
808
845
  * @param outputFormat - The format of the resulting publicKey and privateKey you would like to use.
809
846
  *
810
847
  * @returns An object containing both the publicKey and privateKey, along with a keyType.
@@ -1125,4 +1162,4 @@ interface ParseVersionOptions {
1125
1162
  */
1126
1163
  declare function parseVersion(input: string, options?: ParseVersionOptions): string;
1127
1164
  //#endregion
1128
- export { APIError, ArrayElement, CallReturnType, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, ParseVersionOptions, PublicAndPrivateKey, RecordKey, RemoveUndefined, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getPublicAndPrivateKey, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, stringListToArray, stringifyDotenv, truncate, wait };
1165
+ export { APIError, ArrayElement, CallReturnType, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FILE_PATH_REGEX, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, ParseVersionOptions, PublicAndPrivateKey, RecordKey, RemoveUndefined, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getPublicAndPrivateKey, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFilePath, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, stringListToArray, stringifyDotenv, truncate, wait };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,9 @@ import { ZodError, ZodType, z as z$1 } from "zod";
2
2
  import sodium from "libsodium-wrappers";
3
3
  import { DotenvParseOutput } from "dotenv";
4
4
 
5
+ //#region src/constants/FILE_PATH_REGEX.d.ts
6
+ declare const FILE_PATH_REGEX: string;
7
+ //#endregion
5
8
  //#region src/constants/NAMESPACE_EXPORT_REGEX.d.ts
6
9
  declare const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
7
10
  //#endregion
@@ -414,9 +417,9 @@ type FormDataArrayResolutionStrategy = "stringify" | "multiple";
414
417
  *
415
418
  * @template Key - The type of the key of the input record.
416
419
  */
417
- interface CreateFormDataOptionsBase<Key$1 extends RecordKey> {
420
+ interface CreateFormDataOptionsBase<Key extends RecordKey> {
418
421
  /** How to resolve any arrays provided in the data (can either stringify them or add them multiple times). */
419
- arrayResolution?: FormDataArrayResolutionStrategy | Partial<Record<Key$1, FormDataArrayResolutionStrategy>>;
422
+ arrayResolution?: FormDataArrayResolutionStrategy | Partial<Record<Key, FormDataArrayResolutionStrategy>>;
420
423
  }
421
424
  /**
422
425
  * Options for resolving form data when it may be undefined or null, but not both.
@@ -425,11 +428,11 @@ interface CreateFormDataOptionsBase<Key$1 extends RecordKey> {
425
428
  *
426
429
  * @template Key - The type of the key of the input record.
427
430
  */
428
- interface CreateFormDataOptionsUndefinedOrNullResolution<Key$1 extends RecordKey> extends CreateFormDataOptionsBase<Key$1> {
431
+ interface CreateFormDataOptionsUndefinedOrNullResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
429
432
  /** How to resolve undefined data (May either stringify to 'undefined', resolve to an empty string, or omit entirely). */
430
- undefinedResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key$1, FormDataNullableResolutionStrategy>>;
433
+ undefinedResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
431
434
  /** How to resolve null data (May either stringify to 'null', resolve to an empty string, or omit entirely). */
432
- nullResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key$1, FormDataNullableResolutionStrategy>>;
435
+ nullResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
433
436
  /** @note This must not be provided at the same time as undefinedResolution and/or nullResolution. */
434
437
  nullableResolution?: never;
435
438
  }
@@ -440,13 +443,13 @@ interface CreateFormDataOptionsUndefinedOrNullResolution<Key$1 extends RecordKey
440
443
  *
441
444
  * @template Key - The type of the key of the input record.
442
445
  */
443
- interface CreateFormDataOptionsNullableResolution<Key$1 extends RecordKey> extends CreateFormDataOptionsBase<Key$1> {
446
+ interface CreateFormDataOptionsNullableResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
444
447
  /** @note This must not be provided at the same time as nullableResolution. */
445
448
  undefinedResolution?: never;
446
449
  /** @note This must not be provided at the same time as nullableResolution. */
447
450
  nullResolution?: never;
448
451
  /** How to resolve nullable data (May either stringify to 'undefined | null', resolve to an empty string, or omit entirely). */
449
- nullableResolution: FormDataNullableResolutionStrategy | Partial<Record<Key$1, FormDataNullableResolutionStrategy>>;
452
+ nullableResolution: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
450
453
  }
451
454
  /**
452
455
  * Options for resolving form data.
@@ -455,7 +458,7 @@ interface CreateFormDataOptionsNullableResolution<Key$1 extends RecordKey> exten
455
458
  *
456
459
  * @template Key - The type of the key of the input record.
457
460
  */
458
- type CreateFormDataOptions<Key$1 extends RecordKey> = CreateFormDataOptionsUndefinedOrNullResolution<Key$1> | CreateFormDataOptionsNullableResolution<Key$1>;
461
+ type CreateFormDataOptions<Key extends RecordKey> = CreateFormDataOptionsUndefinedOrNullResolution<Key> | CreateFormDataOptionsNullableResolution<Key>;
459
462
  /**
460
463
  * Creates FormData from a given object, resolving non-string types as appropriate.
461
464
  *
@@ -632,6 +635,28 @@ type Env = CreateEnumType<typeof Env>;
632
635
  */
633
636
  declare function parseEnv(data: unknown): Env;
634
637
  //#endregion
638
+ //#region src/functions/parsers/parseFilePath.d.ts
639
+ interface FilePathData {
640
+ /** The file path without the final part. */
641
+ directory: string;
642
+ /** The final part of the file path. */
643
+ base: string;
644
+ /** The full file path, normalised. */
645
+ fullPath: string;
646
+ }
647
+ /**
648
+ * Takes a file path string and parses it into the directory part, the base part, and the full path.
649
+ *
650
+ * @category Parsers
651
+ *
652
+ * @param filePath - The file path to parse.
653
+ *
654
+ * @throws {DataError} If the file path is invalid.
655
+ *
656
+ * @returns An object representing the different ways the file path can be represented.
657
+ */
658
+ declare function parseFilePath(filePath: string): FilePathData;
659
+ //#endregion
635
660
  //#region src/functions/parsers/parseFormData.d.ts
636
661
  /**
637
662
  * Returns a parsed object given FormData and a data parser function to call on the resulting object.
@@ -787,6 +812,10 @@ interface PublicAndPrivateKey<KeyType extends Uint8Array | string> {
787
812
  /**
788
813
  * Returns the public key and private key, properly narrowing down types depending on the provided `outputFormat`.
789
814
  *
815
+ * @deprecated Please use `sodium.crypto_box_keypair` from `libsodium-wrappers` instead.
816
+ *
817
+ * This function was initially created to deal with a typing issue with the package introduced in v0.8.1 of said package, but this seems to have been fixed in v0.8.2
818
+ *
790
819
  * @returns An object containing both the publicKey and privateKey, along with a keyType.
791
820
  *
792
821
  * Because you have not provided an `outputFormat`, the keys will be typed as `Uint8Array`.
@@ -795,6 +824,10 @@ declare function getPublicAndPrivateKey(): PublicAndPrivateKey<Uint8Array>;
795
824
  /**
796
825
  * Returns the public key and private key, properly narrowing down types depending on the provided `outputFormat`.
797
826
  *
827
+ * @deprecated Please use `sodium.crypto_box_keypair` from `libsodium-wrappers` instead.
828
+ *
829
+ * This function was initially created to deal with a typing issue with the package introduced in v0.8.1 of said package, but this seems to have been fixed in v0.8.2
830
+ *
798
831
  * @param outputFormat - The format of the resulting publicKey and privateKey you would like to use.
799
832
  *
800
833
  * @returns An object containing both the publicKey and privateKey, along with a keyType.
@@ -805,6 +838,10 @@ declare function getPublicAndPrivateKey(outputFormat: "uint8array"): PublicAndPr
805
838
  /**
806
839
  * Returns the public key and private key, properly narrowing down types depending on the provided `outputFormat`.
807
840
  *
841
+ * @deprecated Please use `sodium.crypto_box_keypair` from `libsodium-wrappers` instead.
842
+ *
843
+ * This function was initially created to deal with a typing issue with the package introduced in v0.8.1 of said package, but this seems to have been fixed in v0.8.2
844
+ *
808
845
  * @param outputFormat - The format of the resulting publicKey and privateKey you would like to use.
809
846
  *
810
847
  * @returns An object containing both the publicKey and privateKey, along with a keyType.
@@ -1125,4 +1162,4 @@ interface ParseVersionOptions {
1125
1162
  */
1126
1163
  declare function parseVersion(input: string, options?: ParseVersionOptions): string;
1127
1164
  //#endregion
1128
- export { APIError, ArrayElement, CallReturnType, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, type IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, type ParseVersionOptions, type PublicAndPrivateKey, RecordKey, RemoveUndefined, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getPublicAndPrivateKey, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, stringListToArray, stringifyDotenv, truncate, wait };
1165
+ export { APIError, ArrayElement, CallReturnType, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FILE_PATH_REGEX, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, type IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, type ParseVersionOptions, type PublicAndPrivateKey, RecordKey, RemoveUndefined, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getPublicAndPrivateKey, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFilePath, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, stringListToArray, stringifyDotenv, truncate, wait };
package/dist/index.js CHANGED
@@ -1,7 +1,12 @@
1
1
  import z, { z as z$1 } from "zod";
2
- import sodium from "libsodium-wrappers";
3
2
  import path from "node:path";
3
+ import sodium from "libsodium-wrappers";
4
+
5
+ //#region src/constants/FILE_PATH_REGEX.ts
6
+ const FILE_PATH_REGEX = String.raw`^(?<directory>.+)[\/\\](?<base>[^\/\\]+)$`;
7
+ var FILE_PATH_REGEX_default = FILE_PATH_REGEX;
4
8
 
9
+ //#endregion
5
10
  //#region src/constants/NAMESPACE_EXPORT_REGEX.ts
6
11
  const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
7
12
  var NAMESPACE_EXPORT_REGEX_default = NAMESPACE_EXPORT_REGEX;
@@ -623,17 +628,17 @@ function createFormData(data, options = {
623
628
  default: throw new TypeError("SLOPPY_PURE_JAVASCRIPT_USER_ERROR");
624
629
  }
625
630
  }
626
- function resolveNullables(key, value, options$1) {
627
- if (options$1.nullableResolution) {
628
- resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.nullableResolution));
631
+ function resolveNullables(key, value, options) {
632
+ if (options.nullableResolution) {
633
+ resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options.nullableResolution));
629
634
  return;
630
635
  }
631
- if (options$1.undefinedResolution || options$1.nullResolution) {
632
- if (data[key] === void 0 && options$1.undefinedResolution) {
633
- resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.undefinedResolution));
636
+ if (options.undefinedResolution || options.nullResolution) {
637
+ if (data[key] === void 0 && options.undefinedResolution) {
638
+ resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options.undefinedResolution));
634
639
  return;
635
640
  }
636
- if (data[key] === null && options$1.nullResolution) resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options$1.nullResolution));
641
+ if (data[key] === null && options.nullResolution) resolveNullablesByStrategy(key, value, getNullableResolutionStrategy(key, options.nullResolution));
637
642
  }
638
643
  }
639
644
  const entries = Object.entries(data);
@@ -854,8 +859,8 @@ function _parseZodSchema(parsedResult, data, onError) {
854
859
  }
855
860
  throw new DataError_default(data, Object.entries(allErrorCodes).toSorted(([_, firstCount], [__, secondCount]) => {
856
861
  return secondCount - firstCount;
857
- }).map(([code, count], _, allErrorCodes$1) => {
858
- return allErrorCodes$1.length === 1 && count === 1 ? code : `${code}×${count}`;
862
+ }).map(([code, count], _, allErrorCodes) => {
863
+ return allErrorCodes.length === 1 && count === 1 ? code : `${code}×${count}`;
859
864
  }).join(","), `\n\n${z.prettifyError(parsedResult.error)}\n`);
860
865
  }
861
866
  return parsedResult.data;
@@ -915,6 +920,38 @@ function parseEnv(data) {
915
920
  }
916
921
  var parseEnv_default = parseEnv;
917
922
 
923
+ //#endregion
924
+ //#region src/functions/parsers/parseFilePath.ts
925
+ /**
926
+ * Takes a file path string and parses it into the directory part, the base part, and the full path.
927
+ *
928
+ * @category Parsers
929
+ *
930
+ * @param filePath - The file path to parse.
931
+ *
932
+ * @throws {DataError} If the file path is invalid.
933
+ *
934
+ * @returns An object representing the different ways the file path can be represented.
935
+ */
936
+ function parseFilePath(filePath) {
937
+ const caughtGroups = filePath.match(RegExp(FILE_PATH_REGEX_default));
938
+ if (!caughtGroups) {
939
+ if (!(filePath.includes("/") || filePath.includes("\\")) && filePath.includes(".")) return {
940
+ directory: "",
941
+ base: filePath,
942
+ fullPath: filePath
943
+ };
944
+ throw new DataError_default({ filePath }, "INVALID_FILE_PATH", "The file path you provided is not valid.");
945
+ }
946
+ if (!caughtGroups.groups) throw new DataError_default({ filePath }, "PARSING_ERROR", "An error occurred while trying to parse the data.");
947
+ return {
948
+ directory: caughtGroups.groups.directory,
949
+ base: caughtGroups.groups.base,
950
+ fullPath: path.join(caughtGroups.groups.directory.replaceAll("\\", "/"), caughtGroups.groups.base)
951
+ };
952
+ }
953
+ var parseFilePath_default = parseFilePath;
954
+
918
955
  //#endregion
919
956
  //#region src/functions/parsers/parseFormData.ts
920
957
  /**
@@ -1071,6 +1108,10 @@ var encryptWithKey_default = encryptWithKey;
1071
1108
  /**
1072
1109
  * Returns the public key and private key, properly narrowing down types depending on the provided `outputFormat`.
1073
1110
  *
1111
+ * @deprecated Please use `sodium.crypto_box_keypair` from `libsodium-wrappers` instead.
1112
+ *
1113
+ * This function was initially created to deal with a typing issue with the package introduced in v0.8.1 of said package, but this seems to have been fixed in v0.8.2
1114
+ *
1074
1115
  * @param outputFormat - The format of the resulting publicKey and privateKey you would like to use.
1075
1116
  *
1076
1117
  * @returns An object containing both the publicKey and privateKey, along with a keyType.
@@ -1135,8 +1176,8 @@ function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
1135
1176
  result += sequenceOfCapitals.toLowerCase();
1136
1177
  } else {
1137
1178
  if (result) result += "-";
1138
- result += sequenceOfCapitals.split("").map((character$1) => {
1139
- return character$1.toLowerCase();
1179
+ result += sequenceOfCapitals.split("").map((character) => {
1180
+ return character.toLowerCase();
1140
1181
  }).join("-");
1141
1182
  }
1142
1183
  outerIndex = innerIndex;
@@ -1391,9 +1432,9 @@ function reduceLines(lines, { preserveTabs = true }) {
1391
1432
  */
1392
1433
  function normaliseIndents(first, ...args) {
1393
1434
  if (typeof first === "object" && first !== null && !Array.isArray(first)) {
1394
- const options$1 = first;
1395
- return (strings$1, ...interpolations) => {
1396
- return normaliseIndents(strings$1, ...interpolations, options$1);
1435
+ const options = first;
1436
+ return (strings, ...interpolations) => {
1437
+ return normaliseIndents(strings, ...interpolations, options);
1397
1438
  };
1398
1439
  }
1399
1440
  const strings = first;
@@ -1520,4 +1561,4 @@ function incrementVersion(version, incrementType, options) {
1520
1561
  var incrementVersion_default = incrementVersion;
1521
1562
 
1522
1563
  //#endregion
1523
- export { APIError_default as APIError, DataError_default as DataError, Env, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX_default as VERSION_NUMBER_REGEX, VersionNumber_default as VersionNumber, VersionType, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, determineVersionType_default as determineVersionType, encryptWithKey_default as encryptWithKey, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getIndividualVersionNumbers_default as getIndividualVersionNumbers, getInterpolations_default as getInterpolations, getPublicAndPrivateKey_default as getPublicAndPrivateKey, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, incrementVersion_default as incrementVersion, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, parseVersion_default as parseVersion, parseVersionType_default as parseVersionType, parseZodSchema_default as parseZodSchema, parseZodSchemaAsync_default as parseZodSchemaAsync, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, removeUndefinedFromObject_default as removeUndefinedFromObject, stringListToArray_default as stringListToArray, stringifyDotenv_default as stringifyDotenv, truncate_default as truncate, wait_default as wait };
1564
+ export { APIError_default as APIError, DataError_default as DataError, Env, FILE_PATH_REGEX_default as FILE_PATH_REGEX, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX_default as VERSION_NUMBER_REGEX, VersionNumber_default as VersionNumber, VersionType, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, determineVersionType_default as determineVersionType, encryptWithKey_default as encryptWithKey, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getIndividualVersionNumbers_default as getIndividualVersionNumbers, getInterpolations_default as getInterpolations, getPublicAndPrivateKey_default as getPublicAndPrivateKey, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, incrementVersion_default as incrementVersion, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, parseEnv_default as parseEnv, parseFilePath_default as parseFilePath, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, parseVersion_default as parseVersion, parseVersionType_default as parseVersionType, parseZodSchema_default as parseZodSchema, parseZodSchemaAsync_default as parseZodSchemaAsync, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, removeUndefinedFromObject_default as removeUndefinedFromObject, stringListToArray_default as stringListToArray, stringifyDotenv_default as stringifyDotenv, truncate_default as truncate, wait_default as wait };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "4.11.0",
3
+ "version": "4.12.0",
4
4
  "description": "Helpful utility functions.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,24 +17,24 @@
17
17
  ],
18
18
  "dependencies": {
19
19
  "dotenv": "^17.2.3",
20
- "libsodium-wrappers": "^0.8.1",
20
+ "libsodium-wrappers": "^0.8.2",
21
21
  "zod": "^4.3.6"
22
22
  },
23
23
  "devDependencies": {
24
- "@alextheman/eslint-plugin": "^5.4.3",
25
- "@types/node": "^25.0.10",
26
- "@typescript-eslint/types": "^8.53.1",
27
- "alex-c-line": "^1.20.0",
24
+ "@alextheman/eslint-plugin": "^5.5.0",
25
+ "@types/node": "^25.1.0",
26
+ "@typescript-eslint/types": "^8.54.0",
27
+ "alex-c-line": "^1.21.2",
28
28
  "dotenv-cli": "^11.0.0",
29
29
  "eslint": "^9.39.2",
30
- "globals": "^17.1.0",
30
+ "globals": "^17.2.0",
31
31
  "husky": "^9.1.7",
32
32
  "jsdom": "^27.4.0",
33
33
  "prettier": "^3.8.1",
34
- "tsdown": "^0.19.0",
34
+ "tsdown": "^0.20.1",
35
35
  "typedoc": "^0.28.16",
36
36
  "typescript": "^5.9.3",
37
- "vite-tsconfig-paths": "^6.0.4",
37
+ "vite-tsconfig-paths": "^6.0.5",
38
38
  "vitest": "^4.0.18"
39
39
  },
40
40
  "engines": {