npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

h3-valibot

v0.0.9

Published

🤖 Schema validation for h3 using Valibot

Downloads

134

Readme

h3-valibot

npm version npm downloads Github Actions CI License

Schema validation for h3 using Valibot 🤖

Install


# Using npm
npm install h3-valibot

# Using yarn
yarn add h3-valibot

Validation

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

// 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
  • useValidatedParams
  • useValidatedQuery
  • useSafeValidatedBody
  • 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.

Errors

h3-valibot throws an ValiError when the validation fails:

Example

{
  "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:

export default defineNuxtConfig({
  modules: [
    // ...
    'h3-valibot/nuxt',
  ],
})

License

Published under MIT - Made with ❤️ by Conner Bachmann