setAsync
Creates a set schema.
const Schema = v.setAsync<TValue, TMessage>(value, message);
Generics
TValueextends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>TMessageextends ErrorMessage<SetIssue> | undefined
Parameters
valueTValuemessageTMessage
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
SchemaSetSchemaAsync<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/