@alextheman/utility 5.14.0 → 5.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +48 -2
- package/dist/index.d.cts +270 -228
- package/dist/index.d.ts +269 -227
- package/dist/index.js +48 -3
- package/dist/internal/index.cjs +31 -2
- package/dist/internal/index.d.cts +36 -18
- package/dist/internal/index.d.ts +36 -18
- package/dist/internal/index.js +31 -2
- package/dist/node/index.cjs +31 -2
- package/dist/node/index.js +31 -2
- package/dist/v6/index.cjs +31 -4
- package/dist/v6/index.d.cts +40 -32
- package/dist/v6/index.d.ts +40 -32
- package/dist/v6/index.js +32 -4
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ declare const VERSION_NUMBER_PATTERN: string;
|
|
|
17
17
|
declare const VERSION_NUMBER_REGEX: RegExp;
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/root/deprecated/DataError.d.ts
|
|
20
|
-
interface ExpectErrorOptions$
|
|
20
|
+
interface ExpectErrorOptions$1 {
|
|
21
21
|
expectedCode?: string;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
@@ -59,7 +59,7 @@ declare class DataError<DataType extends Record<PropertyKey, unknown> = Record<P
|
|
|
59
59
|
*
|
|
60
60
|
* @returns The `DataError` that was thrown by the `errorFunction`
|
|
61
61
|
*/
|
|
62
|
-
static expectError(errorFunction: () => unknown, options?: ExpectErrorOptions$
|
|
62
|
+
static expectError(errorFunction: () => unknown, options?: ExpectErrorOptions$1): DataError;
|
|
63
63
|
/**
|
|
64
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
65
|
*
|
|
@@ -71,7 +71,7 @@ declare class DataError<DataType extends Record<PropertyKey, unknown> = Record<P
|
|
|
71
71
|
*
|
|
72
72
|
* @returns The `DataError` that was thrown by the `errorFunction`
|
|
73
73
|
*/
|
|
74
|
-
static expectErrorAsync(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions$
|
|
74
|
+
static expectErrorAsync(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions$1): Promise<DataError>;
|
|
75
75
|
}
|
|
76
76
|
//#endregion
|
|
77
77
|
//#region src/root/deprecated/RecordKey.d.ts
|
|
@@ -84,6 +84,32 @@ declare class DataError<DataType extends Record<PropertyKey, unknown> = Record<P
|
|
|
84
84
|
*/
|
|
85
85
|
type RecordKey = string | number | symbol;
|
|
86
86
|
//#endregion
|
|
87
|
+
//#region src/root/types/APIError.d.ts
|
|
88
|
+
type HTTPErrorCode = 400 | 401 | 403 | 404 | 418 | 500;
|
|
89
|
+
declare const httpErrorCodeLookup: Record<HTTPErrorCode, string>;
|
|
90
|
+
/**
|
|
91
|
+
* Represents common errors you may get from a HTTP API request.
|
|
92
|
+
*
|
|
93
|
+
* @category Types
|
|
94
|
+
*/
|
|
95
|
+
declare class APIError extends Error {
|
|
96
|
+
status: number;
|
|
97
|
+
/**
|
|
98
|
+
* @param status - A HTTP status code. Can be any number, but numbers between 400 and 600 are encouraged to fit with HTTP status code conventions.
|
|
99
|
+
* @param message - An error message to display alongside the status code.
|
|
100
|
+
* @param options - Extra options to be passed to super Error constructor.
|
|
101
|
+
*/
|
|
102
|
+
constructor(status?: HTTPErrorCode | number, message?: string, options?: ErrorOptions);
|
|
103
|
+
/**
|
|
104
|
+
* Checks whether the given input may have been caused by an APIError.
|
|
105
|
+
*
|
|
106
|
+
* @param input - The input to check.
|
|
107
|
+
*
|
|
108
|
+
* @returns `true` if the input is an APIError, and `false` otherwise. The type of the input will also be narrowed down to APIError if `true`.
|
|
109
|
+
*/
|
|
110
|
+
static check(input: unknown): input is APIError;
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
87
113
|
//#region src/root/functions/arrayHelpers/fillArray.d.ts
|
|
88
114
|
/**
|
|
89
115
|
* Creates a new array where each element is the resolved result of the provided asynchronous callback.
|
|
@@ -503,209 +529,6 @@ declare function removeUndefinedFromObject<RecordType extends Record<PropertyKey
|
|
|
503
529
|
*/
|
|
504
530
|
declare function parseBoolean(inputString: string): boolean;
|
|
505
531
|
//#endregion
|
|
506
|
-
//#region src/root/types/APIError.d.ts
|
|
507
|
-
type HTTPErrorCode = 400 | 401 | 403 | 404 | 418 | 500;
|
|
508
|
-
declare const httpErrorCodeLookup: Record<HTTPErrorCode, string>;
|
|
509
|
-
/**
|
|
510
|
-
* Represents common errors you may get from a HTTP API request.
|
|
511
|
-
*
|
|
512
|
-
* @category Types
|
|
513
|
-
*/
|
|
514
|
-
declare class APIError extends Error {
|
|
515
|
-
status: number;
|
|
516
|
-
/**
|
|
517
|
-
* @param status - A HTTP status code. Can be any number, but numbers between 400 and 600 are encouraged to fit with HTTP status code conventions.
|
|
518
|
-
* @param message - An error message to display alongside the status code.
|
|
519
|
-
* @param options - Extra options to be passed to super Error constructor.
|
|
520
|
-
*/
|
|
521
|
-
constructor(status?: HTTPErrorCode | number, message?: string, options?: ErrorOptions);
|
|
522
|
-
/**
|
|
523
|
-
* Checks whether the given input may have been caused by an APIError.
|
|
524
|
-
*
|
|
525
|
-
* @param input - The input to check.
|
|
526
|
-
*
|
|
527
|
-
* @returns `true` if the input is an APIError, and `false` otherwise. The type of the input will also be narrowed down to APIError if `true`.
|
|
528
|
-
*/
|
|
529
|
-
static check(input: unknown): input is APIError;
|
|
530
|
-
}
|
|
531
|
-
//#endregion
|
|
532
|
-
//#region src/root/types/VersionNumber.d.ts
|
|
533
|
-
/**
|
|
534
|
-
* Options to apply to the stringification of the version number.
|
|
535
|
-
*
|
|
536
|
-
* @category Class Options
|
|
537
|
-
*/
|
|
538
|
-
interface FormatOptionsBase {
|
|
539
|
-
/** Whether you want to omit the "v" prefix or not (defaults to false). */
|
|
540
|
-
omitPrefix?: boolean;
|
|
541
|
-
}
|
|
542
|
-
interface FormatOptionsIncludeMinor extends FormatOptionsBase {
|
|
543
|
-
/** Whether you want to omit the minor version or not */
|
|
544
|
-
omitMinor?: false;
|
|
545
|
-
/** Whether you want to omit the patch version or not */
|
|
546
|
-
omitPatch?: boolean;
|
|
547
|
-
}
|
|
548
|
-
interface FormatOptionsOmitMinor extends FormatOptionsBase {
|
|
549
|
-
/** Whether you want to omit the minor version or not */
|
|
550
|
-
omitMinor?: true;
|
|
551
|
-
/** Whether you want to omit the patch version or not */
|
|
552
|
-
omitPatch?: never;
|
|
553
|
-
}
|
|
554
|
-
type FormatStringOptions = FormatOptionsIncludeMinor | FormatOptionsOmitMinor;
|
|
555
|
-
/**
|
|
556
|
-
* Represents a software version number, considered to be made up of a major, minor, and patch part.
|
|
557
|
-
*
|
|
558
|
-
* @category Types
|
|
559
|
-
*/
|
|
560
|
-
declare class VersionNumber {
|
|
561
|
-
private static readonly NON_NEGATIVE_TUPLE_ERROR;
|
|
562
|
-
/** The major number. Increments when a feature is removed or changed in a way that is not backwards-compatible with the previous release. */
|
|
563
|
-
readonly major: number;
|
|
564
|
-
/** The minor number. Increments when a new feature is added/deprecated and is expected to be backwards-compatible with the previous release. */
|
|
565
|
-
readonly minor: number;
|
|
566
|
-
/** The patch number. Increments when the next release is fixing a bug or doing a small refactor that should not be noticeable in practice. */
|
|
567
|
-
readonly patch: number;
|
|
568
|
-
/**
|
|
569
|
-
* @param input - The input to create a new instance of `VersionNumber` from.
|
|
570
|
-
*/
|
|
571
|
-
constructor(input: string | [number, number, number] | VersionNumber);
|
|
572
|
-
/**
|
|
573
|
-
* Gets the current version type of the current instance of `VersionNumber`.
|
|
574
|
-
*
|
|
575
|
-
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
576
|
-
*/
|
|
577
|
-
get type(): VersionType;
|
|
578
|
-
private static formatString;
|
|
579
|
-
/**
|
|
580
|
-
* Checks if the provided version numbers have the exact same major, minor, and patch numbers.
|
|
581
|
-
*
|
|
582
|
-
* @param firstVersion - The first version number to compare.
|
|
583
|
-
* @param secondVersion - The second version number to compare.
|
|
584
|
-
*
|
|
585
|
-
* @returns `true` if the provided version numbers have exactly the same major, minor, and patch numbers, and returns `false` otherwise.
|
|
586
|
-
*/
|
|
587
|
-
static isEqual(firstVersion: VersionNumber, secondVersion: VersionNumber): boolean;
|
|
588
|
-
/**
|
|
589
|
-
* Get a formatted string representation of the current version number
|
|
590
|
-
*
|
|
591
|
-
* @param options - Options to apply to the string formatting.
|
|
592
|
-
*
|
|
593
|
-
* @returns A formatted string representation of the current version number with the options applied.
|
|
594
|
-
*/
|
|
595
|
-
format(options?: FormatStringOptions): string;
|
|
596
|
-
/**
|
|
597
|
-
* Increments the current version number by the given increment type, returning the result as a new reference in memory.
|
|
598
|
-
*
|
|
599
|
-
* @param incrementType - The type of increment. Can be one of the following:
|
|
600
|
-
* - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
|
|
601
|
-
* - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
|
|
602
|
-
* - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
|
|
603
|
-
* @param incrementAmount - The amount to increment by (defaults to 1).
|
|
604
|
-
*
|
|
605
|
-
* @returns A new instance of `VersionNumber` with the increment applied.
|
|
606
|
-
*/
|
|
607
|
-
increment(incrementType: VersionType, incrementAmount?: number): VersionNumber;
|
|
608
|
-
/**
|
|
609
|
-
* Ensures that the VersionNumber behaves correctly when attempted to be coerced to a string.
|
|
610
|
-
*
|
|
611
|
-
* @param hint - Not used as of now, but generally used to help with numeric coercion, I think (which we most likely do not need for version numbers).
|
|
612
|
-
*
|
|
613
|
-
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
614
|
-
*/
|
|
615
|
-
[Symbol.toPrimitive](hint: "default" | "string" | "number"): string;
|
|
616
|
-
/**
|
|
617
|
-
* Ensures that the VersionNumber behaves correctly when attempted to be converted to JSON.
|
|
618
|
-
*
|
|
619
|
-
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
620
|
-
*/
|
|
621
|
-
toJSON(): string;
|
|
622
|
-
/**
|
|
623
|
-
* Get a string representation of the current version number.
|
|
624
|
-
*
|
|
625
|
-
* @returns A stringified representation of the current version number with the prefix.
|
|
626
|
-
*/
|
|
627
|
-
toString(): string;
|
|
628
|
-
}
|
|
629
|
-
declare const zodVersionNumber: z$1.ZodType<VersionNumber>;
|
|
630
|
-
//#endregion
|
|
631
|
-
//#region src/root/types/ArrayElement.d.ts
|
|
632
|
-
/**
|
|
633
|
-
* Gets the individual element types from an array type.
|
|
634
|
-
*
|
|
635
|
-
* @category Types
|
|
636
|
-
*
|
|
637
|
-
* @template ArrayType - The type of the array itself.
|
|
638
|
-
*/
|
|
639
|
-
type ArrayElement<ArrayType extends ReadonlyArray<unknown>> = ArrayType extends ReadonlyArray<infer ElementType> ? ElementType : never;
|
|
640
|
-
//#endregion
|
|
641
|
-
//#region src/root/types/CallReturnType.d.ts
|
|
642
|
-
type CallReturnType<Function, Arguments> = Function extends ((arg: Arguments) => infer Return) ? Return : never;
|
|
643
|
-
//#endregion
|
|
644
|
-
//#region src/root/types/CreateEnumType.d.ts
|
|
645
|
-
/**
|
|
646
|
-
* Get the value types from a const object so the object can behave similarly to an enum.
|
|
647
|
-
*
|
|
648
|
-
* @category Types
|
|
649
|
-
*
|
|
650
|
-
* @template ObjectType - The type of the object to get the value types for.
|
|
651
|
-
*/
|
|
652
|
-
type CreateEnumType<ObjectType extends Record<PropertyKey, unknown>> = ObjectType[keyof ObjectType];
|
|
653
|
-
//#endregion
|
|
654
|
-
//#region src/root/types/DisallowUndefined.d.ts
|
|
655
|
-
/**
|
|
656
|
-
* Resolves to an error message type if the type argument could potentially be undefined.
|
|
657
|
-
*
|
|
658
|
-
* @category Types
|
|
659
|
-
*
|
|
660
|
-
* @template InputType - The type to disallow undefined on.
|
|
661
|
-
*/
|
|
662
|
-
type DisallowUndefined<InputType> = undefined extends InputType ? ["Error: Generic type cannot include undefined"] : InputType;
|
|
663
|
-
//#endregion
|
|
664
|
-
//#region src/root/types/IgnoreCase.d.ts
|
|
665
|
-
/**
|
|
666
|
-
* Allows case-insensitive variants of a known string type.
|
|
667
|
-
*
|
|
668
|
-
* @category Types
|
|
669
|
-
*
|
|
670
|
-
* @template StringType - The input string type.
|
|
671
|
-
*/
|
|
672
|
-
type IgnoreCase<StringType extends string> = string extends StringType ? string : StringType extends `${infer FirstCharacter}${infer SecondCharacter}${infer Remainder}` ? `${Uppercase<FirstCharacter> | Lowercase<FirstCharacter>}${Uppercase<SecondCharacter> | Lowercase<SecondCharacter>}${IgnoreCase<Remainder>}` : StringType extends `${infer FirstCharacter}${infer Remainder}` ? `${Uppercase<FirstCharacter> | Lowercase<FirstCharacter>}${IgnoreCase<Remainder>}` : "";
|
|
673
|
-
//#endregion
|
|
674
|
-
//#region src/root/types/IsTypeArgumentString.d.ts
|
|
675
|
-
type IsTypeArgumentString<Argument extends string> = Argument;
|
|
676
|
-
//#endregion
|
|
677
|
-
//#region src/root/types/NonUndefined.d.ts
|
|
678
|
-
/**
|
|
679
|
-
* Resolves to `never` if the given type may be undefined.
|
|
680
|
-
*
|
|
681
|
-
* @category Types
|
|
682
|
-
*
|
|
683
|
-
* @template InputType - The type to check.
|
|
684
|
-
*/
|
|
685
|
-
type NonUndefined<InputType> = InputType extends undefined ? never : InputType;
|
|
686
|
-
//#endregion
|
|
687
|
-
//#region src/root/types/NullableOnCondition.d.ts
|
|
688
|
-
/**
|
|
689
|
-
* Resolves to the given type if the first type is `true`, otherwise resolves to `null`
|
|
690
|
-
*
|
|
691
|
-
* @category Types
|
|
692
|
-
*
|
|
693
|
-
* @param Condition - The condition to check.
|
|
694
|
-
* @param ResolvedTypeIfTrue - The type to resolve to if the condition may be `true`.
|
|
695
|
-
*/
|
|
696
|
-
type NullableOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | null;
|
|
697
|
-
//#endregion
|
|
698
|
-
//#region src/root/types/OptionalOnCondition.d.ts
|
|
699
|
-
/**
|
|
700
|
-
* Resolves to the given type if the first type is `true`, otherwise resolves to `undefined`
|
|
701
|
-
*
|
|
702
|
-
* @category Types
|
|
703
|
-
*
|
|
704
|
-
* @param Condition - The condition to check.
|
|
705
|
-
* @param ResolvedTypeIfTrue - The type to resolve to if the condition may be `true`.
|
|
706
|
-
*/
|
|
707
|
-
type OptionalOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | undefined;
|
|
708
|
-
//#endregion
|
|
709
532
|
//#region src/root/functions/parsers/parseEnv.d.ts
|
|
710
533
|
/**
|
|
711
534
|
* Represents the three common development environments.
|
|
@@ -1111,8 +934,209 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
|
|
|
1111
934
|
*/
|
|
1112
935
|
declare const normalizeIndents: typeof normaliseIndents;
|
|
1113
936
|
//#endregion
|
|
937
|
+
//#region src/root/types/VersionNumber.d.ts
|
|
938
|
+
/**
|
|
939
|
+
* Options to apply to the stringification of the version number.
|
|
940
|
+
*
|
|
941
|
+
* @category Class Options
|
|
942
|
+
*/
|
|
943
|
+
interface FormatOptionsBase {
|
|
944
|
+
/** Whether you want to omit the "v" prefix or not (defaults to false). */
|
|
945
|
+
omitPrefix?: boolean;
|
|
946
|
+
}
|
|
947
|
+
interface FormatOptionsIncludeMinor extends FormatOptionsBase {
|
|
948
|
+
/** Whether you want to omit the minor version or not */
|
|
949
|
+
omitMinor?: false;
|
|
950
|
+
/** Whether you want to omit the patch version or not */
|
|
951
|
+
omitPatch?: boolean;
|
|
952
|
+
}
|
|
953
|
+
interface FormatOptionsOmitMinor extends FormatOptionsBase {
|
|
954
|
+
/** Whether you want to omit the minor version or not */
|
|
955
|
+
omitMinor?: true;
|
|
956
|
+
/** Whether you want to omit the patch version or not */
|
|
957
|
+
omitPatch?: never;
|
|
958
|
+
}
|
|
959
|
+
type FormatStringOptions = FormatOptionsIncludeMinor | FormatOptionsOmitMinor;
|
|
960
|
+
/**
|
|
961
|
+
* Represents a software version number, considered to be made up of a major, minor, and patch part.
|
|
962
|
+
*
|
|
963
|
+
* @category Types
|
|
964
|
+
*/
|
|
965
|
+
declare class VersionNumber {
|
|
966
|
+
private static readonly NON_NEGATIVE_TUPLE_ERROR;
|
|
967
|
+
/** The major number. Increments when a feature is removed or changed in a way that is not backwards-compatible with the previous release. */
|
|
968
|
+
readonly major: number;
|
|
969
|
+
/** The minor number. Increments when a new feature is added/deprecated and is expected to be backwards-compatible with the previous release. */
|
|
970
|
+
readonly minor: number;
|
|
971
|
+
/** The patch number. Increments when the next release is fixing a bug or doing a small refactor that should not be noticeable in practice. */
|
|
972
|
+
readonly patch: number;
|
|
973
|
+
/**
|
|
974
|
+
* @param input - The input to create a new instance of `VersionNumber` from.
|
|
975
|
+
*/
|
|
976
|
+
constructor(input: string | [number, number, number] | VersionNumber);
|
|
977
|
+
/**
|
|
978
|
+
* Gets the current version type of the current instance of `VersionNumber`.
|
|
979
|
+
*
|
|
980
|
+
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
981
|
+
*/
|
|
982
|
+
get type(): VersionType;
|
|
983
|
+
private static formatString;
|
|
984
|
+
/**
|
|
985
|
+
* Checks if the provided version numbers have the exact same major, minor, and patch numbers.
|
|
986
|
+
*
|
|
987
|
+
* @param firstVersion - The first version number to compare.
|
|
988
|
+
* @param secondVersion - The second version number to compare.
|
|
989
|
+
*
|
|
990
|
+
* @returns `true` if the provided version numbers have exactly the same major, minor, and patch numbers, and returns `false` otherwise.
|
|
991
|
+
*/
|
|
992
|
+
static isEqual(firstVersion: VersionNumber, secondVersion: VersionNumber): boolean;
|
|
993
|
+
/**
|
|
994
|
+
* Get a formatted string representation of the current version number
|
|
995
|
+
*
|
|
996
|
+
* @param options - Options to apply to the string formatting.
|
|
997
|
+
*
|
|
998
|
+
* @returns A formatted string representation of the current version number with the options applied.
|
|
999
|
+
*/
|
|
1000
|
+
format(options?: FormatStringOptions): string;
|
|
1001
|
+
/**
|
|
1002
|
+
* Increments the current version number by the given increment type, returning the result as a new reference in memory.
|
|
1003
|
+
*
|
|
1004
|
+
* @param incrementType - The type of increment. Can be one of the following:
|
|
1005
|
+
* - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
|
|
1006
|
+
* - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
|
|
1007
|
+
* - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
|
|
1008
|
+
* @param incrementAmount - The amount to increment by (defaults to 1).
|
|
1009
|
+
*
|
|
1010
|
+
* @returns A new instance of `VersionNumber` with the increment applied.
|
|
1011
|
+
*/
|
|
1012
|
+
increment(incrementType: VersionType, incrementAmount?: number): VersionNumber;
|
|
1013
|
+
/**
|
|
1014
|
+
* Ensures that the VersionNumber behaves correctly when attempted to be coerced to a string.
|
|
1015
|
+
*
|
|
1016
|
+
* @param hint - Not used as of now, but generally used to help with numeric coercion, I think (which we most likely do not need for version numbers).
|
|
1017
|
+
*
|
|
1018
|
+
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
1019
|
+
*/
|
|
1020
|
+
[Symbol.toPrimitive](hint: "default" | "string" | "number"): string;
|
|
1021
|
+
/**
|
|
1022
|
+
* Ensures that the VersionNumber behaves correctly when attempted to be converted to JSON.
|
|
1023
|
+
*
|
|
1024
|
+
* @returns A stringified representation of the current version number, prefixed with `v`.
|
|
1025
|
+
*/
|
|
1026
|
+
toJSON(): string;
|
|
1027
|
+
/**
|
|
1028
|
+
* Get a string representation of the current version number.
|
|
1029
|
+
*
|
|
1030
|
+
* @returns A stringified representation of the current version number with the prefix.
|
|
1031
|
+
*/
|
|
1032
|
+
toString(): string;
|
|
1033
|
+
}
|
|
1034
|
+
declare const zodVersionNumber: z$1.ZodType<VersionNumber>;
|
|
1035
|
+
//#endregion
|
|
1036
|
+
//#region src/root/types/ArrayElement.d.ts
|
|
1037
|
+
/**
|
|
1038
|
+
* Gets the individual element types from an array type.
|
|
1039
|
+
*
|
|
1040
|
+
* @category Types
|
|
1041
|
+
*
|
|
1042
|
+
* @template ArrayType - The type of the array itself.
|
|
1043
|
+
*/
|
|
1044
|
+
type ArrayElement<ArrayType extends ReadonlyArray<unknown>> = ArrayType extends ReadonlyArray<infer ElementType> ? ElementType : never;
|
|
1045
|
+
//#endregion
|
|
1046
|
+
//#region src/root/types/CallReturnType.d.ts
|
|
1047
|
+
type CallReturnType<Function, Arguments> = Function extends ((arg: Arguments) => infer Return) ? Return : never;
|
|
1048
|
+
//#endregion
|
|
1049
|
+
//#region src/root/types/CreateEnumType.d.ts
|
|
1050
|
+
/**
|
|
1051
|
+
* Get the value types from a const object so the object can behave similarly to an enum.
|
|
1052
|
+
*
|
|
1053
|
+
* @category Types
|
|
1054
|
+
*
|
|
1055
|
+
* @template ObjectType - The type of the object to get the value types for.
|
|
1056
|
+
*/
|
|
1057
|
+
type CreateEnumType<ObjectType extends Record<PropertyKey, unknown>> = ObjectType[keyof ObjectType];
|
|
1058
|
+
//#endregion
|
|
1059
|
+
//#region src/root/types/DisallowUndefined.d.ts
|
|
1060
|
+
/**
|
|
1061
|
+
* Resolves to an error message type if the type argument could potentially be undefined.
|
|
1062
|
+
*
|
|
1063
|
+
* @category Types
|
|
1064
|
+
*
|
|
1065
|
+
* @template InputType - The type to disallow undefined on.
|
|
1066
|
+
*/
|
|
1067
|
+
type DisallowUndefined<InputType> = undefined extends InputType ? ["Error: Generic type cannot include undefined"] : InputType;
|
|
1068
|
+
//#endregion
|
|
1069
|
+
//#region src/root/types/IgnoreCase.d.ts
|
|
1070
|
+
/**
|
|
1071
|
+
* Allows case-insensitive variants of a known string type.
|
|
1072
|
+
*
|
|
1073
|
+
* @category Types
|
|
1074
|
+
*
|
|
1075
|
+
* @template StringType - The input string type.
|
|
1076
|
+
*/
|
|
1077
|
+
type IgnoreCase<StringType extends string> = string extends StringType ? string : StringType extends `${infer FirstCharacter}${infer SecondCharacter}${infer Remainder}` ? `${Uppercase<FirstCharacter> | Lowercase<FirstCharacter>}${Uppercase<SecondCharacter> | Lowercase<SecondCharacter>}${IgnoreCase<Remainder>}` : StringType extends `${infer FirstCharacter}${infer Remainder}` ? `${Uppercase<FirstCharacter> | Lowercase<FirstCharacter>}${IgnoreCase<Remainder>}` : "";
|
|
1078
|
+
//#endregion
|
|
1079
|
+
//#region src/root/types/IsTypeArgumentString.d.ts
|
|
1080
|
+
type IsTypeArgumentString<Argument extends string> = Argument;
|
|
1081
|
+
//#endregion
|
|
1082
|
+
//#region src/root/types/NonNull.d.ts
|
|
1083
|
+
/**
|
|
1084
|
+
* Removes `null` from a type.
|
|
1085
|
+
*
|
|
1086
|
+
* @category Types
|
|
1087
|
+
*
|
|
1088
|
+
* @template InputType - The type to check.
|
|
1089
|
+
*/
|
|
1090
|
+
type NonNull<InputType> = InputType extends null ? never : InputType;
|
|
1091
|
+
//#endregion
|
|
1092
|
+
//#region src/root/types/NonUndefined.d.ts
|
|
1093
|
+
/**
|
|
1094
|
+
* Removes `undefined` from a type.
|
|
1095
|
+
*
|
|
1096
|
+
* @category Types
|
|
1097
|
+
*
|
|
1098
|
+
* @template InputType - The type to check.
|
|
1099
|
+
*/
|
|
1100
|
+
type NonUndefined<InputType> = InputType extends undefined ? never : InputType;
|
|
1101
|
+
//#endregion
|
|
1102
|
+
//#region src/root/types/NullableOnCondition.d.ts
|
|
1103
|
+
/**
|
|
1104
|
+
* Resolves to the given type if the first type is `true`, otherwise resolves to `null`
|
|
1105
|
+
*
|
|
1106
|
+
* @category Types
|
|
1107
|
+
*
|
|
1108
|
+
* @param Condition - The condition to check.
|
|
1109
|
+
* @param ResolvedTypeIfTrue - The type to resolve to if the condition may be `true`.
|
|
1110
|
+
*/
|
|
1111
|
+
type NullableOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | null;
|
|
1112
|
+
//#endregion
|
|
1113
|
+
//#region src/root/types/OptionalOnCondition.d.ts
|
|
1114
|
+
/**
|
|
1115
|
+
* Resolves to the given type if the first type is `true`, otherwise resolves to `undefined`
|
|
1116
|
+
*
|
|
1117
|
+
* @category Types
|
|
1118
|
+
*
|
|
1119
|
+
* @param Condition - The condition to check.
|
|
1120
|
+
* @param ResolvedTypeIfTrue - The type to resolve to if the condition may be `true`.
|
|
1121
|
+
*/
|
|
1122
|
+
type OptionalOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | undefined;
|
|
1123
|
+
//#endregion
|
|
1124
|
+
//#region src/root/errors/assertNotNull.d.ts
|
|
1125
|
+
/**
|
|
1126
|
+
* Asserts that a given input is not `null`, and throws a DataError if it does.
|
|
1127
|
+
*
|
|
1128
|
+
* If no error is thrown from this, the input type gets narrowed down to not include `null`.
|
|
1129
|
+
*
|
|
1130
|
+
* @template InputType The type of the input.
|
|
1131
|
+
*
|
|
1132
|
+
* @param input - The input to assert against
|
|
1133
|
+
*
|
|
1134
|
+
* @throws {DataError} If the input is `null`.
|
|
1135
|
+
*/
|
|
1136
|
+
declare function assertNotNull<InputType>(input: InputType): asserts input is NonNull<InputType>;
|
|
1137
|
+
//#endregion
|
|
1114
1138
|
//#region src/v6/CodeError.d.ts
|
|
1115
|
-
interface ExpectErrorOptions
|
|
1139
|
+
interface ExpectErrorOptions<ErrorCode extends string = string> {
|
|
1116
1140
|
expectedCode?: ErrorCode;
|
|
1117
1141
|
}
|
|
1118
1142
|
/**
|
|
@@ -1137,8 +1161,21 @@ declare class CodeError<ErrorCode extends string = string> extends Error {
|
|
|
1137
1161
|
*
|
|
1138
1162
|
* @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`.
|
|
1139
1163
|
*/
|
|
1140
|
-
static check(input: unknown): input is CodeError<
|
|
1141
|
-
protected static checkCaughtError<ErrorCode extends string = string>(this: typeof CodeError, error: unknown, options?: ExpectErrorOptions
|
|
1164
|
+
static check<ErrorCode extends string = string>(input: unknown): input is CodeError<ErrorCode>;
|
|
1165
|
+
protected static checkCaughtError<ErrorCode extends string = string>(this: typeof CodeError, error: unknown, options?: ExpectErrorOptions<ErrorCode>): CodeError<ErrorCode>;
|
|
1166
|
+
/**
|
|
1167
|
+
* Check a `CodeError` against its error code
|
|
1168
|
+
*
|
|
1169
|
+
* This will also automatically narrow down the type of the input to be `CodeError`, with its error code properly typed if this function returns true.
|
|
1170
|
+
*
|
|
1171
|
+
* @template ErrorCode The type of the error code
|
|
1172
|
+
*
|
|
1173
|
+
* @param input - The input to check.
|
|
1174
|
+
* @param code - The expected code of the resulting error.
|
|
1175
|
+
*
|
|
1176
|
+
* @returns `true` if the error code matches the expected code, and `false` otherwise. The type of the input will also be narrowed down to CodeError, and its code will be narrowed to the expected code's type if the function returns `true`.
|
|
1177
|
+
*/
|
|
1178
|
+
static checkWithCode<ErrorCode extends string = string>(input: unknown, code: ErrorCode): input is CodeError<ErrorCode>;
|
|
1142
1179
|
/**
|
|
1143
1180
|
* 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.
|
|
1144
1181
|
*
|
|
@@ -1150,7 +1187,7 @@ declare class CodeError<ErrorCode extends string = string> extends Error {
|
|
|
1150
1187
|
*
|
|
1151
1188
|
* @returns The `CodeError` that was thrown by the `errorFunction`
|
|
1152
1189
|
*/
|
|
1153
|
-
static expectError<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => unknown, options?: ExpectErrorOptions
|
|
1190
|
+
static expectError<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => unknown, options?: ExpectErrorOptions<ErrorCode>): CodeError<ErrorCode>;
|
|
1154
1191
|
/**
|
|
1155
1192
|
* 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.
|
|
1156
1193
|
*
|
|
@@ -1162,18 +1199,10 @@ declare class CodeError<ErrorCode extends string = string> extends Error {
|
|
|
1162
1199
|
*
|
|
1163
1200
|
* @returns The `CodeError` that was thrown by the `errorFunction`
|
|
1164
1201
|
*/
|
|
1165
|
-
static expectErrorAsync<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions
|
|
1202
|
+
static expectErrorAsync<ErrorCode extends string = string>(this: typeof CodeError, errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<CodeError>;
|
|
1166
1203
|
}
|
|
1167
1204
|
//#endregion
|
|
1168
1205
|
//#region src/v6/DataError.d.ts
|
|
1169
|
-
type DefaultDataErrorCode = "INVALID_DATA";
|
|
1170
|
-
interface ExpectErrorOptions<ErrorCode extends string = DefaultDataErrorCode> {
|
|
1171
|
-
expectedCode?: ErrorCode | DefaultDataErrorCode;
|
|
1172
|
-
}
|
|
1173
|
-
declare const DataErrorCode: {
|
|
1174
|
-
readonly INVALID_DATA: "INVALID_DATA";
|
|
1175
|
-
};
|
|
1176
|
-
type DataErrorCode = CreateEnumType<typeof DataErrorCode>;
|
|
1177
1206
|
/**
|
|
1178
1207
|
* Represents errors you may get that may've been caused by a specific piece of data.
|
|
1179
1208
|
*
|
|
@@ -1181,7 +1210,7 @@ type DataErrorCode = CreateEnumType<typeof DataErrorCode>;
|
|
|
1181
1210
|
*
|
|
1182
1211
|
* @template DataType - The type of the data that caused the error.
|
|
1183
1212
|
*/
|
|
1184
|
-
declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string =
|
|
1213
|
+
declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = string> extends CodeError<ErrorCode> {
|
|
1185
1214
|
data: DataType;
|
|
1186
1215
|
/**
|
|
1187
1216
|
* @param data - The data that caused the error.
|
|
@@ -1189,7 +1218,7 @@ declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>
|
|
|
1189
1218
|
* @param message - A human-readable error message (e.g. The data provided is invalid).
|
|
1190
1219
|
* @param options - Extra options to pass to super Error constructor.
|
|
1191
1220
|
*/
|
|
1192
|
-
constructor(data: DataType, code
|
|
1221
|
+
constructor(data: DataType, code: ErrorCode, message?: string, options?: ErrorOptions);
|
|
1193
1222
|
/**
|
|
1194
1223
|
* Checks whether the given input may have been caused by a DataError.
|
|
1195
1224
|
*
|
|
@@ -1197,7 +1226,20 @@ declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>
|
|
|
1197
1226
|
*
|
|
1198
1227
|
* @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`.
|
|
1199
1228
|
*/
|
|
1200
|
-
static check<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string =
|
|
1229
|
+
static check<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = string>(input: unknown): input is DataError$1<DataType, ErrorCode>;
|
|
1230
|
+
/**
|
|
1231
|
+
* Check a `DataError` against its error code
|
|
1232
|
+
*
|
|
1233
|
+
* This will also automatically narrow down the type of the input to be `DataError`, with its error code properly typed if this function returns true.
|
|
1234
|
+
*
|
|
1235
|
+
* @template ErrorCode The type of the error code
|
|
1236
|
+
*
|
|
1237
|
+
* @param input - The input to check.
|
|
1238
|
+
* @param code - The expected code of the resulting error.
|
|
1239
|
+
*
|
|
1240
|
+
* @returns `true` if the error code matches the expected code, and `false` otherwise. The type of the input will also be narrowed down to `DataError`, and its code will be narrowed to the expected code's type if the function returns `true`.
|
|
1241
|
+
*/
|
|
1242
|
+
static checkWithCode<DataType extends object = Record<PropertyKey, unknown>, ErrorCode extends string = string>(input: unknown, code: ErrorCode): input is DataError$1<DataType, ErrorCode>;
|
|
1201
1243
|
/**
|
|
1202
1244
|
* 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.
|
|
1203
1245
|
*
|
|
@@ -1209,7 +1251,7 @@ declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>
|
|
|
1209
1251
|
*
|
|
1210
1252
|
* @returns The `DataError` that was thrown by the `errorFunction`
|
|
1211
1253
|
*/
|
|
1212
|
-
static expectError<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string =
|
|
1254
|
+
static expectError<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = string>(errorFunction: () => unknown, options?: ExpectErrorOptions<ErrorCode>): DataError$1<DataType, ErrorCode>;
|
|
1213
1255
|
/**
|
|
1214
1256
|
* 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.
|
|
1215
1257
|
*
|
|
@@ -1221,7 +1263,7 @@ declare class DataError$1<DataType extends object = Record<PropertyKey, unknown>
|
|
|
1221
1263
|
*
|
|
1222
1264
|
* @returns The `DataError` that was thrown by the `errorFunction`
|
|
1223
1265
|
*/
|
|
1224
|
-
static expectErrorAsync<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string =
|
|
1266
|
+
static expectErrorAsync<DataType extends Record<PropertyKey, unknown>, ErrorCode extends string = string>(errorFunction: () => Promise<unknown>, options?: ExpectErrorOptions<ErrorCode>): Promise<DataError$1<DataType, ErrorCode>>;
|
|
1225
1267
|
}
|
|
1226
1268
|
//#endregion
|
|
1227
1269
|
//#region src/root/zod/parseZodSchema.d.ts
|
|
@@ -1278,9 +1320,9 @@ declare const az: {
|
|
|
1278
1320
|
versionNumber: () => ZodType<VersionNumber, unknown>;
|
|
1279
1321
|
fieldDate: () => ZodCoercedDate<string | null>;
|
|
1280
1322
|
with: <SchemaType extends ZodType>(schema: SchemaType) => {
|
|
1281
|
-
parse: <ErrorType extends Error = DataError$1<Record<PropertyKey, unknown>,
|
|
1282
|
-
parseAsync: <ErrorType extends Error = DataError$1<Record<PropertyKey, unknown>,
|
|
1323
|
+
parse: <ErrorType extends Error = DataError$1<Record<PropertyKey, unknown>, string>>(input: unknown, error?: ErrorType | ((zodError: z$1.ZodError<unknown>) => void | ErrorType)) => ReturnType<typeof parseZodSchema<SchemaType, ErrorType>>;
|
|
1324
|
+
parseAsync: <ErrorType extends Error = DataError$1<Record<PropertyKey, unknown>, string>>(input: unknown, error?: ErrorType | ((zodError: z$1.ZodError<unknown>) => void | ErrorType)) => ReturnType<typeof parseZodSchemaAsync<SchemaType, ErrorType>>;
|
|
1283
1325
|
};
|
|
1284
1326
|
};
|
|
1285
1327
|
//#endregion
|
|
1286
|
-
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, az, 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 };
|
|
1328
|
+
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 NonNull, 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, assertNotNull, az, 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 };
|