@alextheman/utility 4.3.6 → 4.4.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
@@ -825,7 +825,7 @@ var parseBoolean_default = parseBoolean;
825
825
  *
826
826
  * @param schema - The Zod schema to use in parsing.
827
827
  * @param data - The data to parse.
828
- * @param error - A custom error to throw on invalid data (defaults to `DataError`).
828
+ * @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.
829
829
  *
830
830
  * @throws {DataError} If the given data cannot be parsed according to the schema.
831
831
  *
@@ -833,7 +833,13 @@ var parseBoolean_default = parseBoolean;
833
833
  */
834
834
  function parseZodSchema(schema, data, error) {
835
835
  const parsedResult = schema.safeParse(data);
836
- if (!parsedResult.success) throw error ?? new DataError_default(data);
836
+ if (!parsedResult.success) {
837
+ if (error) {
838
+ if (error instanceof Error) throw error;
839
+ else if (typeof error === "function") throw error(parsedResult.error);
840
+ }
841
+ throw new DataError_default(data, parsedResult.error.issues[0]?.code.toUpperCase(), parsedResult.error.issues[0].message);
842
+ }
837
843
  return parsedResult.data;
838
844
  }
839
845
  var parseZodSchema_default = parseZodSchema;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { ZodType, core } from "zod";
1
+ import { ZodError, ZodType, core } from "zod";
2
2
 
3
3
  //#region src/constants/NAMESPACE_EXPORT_REGEX.d.ts
4
4
  declare const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
@@ -674,13 +674,13 @@ declare function parseVersionType(data: unknown): VersionType;
674
674
  *
675
675
  * @param schema - The Zod schema to use in parsing.
676
676
  * @param data - The data to parse.
677
- * @param error - A custom error to throw on invalid data (defaults to `DataError`).
677
+ * @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.
678
678
  *
679
679
  * @throws {DataError} If the given data cannot be parsed according to the schema.
680
680
  *
681
681
  * @returns The parsed data from the Zod schema.
682
682
  */
683
- declare function parseZodSchema<Output, Input, Internals extends core.$ZodTypeInternals<Output, Input>, ErrorType extends Error>(schema: ZodType<Output, Input, Internals>, data: unknown, error?: ErrorType): core.output<ZodType<Output, Input, Internals>>;
683
+ 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>>;
684
684
  //#endregion
685
685
  //#region src/functions/recursive/deepCopy.d.ts
686
686
  /**
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ZodType, core } from "zod";
1
+ import { ZodError, ZodType, core } from "zod";
2
2
 
3
3
  //#region src/constants/NAMESPACE_EXPORT_REGEX.d.ts
4
4
  declare const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
@@ -674,13 +674,13 @@ declare function parseVersionType(data: unknown): VersionType;
674
674
  *
675
675
  * @param schema - The Zod schema to use in parsing.
676
676
  * @param data - The data to parse.
677
- * @param error - A custom error to throw on invalid data (defaults to `DataError`).
677
+ * @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.
678
678
  *
679
679
  * @throws {DataError} If the given data cannot be parsed according to the schema.
680
680
  *
681
681
  * @returns The parsed data from the Zod schema.
682
682
  */
683
- declare function parseZodSchema<Output, Input, Internals extends core.$ZodTypeInternals<Output, Input>, ErrorType extends Error>(schema: ZodType<Output, Input, Internals>, data: unknown, error?: ErrorType): core.output<ZodType<Output, Input, Internals>>;
683
+ 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>>;
684
684
  //#endregion
685
685
  //#region src/functions/recursive/deepCopy.d.ts
686
686
  /**
package/dist/index.js CHANGED
@@ -796,7 +796,7 @@ var parseBoolean_default = parseBoolean;
796
796
  *
797
797
  * @param schema - The Zod schema to use in parsing.
798
798
  * @param data - The data to parse.
799
- * @param error - A custom error to throw on invalid data (defaults to `DataError`).
799
+ * @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.
800
800
  *
801
801
  * @throws {DataError} If the given data cannot be parsed according to the schema.
802
802
  *
@@ -804,7 +804,13 @@ var parseBoolean_default = parseBoolean;
804
804
  */
805
805
  function parseZodSchema(schema, data, error) {
806
806
  const parsedResult = schema.safeParse(data);
807
- if (!parsedResult.success) throw error ?? new DataError_default(data);
807
+ if (!parsedResult.success) {
808
+ if (error) {
809
+ if (error instanceof Error) throw error;
810
+ else if (typeof error === "function") throw error(parsedResult.error);
811
+ }
812
+ throw new DataError_default(data, parsedResult.error.issues[0]?.code.toUpperCase(), parsedResult.error.issues[0].message);
813
+ }
808
814
  return parsedResult.data;
809
815
  }
810
816
  var parseZodSchema_default = parseZodSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "4.3.6",
3
+ "version": "4.4.0",
4
4
  "description": "Helpful utility functions.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,19 +16,19 @@
16
16
  "dist"
17
17
  ],
18
18
  "dependencies": {
19
- "zod": "^4.2.1"
19
+ "zod": "^4.3.4"
20
20
  },
21
21
  "devDependencies": {
22
- "@alextheman/eslint-plugin": "^5.4.0",
22
+ "@alextheman/eslint-plugin": "^5.4.2",
23
23
  "@types/node": "^25.0.3",
24
- "alex-c-line": "^1.10.2",
24
+ "alex-c-line": "^1.15.0",
25
25
  "dotenv-cli": "^11.0.0",
26
26
  "eslint": "^9.39.2",
27
- "globals": "^16.5.0",
27
+ "globals": "^17.0.0",
28
28
  "husky": "^9.1.7",
29
29
  "jsdom": "^27.4.0",
30
30
  "prettier": "^3.7.4",
31
- "tsdown": "^0.18.3",
31
+ "tsdown": "0.19.0-beta.1",
32
32
  "typedoc": "^0.28.15",
33
33
  "typescript": "^5.9.3",
34
34
  "vite-tsconfig-paths": "^6.0.3",
@@ -55,6 +55,7 @@
55
55
  "lint-prettier-javascript": "prettier --check \"./**/*.js\"",
56
56
  "lint-prettier-typescript": "prettier --check --parser typescript \"./**/*.ts\"",
57
57
  "lint-tsc": "tsc --noEmit",
58
+ "pre-commit": "alex-c-line pre-commit",
58
59
  "prepare-live-eslint-plugin": "pnpm uninstall @alextheman/eslint-plugin && pnpm install --save-dev @alextheman/eslint-plugin",
59
60
  "prepare-local-eslint-plugin": "dotenv -e .env -- sh -c 'ESLINT_PLUGIN_PATH=${LOCAL_ESLINT_PLUGIN_PATH:-../eslint-plugin}; pnpm --prefix \"$ESLINT_PLUGIN_PATH\" run build && pnpm uninstall @alextheman/eslint-plugin && pnpm install --save-dev file:\"$ESLINT_PLUGIN_PATH\"'",
60
61
  "test": "vitest run",