Public
Script
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

Zod works great out-of-the-box with Val Town: just import it as npm:zod and parse something! Here's an example below.

Tips

  • Right now it's not possible to create a script val that immediately returns a Zod parser because its parsers can't be serialized. It's best to either expose a method that returns a parser, or to create and use the parser in the same val.
1
2
3
4
5
6
export const zodExample = (async () => {
const z = await import("npm:zod");
await setTimeout(() => {}, 100);
const x = z.object({ test: z.string() }); // type .object after z
return x.safeParse({ test: "bar" });
})();
October 23, 2023