@alextheman/utility 4.8.0 → 4.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -830,6 +830,22 @@ function omitProperties(object, keysToOmit) {
830
830
  }
831
831
  var omitProperties_default = omitProperties;
832
832
 
833
+ //#endregion
834
+ //#region src/functions/objectHelpers/removeUndefinedFromObject.ts
835
+ /**
836
+ * Removes entries whose values are `undefined` from a given object (not including null etc.).
837
+ *
838
+ * @param object - The object to remove undefined entries from.
839
+ *
840
+ * @returns An object with a new reference in memory, with undefined entries removed.
841
+ */
842
+ function removeUndefinedFromObject(object) {
843
+ return Object.fromEntries(Object.entries(object).filter(([_, value]) => {
844
+ return value !== void 0;
845
+ }));
846
+ }
847
+ var removeUndefinedFromObject_default = removeUndefinedFromObject;
848
+
833
849
  //#endregion
834
850
  //#region src/functions/parsers/parseBoolean.ts
835
851
  /**
@@ -851,25 +867,8 @@ function parseBoolean(inputString) {
851
867
  var parseBoolean_default = parseBoolean;
852
868
 
853
869
  //#endregion
854
- //#region src/functions/parsers/parseZodSchema.ts
855
- /**
856
- * An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
857
- *
858
- * @category Parsers
859
- *
860
- * @template SchemaType - The Zod schema type.
861
- * @template ErrorType - The type of error to throw on invalid data.
862
- *
863
- * @param schema - The Zod schema to use in parsing.
864
- * @param data - The data to parse.
865
- * @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
866
- *
867
- * @throws {DataError} If the given data cannot be parsed according to the schema.
868
- *
869
- * @returns The parsed data from the Zod schema.
870
- */
871
- function parseZodSchema(schema, data, onError) {
872
- const parsedResult = schema.safeParse(data);
870
+ //#region src/functions/parsers/zod/_parseZodSchema.ts
871
+ function _parseZodSchema(parsedResult, data, onError) {
873
872
  if (!parsedResult.success) {
874
873
  if (onError) {
875
874
  if (onError instanceof Error) throw onError;
@@ -887,10 +886,35 @@ function parseZodSchema(schema, data, onError) {
887
886
  return secondCount - firstCount;
888
887
  }).map(([code, count], _, allErrorCodes$1) => {
889
888
  return allErrorCodes$1.length === 1 && count === 1 ? code : `${code}×${count}`;
890
- }).join(","), `\n\n${zod.z.prettifyError(parsedResult.error)}\n`);
889
+ }).join(","), `\n\n${zod.default.prettifyError(parsedResult.error)}\n`);
891
890
  }
892
891
  return parsedResult.data;
893
892
  }
893
+ var _parseZodSchema_default = _parseZodSchema;
894
+
895
+ //#endregion
896
+ //#region src/functions/parsers/zod/parseZodSchema.ts
897
+ /**
898
+ * An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
899
+ *
900
+ * NOTE: Use `parseZodSchemaAsync` if your schema includes an asynchronous function.
901
+ *
902
+ * @category Parsers
903
+ *
904
+ * @template SchemaType - The Zod schema type.
905
+ * @template ErrorType - The type of error to throw on invalid data.
906
+ *
907
+ * @param schema - The Zod schema to use in parsing.
908
+ * @param data - The data to parse.
909
+ * @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
910
+ *
911
+ * @throws {DataError} If the given data cannot be parsed according to the schema.
912
+ *
913
+ * @returns The parsed data from the Zod schema.
914
+ */
915
+ function parseZodSchema(schema, data, onError) {
916
+ return _parseZodSchema_default(schema.safeParse(data), data, onError);
917
+ }
894
918
  var parseZodSchema_default = parseZodSchema;
895
919
 
896
920
  //#endregion
@@ -973,6 +997,29 @@ function parseVersionType(data) {
973
997
  }
974
998
  var parseVersionType_default = parseVersionType;
975
999
 
1000
+ //#endregion
1001
+ //#region src/functions/parsers/zod/parseZodSchemaAsync.ts
1002
+ /**
1003
+ * An alternative function to zodSchema.parseAsync() that can be used to strictly parse asynchronous Zod schemas.
1004
+ *
1005
+ * @category Parsers
1006
+ *
1007
+ * @template SchemaType - The Zod schema type.
1008
+ * @template ErrorType - The type of error to throw on invalid data.
1009
+ *
1010
+ * @param schema - The Zod schema to use in parsing.
1011
+ * @param data - The data to parse.
1012
+ * @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
1013
+ *
1014
+ * @throws {DataError} If the given data cannot be parsed according to the schema.
1015
+ *
1016
+ * @returns The parsed data from the Zod schema.
1017
+ */
1018
+ async function parseZodSchemaAsync(schema, data, onError) {
1019
+ return _parseZodSchema_default(await schema.safeParseAsync(data), data, onError);
1020
+ }
1021
+ var parseZodSchemaAsync_default = parseZodSchemaAsync;
1022
+
976
1023
  //#endregion
977
1024
  //#region src/functions/recursive/deepCopy.ts
978
1025
  function callDeepCopy(input) {
@@ -1527,9 +1574,11 @@ exports.parseIntStrict = parseIntStrict_default;
1527
1574
  exports.parseVersion = parseVersion_default;
1528
1575
  exports.parseVersionType = parseVersionType_default;
1529
1576
  exports.parseZodSchema = parseZodSchema_default;
1577
+ exports.parseZodSchemaAsync = parseZodSchemaAsync_default;
1530
1578
  exports.randomiseArray = randomiseArray_default;
1531
1579
  exports.range = range_default;
1532
1580
  exports.removeDuplicates = removeDuplicates_default;
1581
+ exports.removeUndefinedFromObject = removeUndefinedFromObject_default;
1533
1582
  exports.stringListToArray = stringListToArray_default;
1534
1583
  exports.stringifyDotenv = stringifyDotenv_default;
1535
1584
  exports.truncate = truncate_default;
package/dist/index.d.cts CHANGED
@@ -410,9 +410,9 @@ type FormDataArrayResolutionStrategy = "stringify" | "multiple";
410
410
  *
411
411
  * @template Key - The type of the key of the input record.
412
412
  */
413
- interface CreateFormDataOptionsBase<Key extends RecordKey> {
413
+ interface CreateFormDataOptionsBase<Key$1 extends RecordKey> {
414
414
  /** How to resolve any arrays provided in the data (can either stringify them or add them multiple times). */
415
- arrayResolution?: FormDataArrayResolutionStrategy | Partial<Record<Key, FormDataArrayResolutionStrategy>>;
415
+ arrayResolution?: FormDataArrayResolutionStrategy | Partial<Record<Key$1, FormDataArrayResolutionStrategy>>;
416
416
  }
417
417
  /**
418
418
  * Options for resolving form data when it may be undefined or null, but not both.
@@ -421,11 +421,11 @@ interface CreateFormDataOptionsBase<Key extends RecordKey> {
421
421
  *
422
422
  * @template Key - The type of the key of the input record.
423
423
  */
424
- interface CreateFormDataOptionsUndefinedOrNullResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
424
+ interface CreateFormDataOptionsUndefinedOrNullResolution<Key$1 extends RecordKey> extends CreateFormDataOptionsBase<Key$1> {
425
425
  /** How to resolve undefined data (May either stringify to 'undefined', resolve to an empty string, or omit entirely). */
426
- undefinedResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
426
+ undefinedResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key$1, FormDataNullableResolutionStrategy>>;
427
427
  /** How to resolve null data (May either stringify to 'null', resolve to an empty string, or omit entirely). */
428
- nullResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
428
+ nullResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key$1, FormDataNullableResolutionStrategy>>;
429
429
  /** @note This must not be provided at the same time as undefinedResolution and/or nullResolution. */
430
430
  nullableResolution?: never;
431
431
  }
@@ -436,13 +436,13 @@ interface CreateFormDataOptionsUndefinedOrNullResolution<Key extends RecordKey>
436
436
  *
437
437
  * @template Key - The type of the key of the input record.
438
438
  */
439
- interface CreateFormDataOptionsNullableResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
439
+ interface CreateFormDataOptionsNullableResolution<Key$1 extends RecordKey> extends CreateFormDataOptionsBase<Key$1> {
440
440
  /** @note This must not be provided at the same time as nullableResolution. */
441
441
  undefinedResolution?: never;
442
442
  /** @note This must not be provided at the same time as nullableResolution. */
443
443
  nullResolution?: never;
444
444
  /** How to resolve nullable data (May either stringify to 'undefined | null', resolve to an empty string, or omit entirely). */
445
- nullableResolution: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
445
+ nullableResolution: FormDataNullableResolutionStrategy | Partial<Record<Key$1, FormDataNullableResolutionStrategy>>;
446
446
  }
447
447
  /**
448
448
  * Options for resolving form data.
@@ -451,7 +451,7 @@ interface CreateFormDataOptionsNullableResolution<Key extends RecordKey> extends
451
451
  *
452
452
  * @template Key - The type of the key of the input record.
453
453
  */
454
- type CreateFormDataOptions<Key extends RecordKey> = CreateFormDataOptionsUndefinedOrNullResolution<Key> | CreateFormDataOptionsNullableResolution<Key>;
454
+ type CreateFormDataOptions<Key$1 extends RecordKey> = CreateFormDataOptionsUndefinedOrNullResolution<Key$1> | CreateFormDataOptionsNullableResolution<Key$1>;
455
455
  /**
456
456
  * Creates FormData from a given object, resolving non-string types as appropriate.
457
457
  *
@@ -578,6 +578,17 @@ declare function getRecordKeys<InputRecordType extends Record<RecordKey, unknown
578
578
  */
579
579
  declare function omitProperties<ObjectType extends Record<string, unknown> | Readonly<Record<string, unknown>>, KeysToOmit extends keyof ObjectType>(object: ObjectType, keysToOmit: KeysToOmit | readonly KeysToOmit[]): Omit<ObjectType, KeysToOmit>;
580
580
  //#endregion
581
+ //#region src/functions/objectHelpers/removeUndefinedFromObject.d.ts
582
+ type RemoveUndefined<RecordType extends Record<RecordKey, unknown>> = { [Key in keyof RecordType]: Exclude<RecordType[Key], undefined> };
583
+ /**
584
+ * Removes entries whose values are `undefined` from a given object (not including null etc.).
585
+ *
586
+ * @param object - The object to remove undefined entries from.
587
+ *
588
+ * @returns An object with a new reference in memory, with undefined entries removed.
589
+ */
590
+ declare function removeUndefinedFromObject<RecordType extends Record<RecordKey, unknown>>(object: RecordType): RemoveUndefined<RecordType>;
591
+ //#endregion
581
592
  //#region src/functions/parsers/parseBoolean.d.ts
582
593
  /**
583
594
  * Takes a stringly-typed boolean and converts it to an actual boolean type.
@@ -678,10 +689,12 @@ type VersionType = CreateEnumType<typeof VersionType>;
678
689
  */
679
690
  declare function parseVersionType(data: unknown): VersionType;
680
691
  //#endregion
681
- //#region src/functions/parsers/parseZodSchema.d.ts
692
+ //#region src/functions/parsers/zod/parseZodSchema.d.ts
682
693
  /**
683
694
  * An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
684
695
  *
696
+ * NOTE: Use `parseZodSchemaAsync` if your schema includes an asynchronous function.
697
+ *
685
698
  * @category Parsers
686
699
  *
687
700
  * @template SchemaType - The Zod schema type.
@@ -697,6 +710,25 @@ declare function parseVersionType(data: unknown): VersionType;
697
710
  */
698
711
  declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error>(schema: SchemaType, data: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z.infer<SchemaType>;
699
712
  //#endregion
713
+ //#region src/functions/parsers/zod/parseZodSchemaAsync.d.ts
714
+ /**
715
+ * An alternative function to zodSchema.parseAsync() that can be used to strictly parse asynchronous Zod schemas.
716
+ *
717
+ * @category Parsers
718
+ *
719
+ * @template SchemaType - The Zod schema type.
720
+ * @template ErrorType - The type of error to throw on invalid data.
721
+ *
722
+ * @param schema - The Zod schema to use in parsing.
723
+ * @param data - The data to parse.
724
+ * @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
725
+ *
726
+ * @throws {DataError} If the given data cannot be parsed according to the schema.
727
+ *
728
+ * @returns The parsed data from the Zod schema.
729
+ */
730
+ declare function parseZodSchemaAsync<SchemaType extends ZodType, ErrorType extends Error>(schema: SchemaType, data: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): Promise<z.infer<SchemaType>>;
731
+ //#endregion
700
732
  //#region src/functions/recursive/deepCopy.d.ts
701
733
  /**
702
734
  * Deeply copies an object or array such that all child objects/arrays are also copied.
@@ -1051,4 +1083,4 @@ interface ParseVersionOptions {
1051
1083
  */
1052
1084
  declare function parseVersion(input: string, options?: ParseVersionOptions): string;
1053
1085
  //#endregion
1054
- export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, stringifyDotenv, truncate, wait };
1086
+ export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, ParseVersionOptions, RecordKey, RemoveUndefined, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, stringListToArray, stringifyDotenv, truncate, wait };
package/dist/index.d.ts CHANGED
@@ -410,9 +410,9 @@ type FormDataArrayResolutionStrategy = "stringify" | "multiple";
410
410
  *
411
411
  * @template Key - The type of the key of the input record.
412
412
  */
413
- interface CreateFormDataOptionsBase<Key extends RecordKey> {
413
+ interface CreateFormDataOptionsBase<Key$1 extends RecordKey> {
414
414
  /** How to resolve any arrays provided in the data (can either stringify them or add them multiple times). */
415
- arrayResolution?: FormDataArrayResolutionStrategy | Partial<Record<Key, FormDataArrayResolutionStrategy>>;
415
+ arrayResolution?: FormDataArrayResolutionStrategy | Partial<Record<Key$1, FormDataArrayResolutionStrategy>>;
416
416
  }
417
417
  /**
418
418
  * Options for resolving form data when it may be undefined or null, but not both.
@@ -421,11 +421,11 @@ interface CreateFormDataOptionsBase<Key extends RecordKey> {
421
421
  *
422
422
  * @template Key - The type of the key of the input record.
423
423
  */
424
- interface CreateFormDataOptionsUndefinedOrNullResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
424
+ interface CreateFormDataOptionsUndefinedOrNullResolution<Key$1 extends RecordKey> extends CreateFormDataOptionsBase<Key$1> {
425
425
  /** How to resolve undefined data (May either stringify to 'undefined', resolve to an empty string, or omit entirely). */
426
- undefinedResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
426
+ undefinedResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key$1, FormDataNullableResolutionStrategy>>;
427
427
  /** How to resolve null data (May either stringify to 'null', resolve to an empty string, or omit entirely). */
428
- nullResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
428
+ nullResolution?: FormDataNullableResolutionStrategy | Partial<Record<Key$1, FormDataNullableResolutionStrategy>>;
429
429
  /** @note This must not be provided at the same time as undefinedResolution and/or nullResolution. */
430
430
  nullableResolution?: never;
431
431
  }
@@ -436,13 +436,13 @@ interface CreateFormDataOptionsUndefinedOrNullResolution<Key extends RecordKey>
436
436
  *
437
437
  * @template Key - The type of the key of the input record.
438
438
  */
439
- interface CreateFormDataOptionsNullableResolution<Key extends RecordKey> extends CreateFormDataOptionsBase<Key> {
439
+ interface CreateFormDataOptionsNullableResolution<Key$1 extends RecordKey> extends CreateFormDataOptionsBase<Key$1> {
440
440
  /** @note This must not be provided at the same time as nullableResolution. */
441
441
  undefinedResolution?: never;
442
442
  /** @note This must not be provided at the same time as nullableResolution. */
443
443
  nullResolution?: never;
444
444
  /** How to resolve nullable data (May either stringify to 'undefined | null', resolve to an empty string, or omit entirely). */
445
- nullableResolution: FormDataNullableResolutionStrategy | Partial<Record<Key, FormDataNullableResolutionStrategy>>;
445
+ nullableResolution: FormDataNullableResolutionStrategy | Partial<Record<Key$1, FormDataNullableResolutionStrategy>>;
446
446
  }
447
447
  /**
448
448
  * Options for resolving form data.
@@ -451,7 +451,7 @@ interface CreateFormDataOptionsNullableResolution<Key extends RecordKey> extends
451
451
  *
452
452
  * @template Key - The type of the key of the input record.
453
453
  */
454
- type CreateFormDataOptions<Key extends RecordKey> = CreateFormDataOptionsUndefinedOrNullResolution<Key> | CreateFormDataOptionsNullableResolution<Key>;
454
+ type CreateFormDataOptions<Key$1 extends RecordKey> = CreateFormDataOptionsUndefinedOrNullResolution<Key$1> | CreateFormDataOptionsNullableResolution<Key$1>;
455
455
  /**
456
456
  * Creates FormData from a given object, resolving non-string types as appropriate.
457
457
  *
@@ -578,6 +578,17 @@ declare function getRecordKeys<InputRecordType extends Record<RecordKey, unknown
578
578
  */
579
579
  declare function omitProperties<ObjectType extends Record<string, unknown> | Readonly<Record<string, unknown>>, KeysToOmit extends keyof ObjectType>(object: ObjectType, keysToOmit: KeysToOmit | readonly KeysToOmit[]): Omit<ObjectType, KeysToOmit>;
580
580
  //#endregion
581
+ //#region src/functions/objectHelpers/removeUndefinedFromObject.d.ts
582
+ type RemoveUndefined<RecordType extends Record<RecordKey, unknown>> = { [Key in keyof RecordType]: Exclude<RecordType[Key], undefined> };
583
+ /**
584
+ * Removes entries whose values are `undefined` from a given object (not including null etc.).
585
+ *
586
+ * @param object - The object to remove undefined entries from.
587
+ *
588
+ * @returns An object with a new reference in memory, with undefined entries removed.
589
+ */
590
+ declare function removeUndefinedFromObject<RecordType extends Record<RecordKey, unknown>>(object: RecordType): RemoveUndefined<RecordType>;
591
+ //#endregion
581
592
  //#region src/functions/parsers/parseBoolean.d.ts
582
593
  /**
583
594
  * Takes a stringly-typed boolean and converts it to an actual boolean type.
@@ -678,10 +689,12 @@ type VersionType = CreateEnumType<typeof VersionType>;
678
689
  */
679
690
  declare function parseVersionType(data: unknown): VersionType;
680
691
  //#endregion
681
- //#region src/functions/parsers/parseZodSchema.d.ts
692
+ //#region src/functions/parsers/zod/parseZodSchema.d.ts
682
693
  /**
683
694
  * An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
684
695
  *
696
+ * NOTE: Use `parseZodSchemaAsync` if your schema includes an asynchronous function.
697
+ *
685
698
  * @category Parsers
686
699
  *
687
700
  * @template SchemaType - The Zod schema type.
@@ -697,6 +710,25 @@ declare function parseVersionType(data: unknown): VersionType;
697
710
  */
698
711
  declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error>(schema: SchemaType, data: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z$1.infer<SchemaType>;
699
712
  //#endregion
713
+ //#region src/functions/parsers/zod/parseZodSchemaAsync.d.ts
714
+ /**
715
+ * An alternative function to zodSchema.parseAsync() that can be used to strictly parse asynchronous Zod schemas.
716
+ *
717
+ * @category Parsers
718
+ *
719
+ * @template SchemaType - The Zod schema type.
720
+ * @template ErrorType - The type of error to throw on invalid data.
721
+ *
722
+ * @param schema - The Zod schema to use in parsing.
723
+ * @param data - The data to parse.
724
+ * @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
725
+ *
726
+ * @throws {DataError} If the given data cannot be parsed according to the schema.
727
+ *
728
+ * @returns The parsed data from the Zod schema.
729
+ */
730
+ declare function parseZodSchemaAsync<SchemaType extends ZodType, ErrorType extends Error>(schema: SchemaType, data: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): Promise<z$1.infer<SchemaType>>;
731
+ //#endregion
700
732
  //#region src/functions/recursive/deepCopy.d.ts
701
733
  /**
702
734
  * Deeply copies an object or array such that all child objects/arrays are also copied.
@@ -1051,4 +1083,4 @@ interface ParseVersionOptions {
1051
1083
  */
1052
1084
  declare function parseVersion(input: string, options?: ParseVersionOptions): string;
1053
1085
  //#endregion
1054
- export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, type IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, type ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, stringifyDotenv, truncate, wait };
1086
+ export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, type IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, type ParseVersionOptions, RecordKey, RemoveUndefined, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, stringListToArray, stringifyDotenv, truncate, wait };
package/dist/index.js CHANGED
@@ -800,6 +800,22 @@ function omitProperties(object, keysToOmit) {
800
800
  }
801
801
  var omitProperties_default = omitProperties;
802
802
 
803
+ //#endregion
804
+ //#region src/functions/objectHelpers/removeUndefinedFromObject.ts
805
+ /**
806
+ * Removes entries whose values are `undefined` from a given object (not including null etc.).
807
+ *
808
+ * @param object - The object to remove undefined entries from.
809
+ *
810
+ * @returns An object with a new reference in memory, with undefined entries removed.
811
+ */
812
+ function removeUndefinedFromObject(object) {
813
+ return Object.fromEntries(Object.entries(object).filter(([_, value]) => {
814
+ return value !== void 0;
815
+ }));
816
+ }
817
+ var removeUndefinedFromObject_default = removeUndefinedFromObject;
818
+
803
819
  //#endregion
804
820
  //#region src/functions/parsers/parseBoolean.ts
805
821
  /**
@@ -821,25 +837,8 @@ function parseBoolean(inputString) {
821
837
  var parseBoolean_default = parseBoolean;
822
838
 
823
839
  //#endregion
824
- //#region src/functions/parsers/parseZodSchema.ts
825
- /**
826
- * An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
827
- *
828
- * @category Parsers
829
- *
830
- * @template SchemaType - The Zod schema type.
831
- * @template ErrorType - The type of error to throw on invalid data.
832
- *
833
- * @param schema - The Zod schema to use in parsing.
834
- * @param data - The data to parse.
835
- * @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
836
- *
837
- * @throws {DataError} If the given data cannot be parsed according to the schema.
838
- *
839
- * @returns The parsed data from the Zod schema.
840
- */
841
- function parseZodSchema(schema, data, onError) {
842
- const parsedResult = schema.safeParse(data);
840
+ //#region src/functions/parsers/zod/_parseZodSchema.ts
841
+ function _parseZodSchema(parsedResult, data, onError) {
843
842
  if (!parsedResult.success) {
844
843
  if (onError) {
845
844
  if (onError instanceof Error) throw onError;
@@ -857,10 +856,35 @@ function parseZodSchema(schema, data, onError) {
857
856
  return secondCount - firstCount;
858
857
  }).map(([code, count], _, allErrorCodes$1) => {
859
858
  return allErrorCodes$1.length === 1 && count === 1 ? code : `${code}×${count}`;
860
- }).join(","), `\n\n${z$1.prettifyError(parsedResult.error)}\n`);
859
+ }).join(","), `\n\n${z.prettifyError(parsedResult.error)}\n`);
861
860
  }
862
861
  return parsedResult.data;
863
862
  }
863
+ var _parseZodSchema_default = _parseZodSchema;
864
+
865
+ //#endregion
866
+ //#region src/functions/parsers/zod/parseZodSchema.ts
867
+ /**
868
+ * An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
869
+ *
870
+ * NOTE: Use `parseZodSchemaAsync` if your schema includes an asynchronous function.
871
+ *
872
+ * @category Parsers
873
+ *
874
+ * @template SchemaType - The Zod schema type.
875
+ * @template ErrorType - The type of error to throw on invalid data.
876
+ *
877
+ * @param schema - The Zod schema to use in parsing.
878
+ * @param data - The data to parse.
879
+ * @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
880
+ *
881
+ * @throws {DataError} If the given data cannot be parsed according to the schema.
882
+ *
883
+ * @returns The parsed data from the Zod schema.
884
+ */
885
+ function parseZodSchema(schema, data, onError) {
886
+ return _parseZodSchema_default(schema.safeParse(data), data, onError);
887
+ }
864
888
  var parseZodSchema_default = parseZodSchema;
865
889
 
866
890
  //#endregion
@@ -943,6 +967,29 @@ function parseVersionType(data) {
943
967
  }
944
968
  var parseVersionType_default = parseVersionType;
945
969
 
970
+ //#endregion
971
+ //#region src/functions/parsers/zod/parseZodSchemaAsync.ts
972
+ /**
973
+ * An alternative function to zodSchema.parseAsync() that can be used to strictly parse asynchronous Zod schemas.
974
+ *
975
+ * @category Parsers
976
+ *
977
+ * @template SchemaType - The Zod schema type.
978
+ * @template ErrorType - The type of error to throw on invalid data.
979
+ *
980
+ * @param schema - The Zod schema to use in parsing.
981
+ * @param data - The data to parse.
982
+ * @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
983
+ *
984
+ * @throws {DataError} If the given data cannot be parsed according to the schema.
985
+ *
986
+ * @returns The parsed data from the Zod schema.
987
+ */
988
+ async function parseZodSchemaAsync(schema, data, onError) {
989
+ return _parseZodSchema_default(await schema.safeParseAsync(data), data, onError);
990
+ }
991
+ var parseZodSchemaAsync_default = parseZodSchemaAsync;
992
+
946
993
  //#endregion
947
994
  //#region src/functions/recursive/deepCopy.ts
948
995
  function callDeepCopy(input) {
@@ -1451,4 +1498,4 @@ function incrementVersion(version, incrementType, options) {
1451
1498
  var incrementVersion_default = incrementVersion;
1452
1499
 
1453
1500
  //#endregion
1454
- export { APIError_default as APIError, DataError_default as DataError, Env, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX_default as VERSION_NUMBER_REGEX, VersionNumber_default as VersionNumber, VersionType, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, determineVersionType_default as determineVersionType, encryptWithKey_default as encryptWithKey, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getIndividualVersionNumbers_default as getIndividualVersionNumbers, getInterpolations_default as getInterpolations, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, incrementVersion_default as incrementVersion, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, parseVersion_default as parseVersion, parseVersionType_default as parseVersionType, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, stringListToArray_default as stringListToArray, stringifyDotenv_default as stringifyDotenv, truncate_default as truncate, wait_default as wait };
1501
+ export { APIError_default as APIError, DataError_default as DataError, Env, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX_default as VERSION_NUMBER_REGEX, VersionNumber_default as VersionNumber, VersionType, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, determineVersionType_default as determineVersionType, encryptWithKey_default as encryptWithKey, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getIndividualVersionNumbers_default as getIndividualVersionNumbers, getInterpolations_default as getInterpolations, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, incrementVersion_default as incrementVersion, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, parseVersion_default as parseVersion, parseVersionType_default as parseVersionType, parseZodSchema_default as parseZodSchema, parseZodSchemaAsync_default as parseZodSchemaAsync, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, removeUndefinedFromObject_default as removeUndefinedFromObject, stringListToArray_default as stringListToArray, stringifyDotenv_default as stringifyDotenv, truncate_default as truncate, wait_default as wait };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "4.8.0",
3
+ "version": "4.10.0",
4
4
  "description": "Helpful utility functions.",
5
5
  "repository": {
6
6
  "type": "git",