map
Creates a map schema.
const Schema = v.map<TKey, TValue, TMessage>(key, value, message);
Generics
TKeyextends BaseSchema<unknown, unknown, BaseIssue<unknown>>TValueextends BaseSchema<unknown, unknown, BaseIssue<unknown>>TMessageextends ErrorMessage<MapIssue> | undefined
Parameters
keyTKeyvalueTValuemessageTMessage
Explanation
With map you can validate the data type of the input and whether the entries matches key and value. If the input is not a map, you can use message to customize the error message.
Returns
SchemaMapSchema<TKey, TValue, TMessage>
Examples
The following examples show how map can be used.
String map schema
Schema to validate a map with string values.
const StringMapSchema = v.map(v.string(), v.string());
Object map schema
Schema to validate a map with object values.
const ObjectMapSchema = v.map(v.string(), v.object({ key: v.string() }));
Related
The following APIs can be combined with map.
Schemas
any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, intersect, lazy, literal, looseObject, looseTuple, 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, getDefault, getDefaults, getFallback, getFallbacks, is, message, parse, parser, pipe, safeParse, safeParser
Actions
check, brand, description, flavor, guard, maxSize, metadata, minSize, notSize, rawCheck, rawTransform, readonly, size, title, transform
Utils
entriesFromList, isOfKind, isOfType
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/map/