Skip to content

Commit 86fffbd

Browse files
committed
docs: update readme
1 parent 3617851 commit 86fffbd

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

Diff for: README.md

+40-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ yarn add h3-valibot
2323
```ts router.ts
2424
import { useValidatedBody, v } from 'h3-valibot'
2525

26-
import { createApp, createRouter, eventHandler } from "h3";
26+
import { createApp, createRouter, eventHandler } from 'h3';
2727
import { email, minLength, string, objectAsync } from 'valibot';
2828

2929
export const app = createApp();
@@ -42,11 +42,48 @@ router.post("/login", eventHandler(async (event) => {
4242
);
4343
```
4444

45+
### Safe Validation
46+
47+
```ts
48+
// same as above
49+
50+
router.post("/login", eventHandler(async (event) => {
51+
const body = await useSafeValidatedBody(event, LoginSchema);
52+
53+
if (!body.success) // do something
54+
55+
return body.output;
56+
}),
57+
);
58+
```
59+
60+
## Utils available
61+
62+
`h3-valibot` provides a series of utils, that each also comes in the `useSafeValidated*` variant for safe validation (doesn't throw an error):
63+
64+
- `useValidatedBody`
65+
- `useValidatedParams`
66+
- `useValidatedQuery`
67+
68+
Each one accepts an h3 `event`, a valibot `schema` and optionally a parser `config`.
69+
70+
### Helpers
71+
72+
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.
73+
74+
- `boolAsString`
75+
- `checkboxAsString`
76+
- `intAsString`
77+
- `numAsString`
78+
- `uuid`
79+
80+
For more details or examples please refer to their JSdocs or [source code](/src/core/schemas.ts).
81+
4582
## Errors
4683

47-
h3-valibot throws an `ValiError` when the validation fails:
84+
`h3-valibot` throws an `ValiError` when the validation fails:
4885

49-
Exampl
86+
Example
5087
```json
5188
{
5289
"statusCode": 400,

0 commit comments

Comments
 (0)