@alextheman/utility 5.12.0 → 5.13.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.d.cts CHANGED
@@ -16,6 +16,74 @@ declare const UUID_REGEX: RegExp;
16
16
  declare const VERSION_NUMBER_PATTERN: string;
17
17
  declare const VERSION_NUMBER_REGEX: RegExp;
18
18
  //#endregion
19
+ //#region src/root/deprecated/DataError.d.ts
20
+ interface ExpectErrorOptions$2 {
21
+ expectedCode?: string;
22
+ }
23
+ /**
24
+ * Represents errors you may get that may've been caused by a specific piece of data.
25
+ *
26
+ * @category Types
27
+ *
28
+ * @deprecated Please use `DataError` from `@alextheman/utility/v6` instead.
29
+ *
30
+ * @template DataType - The type of the data that caused the error.
31
+ */
32
+ declare class DataError<DataType extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>> extends Error {
33
+ code: string;
34
+ data: DataType;
35
+ /**
36
+ * @param data - The data that caused the error.
37
+ * @param code - A standardised code (e.g. UNEXPECTED_DATA).
38
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
39
+ * @param options - Extra options to pass to super Error constructor.
40
+ */
41
+ constructor(data: DataType, code?: string, message?: string, options?: ErrorOptions);
42
+ private static checkCaughtError;
43
+ /**
44
+ * Checks whether the given input may have been caused by a DataError.
45
+ *
46
+ * @param input - The input to check.
47
+ *
48
+ * @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`.
49
+ */
50
+ static check<DataType extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>>(input: unknown): input is DataError<DataType>;
51
+ /**
52
+ * Gets the thrown `DataError` from a given function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
53
+ *
54
+ * @param errorFunction - The function expected to throw the error.
55
+ * @param options - Extra options to apply.
56
+ *
57
+ * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
58
+ * @throws {Error} If no `DataError` was thrown by the `errorFunction`
59
+ *
60
+ * @returns The `DataError` that was thrown by the `errorFunction`
61
+ */
62
+ static expectError(errorFunction: () => unknown, options?: ExpectErrorOptions$2): DataError;
63
+ /**
64
+ * Gets the thrown `DataError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
65
+ *
66
+ * @param errorFunction - The function expected to throw the error.
67
+ * @param options - Extra options to apply.
68
+ *
69
+ * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
70
+ * @throws {Error} If no `DataError` was thrown by the `errorFunction`
71
+ *
72
+ * @returns The `DataError` that was thrown by the `errorFunction`
73
+ */
74
+ static expectErrorAsync(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions$2): Promise<DataError>;
75
+ }
76
+ //#endregion
77
+ //#region src/root/deprecated/RecordKey.d.ts
78
+ /**
79
+ * Represents the native Record's possible key type.
80
+ *
81
+ * @category Types
82
+ *
83
+ * @deprecated Please use the native `PropertyKey` type instead.
84
+ */
85
+ type RecordKey = string | number | symbol;
86
+ //#endregion
19
87
  //#region src/root/functions/arrayHelpers/fillArray.d.ts
20
88
  /**
21
89
  * Creates a new array where each element is the resolved result of the provided asynchronous callback.
@@ -461,62 +529,6 @@ declare class APIError extends Error {
461
529
  static check(input: unknown): input is APIError;
462
530
  }
463
531
  //#endregion
464
- //#region src/root/types/DataError.d.ts
465
- interface ExpectErrorOptions {
466
- expectedCode?: string;
467
- }
468
- /**
469
- * Represents errors you may get that may've been caused by a specific piece of data.
470
- *
471
- * @category Types
472
- *
473
- * @template DataType - The type of the data that caused the error.
474
- */
475
- declare class DataError<DataType extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>> extends Error {
476
- code: string;
477
- data: DataType;
478
- /**
479
- * @param data - The data that caused the error.
480
- * @param code - A standardised code (e.g. UNEXPECTED_DATA).
481
- * @param message - A human-readable error message (e.g. The data provided is invalid).
482
- * @param options - Extra options to pass to super Error constructor.
483
- */
484
- constructor(data: DataType, code?: string, message?: string, options?: ErrorOptions);
485
- private static checkCaughtError;
486
- /**
487
- * Checks whether the given input may have been caused by a DataError.
488
- *
489
- * @param input - The input to check.
490
- *
491
- * @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`.
492
- */
493
- static check<DataType extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>>(input: unknown): input is DataError<DataType>;
494
- /**
495
- * Gets the thrown `DataError` from a given function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
496
- *
497
- * @param errorFunction - The function expected to throw the error.
498
- * @param options - Extra options to apply.
499
- *
500
- * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
501
- * @throws {Error} If no `DataError` was thrown by the `errorFunction`
502
- *
503
- * @returns The `DataError` that was thrown by the `errorFunction`
504
- */
505
- static expectError(errorFunction: () => unknown, options?: ExpectErrorOptions): DataError;
506
- /**
507
- * Gets the thrown `DataError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
508
- *
509
- * @param errorFunction - The function expected to throw the error.
510
- * @param options - Extra options to apply.
511
- *
512
- * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
513
- * @throws {Error} If no `DataError` was thrown by the `errorFunction`
514
- *
515
- * @returns The `DataError` that was thrown by the `errorFunction`
516
- */
517
- static expectErrorAsync(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions): Promise<DataError>;
518
- }
519
- //#endregion
520
532
  //#region src/root/types/VersionNumber.d.ts
521
533
  /**
522
534
  * Options to apply to the stringification of the version number.
@@ -794,6 +806,119 @@ type VersionType = CreateEnumType<typeof VersionType>;
794
806
  */
795
807
  declare function parseVersionType(input: unknown): VersionType;
796
808
  //#endregion
809
+ //#region src/v6/CodeError.d.ts
810
+ interface ExpectErrorOptions$1<ErrorCode extends string = string> {
811
+ expectedCode?: ErrorCode;
812
+ }
813
+ /**
814
+ * Represents errors that can be described using a standardised error code, and a human-readable error message.
815
+ *
816
+ * @category Types
817
+ *
818
+ * @template ErrorCode The type of the standardised error code.
819
+ */
820
+ declare class CodeError<ErrorCode extends string = string> extends Error {
821
+ code: ErrorCode;
822
+ /**
823
+ * @param code - A standardised code (e.g. UNEXPECTED_DATA).
824
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
825
+ * @param options - Extra options to pass to super Error constructor.
826
+ */
827
+ constructor(code: ErrorCode, message?: string, options?: ErrorOptions);
828
+ /**
829
+ * Checks whether the given input may have been caused by a CodeError.
830
+ *
831
+ * @param input - The input to check.
832
+ *
833
+ * @returns `true` if the input is a CodeError, and `false` otherwise. The type of the input will also be narrowed down to CodeError if `true`.
834
+ */
835
+ static check(input: unknown): input is CodeError<string>;
836
+ protected static checkCaughtError<ErrorCode extends string = string>(this: typeof CodeError, error: unknown, options?: ExpectErrorOptions$1<ErrorCode>): CodeError;
837
+ /**
838
+ * Gets the thrown `CodeError` from a given function if one was thrown, and re-throws any other errors, or throws a default `CodeError` if no error thrown.
839
+ *
840
+ * @param errorFunction - The function expected to throw the error.
841
+ * @param options - Extra options to apply.
842
+ *
843
+ * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `CodeError`.
844
+ * @throws {Error} If no `CodeError` was thrown by the `errorFunction`
845
+ *
846
+ * @returns The `CodeError` that was thrown by the `errorFunction`
847
+ */
848
+ static expectError<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => unknown, options?: ExpectErrorOptions$1<ErrorCode>): CodeError;
849
+ /**
850
+ * Gets the thrown `CodeError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `CodeError` if no error thrown.
851
+ *
852
+ * @param errorFunction - The function expected to throw the error.
853
+ * @param options - Extra options to apply.
854
+ *
855
+ * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `CodeError`.
856
+ * @throws {Error} If no `CodeError` was thrown by the `errorFunction`
857
+ *
858
+ * @returns The `CodeError` that was thrown by the `errorFunction`
859
+ */
860
+ static expectErrorAsync<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions$1<ErrorCode>): Promise<CodeError>;
861
+ }
862
+ //#endregion
863
+ //#region src/v6/DataError.d.ts
864
+ type DefaultDataErrorCode = "INVALID_DATA";
865
+ interface ExpectErrorOptions<ErrorCode extends string = DefaultDataErrorCode> {
866
+ expectedCode?: ErrorCode | DefaultDataErrorCode;
867
+ }
868
+ declare const DataErrorCode: {
869
+ readonly INVALID_DATA: "INVALID_DATA";
870
+ };
871
+ type DataErrorCode = CreateEnumType<typeof DataErrorCode>;
872
+ /**
873
+ * Represents errors you may get that may've been caused by a specific piece of data.
874
+ *
875
+ * @category Types
876
+ *
877
+ * @template DataType - The type of the data that caused the error.
878
+ */
879
+ declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = DataErrorCode> extends CodeError<ErrorCode | DataErrorCode> {
880
+ data: DataType;
881
+ /**
882
+ * @param data - The data that caused the error.
883
+ * @param code - A standardised code (e.g. UNEXPECTED_DATA).
884
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
885
+ * @param options - Extra options to pass to super Error constructor.
886
+ */
887
+ constructor(data: DataType, code?: ErrorCode | DefaultDataErrorCode, message?: string, options?: ErrorOptions);
888
+ /**
889
+ * Checks whether the given input may have been caused by a DataError.
890
+ *
891
+ * @param input - The input to check.
892
+ *
893
+ * @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`.
894
+ */
895
+ static check<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = DataErrorCode>(input: unknown): input is DataError$1<DataType, ErrorCode>;
896
+ /**
897
+ * Gets the thrown `DataError` from a given function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
898
+ *
899
+ * @param errorFunction - The function expected to throw the error.
900
+ * @param options - Extra options to apply.
901
+ *
902
+ * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
903
+ * @throws {Error} If no `DataError` was thrown by the `errorFunction`
904
+ *
905
+ * @returns The `DataError` that was thrown by the `errorFunction`
906
+ */
907
+ static expectError<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = DefaultDataErrorCode>(errorFunction: () => unknown, options?: ExpectErrorOptions<ErrorCode>): DataError$1<DataType, ErrorCode>;
908
+ /**
909
+ * Gets the thrown `DataError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
910
+ *
911
+ * @param errorFunction - The function expected to throw the error.
912
+ * @param options - Extra options to apply.
913
+ *
914
+ * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
915
+ * @throws {Error} If no `DataError` was thrown by the `errorFunction`
916
+ *
917
+ * @returns The `DataError` that was thrown by the `errorFunction`
918
+ */
919
+ static expectErrorAsync<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = DefaultDataErrorCode>(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<DataError$1<DataType, ErrorCode>>;
920
+ }
921
+ //#endregion
797
922
  //#region src/root/functions/parsers/zod/parseZodSchema.d.ts
798
923
  /**
799
924
  * An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
@@ -809,11 +934,11 @@ declare function parseVersionType(input: unknown): VersionType;
809
934
  * @param input - The data to parse.
810
935
  * @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
811
936
  *
812
- * @throws {DataError} If the given data cannot be parsed according to the schema.
937
+ * @throws {DataErrorCode} If the given data cannot be parsed according to the schema.
813
938
  *
814
939
  * @returns The parsed data from the Zod schema.
815
940
  */
816
- declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error = DataError>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z.infer<SchemaType>;
941
+ declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error = DataError$1>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z.infer<SchemaType>;
817
942
  //#endregion
818
943
  //#region src/root/functions/parsers/zod/parseZodSchemaAsync.d.ts
819
944
  /**
@@ -832,7 +957,7 @@ declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Er
832
957
  *
833
958
  * @returns The parsed data from the Zod schema.
834
959
  */
835
- declare function parseZodSchemaAsync<SchemaType extends ZodType, ErrorType extends Error = DataError>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): Promise<z.infer<SchemaType>>;
960
+ declare function parseZodSchemaAsync<SchemaType extends ZodType, ErrorType extends Error = DataError$1>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): Promise<z.infer<SchemaType>>;
836
961
  //#endregion
837
962
  //#region src/root/functions/recursive/deepCopy.d.ts
838
963
  /**
@@ -1139,14 +1264,4 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
1139
1264
  */
1140
1265
  declare const normalizeIndents: typeof normaliseIndents;
1141
1266
  //#endregion
1142
- //#region src/root/deprecated/RecordKey.d.ts
1143
- /**
1144
- * Represents the native Record's possible key type.
1145
- *
1146
- * @category Types
1147
- *
1148
- * @deprecated Please use the native `PropertyKey` type instead.
1149
- */
1150
- type RecordKey = string | number | symbol;
1151
- //#endregion
1152
1267
  export { APIError, type ArrayElement, type CallReturnType, CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, KebabToCamelOptions, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, type StringListToArrayOptions, ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
package/dist/index.d.ts CHANGED
@@ -16,6 +16,74 @@ declare const UUID_REGEX: RegExp;
16
16
  declare const VERSION_NUMBER_PATTERN: string;
17
17
  declare const VERSION_NUMBER_REGEX: RegExp;
18
18
  //#endregion
19
+ //#region src/root/deprecated/DataError.d.ts
20
+ interface ExpectErrorOptions$2 {
21
+ expectedCode?: string;
22
+ }
23
+ /**
24
+ * Represents errors you may get that may've been caused by a specific piece of data.
25
+ *
26
+ * @category Types
27
+ *
28
+ * @deprecated Please use `DataError` from `@alextheman/utility/v6` instead.
29
+ *
30
+ * @template DataType - The type of the data that caused the error.
31
+ */
32
+ declare class DataError<DataType extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>> extends Error {
33
+ code: string;
34
+ data: DataType;
35
+ /**
36
+ * @param data - The data that caused the error.
37
+ * @param code - A standardised code (e.g. UNEXPECTED_DATA).
38
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
39
+ * @param options - Extra options to pass to super Error constructor.
40
+ */
41
+ constructor(data: DataType, code?: string, message?: string, options?: ErrorOptions);
42
+ private static checkCaughtError;
43
+ /**
44
+ * Checks whether the given input may have been caused by a DataError.
45
+ *
46
+ * @param input - The input to check.
47
+ *
48
+ * @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`.
49
+ */
50
+ static check<DataType extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>>(input: unknown): input is DataError<DataType>;
51
+ /**
52
+ * Gets the thrown `DataError` from a given function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
53
+ *
54
+ * @param errorFunction - The function expected to throw the error.
55
+ * @param options - Extra options to apply.
56
+ *
57
+ * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
58
+ * @throws {Error} If no `DataError` was thrown by the `errorFunction`
59
+ *
60
+ * @returns The `DataError` that was thrown by the `errorFunction`
61
+ */
62
+ static expectError(errorFunction: () => unknown, options?: ExpectErrorOptions$2): DataError;
63
+ /**
64
+ * Gets the thrown `DataError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
65
+ *
66
+ * @param errorFunction - The function expected to throw the error.
67
+ * @param options - Extra options to apply.
68
+ *
69
+ * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
70
+ * @throws {Error} If no `DataError` was thrown by the `errorFunction`
71
+ *
72
+ * @returns The `DataError` that was thrown by the `errorFunction`
73
+ */
74
+ static expectErrorAsync(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions$2): Promise<DataError>;
75
+ }
76
+ //#endregion
77
+ //#region src/root/deprecated/RecordKey.d.ts
78
+ /**
79
+ * Represents the native Record's possible key type.
80
+ *
81
+ * @category Types
82
+ *
83
+ * @deprecated Please use the native `PropertyKey` type instead.
84
+ */
85
+ type RecordKey = string | number | symbol;
86
+ //#endregion
19
87
  //#region src/root/functions/arrayHelpers/fillArray.d.ts
20
88
  /**
21
89
  * Creates a new array where each element is the resolved result of the provided asynchronous callback.
@@ -461,62 +529,6 @@ declare class APIError extends Error {
461
529
  static check(input: unknown): input is APIError;
462
530
  }
463
531
  //#endregion
464
- //#region src/root/types/DataError.d.ts
465
- interface ExpectErrorOptions {
466
- expectedCode?: string;
467
- }
468
- /**
469
- * Represents errors you may get that may've been caused by a specific piece of data.
470
- *
471
- * @category Types
472
- *
473
- * @template DataType - The type of the data that caused the error.
474
- */
475
- declare class DataError<DataType extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>> extends Error {
476
- code: string;
477
- data: DataType;
478
- /**
479
- * @param data - The data that caused the error.
480
- * @param code - A standardised code (e.g. UNEXPECTED_DATA).
481
- * @param message - A human-readable error message (e.g. The data provided is invalid).
482
- * @param options - Extra options to pass to super Error constructor.
483
- */
484
- constructor(data: DataType, code?: string, message?: string, options?: ErrorOptions);
485
- private static checkCaughtError;
486
- /**
487
- * Checks whether the given input may have been caused by a DataError.
488
- *
489
- * @param input - The input to check.
490
- *
491
- * @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`.
492
- */
493
- static check<DataType extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>>(input: unknown): input is DataError<DataType>;
494
- /**
495
- * Gets the thrown `DataError` from a given function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
496
- *
497
- * @param errorFunction - The function expected to throw the error.
498
- * @param options - Extra options to apply.
499
- *
500
- * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
501
- * @throws {Error} If no `DataError` was thrown by the `errorFunction`
502
- *
503
- * @returns The `DataError` that was thrown by the `errorFunction`
504
- */
505
- static expectError(errorFunction: () => unknown, options?: ExpectErrorOptions): DataError;
506
- /**
507
- * Gets the thrown `DataError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
508
- *
509
- * @param errorFunction - The function expected to throw the error.
510
- * @param options - Extra options to apply.
511
- *
512
- * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
513
- * @throws {Error} If no `DataError` was thrown by the `errorFunction`
514
- *
515
- * @returns The `DataError` that was thrown by the `errorFunction`
516
- */
517
- static expectErrorAsync(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions): Promise<DataError>;
518
- }
519
- //#endregion
520
532
  //#region src/root/types/VersionNumber.d.ts
521
533
  /**
522
534
  * Options to apply to the stringification of the version number.
@@ -794,6 +806,119 @@ type VersionType = CreateEnumType<typeof VersionType>;
794
806
  */
795
807
  declare function parseVersionType(input: unknown): VersionType;
796
808
  //#endregion
809
+ //#region src/v6/CodeError.d.ts
810
+ interface ExpectErrorOptions$1<ErrorCode extends string = string> {
811
+ expectedCode?: ErrorCode;
812
+ }
813
+ /**
814
+ * Represents errors that can be described using a standardised error code, and a human-readable error message.
815
+ *
816
+ * @category Types
817
+ *
818
+ * @template ErrorCode The type of the standardised error code.
819
+ */
820
+ declare class CodeError<ErrorCode extends string = string> extends Error {
821
+ code: ErrorCode;
822
+ /**
823
+ * @param code - A standardised code (e.g. UNEXPECTED_DATA).
824
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
825
+ * @param options - Extra options to pass to super Error constructor.
826
+ */
827
+ constructor(code: ErrorCode, message?: string, options?: ErrorOptions);
828
+ /**
829
+ * Checks whether the given input may have been caused by a CodeError.
830
+ *
831
+ * @param input - The input to check.
832
+ *
833
+ * @returns `true` if the input is a CodeError, and `false` otherwise. The type of the input will also be narrowed down to CodeError if `true`.
834
+ */
835
+ static check(input: unknown): input is CodeError<string>;
836
+ protected static checkCaughtError<ErrorCode extends string = string>(this: typeof CodeError, error: unknown, options?: ExpectErrorOptions$1<ErrorCode>): CodeError;
837
+ /**
838
+ * Gets the thrown `CodeError` from a given function if one was thrown, and re-throws any other errors, or throws a default `CodeError` if no error thrown.
839
+ *
840
+ * @param errorFunction - The function expected to throw the error.
841
+ * @param options - Extra options to apply.
842
+ *
843
+ * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `CodeError`.
844
+ * @throws {Error} If no `CodeError` was thrown by the `errorFunction`
845
+ *
846
+ * @returns The `CodeError` that was thrown by the `errorFunction`
847
+ */
848
+ static expectError<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => unknown, options?: ExpectErrorOptions$1<ErrorCode>): CodeError;
849
+ /**
850
+ * Gets the thrown `CodeError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `CodeError` if no error thrown.
851
+ *
852
+ * @param errorFunction - The function expected to throw the error.
853
+ * @param options - Extra options to apply.
854
+ *
855
+ * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `CodeError`.
856
+ * @throws {Error} If no `CodeError` was thrown by the `errorFunction`
857
+ *
858
+ * @returns The `CodeError` that was thrown by the `errorFunction`
859
+ */
860
+ static expectErrorAsync<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions$1<ErrorCode>): Promise<CodeError>;
861
+ }
862
+ //#endregion
863
+ //#region src/v6/DataError.d.ts
864
+ type DefaultDataErrorCode = "INVALID_DATA";
865
+ interface ExpectErrorOptions<ErrorCode extends string = DefaultDataErrorCode> {
866
+ expectedCode?: ErrorCode | DefaultDataErrorCode;
867
+ }
868
+ declare const DataErrorCode: {
869
+ readonly INVALID_DATA: "INVALID_DATA";
870
+ };
871
+ type DataErrorCode = CreateEnumType<typeof DataErrorCode>;
872
+ /**
873
+ * Represents errors you may get that may've been caused by a specific piece of data.
874
+ *
875
+ * @category Types
876
+ *
877
+ * @template DataType - The type of the data that caused the error.
878
+ */
879
+ declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = DataErrorCode> extends CodeError<ErrorCode | DataErrorCode> {
880
+ data: DataType;
881
+ /**
882
+ * @param data - The data that caused the error.
883
+ * @param code - A standardised code (e.g. UNEXPECTED_DATA).
884
+ * @param message - A human-readable error message (e.g. The data provided is invalid).
885
+ * @param options - Extra options to pass to super Error constructor.
886
+ */
887
+ constructor(data: DataType, code?: ErrorCode | DefaultDataErrorCode, message?: string, options?: ErrorOptions);
888
+ /**
889
+ * Checks whether the given input may have been caused by a DataError.
890
+ *
891
+ * @param input - The input to check.
892
+ *
893
+ * @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`.
894
+ */
895
+ static check<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = DataErrorCode>(input: unknown): input is DataError$1<DataType, ErrorCode>;
896
+ /**
897
+ * Gets the thrown `DataError` from a given function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
898
+ *
899
+ * @param errorFunction - The function expected to throw the error.
900
+ * @param options - Extra options to apply.
901
+ *
902
+ * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
903
+ * @throws {Error} If no `DataError` was thrown by the `errorFunction`
904
+ *
905
+ * @returns The `DataError` that was thrown by the `errorFunction`
906
+ */
907
+ static expectError<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = DefaultDataErrorCode>(errorFunction: () => unknown, options?: ExpectErrorOptions<ErrorCode>): DataError$1<DataType, ErrorCode>;
908
+ /**
909
+ * Gets the thrown `DataError` from a given asynchronous function if one was thrown, and re-throws any other errors, or throws a default `DataError` if no error thrown.
910
+ *
911
+ * @param errorFunction - The function expected to throw the error.
912
+ * @param options - Extra options to apply.
913
+ *
914
+ * @throws {Error} Any other errors thrown by the `errorFunction` that are not a `DataError`.
915
+ * @throws {Error} If no `DataError` was thrown by the `errorFunction`
916
+ *
917
+ * @returns The `DataError` that was thrown by the `errorFunction`
918
+ */
919
+ static expectErrorAsync<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = DefaultDataErrorCode>(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<DataError$1<DataType, ErrorCode>>;
920
+ }
921
+ //#endregion
797
922
  //#region src/root/functions/parsers/zod/parseZodSchema.d.ts
798
923
  /**
799
924
  * An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
@@ -809,11 +934,11 @@ declare function parseVersionType(input: unknown): VersionType;
809
934
  * @param input - The data to parse.
810
935
  * @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
811
936
  *
812
- * @throws {DataError} If the given data cannot be parsed according to the schema.
937
+ * @throws {DataErrorCode} If the given data cannot be parsed according to the schema.
813
938
  *
814
939
  * @returns The parsed data from the Zod schema.
815
940
  */
816
- declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error = DataError>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z.infer<SchemaType>;
941
+ declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error = DataError$1>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z.infer<SchemaType>;
817
942
  //#endregion
818
943
  //#region src/root/functions/parsers/zod/parseZodSchemaAsync.d.ts
819
944
  /**
@@ -832,7 +957,7 @@ declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Er
832
957
  *
833
958
  * @returns The parsed data from the Zod schema.
834
959
  */
835
- declare function parseZodSchemaAsync<SchemaType extends ZodType, ErrorType extends Error = DataError>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): Promise<z.infer<SchemaType>>;
960
+ declare function parseZodSchemaAsync<SchemaType extends ZodType, ErrorType extends Error = DataError$1>(schema: SchemaType, input: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): Promise<z.infer<SchemaType>>;
836
961
  //#endregion
837
962
  //#region src/root/functions/recursive/deepCopy.d.ts
838
963
  /**
@@ -1139,14 +1264,4 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
1139
1264
  */
1140
1265
  declare const normalizeIndents: typeof normaliseIndents;
1141
1266
  //#endregion
1142
- //#region src/root/deprecated/RecordKey.d.ts
1143
- /**
1144
- * Represents the native Record's possible key type.
1145
- *
1146
- * @category Types
1147
- *
1148
- * @deprecated Please use the native `PropertyKey` type instead.
1149
- */
1150
- type RecordKey = string | number | symbol;
1151
- //#endregion
1152
1267
  export { APIError, type ArrayElement, type CallReturnType, CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, KebabToCamelOptions, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, type StringListToArrayOptions, ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };