@typed-web/form-valibot
v0.1.1
Published
Valibot error adapters for form handling
Downloads
92
Maintainers
Readme
@typed-web/form-valibot
Convert Valibot validation issues to flat or nested error objects.
Installation
npm install @typed-web/form-valibot valibotExports
valibotIssuesToFlatObject- Convert to flat error objectvalibotIssuesToNestedObject- Convert to nested error object
Usage
import * as v from "valibot";
import { valibotIssuesToFlatObject } from "@typed-web/form-valibot";
const schema = v.object({
name: v.string(),
email: v.pipe(v.string(), v.email()),
});
const result = v.safeParse(schema, { name: "", email: "invalid" });
if (!result.success) {
const flat = valibotIssuesToFlatObject(result.issues);
// { "name": "Required", "email": "Invalid email" }
}License
MIT
