Minimal helper for extracting typed, validated values from Valibot schemas.
Cloudflare Workers, Hono, and other runtime environments benefit from explicit contracts and clear validation flows.
But valibot.safeParse() gives you nested boilerplate, and parsing logic often gets duplicated or abstracted too deeply.
valext embraces a simple idea:
const result = extract(schema).from(unknownValue, issues => console.warn(issues)) pnpm add @gambonny/valextimport { validator } from 'hono/validator'
import { extract } from '@gambonny/valext'
import { signupSchema } from './schemas'
app.post(
'/signup',
validator('json', async (body, c) => {
const { success, output } = extract(signupSchema).from(body, issues =>
c.var.logger.warn('validation failed', { issues }),
)
return success ? output : c.text('Invalid input')
}),
)Returns:
{
success: true;
output: T;
issues: undefined;
}or:
{
success: false;
output: undefined;
issues: ValibotFlattenedIssues;
}Exactly like valibot.safeParse(), but lets you pass a callback for flattened errors.
Exactly like valibot.parse(). Will throw if input is invalid.
- ✅
valextusesvalibot.safeParse()under the hood. - ✅ Errors are flattened with
valibot.flatten().nestedfor easy rendering/logging. - ✅ If you need raw nested issues, just use
valibot.safeParse()directly — you’re not locked in.
Reminder:
valextis not an abstraction layer — it’s a tool for making your intent clear at the point of use.