Spec-Zone.ru › Valibot

parserAsync

Returns a function that parses an unknown input based on a schema.

const parser = v.parserAsync<TSchema, TConfig>(schema, config);

Generics

  • TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
  • TConfig extends Config<InferIssue<TSchema>> | undefined

Parameters

  • schema TSchema
  • config TConfig

Returns

  • parser ParserAsync<TSchema, TConfig>

Examples

The following examples show how parserAsync can be used.

import { isEmailPresent } from '~/api';

try {
  const StoredEmailSchema = v.pipeAsync(
    v.string(),
    v.email(),
    v.checkAsync(isEmailPresent, 'The email is not in the database.')
  );
  const storedEmailParser = v.parserAsync(StoredEmailSchema);
  const storedEmail = await storedEmailParser('jane@example.com');

  // Handle errors if one occurs
} catch (error) {
  console.error(error);
}

Related

The following APIs can be combined with parserAsync.

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

Async

arrayAsync, customAsync, exactOptionalAsync, fallbackAsync, intersectAsync, lazyAsync, looseObjectAsync, looseTupleAsync, mapAsync, nonNullableAsync, nonNullishAsync, nonOptionalAsync, nullableAsync, nullishAsync, objectAsync, objectWithRestAsync, optionalAsync, partialAsync, pipeAsync, recordAsync, requiredAsync, setAsync, strictObjectAsync, strictTupleAsync, tupleAsync, tupleWithRestAsync, unionAsync, variantAsync

© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/parserAsync/

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API