Skip to content

Commit

Permalink
use valibot to parse args in alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
yuheiy committed Oct 13, 2024
1 parent f550008 commit b797cd3
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/scripts/components/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ Alpine.data('example', (initialValue = 0) => {
// then `initialValue` is inferred as a Number value

/**
* For more complex type narrowing, consider using Superstruct:
* https://www.npmjs.com/package/superstruct
* For more complex type narrowing, consider using Valibot:
* https://valibot.dev/
*
* @example
* import { assert, number, object, string } from 'superstruct';
* const User = object({ id: number(), name: string() });
* const input: unknown = { id: 1, name: 'Taro' };
* assert(input, User);
* import * as v from 'valibot';
* const UserSchema = v.object({ id: v.number(), name: v.string() });
* const data: unknown = { id: 1, name: 'Taro' };
* v.assert(UserSchema, data);
* data; // { id: string, name: string }
*/

return {
Expand Down

0 comments on commit b797cd3

Please sign in to comment.