Spec-Zone.ru › Valibot

examples

Creates an examples metadata action.

const Action = v.examples<TInput, TExamples>(examples_);

Generics

  • TInput extends any
  • TExamples extends readonly TInput[]

Parameters

  • examples_ TExamples

Explanation

With examples you can provide examples for a schema. This can be useful when working with AI tools or for documentation purposes.

Returns

  • Action ExamplesAction<TInput, TExamples>

Examples

The following examples show how examples can be used.

String schema

Schema to validate a string with examples.

const StringSchema = v.pipe(v.string(), v.examples(['foo', 'bar', 'baz']));

Number schema

Schema to validate a number with examples.

const NumberSchema = v.pipe(v.number(), v.examples([1, 2, 3]));

Related

The following APIs can be combined with examples.

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

getExamples, pipe

Utils

isOfKind, isOfType

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

Spec-Zone.ru

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