zod-compiler 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -0
- package/dist/index.d.ts +670 -0
- package/dist/index.js +2550 -0
- package/dist/index.mjs +2536 -0
- package/dist/standalone.d.ts +294 -0
- package/dist/standalone.js +523 -0
- package/dist/standalone.mjs +514 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>⚡ <code>zod-compiler</code> ⚡</h1>
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
### Speed up your Zod schemas
|
|
6
|
+
```ts
|
|
7
|
+
import z from 'zod';
|
|
8
|
+
|
|
9
|
+
const schema = z.object({
|
|
10
|
+
title: z.string().min(3).max(64),
|
|
11
|
+
tags: z.array(z.string()).optional(),
|
|
12
|
+
...
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// ❌ slow!
|
|
16
|
+
const { success, data, error } = schema.safeParse(input);
|
|
17
|
+
|
|
18
|
+
// 🚀
|
|
19
|
+
import zc from 'zod-compiler';
|
|
20
|
+
const compiledSchema = zc.compile(schema);
|
|
21
|
+
|
|
22
|
+
const { success, data, error } = compiledSchema.safeParse(input);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Export your Zod schemas to TypeScript types
|
|
26
|
+
```ts
|
|
27
|
+
console.log(zc.types(schema));
|
|
28
|
+
// export type Schema = {
|
|
29
|
+
// title: string;
|
|
30
|
+
// tags?: string[];
|
|
31
|
+
// ...
|
|
32
|
+
// };
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
```shell
|
|
37
|
+
$ npm i --save zod-compiler
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Requires **Zod 3.x** and **TypeScript 5.x** to be installed.
|