@alextheman/utility 5.15.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 +17 -0
- package/dist/index.d.cts +229 -215
- package/dist/index.d.ts +228 -214
- package/dist/index.js +17 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1830,6 +1830,22 @@ var DataError = class DataError extends Error {
|
|
|
1830
1830
|
}
|
|
1831
1831
|
};
|
|
1832
1832
|
//#endregion
|
|
1833
|
+
//#region src/root/errors/assertNotNull.ts
|
|
1834
|
+
/**
|
|
1835
|
+
* Asserts that a given input is not `null`, and throws a DataError if it does.
|
|
1836
|
+
*
|
|
1837
|
+
* If no error is thrown from this, the input type gets narrowed down to not include `null`.
|
|
1838
|
+
*
|
|
1839
|
+
* @template InputType The type of the input.
|
|
1840
|
+
*
|
|
1841
|
+
* @param input - The input to assert against
|
|
1842
|
+
*
|
|
1843
|
+
* @throws {DataError} If the input is `null`.
|
|
1844
|
+
*/
|
|
1845
|
+
function assertNotNull(input) {
|
|
1846
|
+
if (input === null) throw new DataError$1({ input }, "NULL_INPUT", "Expected the input not to be null");
|
|
1847
|
+
}
|
|
1848
|
+
//#endregion
|
|
1833
1849
|
exports.APIError = APIError;
|
|
1834
1850
|
exports.DataError = DataError;
|
|
1835
1851
|
exports.Env = Env;
|
|
@@ -1844,6 +1860,7 @@ exports.VersionNumber = VersionNumber;
|
|
|
1844
1860
|
exports.VersionType = VersionType;
|
|
1845
1861
|
exports.addDaysToDate = addDaysToDate;
|
|
1846
1862
|
exports.appendSemicolon = appendSemicolon;
|
|
1863
|
+
exports.assertNotNull = assertNotNull;
|
|
1847
1864
|
exports.az = az;
|
|
1848
1865
|
exports.calculateMonthlyDifference = calculateMonthlyDifference;
|
|
1849
1866
|
exports.camelToKebab = camelToKebab;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DotenvParseOutput } from "dotenv";
|
|
2
1
|
import z, { ZodCoercedDate, ZodCoercedNumber, ZodError, ZodType, z as z$1 } from "zod";
|
|
2
|
+
import { DotenvParseOutput } from "dotenv";
|
|
3
3
|
|
|
4
4
|
//#region src/root/constants/FILE_PATH_REGEX.d.ts
|
|
5
5
|
declare const FILE_PATH_PATTERN: string;
|
|
@@ -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,219 +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.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/NonNull.d.ts
|
|
678
|
-
/**
|
|
679
|
-
* Removes `null` from a type.
|
|
680
|
-
*
|
|
681
|
-
* @category Types
|
|
682
|
-
*
|
|
683
|
-
* @template InputType - The type to check.
|
|
684
|
-
*/
|
|
685
|
-
type NonNull<InputType> = InputType extends null ? never : InputType;
|
|
686
|
-
//#endregion
|
|
687
|
-
//#region src/root/types/NonUndefined.d.ts
|
|
688
|
-
/**
|
|
689
|
-
* Removes `undefined` from a type.
|
|
690
|
-
*
|
|
691
|
-
* @category Types
|
|
692
|
-
*
|
|
693
|
-
* @template InputType - The type to check.
|
|
694
|
-
*/
|
|
695
|
-
type NonUndefined<InputType> = InputType extends undefined ? never : InputType;
|
|
696
|
-
//#endregion
|
|
697
|
-
//#region src/root/types/NullableOnCondition.d.ts
|
|
698
|
-
/**
|
|
699
|
-
* Resolves to the given type if the first type is `true`, otherwise resolves to `null`
|
|
700
|
-
*
|
|
701
|
-
* @category Types
|
|
702
|
-
*
|
|
703
|
-
* @param Condition - The condition to check.
|
|
704
|
-
* @param ResolvedTypeIfTrue - The type to resolve to if the condition may be `true`.
|
|
705
|
-
*/
|
|
706
|
-
type NullableOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | null;
|
|
707
|
-
//#endregion
|
|
708
|
-
//#region src/root/types/OptionalOnCondition.d.ts
|
|
709
|
-
/**
|
|
710
|
-
* Resolves to the given type if the first type is `true`, otherwise resolves to `undefined`
|
|
711
|
-
*
|
|
712
|
-
* @category Types
|
|
713
|
-
*
|
|
714
|
-
* @param Condition - The condition to check.
|
|
715
|
-
* @param ResolvedTypeIfTrue - The type to resolve to if the condition may be `true`.
|
|
716
|
-
*/
|
|
717
|
-
type OptionalOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | undefined;
|
|
718
|
-
//#endregion
|
|
719
532
|
//#region src/root/functions/parsers/parseEnv.d.ts
|
|
720
533
|
/**
|
|
721
534
|
* Represents the three common development environments.
|
|
@@ -1121,6 +934,207 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
|
|
|
1121
934
|
*/
|
|
1122
935
|
declare const normalizeIndents: typeof normaliseIndents;
|
|
1123
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.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
|
|
1124
1138
|
//#region src/v6/CodeError.d.ts
|
|
1125
1139
|
interface ExpectErrorOptions<ErrorCode extends string = string> {
|
|
1126
1140
|
expectedCode?: ErrorCode;
|
|
@@ -1311,4 +1325,4 @@ declare const az: {
|
|
|
1311
1325
|
};
|
|
1312
1326
|
};
|
|
1313
1327
|
//#endregion
|
|
1314
|
-
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, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -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,219 +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/NonNull.d.ts
|
|
678
|
-
/**
|
|
679
|
-
* Removes `null` from a type.
|
|
680
|
-
*
|
|
681
|
-
* @category Types
|
|
682
|
-
*
|
|
683
|
-
* @template InputType - The type to check.
|
|
684
|
-
*/
|
|
685
|
-
type NonNull<InputType> = InputType extends null ? never : InputType;
|
|
686
|
-
//#endregion
|
|
687
|
-
//#region src/root/types/NonUndefined.d.ts
|
|
688
|
-
/**
|
|
689
|
-
* Removes `undefined` from a type.
|
|
690
|
-
*
|
|
691
|
-
* @category Types
|
|
692
|
-
*
|
|
693
|
-
* @template InputType - The type to check.
|
|
694
|
-
*/
|
|
695
|
-
type NonUndefined<InputType> = InputType extends undefined ? never : InputType;
|
|
696
|
-
//#endregion
|
|
697
|
-
//#region src/root/types/NullableOnCondition.d.ts
|
|
698
|
-
/**
|
|
699
|
-
* Resolves to the given type if the first type is `true`, otherwise resolves to `null`
|
|
700
|
-
*
|
|
701
|
-
* @category Types
|
|
702
|
-
*
|
|
703
|
-
* @param Condition - The condition to check.
|
|
704
|
-
* @param ResolvedTypeIfTrue - The type to resolve to if the condition may be `true`.
|
|
705
|
-
*/
|
|
706
|
-
type NullableOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | null;
|
|
707
|
-
//#endregion
|
|
708
|
-
//#region src/root/types/OptionalOnCondition.d.ts
|
|
709
|
-
/**
|
|
710
|
-
* Resolves to the given type if the first type is `true`, otherwise resolves to `undefined`
|
|
711
|
-
*
|
|
712
|
-
* @category Types
|
|
713
|
-
*
|
|
714
|
-
* @param Condition - The condition to check.
|
|
715
|
-
* @param ResolvedTypeIfTrue - The type to resolve to if the condition may be `true`.
|
|
716
|
-
*/
|
|
717
|
-
type OptionalOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | undefined;
|
|
718
|
-
//#endregion
|
|
719
532
|
//#region src/root/functions/parsers/parseEnv.d.ts
|
|
720
533
|
/**
|
|
721
534
|
* Represents the three common development environments.
|
|
@@ -1121,6 +934,207 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
|
|
|
1121
934
|
*/
|
|
1122
935
|
declare const normalizeIndents: typeof normaliseIndents;
|
|
1123
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
|
|
1124
1138
|
//#region src/v6/CodeError.d.ts
|
|
1125
1139
|
interface ExpectErrorOptions<ErrorCode extends string = string> {
|
|
1126
1140
|
expectedCode?: ErrorCode;
|
|
@@ -1311,4 +1325,4 @@ declare const az: {
|
|
|
1311
1325
|
};
|
|
1312
1326
|
};
|
|
1313
1327
|
//#endregion
|
|
1314
|
-
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, 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 };
|
package/dist/index.js
CHANGED
|
@@ -1806,4 +1806,20 @@ var DataError = class DataError extends Error {
|
|
|
1806
1806
|
}
|
|
1807
1807
|
};
|
|
1808
1808
|
//#endregion
|
|
1809
|
-
|
|
1809
|
+
//#region src/root/errors/assertNotNull.ts
|
|
1810
|
+
/**
|
|
1811
|
+
* Asserts that a given input is not `null`, and throws a DataError if it does.
|
|
1812
|
+
*
|
|
1813
|
+
* If no error is thrown from this, the input type gets narrowed down to not include `null`.
|
|
1814
|
+
*
|
|
1815
|
+
* @template InputType The type of the input.
|
|
1816
|
+
*
|
|
1817
|
+
* @param input - The input to assert against
|
|
1818
|
+
*
|
|
1819
|
+
* @throws {DataError} If the input is `null`.
|
|
1820
|
+
*/
|
|
1821
|
+
function assertNotNull(input) {
|
|
1822
|
+
if (input === null) throw new DataError$1({ input }, "NULL_INPUT", "Expected the input not to be null");
|
|
1823
|
+
}
|
|
1824
|
+
//#endregion
|
|
1825
|
+
export { APIError, DataError, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, ONE_DAY_IN_MILLISECONDS, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, 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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "5.15.
|
|
3
|
+
"version": "5.15.1",
|
|
4
4
|
"description": "Helpful utility functions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"jsdom": "29.0.2",
|
|
53
53
|
"prettier": "3.8.3",
|
|
54
54
|
"tempy": "3.2.0",
|
|
55
|
-
"tsdown": "0.21.
|
|
55
|
+
"tsdown": "0.21.9",
|
|
56
56
|
"tsx": "4.21.0",
|
|
57
57
|
"typedoc": "0.28.19",
|
|
58
58
|
"typedoc-plugin-markdown": "4.11.0",
|