@kbml-tentacles/forms-valibot
v3.0.0
Published
Valibot validation adapter for @kbml-tentacles/forms.
Maintainers
Readme
@kbml-tentacles/forms-valibot
Valibot validation adapter for @kbml-tentacles/forms. Plug a Valibot schema into a field validator — issues with their full path flow through unchanged.
npm install valibot @kbml-tentacles/core @kbml-tentacles/forms @kbml-tentacles/forms-valibotQuick start
import * as v from "valibot";
import { createFormContract } from "@kbml-tentacles/forms";
import { valibot, valibotAsync } from "@kbml-tentacles/forms-valibot";
const contract = createFormContract()
.field("email", (f) =>
f<string>().default("").validate(valibot(v.pipe(v.string(), v.email("Invalid")))),
)
.field("username", (f) =>
f<string>().default("").validateAsync(
valibotAsync(
v.pipeAsync(
v.string(),
v.checkAsync(async (val) => await isAvailable(val), "Taken"),
),
),
),
);API
valibot(schema)— sync validator usingsafeParse. Each issue maps to{ path, message }.valibotAsync(schema)— async validator usingsafeParseAsyncfor schemas built withpipeAsync/checkAsync. Pair with.validateAsync(...)for debounce + cancellation.
Documentation
- How-to: use a schema validator
- Reference:
docs/reference/validators
Peer dependencies
valibot >=0.30@kbml-tentacles/core ^1.0.0@kbml-tentacles/forms ^1.0.0
License
MIT © Nikita Lumpov
