Skip to content

timdeschryver/zod-to-mini

Repository files navigation

Zod to mini

What

Zod v4 introduces a new minimalist API through @zod/mini that follows a more functional approach. This tool helps you migrate your existing Zod v3 codebase to the new format with minimal effort.

Running the migration tool

npx zod-to-mini-converter

Usage

Run the command in the root of your project to migrate all your files to the new format.

By default, the tool uses your project's tsconfig.json for configuration. You can specify a different tsconfig path if needed:

npx zod-to-mini path/to/custom/tsconfig.json

What does it migrate?

  • Imports: Replaces imports from zod with @zod/mini
  • Validation methods: Replaces method chaining with the new functional check pipe syntax
  • Deprecated methods: Updates deprecated methods with their newer equivalents
  • Method mappings: Transforms method names according to the new API

Examples

Before:

import * as z from 'zod';

const userSchema = z.object({
  username: z.string().min(3).max(20),
  email: z.string().email(),
  age: z.number().min(18).optional(),
});

After:

import * as z from '@zod/mini';

const userSchema = z.object({
  username: z.string().check(z.minLength(3), z.maxLength(20)),
  email: z.string().check(z.email()),
  age: z.optional(z.number().check(z.gte(18))),
});

What's not included in @zod/mini

If you use any of the following methods in your Zod schemas, then these methods will not be migrated. After the migration there will be compilation errors that need manual adjustments. If you need these methods, you can use the zod package.

  • transform
  • coerce
  • default

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

Found an issue? Please open an issue.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors