0.1.2 โข Published 5 months ago
@lucaconlaq/zod-to-code v0.1.2
Zod To Code
Generate JavaScript/TypeScript code from Zod schemas โ round-trip safe ๐
โจ 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
Type | Status |
---|---|
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 |