@bemedev/valibot-addons
v0.1.0
Published
//TODO
Downloads
22
Readme
@bemedev/valibot-addons
Valibot schema utilities — sync, safe, strict, tuple and async parse variants from a single create() call.
Installation
pnpm add @bemedev/valibot-addons valibotUsage
create(schema)
Wraps a Valibot schema and returns a function with multiple parse variants:
import * as v from 'valibot';
import { create } from '@bemedev/valibot-addons';
const parseString = create(v.string());
// Sync — throws on invalid input
parseString('hello'); // => 'hello'
// .input — identity (pass-through, typed)
parseString.input('hello'); // => 'hello'
// .safe — never throws, returns SafeParseResult
parseString.safe('hello'); // => { success: true, output: 'hello' }
parseString.safe(42); // => { success: false, issues: [...] }
// .strict — same as sync but accepts unknown input type
parseString.strict('hello'); // => 'hello'
// .typed — alias of sync with explicit typed signature
parseString.typed('hello'); // => 'hello'
// .tuple — parse multiple values at once
parseString.tuple('hello', 'world'); // => ['hello', 'world']
parseString.tuple.withConfig({ abortEarly: true }, 'hello'); // => ['hello']
// .async — async variants mirroring all sync methods
await parseString.async('hello'); // => 'hello'
await parseString.async.safe('hello'); // => { success: true, … }
await parseString.async.strict('hello'); // => 'hello'
await parseString.async.typed('hello'); // => 'hello'
const [a, b] = parseString.async.tuple('hello', 'world');
await a; // => 'hello'
await b; // => 'world'
parseString.async.tuple.withConfig({}, 'hello', 'world');Licence
MIT
CHANGE_LOG
Read CHANGE_LOG.md for more details about the changes.
Auteur
chlbri ([email protected])
