1.0.1 • Published 2 years ago

@serouslabs/joi-to-zod-codemod v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Joi to Zod Codemod

A TypeScript codemod that automatically transforms Joi schema validations to Zod schema validations in your codebase.

Requirements

  • Node.js v12.0.0 or higher
  • npm v6.0.0 or higher

Installation

  1. Clone this repository:
git clone https://github.com/tsmada/joi-to-zod-codemod.git
  1. Navigate to repo dir:
cd joi-to-zod-codemod
  1. Install
npm install

Usage

To run the codemod, execute the following command in your terminal, replacing with the path to the directory containing your TypeScript files:

npx ts-node src/joi-to-zod-codemod.ts <path>

For example:

npx ts-node src/joi-to-zod-codemod.ts ./src/services

This will apply the Joi to Zod transformation on all TypeScript files in the specified directory.

How It Works

The codemod uses Babel to parse your TypeScript code into an Abstract Syntax Tree (AST), traverse the AST to find Joi schema validation functions, and replace them with their Zod equivalents. The transformed code is then written back to the file.

The codemod will update import statements and transform the following Joi functions to their Zod equivalents:

  • string
  • number
  • boolean
  • object
  • array
  • date

Issues

I probably forgot a ton of stuff here so create a new issue/PR if you're ready to do the needful