Skip to main content
Home

Built and signed on GitHub Actions

Zod error utilities

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
82%
Published
7 months ago (1.0.0)

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.

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@luxass/zod-error-utils

Import symbol

import * as zod_error_utils from "@luxass/zod-error-utils";
or

Import directly with a jsr specifier

import * as zod_error_utils from "jsr:@luxass/zod-error-utils";

Add Package

pnpm i jsr:@luxass/zod-error-utils
or (using pnpm 10.8 or older)
pnpm dlx jsr add @luxass/zod-error-utils

Import symbol

import * as zod_error_utils from "@luxass/zod-error-utils";

Add Package

yarn add jsr:@luxass/zod-error-utils
or (using Yarn 4.8 or older)
yarn dlx jsr add @luxass/zod-error-utils

Import symbol

import * as zod_error_utils from "@luxass/zod-error-utils";

Add Package

vlt install jsr:@luxass/zod-error-utils

Import symbol

import * as zod_error_utils from "@luxass/zod-error-utils";

Add Package

npx jsr add @luxass/zod-error-utils

Import symbol

import * as zod_error_utils from "@luxass/zod-error-utils";

Add Package

bunx jsr add @luxass/zod-error-utils

Import symbol

import * as zod_error_utils from "@luxass/zod-error-utils";