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

unplugin-zod-jsdoc

v0.1.2

Published

Universal plugin for transforming JSDoc comments on Zod v4 schemas into runtime metadata

Readme

unplugin-zod-jsdoc

npm

Universal plugin for transforming JSDoc comments on Zod schemas into runtime metadata.

Features

  • 🔄 Universal: Works with Vite, Rollup, Rolldown, webpack, Rspack, esbuild, and Farm
  • 📝 Transforms JSDoc comments into Zod v4 .meta() calls
  • 🎯 TypeScript support
  • ⚡ Fast and efficient by using the oxc-toolchain
  • 🛠 Zero configuration required

[!IMPORTANT] This plugin only works with Zod >= 3.25.0 and < 4.0.0.

You need to import zod/v4 instead of zod to use this plugin.

Installation

npm install unplugin-zod-jsdoc --save-dev

Configuration

Build Tools
// vite.config.ts
import ZodJsdoc from "unplugin-zod-jsdoc/vite";

export default defineConfig({
  plugins: [ZodJsdoc()],
});

// rollup.config.js
import ZodJsdoc from "unplugin-zod-jsdoc/rollup";

export default {
  plugins: [ZodJsdoc()],
};

// rolldown.config.js
import ZodJsdoc from "unplugin-zod-jsdoc/rolldown";

export default {
  plugins: [ZodJsdoc()],
};

// webpack.config.js
module.exports = {
  /* ... */
  plugins: [require("unplugin-zod-jsdoc/webpack")()],
};

// rspack.config.js
module.exports = {
  /* ... */
  plugins: [require("unplugin-zod-jsdoc/rspack")()],
};

// esbuild.config.js
import { build } from "esbuild";
import ZodJsdoc from "unplugin-zod-jsdoc/esbuild";

build({
  plugins: [ZodJsdoc()],
});

// farm.config.ts
import ZodJsdoc from "unplugin-zod-jsdoc/farm";

export default defineConfig({
  plugins: [ZodJsdoc()],
});

Options

You can pass optional options to the plugin for further customization.

interface PluginOptions {
  /**
   * Enable in development mode.
   * Can improve performance by disabling the transformation in development.
   * @default true
   */
  enableInDev?: boolean;
}

Example

Input

/**
 * User's full name.
 * Second line in description.
 */
const nameSchema = z.string().min(1);

/**
 * User's email address
 */
const emailSchema = z.string().email();

const userSchema = z.object({
  /**
   * Unique identifier for the user
   */
  id: z.string().uuid(),
  name: nameSchema,
  email: emailSchema,
});

Output

/**
 * User's full name.
 * Second line in description.
 */
const nameSchema = z
  .string()
  .min(1)
  .meta({ description: `User's full name. Second line in description.` });

/**
 * User's email address
 */
const emailSchema = z
  .string()
  .email()
  .meta({ description: `User's email address` });

const userSchema = z.object({
  /**
   * Unique identifier for the user
   */
  id: z.string().uuid().meta({ description: `Unique identifier for the user` }),
  name: nameSchema,
  email: emailSchema,
});

As you can see, newlines are not preserved in the output.

JSON Schema

The plugin can also be used to add additional metadata specific for JSON Schema generation.

For this, the following jsdoc-tags are supported:

  • @example
  • @id
  • @title
  • @deprecated

Example:

/**
 * An object representing a logged-in user
 * @id User
 * @title User Schema
 * @example { id: '123-456 }
 * @deprecated Superseded by User2
 */
const userSchema = z.object({
  /** Unique identifier for the user */
  id: z.string(),
});

const dataSchema = z.object({
  user1: userSchema,
  user2: userSchema,
});

const jsonSchema = z.toJSONSchema(dataSchema, { target: 'draft-7', reused: 'ref' });

console.log(jsonSchema); // =>
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "user1": { "$ref": "#/definitions/User" },
    "user2": { "$ref": "#/definitions/User" }
  },
  "required": ["user1", "user2"],
  "additionalProperties": false,
  "definitions": {
    "User": {
      "description": "An object representing a logged-in user",
      "title": "User Schema",
      "examples": ["{ id: '123-456' }"],
      "id": "User",
      "deprecated": true,
      "type": "object",
      "properties": {
        "id": {
          "description": "The unique identifier for the user",
          "type": "string"
        },
      },
      "required": ["id"],
      "additionalProperties": false
    }
  }
}

How it works

The plugin:

  1. Parses TypeScript/JavaScript files looking for Zod schemas
  2. Finds JSDoc comments that precede zod-calls
  3. Transforms comments into .meta({ description: "..." }) calls
  4. Preserves existing .meta() or .description() calls (doesn't override them)

License

MIT License © 2025