Skip to main content

Built and signed on GitHub Actions

unknownutil validator middleware for Hono

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a month ago (0.1.5)
function uValidator
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.

Examples

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}`,
 })
})

Type Parameters

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; }

Parameters

target: Target
schema: S
optional
hook: Hook<O, E, P>

Return Type

Add Package

deno add @ryoppippi/hono-unknownutil-validator

Import symbol

import { uValidator } from "@ryoppippi/hono-unknownutil-validator";

Add Package

npx jsr add @ryoppippi/hono-unknownutil-validator

Import symbol

import { uValidator } from "@ryoppippi/hono-unknownutil-validator";

Add Package

yarn dlx jsr add @ryoppippi/hono-unknownutil-validator

Import symbol

import { uValidator } from "@ryoppippi/hono-unknownutil-validator";

Add Package

pnpm dlx jsr add @ryoppippi/hono-unknownutil-validator

Import symbol

import { uValidator } from "@ryoppippi/hono-unknownutil-validator";

Add Package

bunx jsr add @ryoppippi/hono-unknownutil-validator

Import symbol

import { uValidator } from "@ryoppippi/hono-unknownutil-validator";