@hono/typia-validator
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

Typia validator middleware for Hono

The validator middleware using Typia for Hono applications.

Usage

import typia, { tags } from 'typia'
import { typiaValidator } from '@hono/typia-validator'

interface Author {
    name: string
    age: number & tags.Type<'uint32'> & tags.Minimum<20> & tags.ExclusiveMaximum<100>
  }

  const validate = typia.createValidate<Author>()

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

Hook:

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

Author

Patryk Dwórznik https://github.com/dworznik

License

MIT

Dependencies (0)

    Dev Dependencies (4)

    Package Sidebar

    Install

    npm i @hono/typia-validator

    Weekly Downloads

    1,316

    Version

    0.0.5

    License

    MIT

    Unpacked Size

    4.47 kB

    Total Files

    5

    Last publish

    Collaborators

    • yusukebe