@kamaalio/joi-to-zod-codemod
v0.0.13
Published
A powerful CLI tool and library for automatically converting [Joi](https://joi.dev/) schema definitions to [Zod](https://zod.dev/) schemas in TypeScript and JavaScript projects. This codemod intelligently transforms validation schemas while preserving com
Downloads
17
Readme
Joi to Zod Codemod
A powerful CLI tool and library for automatically converting Joi schema definitions to Zod schemas in TypeScript and JavaScript projects. This codemod intelligently transforms validation schemas while preserving complex relationships, nested structures, and import dependencies.
Installation
# Using npm
npm install -g @kamaalio/joi-to-zod-codemod
# Using pnpm
pnpm add -g @kamaalio/joi-to-zod-codemod
# Using yarn
yarn global add @kamaalio/joi-to-zod-codemodUsage
CLI Usage
Transform all Joi schemas in the current directory:
joi-to-zod-codemodTransform specific directory:
joi-to-zod-codemod run ./srcCLI Options
| Flag | Short | Default | Description |
| ------- | ----- | ------- | ---------------------------------------- |
| --dry | -d | false | Preview changes without writing to files |
| --log | -l | true | Enable logging output |
Examples
# Dry run to preview changes
joi-to-zod-codemod run --dry
# Transform specific directory with minimal output
joi-to-zod-codemod run ./api --no-logTransformation Examples
Basic Schema Conversion
Before (Joi):
import Joi from 'joi';
const userSchema = Joi.object({
name: Joi.string().min(3).max(30).required(),
email: Joi.string().email().required(),
age: Joi.number().integer().min(18).max(120),
});After (Zod):
import { z } from 'zod';
const userSchema = z.object({
name: z.string().min(3).max(30),
email: z.string().email(),
age: z.number().int().min(18).max(120).optional(),
});Development
Prerequisites
- Node.js >=22.0.0
- pnpm (recommended package manager)
Setup
# Clone the repository
git clone https://github.com/kamaal111/joi-to-zod-codemod.git
cd joi-to-zod-codemod
# Install dependencies
pnpm install
# Build the project
pnpm build
# Run tests
pnpm test
# Run tests with coverage
pnpm test:covScripts
pnpm build- Compile TypeScript and prepare for distributionpnpm test- Run test suitepnpm test:watch- Run tests in watch modepnpm test:cov- Run tests with coveragepnpm lint- Run ESLintpnpm format- Format code with Prettierpnpm type-check- Run TypeScript type checking
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Kamaal Farah - GitHub
Transform your validation schemas with confidence! 🧉
