uValidator<S extends Schema,O extends OutputType<S>,Target extends keyof ValidationTargets,E extends Env,P extends string,V extends { in: [K in Target]: O; out: [K in Target]: O; } = { in: [K in Target]: O; out: [K in Target]: O; },>(target: Target,schema: S,hook?: Hook<O, E, P>,): MiddlewareHandler<E, P, V>
Create a validator middleware with unknownutil schema.
▶Example 1
Example 1
import { is } from '@core/unknownutil' import { Hono } from '@hono/hono' import { uValidator } from '@ryoppippi/hono-unknownutil-validator' const isAuthor = is.ObjectOf({ name: is.String, age: is.Number, }) type Author = U.PredicateType<typeof isAuthor> app.post('/author', uValidator('json', schema), (c) => { const data = c.req.valid('json') return c.json({ success: true, message: `${data.name} is ${data.age}`, }) })
MiddlewareHandler<E, P, V>