Something went wrong. Try again.
Extra schema for validating FormData on Zod & Zod mini 4+
Something went wrong. Try again.
Files
·
Copy SHA
·
Copy SHA
·
Copy SHA
·
Copy SHA
·
Copy SHA
- TypeScript 100%
README.md
@angelo/zfd #
Extra schema for validating FormData on Zod & Zod mini 4+
Bundles ~0.7kb uncompressed; ~0.4kb gzip / brotli
Usage #
Note
While the content of the library might be usable, this readme is still work in progress.
If you're using zod/v4/mini and want to validate FormData server-side (not in-browser):
import { z } from "zod/v4/mini";
import * as zf from "@angelo/zfd/mini-formdata";
// Describe the fields in the `FormData`
// like a normal object.
//
//`FormData` values can only be `string | File`.
const schema = zf.formData(
name: z.string().check(z.minLength(2)),
// Field `age` here will be a stringified number.
// Look into `numeric` in `@angelo/zfd/mini-dom`
// or use Zod's codecs
age: z.string(),
image: z.optional(z.file()),
);
Spec-compliance #
Schema exported from this libary may not perfectly comply with FormData's specification. More specifically:
FormData's specification allows for multiple fields with the same key. This library's schema will only use the latest / bottom-most entry in theFormData.
Development #
- Install dependencies:
pnpm install
- Run development mode:
pnpm dev
- Run the unit tests:
pnpm test
- Build the library:
pnpm build