Socket
Socket
Sign inDemoInstall

zod-rosetty

Package Overview
Dependencies
1
Maintainers
1
Versions
171
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    zod-rosetty

[![Maintainability](https://api.codeclimate.com/v1/badges/e682bef68a588d3a779e/maintainability)](https://codeclimate.com/github/qlaffont/zod-rosetty/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/e682bef68a588d3a779e/test_coverag


Version published
Weekly downloads
1.2K
increased by49.75%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Maintainability Test Coverage npm npm Snyk Vulnerabilities for npm package NPM

zod-rosetty

Translate Zod Errors with rosetty

Inspired by aiji42/zod-i18n .

Usage


pnpm install zod-rosetty zod rosetty

How to use?

import { z } from "zod";
import { zodRosettyMap, ZodErrorMap } from "zod-rosetty";
import { rosetty } from 'rosetty';
import { enGB } from 'date-fns/locale';

//Initialize Rosetty Error Map
z.setErrorMap(zodRosettyMap);

//Initialize Rosetty
const rosettyMap: ZodErrorMap = {
  zod: {
    errors: {
      invalid_string: {
        email: 'Invalid {{validation}}',
      },
    },
    validations: {
      email: 'email',
    },
  },
};
const { t } = rosetty<typeof rosettyMap>(
  { en: { dict: rosettyMap, locale: enGB } },
  'en',
);

const schema = z.string().email();
translateZodErrorMessage(schema.safeParse('test').error, t) // 'Invalid email'

Test

To test this package:

pnpm test

Maintain

This package use TSdx. Please check documentation to update this package.

FAQs

Last updated on 30 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc