parser
Returns a function that parses an unknown input based on a schema.
const parser = v.parser<TSchema, TConfig>(schema, config);
Generics
TSchemaextends BaseSchema<unknown, unknown, BaseIssue<unknown>>TConfigextends Config<InferIssue<TSchema>> | undefined
Parameters
schemaTSchemaconfigTConfig
Returns
parserParser<TSchema, TConfig>
Example
The following example show how parser can be used.
try {
const EmailSchema = v.pipe(v.string(), v.email());
const emailParser = v.parser(EmailSchema);
const email = emailParser('jane@example.com');
// Handle errors if one occurs
} catch (error) {
console.log(error);
}
Related
The following APIs can be combined with parser.
Schemas
any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, intersect, lazy, literal, looseObject, looseTuple, map, nan, never, nonNullable, nonNullish, nonOptional, null, nullable, nullish, number, object, objectWithRest, optional, picklist, promise, record, set, strictObject, strictTuple, string, symbol, tuple, tupleWithRest, undefined, undefinedable, union, unknown, variant, void
Methods
assert, config, fallback, flatten, keyof, message, omit, partial, pick, pipe, required, summarize, unwrap
Utils
getDotPath, isValiError, ValiError
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/parser/