0.2.0 • Published 1 year ago

zod-error-utils v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

zod-error-utils

npm version npm downloads

A set of utilities to work with Zod errors.

📦 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.

0.2.0

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago