Spec-Zone.ru › Valibot

map

Creates a map schema.

const Schema = v.map<TKey, TValue, TMessage>(key, value, message);

Generics

  • TKey extends BaseSchema<unknown, unknown, BaseIssue<unknown>>
  • TValue extends BaseSchema<unknown, unknown, BaseIssue<unknown>>
  • TMessage extends ErrorMessage<MapIssue> | undefined

Parameters

  • key TKey
  • value TValue
  • message TMessage

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

  • Schema MapSchema<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/

Spec-Zone.ru

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