examples
Creates an examples metadata action.
const Action = v.examples<TInput, TExamples>(examples_);
Generics
TInputextends anyTExamplesextends 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
ActionExamplesAction<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
Utils
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/examples/