Spec-Zone.ru › Valibot

setAsync

Creates a set schema.

const Schema = v.setAsync<TValue, TMessage>(value, message);

Generics

  • TValue extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
  • TMessage extends ErrorMessage<SetIssue> | undefined

Parameters

  • value TValue
  • message TMessage

Explanation

With setAsync you can validate the data type of the input and whether the content matches value. If the input is not a set, you can use message to customize the error message.

Returns

  • Schema SetSchemaAsync<TValue, TMessage>

Examples

The following examples show how setAsync can be used.

Allowed IPs schema

Schema to validate a set of allowed IP addresses.

import { isIpAllowed } from '~/api';

const AllowedIPsSchema = v.setAsync(
  v.pipeAsync(
    v.string(),
    v.ip(),
    v.checkAsync(isIpAllowed, 'This IP address is not allowed.')
  )
);

Related

The following APIs can be combined with setAsync.

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, strictObject, strictTuple, string, symbol, tuple, tupleWithRest, undefined, undefinedable, union, unknown, variant, void

Methods

config, getDefault, getFallback

Actions

brand, check, description, flavor, guard, maxSize, metadata, minSize, notSize, rawCheck, rawTransform, readonly, size, title, transform

Utils

entriesFromList, isOfKind, isOfType

Async

arrayAsync, checkAsync, customAsync, exactOptionalAsync, fallbackAsync, getDefaultsAsync, getFallbacksAsync, intersectAsync, lazyAsync, looseObjectAsync, looseTupleAsync, mapAsync, nonNullableAsync, nonNullishAsync, nonOptionalAsync, nullableAsync, nullishAsync, objectAsync, objectWithRestAsync, optionalAsync, parseAsync, parserAsync, pipeAsync, rawCheckAsync, rawTransformAsync, recordAsync, safeParseAsync, safeParserAsync, strictObjectAsync, strictTupleAsync, transformAsync, tupleAsync, tupleWithRestAsync, unionAsync, variantAsync

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

Spec-Zone.ru

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