0.1.2 โ€ข Published 5 months ago

@lucaconlaq/zod-to-code v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Zod To Code

Logo

Generate JavaScript/TypeScript code from Zod schemas โ€” round-trip safe ๐ŸŒ€

npm biome vitest


โœจ What does it do?

  • โœ๏ธ The library does one thing and tries to do it well. It enables code generation from zod schemas.
  • ๐Ÿงช It is fully tested.
  • ๐Ÿงฑ It supports most Zod types (see Supported Types).

๐Ÿš€ Installation

npm i @lucaconlaq/zod-to-code

๐Ÿ“ฆ Usage

import { z } from "zod";
import { zodToCode } from "@lucaconlaq/zod-to-code";

const schema = z.object({
  username: z.string(),
});

const code = zodToCode(schema);
console.log(code);

Outputs:

z.object({
  username: z.string()
})

๐Ÿงฉ Supported Types

TypeStatus
stringโœ… Supported
numberโœ… Supported
booleanโœ… Supported
dateโœ… Supported
bigintโœ… Supported
symbolโœ… Supported
voidโœ… Supported
neverโœ… Supported
unknownโœ… Supported
anyโœ… Supported
objectโœ… Supported
arrayโœ… Supported
tupleโœ… Supported
recordโœ… Supported
mapโœ… Supported
setโœ… Supported
functionโœ… Supported
lazyโœ… Supported
literalโœ… Supported
enumโœ… Supported
nativeEnumโœ… Supported
unionโœ… Supported
intersectionโœ… Supported
orโœ… Supported
andโœ… Supported
.optional()โœ… Supported
.nullable()โœ… Supported
.nullish()โœ… Supported
.default()โœ… Supported
.catch()โœ… Supported
.describe()โœ… Supported
.readonly()โœ… Supported
.brand()โœ… Supported
.int()โœ… Supported
.email()โœ… Supported
.uuid()โœ… Supported
.regex()โœ… Supported
.url()โœ… Supported
.ip()โœ… Supported
.datetime()โœ… Supported
.emoji()โœ… Supported
.refine()โŒ Not Supported
.superRefine()โŒ Not Supported
.transform()โŒ Not Supported
.pipe()โŒ Not Supported
z.custom() (e.g. Buffer)โŒ Not Supported
Effects with unsupported typeโŒ Not Supported
Unknown typeName (mock types)โŒ Not Supported
Non-serializable transformsโŒ Not Supported
0.1.2

5 months ago

0.1.1

5 months ago

0.1.0

5 months ago