{"id":14155675,"url":"https://github.com/Intevel/h3-valibot","last_synced_at":"2025-08-06T01:31:59.962Z","repository":{"id":186378504,"uuid":"675084513","full_name":"Intevel/h3-valibot","owner":"Intevel","description":"🤖 Schema validation for h3 using Valibot ","archived":false,"fork":false,"pushed_at":"2024-10-17T21:19:36.000Z","size":168,"stargazers_count":60,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-05T07:48:00.967Z","etag":null,"topics":["h3","nuxt","schema","schemas","unjs","valibot","validation","zod"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Intevel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-05T18:09:43.000Z","updated_at":"2024-11-24T23:14:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"70bd2f3a-1f0e-43c9-9892-c06e6bd92faa","html_url":"https://github.com/Intevel/h3-valibot","commit_stats":{"total_commits":10,"total_committers":2,"mean_commits":5.0,"dds":"0.19999999999999996","last_synced_commit":"295121743199ab751da4c8053413accbb19d2ff4"},"previous_names":["intevel/h3-valibot"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Intevel%2Fh3-valibot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Intevel%2Fh3-valibot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Intevel%2Fh3-valibot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Intevel%2Fh3-valibot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Intevel","download_url":"https://codeload.github.com/Intevel/h3-valibot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228821409,"owners_count":17977168,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["h3","nuxt","schema","schemas","unjs","valibot","validation","zod"],"created_at":"2024-08-17T08:04:51.908Z","updated_at":"2025-08-06T01:31:59.951Z","avatar_url":"https://github.com/Intevel.png","language":"TypeScript","funding_links":[],"categories":["nuxt"],"sub_categories":[],"readme":"# h3-valibot\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![Github Actions CI][github-actions-ci-src]][github-actions-ci-href]\n[![License][license-src]][license-href]\n\nSchema validation for h3 using Valibot 🤖\n\n## Install\n\n```sh\n# Using npm\nnpm install h3-valibot\n\n# Using pnpm\npnpm install h3-valibot\n\n# Using bun\nbun add h3-valibot\n```\n\n## Validation\n\n```ts router.ts\nimport { useValidatedBody, v, vh } from 'h3-valibot'\n\nimport { createApp, createRouter, eventHandler } from 'h3';\nimport { email, minLength, string, objectAsync } from 'valibot';\n\nexport const app = createApp();\nconst LoginSchema = v.object({\n    email: vh.email,\n    password: v.pipe(v.string(), v.minLength(8)),\n });\n\nconst router = createRouter();\napp.use(router);\n\nrouter.post(\"/login\", eventHandler(async (event) =\u003e {\n    const body = await useValidatedBody(event, LoginSchema);\n    return body;\n  }),\n);\n```\n\n### Safe Validation\n\n```ts\n// same as above\n\nrouter.post(\"/login\", eventHandler(async (event) =\u003e {\n    const body = await useSafeValidatedBody(event, LoginSchema);\n\n    if (!body.success) // do something\n\n    return body.output;\n  }),\n);\n```\n\n## Utils available\n\n`h3-valibot` provides a series of utils and their safe variants (don't throw an h3 error):\n\n- `useValidatedBody`\n- `useValidatedInput`\n- `useValidatedParams`\n- `useValidatedQuery`\n- `useSafeValidatedBody`\n- `useSafeValidatedInput`\n- `useSafeValidatedParams`\n- `useSafeValidatedQuery`\n\nEach one accepts an h3 `event`, a valibot `schema` and optionally a parser `config`.\n\n### Helpers\n\nIt 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.\n\n- `boolAsString`\n- `checkboxAsString`\n- `dateAsString`\n- `intAsString`\n- `numAsString`\n- `email`\n- `uuid`\n\nFor more details or examples please refer to their JSdocs or [source code](/src/core/schemas.ts).\n\n## Errors\n\n`h3-valibot` throws an `ValiError` when the validation fails:\n\nExample\n```json\n{\n  \"statusCode\": 400,\n  \"statusMessage\": \"Bad Request\",\n  \"stack\": [],\n  \"data\": {\n    \"issues\": [\n      {\n        \"validation\": \"email\",\n        \"origin\": \"value\",\n        \"message\": \"Invalid email\",\n        \"input\": \"github@conner-bachmande\",\n        \"path\": [\n          {\n            \"schema\": \"object\",\n            \"input\": {\n              \"email\": \"github@conner-bachmande\",\n              \"password\": \"12345678\"\n            },\n            \"key\": \"email\",\n            \"value\": \"github@conner-bachmande\"\n          }\n        ],\n        \"reason\": \"string\"\n      }\n    ],\n    \"name\": \"ValiError\"\n  }\n}\n```\n\n## Nuxt auto-imports\n\nThis library supports Nuxt's auto-imports, just add it in your `nuxt.config.ts`:\n\n```ts\nexport default defineNuxtConfig({\n  modules: [\n    // ...\n    'h3-valibot/nuxt',\n  ],\n})\n```\n\n## License\n\nPublished under MIT - Made with ❤️ by Conner Bachmann\n\n\u003c!-- Badges --\u003e\n\n[npm-version-src]: https://img.shields.io/npm/v/h3-valibot/latest.svg\n[npm-version-href]: https://npmjs.com/package/h3-valibot\n[npm-downloads-src]: https://img.shields.io/npm/dt/h3-valibot.svg\n[npm-downloads-href]: https://npmjs.com/package/h3-valibot\n[github-actions-ci-src]: https://github.com/intevel/h3-valibot/actions/workflows/ci.yml/badge.svg\n[github-actions-ci-href]: https://github.com/intevel/h3-valibot/actions?query=workflow%3Aci\n[license-src]: https://img.shields.io/npm/l/h3-valibot.svg\n[license-href]: https://npmjs.com/package/h3-valibot\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIntevel%2Fh3-valibot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FIntevel%2Fh3-valibot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIntevel%2Fh3-valibot/lists"}