🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@hono/typebox-validator

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hono/typebox-validator

Validator middleware using TypeBox

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
57K
-18.08%
Maintainers
1
Weekly downloads
 
Created
Source

TypeBox validator middleware for Hono

codecov

Validator middleware using TypeBox for Hono applications. Use TypeBox or JSON Schema to validate incoming requests.

TypeBox

No Hook:

import { tbValidator } from '@hono/typebox-validator'
import Type from 'typebox'

const User = Type.Object({
  name: Type.String(),
  age: Type.Number(),
})

const route = app.post('/user', tbValidator('json', User), (c) => {
  const user = c.req.valid('json')
  return c.json({ success: true, message: `${user.name} is ${user.age}` })
})

Hook:

import { tbValidator } from '@hono/typebox-validator'
import Type from 'typebox'

const User = Type.Object({
  name: Type.String(),
  age: Type.Number(),
})

app.post(
  '/user',
  tbValidator('json', User, (result, c) => {
    if (!result.success) {
      return c.text('Invalid!', 400)
    }
  })
  //...
)

JSON Schema

JSON Schema validation and inference is supported.

import { tbValidator } from '@hono/typebox-validator'

const route = app.post(
  '/user',
  tbValidator('json', {
    type: 'object',
    required: ['name', 'age'],
    properties: {
      name: { type: 'string' },
      age: { type: 'number' },
    },
  }),
  (c) => {
    const user = c.req.valid('json')
    return c.json({ success: true, message: `${user.name} is ${user.age}` })
  }
)

Author

Curtis Larson https://github.com/curtislarson

License

MIT

FAQs

Package last updated on 19 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts