npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

babel-plugin-zod-hoist

1.0.3

@gajus

npmHomeRepoSnykSocket
Downloads:57
$ npm install babel-plugin-zod-hoist
DailyWeeklyMonthlyYearly

Babel Plugin to Hoist Zod Schemas

Hoists Zod schema definitions to the top of the file.

This:

function getSchema() {
  return z.object({ name: z.string() });
}

Becomes this:

const _schema_94b7f = z.object({
  name: z.string(),
});
function getSchema() {
  return _schema_94b7f;
}

Motivation

Initializing Zod schemas is expensive.

By hoisting the schema to the top of the file, we can avoid re-initializing the schema every time we use it.

Why Use This?

  • Performance Boost: Prevents unnecessary re-initialization.
  • Zero Mental Overhead: Write normal Zod code - the hoisting happens automatically.
  • No Code Changes Required: Works with your existing codebase without modifications.

Installation

npm install --save-dev babel-plugin-zod-hoist

Usage

Add the plugin to your Babel configuration:

{
  "plugins": ["babel-plugin-zod-hoist"]
}