@alextheman/utility 4.6.0 → 4.7.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
@@ -857,27 +857,28 @@ var parseBoolean_default = parseBoolean;
857
857
  *
858
858
  * @category Parsers
859
859
  *
860
- * @template Output - The Zod output type.
861
- * @template Input - The Zod input type.
862
- * @template Internals - The Zod internal types based on the output and input types.
860
+ * @template SchemaType - The Zod schema type.
863
861
  * @template ErrorType - The type of error to throw on invalid data.
864
862
  *
865
863
  * @param schema - The Zod schema to use in parsing.
866
864
  * @param data - The data to parse.
867
- * @param error - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error.
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.
868
866
  *
869
867
  * @throws {DataError} If the given data cannot be parsed according to the schema.
870
868
  *
871
869
  * @returns The parsed data from the Zod schema.
872
870
  */
873
- function parseZodSchema(schema, data, error) {
871
+ function parseZodSchema(schema, data, onError) {
874
872
  const parsedResult = schema.safeParse(data);
875
873
  if (!parsedResult.success) {
876
- if (error) {
877
- if (error instanceof Error) throw error;
878
- else if (typeof error === "function") throw error(parsedResult.error);
874
+ if (onError) {
875
+ if (onError instanceof Error) throw onError;
876
+ else if (typeof onError === "function") {
877
+ const evaluatedError = onError(parsedResult.error);
878
+ if (evaluatedError instanceof Error) throw evaluatedError;
879
+ }
879
880
  }
880
- throw new DataError_default(data, parsedResult.error.issues[0]?.code.toUpperCase(), parsedResult.error.issues[0].message);
881
+ throw new DataError_default(data, parsedResult.error.issues[0]?.code?.toUpperCase(), parsedResult.error.issues[0]?.message);
881
882
  }
882
883
  return parsedResult.data;
883
884
  }
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DotenvParseOutput } from "dotenv";
2
- import { ZodError, ZodType, core } from "zod";
2
+ import { ZodError, ZodType, z } from "zod";
3
3
 
4
4
  //#region src/constants/NAMESPACE_EXPORT_REGEX.d.ts
5
5
  declare const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
@@ -684,20 +684,18 @@ declare function parseVersionType(data: unknown): VersionType;
684
684
  *
685
685
  * @category Parsers
686
686
  *
687
- * @template Output - The Zod output type.
688
- * @template Input - The Zod input type.
689
- * @template Internals - The Zod internal types based on the output and input types.
687
+ * @template SchemaType - The Zod schema type.
690
688
  * @template ErrorType - The type of error to throw on invalid data.
691
689
  *
692
690
  * @param schema - The Zod schema to use in parsing.
693
691
  * @param data - The data to parse.
694
- * @param error - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error.
692
+ * @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.
695
693
  *
696
694
  * @throws {DataError} If the given data cannot be parsed according to the schema.
697
695
  *
698
696
  * @returns The parsed data from the Zod schema.
699
697
  */
700
- declare function parseZodSchema<Output, Input, Internals extends core.$ZodTypeInternals<Output, Input>, ErrorType extends Error>(schema: ZodType<Output, Input, Internals>, data: unknown, error?: ErrorType | ((zodError: ZodError) => ErrorType)): core.output<ZodType<Output, Input, Internals>>;
698
+ declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error>(schema: SchemaType, data: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z.infer<SchemaType>;
701
699
  //#endregion
702
700
  //#region src/functions/recursive/deepCopy.d.ts
703
701
  /**
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ZodError, ZodType, core } from "zod";
1
+ import { ZodError, ZodType, z as z$1 } from "zod";
2
2
  import { DotenvParseOutput } from "dotenv";
3
3
 
4
4
  //#region src/constants/NAMESPACE_EXPORT_REGEX.d.ts
@@ -684,20 +684,18 @@ declare function parseVersionType(data: unknown): VersionType;
684
684
  *
685
685
  * @category Parsers
686
686
  *
687
- * @template Output - The Zod output type.
688
- * @template Input - The Zod input type.
689
- * @template Internals - The Zod internal types based on the output and input types.
687
+ * @template SchemaType - The Zod schema type.
690
688
  * @template ErrorType - The type of error to throw on invalid data.
691
689
  *
692
690
  * @param schema - The Zod schema to use in parsing.
693
691
  * @param data - The data to parse.
694
- * @param error - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error.
692
+ * @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.
695
693
  *
696
694
  * @throws {DataError} If the given data cannot be parsed according to the schema.
697
695
  *
698
696
  * @returns The parsed data from the Zod schema.
699
697
  */
700
- declare function parseZodSchema<Output, Input, Internals extends core.$ZodTypeInternals<Output, Input>, ErrorType extends Error>(schema: ZodType<Output, Input, Internals>, data: unknown, error?: ErrorType | ((zodError: ZodError) => ErrorType)): core.output<ZodType<Output, Input, Internals>>;
698
+ declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error>(schema: SchemaType, data: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z$1.infer<SchemaType>;
701
699
  //#endregion
702
700
  //#region src/functions/recursive/deepCopy.d.ts
703
701
  /**
package/dist/index.js CHANGED
@@ -827,27 +827,28 @@ var parseBoolean_default = parseBoolean;
827
827
  *
828
828
  * @category Parsers
829
829
  *
830
- * @template Output - The Zod output type.
831
- * @template Input - The Zod input type.
832
- * @template Internals - The Zod internal types based on the output and input types.
830
+ * @template SchemaType - The Zod schema type.
833
831
  * @template ErrorType - The type of error to throw on invalid data.
834
832
  *
835
833
  * @param schema - The Zod schema to use in parsing.
836
834
  * @param data - The data to parse.
837
- * @param error - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error.
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.
838
836
  *
839
837
  * @throws {DataError} If the given data cannot be parsed according to the schema.
840
838
  *
841
839
  * @returns The parsed data from the Zod schema.
842
840
  */
843
- function parseZodSchema(schema, data, error) {
841
+ function parseZodSchema(schema, data, onError) {
844
842
  const parsedResult = schema.safeParse(data);
845
843
  if (!parsedResult.success) {
846
- if (error) {
847
- if (error instanceof Error) throw error;
848
- else if (typeof error === "function") throw error(parsedResult.error);
844
+ if (onError) {
845
+ if (onError instanceof Error) throw onError;
846
+ else if (typeof onError === "function") {
847
+ const evaluatedError = onError(parsedResult.error);
848
+ if (evaluatedError instanceof Error) throw evaluatedError;
849
+ }
849
850
  }
850
- throw new DataError_default(data, parsedResult.error.issues[0]?.code.toUpperCase(), parsedResult.error.issues[0].message);
851
+ throw new DataError_default(data, parsedResult.error.issues[0]?.code?.toUpperCase(), parsedResult.error.issues[0]?.message);
851
852
  }
852
853
  return parsedResult.data;
853
854
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "4.6.0",
3
+ "version": "4.7.0",
4
4
  "description": "Helpful utility functions.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,20 +23,20 @@
23
23
  "devDependencies": {
24
24
  "@alextheman/eslint-plugin": "^5.4.2",
25
25
  "@types/libsodium-wrappers": "^0.7.14",
26
- "@types/node": "^25.0.5",
27
- "@typescript-eslint/types": "^8.52.0",
28
- "alex-c-line": "^1.17.0",
26
+ "@types/node": "^25.0.9",
27
+ "@typescript-eslint/types": "^8.53.0",
28
+ "alex-c-line": "^1.17.3",
29
29
  "dotenv-cli": "^11.0.0",
30
30
  "eslint": "^9.39.2",
31
31
  "globals": "^17.0.0",
32
32
  "husky": "^9.1.7",
33
33
  "jsdom": "^27.4.0",
34
- "prettier": "^3.7.4",
35
- "tsdown": "^0.18.4",
36
- "typedoc": "^0.28.15",
34
+ "prettier": "^3.8.0",
35
+ "tsdown": "^0.19.0",
36
+ "typedoc": "^0.28.16",
37
37
  "typescript": "^5.9.3",
38
38
  "vite-tsconfig-paths": "^6.0.4",
39
- "vitest": "^4.0.16"
39
+ "vitest": "^4.0.17"
40
40
  },
41
41
  "engines": {
42
42
  "node": ">=22.0.0"