npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@schemashift/yup-zod

v0.14.0

Published

Yup ↔ Zod bidirectional transformer for SchemaShift

Readme

@schemashift/yup-zod

Yup ↔ Zod transformer for SchemaShift. Supports both forward (Yup → Zod) and backward (Zod → Yup) migrations.

npm version npm downloads CI License: MIT

Installation

npm install @schemashift/yup-zod

Usage

import { createYupToZodHandler, createZodToYupHandler } from '@schemashift/yup-zod';
import { TransformEngine } from '@schemashift/core';

const engine = new TransformEngine();
engine.registerHandler('yup', 'zod', createYupToZodHandler());
engine.registerHandler('zod', 'yup', createZodToYupHandler()); // Backward migration (Pro+)

Backward Migration: Zod → Yup

AST-based transformer that converts Zod schemas back to Yup equivalents:

| Zod | Yup | |-----|-----| | z.object({...}) | yup.object({...}) | | z.string() | yup.string() | | z.number() | yup.number() | | z.boolean() | yup.boolean() | | z.date() | yup.date() | | z.array(s) | yup.array().of(s) | | .optional() | .notRequired() | | .nullable() | .nullable() | | .refine(fn, msg) | .test('custom', msg, fn) | | z.enum([...]) | yup.mixed().oneOf([...]) | | z.union([...]) | yup.mixed().oneOf([...]) | | z.literal(val) | yup.mixed().oneOf([val]) | | z.record(k, v) | yup.object() (with TODO) | | z.tuple([...]) | yup.array() (with TODO) |

Tier: Pro+

Transformation Mappings

Imports

| Yup | Zod | |-----|-----| | import * as yup from 'yup' | import { z } from 'zod' | | import yup from 'yup' | import { z } from 'zod' |

Basic Types

| Yup | Zod | |-----|-----| | yup.string() | z.string() | | yup.number() | z.number() | | yup.boolean() | z.boolean() | | yup.date() | z.date() | | yup.array() | z.array() | | yup.object() | z.object() | | yup.mixed() | z.unknown() |

Required/Optional

| Yup | Zod | Notes | |-----|-----|-------| | .required() | (removed) | Zod fields are required by default | | .notRequired() | .optional() | | | .nullable() | .nullable() | | | .defined() | (removed) | Handled by Zod's type system |

String Validations

| Yup | Zod | |-----|-----| | .email() | .email() | | .url() | .url() | | .uuid() | .uuid() | | .min(n) | .min(n) | | .max(n) | .max(n) | | .length(n) | .length(n) | | .matches(regex) | .regex(regex) | | .lowercase() | .toLowerCase() | | .uppercase() | .toUpperCase() | | .trim() | .trim() |

Number Validations

| Yup | Zod | |-----|-----| | .min(n) | .min(n) | | .max(n) | .max(n) | | .positive() | .positive() | | .negative() | .negative() | | .integer() | .int() |

Array Validations

| Yup | Zod | |-----|-----| | .min(n) | .min(n) | | .max(n) | .max(n) | | .length(n) | .length(n) | | .of(schema) | z.array(schema) |

Object Methods

| Yup | Zod | |-----|-----| | .shape({...}) | z.object({...}) | | .pick([...]) | .pick({...}) | | .omit([...]) | .omit({...}) | | .partial() | .partial() | | .strict() | .strict() | | .passthrough() | .passthrough() |

Other

| Yup | Zod | |-----|-----| | .default(value) | .default(value) | | .oneOf([...]) | z.enum([...]) or z.literal().or(...) | | .test(...) | .refine(...) | | .transform(...) | .transform(...) |

Patterns Requiring Manual Review

The transformer generates actionable .superRefine() scaffolding for these patterns (not bare TODOs):

.when() Conditionals

Yup's .when() doesn't have a direct Zod equivalent. The transformer generates a .superRefine() template with the original condition context:

// Yup
const schema = yup.object({
  isBusiness: yup.boolean(),
  companyName: yup.string().when('isBusiness', {
    is: true,
    then: yup.string().required(),
  }),
});

// Generated output (with scaffolding)
/* TODO(schemashift): Convert conditional validation.
   Original: .when('isBusiness', { is: true, then: ..., otherwise: ... })
   Suggested Zod equivalent:
   .superRefine((data, ctx) => {
     if (data.isBusiness === true) {
       // Apply 'then' validation
     } else {
       // Apply 'otherwise' validation
     }
   })
*/
const schema = z.object({
  isBusiness: z.boolean(),
  companyName: z.string().optional(),
}).superRefine((data, ctx) => {
  if (data.isBusiness && !data.companyName) {
    ctx.addIssue({
      code: z.ZodIssueCode.custom,
      message: 'Company name required for business accounts',
      path: ['companyName'],
    });
  }
});

.test() Custom Validations

Complex .test() calls may need adjustment for Zod's .refine() API.

// Yup
yup.string().test('custom', 'Invalid', (value) => customValidation(value))

// Zod
z.string().refine((value) => customValidation(value), 'Invalid')

Async Validations

Yup supports async validation in .test(). Zod requires explicit async handling.

// Yup
yup.string().test('unique', 'Already exists', async (value) => {
  return await checkUnique(value);
})

// Zod
z.string().refine(async (value) => {
  return await checkUnique(value);
}, 'Already exists')
// Note: Use .parseAsync() instead of .parse()

Related Packages

License

MIT