zod-error-utils
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

zod-error-utils

npm version npm downloads

A set of utilities to work with Zod errors.

[!IMPORTANT] This package is not recommended to use for Zod V4, as it has better support for error messages and paths. See the Zod V4 documentation for more information.

📦 Installation

npm install zod-error-utils

🚀 Usage

import { buildZodErrorMap, flattenErrorPath, zodErrorMap } from "zod-error-utils";

const schema = z.object({
  user: z.object({
    name: z.string(),
    isAdministrator: z.boolean(),
  }),
});

const data = {
  user: {
    name: "John Doe",
    isAdministrator: true,
  },
};

const result = schema.safeParse(data, {
  errorMap: zodErrorMap
});

// you can customize the zodErrorMap, by creating a new one using `buildZodErrorMap`.

const customErrorMap = buildZodErrorMap({
  prefixFn(path, message) {
    return `Custom prefix: ${path.join(".")}: ${message}`;
  },
});

📄 License

Published under MIT License.

Readme

Keywords

Package Sidebar

Install

npm i zod-error-utils

Weekly Downloads

84

Version

1.0.0

License

MIT

Unpacked Size

9.64 kB

Total Files

13

Last publish

Collaborators

  • luxass