KO
|
EN
gitlite — search
Search
#typescript
#ai-agents
#ai
#dsh-plugin
#deepseek-harness
#open-source
#claude-code
#codex
#cli
#developer-tools
#react
#windows
h3-valibot
★ 78
Open GitHub ↗
🤖 Schema validation for h3 using Valibot
Download README (.md)
Explore Similar Repositories
goji
:
Commitizen-like Emoji Commit Tool written in Go and AI commit message generator (think cz-emoji and other commitizen adapters but in go) 🚀
react-canvas-editor
:
React version of canvas editor
YyFlight.ToDoList
:
✍【.NET8 MongoDB 待办清单系统】.NET8 MongoDB从入门到实战基础教程,该项目后端使用的是.NET8、前端页面使用Blazor、使用MongoDB存储数据,更多相关内容大家可以看目录中的MongoDB从入门到实战的相关教程。该系列教程可作为.NET Core入门项目进行学习,感兴趣的小伙伴可以关注博主和我一起学习共同进步。
langchainjs-quickstart-demo
:
Build a generative AI application using LangChain.js, from local to Azure
resilience4j-spring-boot3-demo
:
A Spring Boot 3 demo which shows how to use the Resilience4j Spring Boot 3 Starter
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
h3-valibot
?
Download (.md)
# h3-valibot [![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![Github Actions CI][github-actions-ci-src]][github-actions-ci-href] [![License][license-src]][license-href] Schema validation for h3 using Valibot 🤖 ## Install ```sh # Using npm npm install h3-valibot # Using pnpm pnpm install h3-valibot # Using bun bun add h3-valibot ``` ## Validation ```ts router.ts import { useValidatedBody, v, vh } from 'h3-valibot' import { createApp, createRouter, eventHandler } from 'h3'; import { email, minLength, string, objectAsync } from 'valibot'; export const app = createApp(); const LoginSchema = v.object({ email: vh.email, password: v.pipe(v.string(), v.minLength(8)), }); const router = createRouter(); app.use(router); router.post("/login", eventHandler(async (event) => { const body = await useValidatedBody(event, LoginSchema); return body; }), ); ``` ### Safe Validation ```ts // same as above router.post("/login", eventHandler(async (event) => { const body = await useSafeValidatedBody(event, LoginSchema); if (!body.success) // do something return body.output; }), ); ``` ## Utils available `h3-valibot` provides a series of utils and their safe variants (don't throw an h3 error): - `useValidatedBody` - `useValidatedInput` - `useValidatedParams` - `useValidatedQuery` - `useSafeValidatedBody` - `useSafeValidatedInput` - `useSafeValidatedParams` - `useSafeValidatedQuery` Each one accepts an h3 `event`, a valibot `schema` and optionally a parser `config`. ### Helpers It also provides a set of helpers via `vh` object, mainly related to string validation, particularly useful during the prototyping phase of any project. For production use we still suggest to create dedicated schemas with project-related error messages and fallbacks. - `boolAsString` - `checkboxAsString` - `dateAsString` - `intAsString` - `numAsString` - `email` - `uuid` For more details or examples please refer to their JSdocs or [source code](/src/core/schemas.ts). ## Errors `h3-valibot` throws an `ValiError` when the validation fails: Example ```json { "statusCode": 400, "statusMessage": "Bad Request", "stack": [], "data": { "issues": [ { "validation": "email", "origin": "value", "message": "Invalid email", "input": "github@conner-bachmande", "path": [ { "schema": "object", "input": { "email": "github@conner-bachmande", "password": "12345678" }, "key": "email", "value": "github@conner-bachmande" } ], "reason": "string" } ], "name": "ValiError" } } ``` ## Nuxt auto-imports This library supports Nuxt's auto-imports, just add it in your `nuxt.config.ts`: ```ts export default defineNuxtConfig({ modules: [ // ... 'h3-valibot/nuxt', ], }) ``` ## License Published under MIT - Made with ❤️ by Conner Bachmann <!-- Badges --> [npm-version-src]: https://img.shields.io/npm/v/h3-valibot/latest.svg [npm-version-href]: https://npmjs.com/package/h3-valibot [npm-downloads-src]: https://img.shields.io/npm/dt/h3-valibot.svg [npm-downloads-href]: https://npmjs.com/package/h3-valibot [github-actions-ci-src]: https://github.com/intevel/h3-valibot/actions/workflows/ci.yml/badge.svg [github-actions-ci-href]: https://github.com/intevel/h3-valibot/actions?query=workflow%3Aci [license-src]: https://img.shields.io/npm/l/h3-valibot.svg [license-href]: https://npmjs.com/package/h3-valibot