# Valibot
The modular and type safe schema library for validating structural data.
## Schemas
### any
Creates an any schema.
> This schema function exists only for completeness and is not recommended in practice. Instead, `unknown` should be used to accept unknown data.
```ts
const Schema = v.any();
```
#### Returns
- `Schema`
#### Related
The following APIs can be combined with `any`.
##### Schemas
##### Methods
##### Actions
##### Utils
### array
Creates an array schema.
```ts
const Schema = v.array(item, message);
```
#### Generics
- `TItem`
- `TMessage`
#### Parameters
- `item`
- `message`
##### Explanation
With `array` you can validate the data type of the input. If the input is not an array, you can use `message` to customize the error message.
> If your array has a fixed length, consider using `tuple` for a more precise typing.
#### Returns
- `Schema`
#### Examples
The following examples show how `array` can be used.
##### String array schema
Schema to validate an array of strings.
```ts
const StringArraySchema = v.array(v.string(), 'An array is required.');
```
##### Object array schema
Schema to validate an array of objects.
```ts
const ObjectArraySchema = v.array(v.object({ key: v.string() }));
```
##### Validate length
Schema that validates the length of an array.
```ts
const ArrayLengthSchema = v.pipe(
v.array(v.number()),
v.minLength(1),
v.maxLength(3)
);
```
##### Validate content
Schema that validates the content of an array.
```ts
const ArrayContentSchema = v.pipe(
v.array(v.string()),
v.includes('foo'),
v.excludes('bar')
);
```
#### Related
The following APIs can be combined with `array`.
##### Schemas
##### Methods
##### Actions
##### Utils
### bigint
Creates a bigint schema.
```ts
const Schema = v.bigint(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `bigint` you can validate the data type of the input. If the input is not a bigint, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `bigint` can be used.
##### Force minimum
Schema that forces a minimum bigint value.
```ts
const MinBigintSchema = v.pipe(v.bigint(), v.toMinValue(10n));
```
##### Validate maximum
Schema that validates a maximum bigint value.
```ts
const MaxBigintSchema = v.pipe(v.bigint(), v.maxValue(999n));
```
#### Related
The following APIs can be combined with `bigint`.
##### Schemas
##### Methods
##### Actions
##### Utils
### blob
Creates a blob schema.
> The `Blob` class is not available by default in Node.js v16 and below.
```ts
const Schema = v.blob(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `blob` you can validate the data type of the input. If the input is not a blob, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `blob` can be used.
##### Image schema
Schema to validate an image.
```ts
const ImageSchema = v.pipe(
v.blob('Please select an image file.'),
v.mimeType(['image/jpeg', 'image/png'], 'Please select a JPEG or PNG file.'),
v.maxSize(1024 * 1024 * 10, 'Please select a file smaller than 10 MB.')
);
```
#### Related
The following APIs can be combined with `blob`.
##### Schemas
##### Methods
##### Actions
##### Utils
### boolean
Creates a boolean schema.
```ts
const Schema = v.boolean(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `boolean` you can validate the data type of the input. If the input is not a boolean, you can use `message` to customize the error message.
> Instead of using a `pipe` to force `true` or `false` as a value, in most cases it makes more sense to use `literal` for better typing.
#### Returns
- `Schema`
#### Examples
The following examples show how `boolean` can be used.
##### Custom message
Boolean schema with a custom error message.
```ts
const BooleanSchema = v.boolean('A boolean is required');
```
#### Related
The following APIs can be combined with `boolean`.
##### Schemas
##### Methods
##### Actions
##### Utils
### custom
Creates a custom schema.
> This schema function allows you to define a schema that matches a value based on a custom function. Use it whenever you need to define a schema that cannot be expressed using any of the other schema functions.
```ts
const Schema = v.custom(check, message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `check`
- `message`
##### Explanation
With `custom` you can validate the data type of the input. If the input does not match the validation of `check`, you can use `message` to customize the error message.
> Make sure that the validation in `check` matches the data type of `TInput`.
#### Returns
- `Schema`
#### Examples
The following examples show how `custom` can be used.
##### Pixel string schema
Schema to validate a pixel string.
```ts
const PixelStringSchema = v.custom<`${number}px`>((input) =>
typeof input === 'string' ? /^\d+px$/.test(input) : false
);
```
#### Related
The following APIs can be combined with `custom`.
##### Schemas
##### Methods
##### Actions
##### Utils
### date
Creates a date schema.
```ts
const Schema = v.date(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `date` you can validate the data type of the input. If the input is not a date, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `date` can be used.
##### Force minimum
Schema that forces a minimum date of today.
```ts
const MinDateSchema = v.pipe(v.date(), v.toMinValue(new Date()));
```
##### Validate range
Schema that validates a date in a range.
```ts
const DateRangeSchema = v.pipe(
v.date(),
v.minValue(new Date(2019, 0, 1)),
v.maxValue(new Date(2020, 0, 1))
);
```
#### Related
The following APIs can be combined with `date`.
##### Schemas
##### Methods
##### Actions
##### Utils
### enum
Creates an enum schema.
```ts
const Schema = v.enum(enum, message);
```
#### Generics
- `TEnum`
- `TMessage`
#### Parameters
- `enum` {/* prettier-ignore */}
- `message`
##### Explanation
With `enum` you can validate that the input corresponds to an enum option. If the input is invalid, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `enum` can be used.
##### Direction enum
Schema to validate a direction enum option.
```ts
enum Direction {
Left,
Right,
}
const DirectionSchema = v.enum(Direction, 'Invalid direction');
```
#### Related
The following APIs can be combined with `enum`.
##### Schemas
##### Methods
##### Actions
##### Utils
### exactOptional
Creates an exact optional schema.
```ts
const Schema = v.exactOptional(wrapped, default_);
```
#### Generics
- `TWrapped`
- `TDefault`
#### Parameters
- `wrapped`
- `default_` {/* prettier-ignore */}
##### Explanation
With `exactOptional` the validation of your schema will pass missing object entries, and if you specify a `default_` input value, the schema will use it if the object entry is missing. For this reason, the output type may differ from the input type of the schema.
> The difference to `optional` is that this schema function follows the implementation of TypeScript's [`exactOptionalPropertyTypes` configuration](https://www.typescriptlang.org/tsconfig/#exactOptionalPropertyTypes) and only allows missing but not undefined object entries.
#### Returns
- `Schema`
#### Examples
The following examples show how `exactOptional` can be used.
##### Exact optional object entries
Object schema with exact optional entries.
> By using a function as the `default_` parameter, the schema will return a new [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance each time the input is `undefined`.
```ts
const OptionalEntrySchema = v.object({
key1: v.exactOptional(v.string()),
key2: v.exactOptional(v.string(), "I'm the default!"),
key3: v.exactOptional(v.date(), () => new Date()),
});
```
##### Unwrap exact optional schema
Use `unwrap` to undo the effect of `exactOptional`.
```ts
const OptionalNumberSchema = v.exactOptional(v.number());
const NumberSchema = v.unwrap(OptionalNumberSchema);
```
#### Related
The following APIs can be combined with `exactOptional`.
##### Schemas
##### Methods
##### Actions
##### Utils
### file
Creates a file schema.
> The `File` class is not available by default in Node.js v18 and below.
```ts
const Schema = v.file(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `file` you can validate the data type of the input. If the input is not a file, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `file` can be used.
##### Image schema
Schema to validate an image.
```ts
const ImageSchema = v.pipe(
v.file('Please select an image file.'),
v.mimeType(['image/jpeg', 'image/png'], 'Please select a JPEG or PNG file.'),
v.maxSize(1024 * 1024 * 10, 'Please select a file smaller than 10 MB.')
);
```
#### Related
The following APIs can be combined with `file`.
##### Schemas
##### Methods
##### Actions
##### Utils
### function
Creates a function schema.
```ts
const Schema = v.function(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `function` you can validate the data type of the input. If the input is not a function, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Related
The following APIs can be combined with `function`.
##### Schemas
##### Methods
##### Actions
##### Utils
### instance
Creates an instance schema.
```ts
const Schema = v.instance(class_, message);
```
#### Generics
- `TClass`
- `TMessage`
#### Parameters
- `class_` {/* prettier-ignore */}
- `message`
##### Explanation
With `instance` you can validate the data type of the input. If the input is not an instance of the specified `class_`, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `instance` can be used.
##### Error schema
Schema to validate an `Error` instance.
```ts
const ErrorSchema = v.instance(Error, 'Error instance required.');
```
##### File schema
Schema to validate an `File` instance.
```ts
const FileSchema = v.pipe(
v.instance(File),
v.mimeType(['image/jpeg', 'image/png']),
v.maxSize(1024 * 1024 * 10)
);
```
#### Related
The following APIs can be combined with `instance`.
##### Schemas
##### Methods
##### Actions
##### Utils
### intersect
Creates an intersect schema.
> I recommend to read the intersections guide before using this schema function.
```ts
const Schema = v.intersect(options, message);
```
#### Generics
- `TOptions`
- `TMessage`
#### Parameters
- `options`
- `message`
##### Explanation
With `intersect` you can validate if the input matches each of the given `options`. If the output of the intersection cannot be successfully merged, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `intersect` can be used.
##### Object intersection
Schema that combines two object schemas.
```ts
const ObjectSchema = v.intersect([
v.object({ foo: v.string() }),
v.object({ bar: v.number() }),
]);
```
#### Related
The following APIs can be combined with `intersect`.
##### Schemas
##### Methods
##### Actions
##### Utils
### lazy
Creates a lazy schema.
```ts
const Schema = v.lazy(getter);
```
#### Generics
- `TWrapped`
#### Parameters
- `getter`
##### Explanation
The `getter` function is called lazily to retrieve the schema. This is necessary to be able to access the input through the first argument of the `getter` function and to avoid a circular dependency for recursive schemas.
> Due to a TypeScript limitation, the input and output types of recursive schemas cannot be inferred automatically. Therefore, you must explicitly specify these types using `GenericSchema`. Please see the examples below.
#### Returns
- `Schema`
#### Examples
The following examples show how `lazy` can be used.
##### Binary tree schema
Recursive schema to validate a binary tree.
```ts
type BinaryTree = {
element: string;
left: BinaryTree | null;
right: BinaryTree | null;
};
const BinaryTreeSchema: v.GenericSchema = v.object({
element: v.string(),
left: v.nullable(v.lazy(() => BinaryTreeSchema)),
right: v.nullable(v.lazy(() => BinaryTreeSchema)),
});
```
##### JSON data schema
Schema to validate all possible `JSON` values.
```ts
import * as v from 'valibot';
type JsonData =
| string
| number
| boolean
| null
| { [key: string]: JsonData }
| JsonData[];
const JsonSchema: v.GenericSchema = v.lazy(() =>
v.union([
v.string(),
v.number(),
v.boolean(),
v.null(),
v.record(v.string(), JsonSchema),
v.array(JsonSchema),
])
);
```
##### Lazy union schema
Schema to validate a discriminated union of objects.
> In most cases, `union` and `variant` are the better choices for creating such a schema. I recommend using `lazy` only in special cases.
```ts
const LazyUnionSchema = v.lazy((input) => {
if (input && typeof input === 'object' && 'type' in input) {
switch (input.type) {
case 'email':
return v.object({
type: v.literal('email'),
email: v.pipe(v.string(), v.email()),
});
case 'url':
return v.object({
type: v.literal('url'),
url: v.pipe(v.string(), v.url()),
});
case 'date':
return v.object({
type: v.literal('date'),
date: v.pipe(v.string(), v.isoDate()),
});
}
}
return v.never();
});
```
#### Related
The following APIs can be combined with `lazy`.
##### Schemas
##### Methods
##### Actions
##### Utils
### literal
Creates a literal schema.
```ts
const Schema = v.literal(literal, message);
```
#### Generics
- `TLiteral`
- `TMessage`
#### Parameters
- `literal`
- `message`
##### Explanation
With `literal` you can validate that the input matches a specified value. If the input is invalid, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `literal` can be used.
##### String literal
Schema to validate a string literal.
```ts
const StringLiteralSchema = v.literal('foo');
```
##### Number literal
Schema to validate a number literal.
```ts
const NumberLiteralSchema = v.literal(26);
```
##### Boolean literal
Schema to validate a boolean literal.
```ts
const BooleanLiteralSchema = v.literal(true);
```
#### Related
The following APIs can be combined with `literal`.
##### Schemas
##### Methods
##### Actions
##### Utils
### looseObject
Creates a loose object schema.
```ts
const Schema = v.looseObject(entries, message);
```
#### Generics
- `TEntries`
- `TMessage`
#### Parameters
- `entries`
- `message`
##### Explanation
With `looseObject` you can validate the data type of the input and whether the content matches `entries`. If the input is not an object, you can use `message` to customize the error message.
> The difference to `object` is that this schema includes any unknown entries in the output. In addition, this schema filters certain entries from the unknown entries for security reasons.
#### Returns
- `Schema`
#### Examples
The following examples show how `looseObject` can be used. Please see the object guide for more examples and explanations.
##### Simple object schema
Schema to validate a loose object with two specific keys.
```ts
const SimpleObjectSchema = v.looseObject({
key1: v.string(),
key2: v.number(),
});
```
##### Merge several objects
Schema that merges the entries of two object schemas.
```ts
const MergedObjectSchema = v.looseObject({
...ObjectSchema1.entries,
...ObjectSchema2.entries,
});
```
##### Mark keys as optional
Schema to validate an object with partial entries.
```ts
const PartialObjectSchema = v.partial(
v.looseObject({
key1: v.string(),
key2: v.number(),
})
);
```
##### Object with selected entries
Schema to validate only selected entries of a loose object.
```ts
const PickObjectSchema = v.pick(
v.looseObject({
key1: v.string(),
key2: v.number(),
key3: v.boolean(),
}),
['key1', 'key3']
);
```
#### Related
The following APIs can be combined with `looseObject`.
##### Schemas
##### Methods
##### Actions
##### Utils
### looseTuple
Creates a loose tuple schema.
```ts
const Schema = v.looseTuple(items, message);
```
#### Generics
- `TItems`
- `TMessage`
#### Parameters
- `items`
- `message`
##### Explanation
With `looseTuple` you can validate the data type of the input and whether the content matches `items`. If the input is not an array, you can use `message` to customize the error message.
> The difference to `tuple` is that this schema does include unknown items into the output.
#### Returns
- `Schema`
#### Examples
The following examples show how `looseTuple` can be used. Please see the arrays guide for more examples and explanations.
##### Simple tuple schema
Schema to validate a loose tuple with two specific items.
```ts
const SimpleTupleSchema = v.looseTuple([v.string(), v.number()]);
```
#### Related
The following APIs can be combined with `looseTuple`.
##### Schemas
##### Methods
##### Actions
##### Utils
### map
Creates a map schema.
```ts
const Schema = v.map(key, value, message);
```
#### Generics
- `TKey`
- `TValue`
- `TMessage`
#### Parameters
- `key`
- `value`
- `message`
##### 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`
#### Examples
The following examples show how `map` can be used.
##### String map schema
Schema to validate a map with string values.
```ts
const StringMapSchema = v.map(v.string(), v.string());
```
##### Object map schema
Schema to validate a map with object values.
```ts
const ObjectMapSchema = v.map(v.string(), v.object({ key: v.string() }));
```
#### Related
The following APIs can be combined with `map`.
##### Schemas
##### Methods
##### Actions
##### Utils
### nan
Creates a NaN schema.
```ts
const Schema = v.nan(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `nan` you can validate the data type of the input and if it is not `NaN`, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Related
The following APIs can be combined with `nan`.
##### Schemas
##### Methods
##### Actions
##### Utils
### never
Creates a never schema.
```ts
const Schema = v.never(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
When validated, `never` always returns an issue. You can use `message` to customize the error message.
#### Returns
- `Schema`
#### Related
The following APIs can be combined with `never`.
##### Schemas
##### Methods
##### Utils
### nonNullable
Creates a non nullable schema.
> This schema function can be used to override the behavior of `nullable`.
```ts
const Schema = v.nonNullable(wrapped, message);
```
#### Generics
- `TWrapped`
- `TMessage`
#### Parameters
- `wrapped`
- `message`
##### Explanation
With `nonNullable` the validation of your schema will not pass `null` inputs. If the input is `null`, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `nonNullable` can be used.
##### Non nullable string
Schema that does not accept `null`.
```ts
const NonNullableStringSchema = v.nonNullable(v.nullable(v.string()));
```
##### Unwrap non nullable
Use `unwrap` to undo the effect of `nonNullable`.
```ts
const NonNullableNumberSchema = v.nonNullable(v.nullable(v.number()));
const NullableNumberSchema = v.unwrap(NonNullableNumberSchema);
```
#### Related
The following APIs can be combined with `nonNullable`.
##### Schemas
##### Methods
##### Actions
##### Utils
### nonNullish
Creates a non nullish schema.
> This schema function can be used to override the behavior of `nullish`.
```ts
const Schema = v.nonNullish(wrapped, message);
```
#### Generics
- `TWrapped`
- `TMessage`
#### Parameters
- `wrapped`
- `message`
##### Explanation
With `nonNullish` the validation of your schema will not pass `null` and `undefined` inputs. If the input is `null` or `undefined`, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `nonNullish` can be used.
##### Non nullish string
Schema that does not accept `null` and `undefined`.
```ts
const NonNullishStringSchema = v.nonNullish(v.nullish(v.string()));
```
##### Unwrap non nullish
Use `unwrap` to undo the effect of `nonNullish`.
```ts
const NonNullishNumberSchema = v.nonNullish(v.nullish(v.number()));
const NullishNumberSchema = v.unwrap(NonNullishNumberSchema);
```
#### Related
The following APIs can be combined with `nonNullish`.
##### Schemas
##### Methods
##### Actions
##### Utils
### nonOptional
Creates a non optional schema.
> This schema function can be used to override the behavior of `optional`.
```ts
const Schema = v.nonOptional(wrapped, message);
```
#### Generics
- `TWrapped`
- `TMessage`
#### Parameters
- `wrapped`
- `message`
##### Explanation
With `nonOptional` the validation of your schema will not pass `undefined` inputs. If the input is `undefined`, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `nonOptional` can be used.
##### Non optional string
Schema that does not accept `undefined`.
```ts
const NonOptionalStringSchema = v.nonOptional(v.optional(v.string()));
```
##### Unwrap non optional
Use `unwrap` to undo the effect of `nonOptional`.
```ts
const NonOptionalNumberSchema = v.nonOptional(v.optional(v.number()));
const OptionalNumberSchema = v.unwrap(NonOptionalNumberSchema);
```
#### Related
The following APIs can be combined with `nonOptional`.
##### Schemas
##### Methods
##### Actions
##### Utils
### null
Creates a null schema.
```ts
const Schema = v.null(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `null` you can validate the data type of the input and if it is not `null`, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Related
The following APIs can be combined with `null`.
##### Schemas
##### Methods
##### Actions
##### Utils
### nullable
Creates a nullable schema.
```ts
const Schema = v.nullable(wrapped, default_);
```
#### Generics
- `TWrapped`
- `TDefault`
#### Parameters
- `wrapped`
- `default_` {/* prettier-ignore */}
##### Explanation
With `nullable` the validation of your schema will pass `null` inputs, and if you specify a `default_` input value, the schema will use it if the input is `null`. For this reason, the output type may differ from the input type of the schema.
> Note that `nullable` does not accept `undefined` as an input. If you want to accept `undefined` inputs, use `optional`, and if you want to accept `null` and `undefined` inputs, use `nullish` instead. Also, if you want to set a default output value for any invalid input, you should use `fallback` instead.
#### Returns
- `Schema`
#### Examples
The following examples show how `nullable` can be used.
##### Nullable string schema
Schema that accepts `string` and `null`.
```ts
const NullableStringSchema = v.nullable(v.string(), "I'm the default!");
```
##### Nullable date schema
Schema that accepts [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) and `null`.
> By using a function as the `default_` parameter, the schema will return a new [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance each time the input is `null`.
```ts
const NullableDateSchema = v.nullable(v.date(), () => new Date());
```
##### Nullable entry schema
Object schema with a nullable entry.
```ts
const NullableEntrySchema = v.object({
key: v.nullable(v.string()),
});
```
##### Unwrap nullable schema
Use `unwrap` to undo the effect of `nullable`.
```ts
const NullableNumberSchema = v.nullable(v.number());
const NumberSchema = v.unwrap(NullableNumberSchema);
```
#### Related
The following APIs can be combined with `nullable`.
##### Schemas
##### Methods
##### Actions
##### Utils
### nullish
Creates a nullish schema.
```ts
const Schema = v.nullish(wrapped, default_);
```
#### Generics
- `TWrapped`
- `TDefault`
#### Parameters
- `wrapped`
- `default_` {/* prettier-ignore */}
##### Explanation
With `nullish` the validation of your schema will pass `undefined` and `null` inputs, and if you specify a `default_` input value, the schema will use it if the input is `undefined` or `null`. For this reason, the output type may differ from the input type of the schema.
> Note that `nullish` accepts `undefined` and `null` as an input. If you want to accept only `null` inputs, use `nullable`, and if you want to accept only `undefined` inputs, use `optional` instead. Also, if you want to set a default output value for any invalid input, you should use `fallback` instead.
#### Returns
- `Schema`
#### Examples
The following examples show how `nullish` can be used.
##### Nullish string schema
Schema that accepts `string`, `undefined` and `null`.
```ts
const NullishStringSchema = v.nullish(v.string(), "I'm the default!");
```
##### Nullish date schema
Schema that accepts [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date), `undefined` and `null`.
> By using a function as the `default_` parameter, the schema will return a new [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance each time the input is `undefined` or `null`.
```ts
const NullishDateSchema = v.nullish(v.date(), () => new Date());
```
##### Nullish entry schema
Object schema with a nullish entry.
```ts
const NullishEntrySchema = v.object({
key: v.nullish(v.string()),
});
```
##### Unwrap nullish schema
Use `unwrap` to undo the effect of `nullish`.
```ts
const NullishNumberSchema = v.nullish(v.number());
const NumberSchema = v.unwrap(NullishNumberSchema);
```
#### Related
The following APIs can be combined with `nullish`.
##### Schemas
##### Methods
##### Actions
##### Utils
### number
Creates a number schema.
```ts
const Schema = v.number(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `number` you can validate the data type of the input. If the input is not a number, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `number` can be used.
##### Integer schema
Schema to validate an integer.
```ts
const IntegerSchema = v.pipe(v.number(), v.integer());
```
##### Force minimum
Schema that forces a minimum number of 10.
```ts
const MinNumberSchema = v.pipe(v.number(), v.toMinValue(10));
```
##### Validate range
Schema that validates a number in a range.
```ts
const NumberRangeSchema = v.pipe(v.number(), v.minValue(10), v.maxValue(20));
```
#### Related
The following APIs can be combined with `number`.
##### Schemas
##### Methods
##### Actions
##### Utils
### object
Creates an object schema.
```ts
const Schema = v.object(entries, message);
```
#### Generics
- `TEntries`
- `TMessage`
#### Parameters
- `entries`
- `message`
##### Explanation
With `object` you can validate the data type of the input and whether the content matches `entries`. If the input is not an object, you can use `message` to customize the error message.
> This schema removes unknown entries. The output will only include the entries you specify. To include unknown entries, use `looseObject`. To return an issue for unknown entries, use `strictObject`. To include and validate unknown entries, use `objectWithRest`.
#### Returns
- `Schema`
#### Examples
The following examples show how `object` can be used. Please see the object guide for more examples and explanations.
##### Simple object schema
Schema to validate an object with two keys.
```ts
const SimpleObjectSchema = v.object({
key1: v.string(),
key2: v.number(),
});
```
##### Merge several objects
Schema that merges the entries of two object schemas.
```ts
const MergedObjectSchema = v.object({
...ObjectSchema1.entries,
...ObjectSchema2.entries,
});
```
##### Mark keys as optional
Schema to validate an object with partial entries.
```ts
const PartialObjectSchema = v.partial(
v.object({
key1: v.string(),
key2: v.number(),
})
);
```
##### Object with selected entries
Schema to validate only selected entries of an object.
```ts
const PickObjectSchema = v.pick(
v.object({
key1: v.string(),
key2: v.number(),
key3: v.boolean(),
}),
['key1', 'key3']
);
```
#### Related
The following APIs can be combined with `object`.
##### Schemas
##### Methods
##### Actions
##### Utils
### objectWithRest
Creates an object with rest schema.
```ts
const Schema = v.objectWithRest(
entries,
rest,
message
);
```
#### Generics
- `TEntries`
- `TRest`
- `TMessage`
#### Parameters
- `entries`
- `rest`
- `message`
##### Explanation
With `objectWithRest` you can validate the data type of the input and whether the content matches `entries` and `rest`. If the input is not an object, you can use `message` to customize the error message.
> The difference to `object` is that this schema includes unknown entries in the output. In addition, this schema filters certain entries from the unknown entries for security reasons.
#### Returns
- `Schema`
#### Examples
The following examples show how `objectWithRest` can be used. Please see the object guide for more examples and explanations.
##### Object schema with rest
Schema to validate an object with generic rest entries.
```ts
const ObjectSchemaWithRest = v.objectWithRest(
{
key1: v.string(),
key2: v.number(),
},
v.boolean()
);
```
##### Merge several objects
Schema that merges the entries of two object schemas.
```ts
const MergedObjectSchema = v.objectWithRest(
{
...ObjectSchema1.entries,
...ObjectSchema2.entries,
},
v.null()
);
```
##### Mark keys as optional
Schema to validate an object with partial entries.
```ts
const PartialObjectSchema = partial(
objectWithRest(
{
key1: string(),
key2: number(),
},
v.undefined()
)
);
```
##### Object with selected entries
Schema to validate only selected entries of an object.
```ts
const PickObjectSchema = v.pick(
v.objectWithRest(
{
key1: v.string(),
key2: v.number(),
key3: v.boolean(),
},
v.null()
),
['key1', 'key3']
);
```
#### Related
The following APIs can be combined with `objectWithRest`.
##### Schemas
##### Methods
##### Actions
##### Utils
### optional
Creates an optional schema.
```ts
const Schema = v.optional(wrapped, default_);
```
#### Generics
- `TWrapped`
- `TDefault`
#### Parameters
- `wrapped`
- `default_` {/* prettier-ignore */}
##### Explanation
With `optional` the validation of your schema will pass `undefined` inputs, and if you specify a `default_` input value, the schema will use it if the input is `undefined`. For this reason, the output type may differ from the input type of the schema.
> Note that `optional` does not accept `null` as an input. If you want to accept `null` inputs, use `nullable`, and if you want to accept `null` and `undefined` inputs, use `nullish` instead. Also, if you want to set a default output value for any invalid input, you should use `fallback` instead.
#### Returns
- `Schema`
#### Examples
The following examples show how `optional` can be used.
##### Optional string schema
Schema that accepts `string` and `undefined`.
```ts
const OptionalStringSchema = v.optional(v.string(), "I'm the default!");
```
##### Optional date schema
Schema that accepts [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) and `undefined`.
> By using a function as the `default_` parameter, the schema will return a new [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance each time the input is `undefined`.
```ts
const OptionalDateSchema = v.optional(v.date(), () => new Date());
```
##### Optional entry schema
Object schema with an optional entry.
```ts
const OptionalEntrySchema = v.object({
key: v.optional(v.string()),
});
```
##### Unwrap optional schema
Use `unwrap` to undo the effect of `optional`.
```ts
const OptionalNumberSchema = v.optional(v.number());
const NumberSchema = v.unwrap(OptionalNumberSchema);
```
#### Related
The following APIs can be combined with `optional`.
##### Schemas
##### Methods
##### Actions
##### Utils
### picklist
Creates a picklist schema.
```ts
const Schema = v.picklist(options, message);
```
#### Generics
- `TOptions`
- `TMessage`
#### Parameters
- `options`
- `message`
##### Explanation
With `picklist` you can validate that the input corresponds to a picklist option. If the input is invalid, you can use `message` to customize the error message.
> `picklist` works in a similar way to `enum`. However, in many cases it is easier to use because you can pass an array of values instead of an enum.
#### Returns
- `Schema`
#### Examples
The following examples show how `picklist` can be used.
##### Language schema
Schema to validate programming languages.
```ts
const LanguageSchema = v.picklist(['JavaScript', 'TypeScript']);
```
##### Country schema
Schema to validate country codes.
```ts
const countries = [
{ name: 'Germany', code: 'DE' },
{ name: 'France', code: 'FR' },
{ name: 'United States', code: 'US' },
] as const;
const CountrySchema = v.picklist(
countries.map((country) => country.code),
'Please select your country.'
);
```
#### Related
The following APIs can be combined with `picklist`.
##### Schemas
##### Methods
##### Actions
##### Utils
### promise
Creates a promise schema.
```ts
const Schema = v.promise(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `promise` you can validate the data type of the input. If the input is not a promise, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `promise` can be used.
##### Number promise
Schema to validate a promise that resolves to a number.
```ts
const NumberPromiseSchema = v.pipeAsync(
v.promise(),
v.awaitAsync(),
v.number()
);
```
#### Related
The following APIs can be combined with `promise`.
##### Schemas
##### Methods
##### Actions
##### Utils
### record
Creates a record schema.
```ts
const Schema = v.record(key, value, message);
```
#### Generics
- `TKey`
- `TValue`
- `TMessage`
#### Parameters
- `key`
- `value`
- `message`
##### Explanation
With `record` you can validate the data type of the input and whether the entries matches `key` and `value`. If the input is not an object, you can use `message` to customize the error message.
> This schema filters certain entries from the record for security reasons.
> This schema marks an entry as optional if it detects that its key is a literal type. The reason for this is that it is not technically possible to detect missing literal keys without restricting the `key` schema to `string`, `enum` and `picklist`. However, if `enum` and `picklist` are used, it is better to use `object` with `entriesFromList` because it already covers the needed functionality. This decision also reduces the bundle size of `record`, because it only needs to check the entries of the input and not any missing keys.
#### Returns
- `Schema`
#### Examples
The following examples show how `record` can be used.
##### String record schema
Schema to validate a record with strings.
```ts
const StringRecordSchema = v.record(
v.string(),
v.string(),
'An object is required.'
);
```
##### Object record schema
Schema to validate a record of objects.
```ts
const ObjectRecordSchema = v.record(v.string(), v.object({ key: v.string() }));
```
##### Picklist as key
Schema to validate a record with specific optional keys.
```ts
const ProductRecordSchema = v.record(
v.picklist(['product_a', 'product_b', 'product_c']),
v.optional(v.number())
);
```
##### Enum as key
Schema to validate a record with specific optional keys.
```ts
enum Products {
PRODUCT_A = 'product_a',
PRODUCT_B = 'product_b',
PRODUCT_C = 'product_c',
}
const ProductRecordSchema = v.record(v.enum(Products), v.optional(v.number()));
```
#### Related
The following APIs can be combined with `record`.
##### Schemas
##### Methods
##### Actions
##### Utils
### set
Creates a set schema.
```ts
const Schema = v.set(value, message);
```
#### Generics
- `TValue`
- `TMessage`
#### Parameters
- `value`
- `message`
##### Explanation
With `set` 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
- `Schema`
#### Examples
The following examples show how `set` can be used.
##### String set schema
Schema to validate a set with string values.
```ts
const StringSetSchema = v.set(v.string());
```
##### Object set schema
Schema to validate a set with object values.
```ts
const ObjectSetSchema = v.set(v.object({ key: v.string() }));
```
#### Related
The following APIs can be combined with `set`.
##### Schemas
##### Methods
##### Actions
##### Utils
### strictObject
Creates a strict object schema.
```ts
const Schema = v.strictObject(entries, message);
```
#### Generics
- `TEntries`
- `TMessage`
#### Parameters
- `entries`
- `message`
##### Explanation
With `strictObject` you can validate the data type of the input and whether the content matches `entries`. If the input is not an object or does include unknown entries, you can use `message` to customize the error message.
> The difference to `object` is that this schema returns an issue for unknown entries. It intentionally returns only one issue. Otherwise, attackers could send large objects to exhaust device resources. If you want an issue for every unknown key, use the `objectWithRest` schema with `never` for the `rest` argument.
#### Returns
- `Schema`
#### Examples
The following examples show how `strictObject` can be used. Please see the object guide for more examples and explanations.
##### Simple object schema
Schema to validate a strict object with two keys.
```ts
const SimpleObjectSchema = v.strictObject({
key1: v.string(),
key2: v.number(),
});
```
##### Merge several objects
Schema that merges the entries of two object schemas.
```ts
const MergedObjectSchema = v.strictObject({
...ObjectSchema1.entries,
...ObjectSchema2.entries,
});
```
##### Mark keys as optional
Schema to validate an object with partial entries.
```ts
const PartialObjectSchema = v.partial(
v.strictObject({
key1: v.string(),
key2: v.number(),
})
);
```
##### Object with selected entries
Schema to validate only selected entries of a strict object.
```ts
const PickObjectSchema = v.pick(
v.strictObject({
key1: v.string(),
key2: v.number(),
key3: v.boolean(),
}),
['key1', 'key3']
);
```
#### Related
The following APIs can be combined with `strictObject`.
##### Schemas
##### Methods
##### Actions
##### Utils
### strictTuple
Creates a strict tuple schema.
```ts
const Schema = v.strictTuple(items, message);
```
#### Generics
- `TItems`
- `TMessage`
#### Parameters
- `items`
- `message`
##### Explanation
With `strictTuple` you can validate the data type of the input and whether the content matches `items`. If the input is not an array or does include unknown items, you can use `message` to customize the error message.
> The difference to `tuple` is that this schema returns an issue for unknown items. It intentionally returns only one issue. Otherwise, attackers could send large arrays to exhaust device resources. If you want an issue for every unknown item, use the `tupleWithRest` schema with `never` for the `rest` argument.
#### Returns
- `Schema`
#### Examples
The following examples show how `strictTuple` can be used. Please see the arrays guide for more examples and explanations.
##### Simple tuple schema
Schema to validate a strict tuple with two items.
```ts
const SimpleTupleSchema = v.strictTuple([v.string(), v.number()]);
```
#### Related
The following APIs can be combined with `strictTuple`.
##### Schemas
##### Methods
##### Actions
##### Utils
### string
Creates a string schema.
```ts
const Schema = v.string(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `string` you can validate the data type of the input. If the input is not a string, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `string` can be used.
##### Email schema
Schema to validate an email.
```ts
const EmailSchema = v.pipe(
v.string(),
v.nonEmpty('Please enter your email.'),
v.email('The email is badly formatted.'),
v.maxLength(30, 'Your email is too long.')
);
```
##### Password schema
Schema to validate a password.
```ts
const PasswordSchema = v.pipe(
v.string(),
v.minLength(8, 'Your password is too short.'),
v.maxLength(30, 'Your password is too long.'),
v.regex(/[a-z]/, 'Your password must contain a lowercase letter.'),
v.regex(/[A-Z]/, 'Your password must contain a uppercase letter.'),
v.regex(/[0-9]/, 'Your password must contain a number.')
);
```
##### URL schema
Schema to validate a URL.
```ts
const UrlSchema = v.pipe(
v.string('A URL must be string.'),
v.url('The URL is badly formatted.')
);
```
#### Related
The following APIs can be combined with `string`.
##### Schemas
##### Methods
##### Actions
##### Utils
### symbol
Creates a symbol schema.
```ts
const Schema = v.symbol(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `symbol` you can validate the data type of the input. If it is not a symbol, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `symbol` can be used.
##### Custom message
Symbol schema with a custom error message.
```ts
const schema = v.symbol('A symbol is required');
```
#### Related
The following APIs can be combined with `symbol`.
##### Schemas
##### Methods
##### Actions
##### Utils
### tuple
Creates a tuple schema.
```ts
const Schema = v.tuple(items, message);
```
#### Generics
- `TItems`
- `TMessage`
#### Parameters
- `items`
- `message`
##### Explanation
With `tuple` you can validate the data type of the input and whether the content matches `items`. If the input is not an array, you can use `message` to customize the error message.
> This schema removes unknown items. The output will only include the items you specify. To include unknown items, use `looseTuple`. To return an issue for unknown items, use `strictTuple`. To include and validate unknown items, use `tupleWithRest`.
#### Returns
- `Schema`
#### Examples
The following examples show how `tuple` can be used. Please see the arrays guide for more examples and explanations.
##### Simple tuple schema
Schema to validate a tuple with two items.
```ts
const SimpleTupleSchema = v.tuple([v.string(), v.number()]);
```
#### Related
The following APIs can be combined with `tuple`.
##### Schemas
##### Methods
##### Actions
##### Utils
### tupleWithRest
Creates a tuple with rest schema.
```ts
const Schema = v.tupleWithRest(items, rest, message);
```
#### Generics
- `TItems`
- `TRest`
- `TMessage`
#### Parameters
- `items`
- `rest`
- `message`
##### Explanation
With `tupleWithRest` you can validate the data type of the input and whether the content matches `items` and `rest`. If the input is not an array, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `tupleWithRest` can be used. Please see the arrays guide for more examples and explanations.
##### Tuple schema with rest
Schema to validate a tuple with generic rest items.
```ts
const TupleSchemaWithRest = v.tupleWithRest(
[v.string(), v.number()],
v.boolean()
);
```
#### Related
The following APIs can be combined with `tupleWithRest`.
##### Schemas
##### Methods
##### Actions
##### Utils
### undefined
Creates an undefined schema.
```ts
const Schema = v.undefined(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `undefined` you can validate the data type of the input and if it is not `undefined`, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Related
The following APIs can be combined with `undefined`.
##### Schemas
##### Methods
##### Actions
##### Utils
### undefinedable
Creates an undefinedable schema.
```ts
const Schema = v.undefinedable(wrapped, default_);
```
#### Generics
- `TWrapped`
- `TDefault`
#### Parameters
- `wrapped`
- `default_` {/* prettier-ignore */}
##### Explanation
With `undefinedable` the validation of your schema will pass `undefined` inputs, and if you specify a `default_` input value, the schema will use it if the input is `undefined`. For this reason, the output type may differ from the input type of the schema.
> `undefinedable` behaves exactly the same as `optional` at runtime. The only difference is the input and output type when used for object entries. While `optional` adds a question mark to the key, `undefinedable` does not.
> Note that `undefinedable` does not accept `null` as an input. If you want to accept `null` inputs, use `nullable`, and if you want to accept `null` and `undefined` inputs, use `nullish` instead. Also, if you want to set a default output value for any invalid input, you should use `fallback` instead.
#### Returns
- `Schema`
#### Examples
The following examples show how `undefinedable` can be used.
##### Undefinedable string schema
Schema that accepts `string` and `undefined`.
```ts
const UndefinedableStringSchema = v.undefinedable(
v.string(),
"I'm the default!"
);
```
##### Undefinedable date schema
Schema that accepts [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) and `undefined`.
> By using a function as the `default_` parameter, the schema will return a new [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance each time the input is `undefined`.
```ts
const UndefinedableDateSchema = v.undefinedable(v.date(), () => new Date());
```
##### Undefinedable entry schema
Object schema with an undefinedable entry.
```ts
const UndefinedableEntrySchema = v.object({
key: v.undefinedable(v.string()),
});
```
##### Unwrap undefinedable schema
Use `unwrap` to undo the effect of `undefinedable`.
```ts
const UndefinedableNumberSchema = v.undefinedable(v.number());
const NumberSchema = v.unwrap(UndefinedableNumberSchema);
```
#### Related
The following APIs can be combined with `undefinedable`.
##### Schemas
##### Methods
##### Actions
##### Utils
### union
Creates an union schema.
> I recommend that you read the unions guide before using this schema function.
```ts
const Schema = v.union(options, message);
```
#### Generics
- `TOptions`
- `TMessage`
#### Parameters
- `options`
- `message`
##### Explanation
With `union` you can validate if the input matches one of the given `options`. If the input does not match a schema and cannot be clearly assigned to one of the options, you can use `message` to customize the error message.
If a bad input can be uniquely assigned to one of the schemas based on the data type, the result of that schema is returned. Otherwise, a general issue is returned that contains the issues of each schema as subissues. This is a special case within the library, as the issues of `union` can contradict each other.
#### Returns
- `Schema`
#### Examples
The following examples show how `union` can be used.
##### URL schema
Schema to validate an URL or empty string.
```ts
const UrlSchema = v.union([v.pipe(v.string(), v.url()), v.literal('')]);
```
##### Number schema
Schema to validate a number or decimal string.
```ts
const NumberSchema = v.union([v.number(), v.pipe(v.string(), v.decimal())]);
```
##### Date schema
Schema to validate a `Date` or ISO timestamp.
```ts
const DateSchema = v.union([v.date(), v.pipe(v.string(), v.isoTimestamp())]);
```
#### Related
The following APIs can be combined with `union`.
##### Schemas
##### Methods
##### Actions
##### Utils
### unknown
Creates an unknown schema.
> Use this schema function only if the data is truly unknown. Otherwise, use the other more specific schema functions that describe the data exactly.
```ts
const Schema = v.unknown();
```
#### Returns
- `Schema`
#### Related
The following APIs can be combined with `unknown`.
##### Schemas
##### Methods
##### Actions
##### Utils
### variant
Creates a variant schema.
```ts
const Schema = v.variant(key, options, message);
```
#### Generics
- `TKey`
- `TOptions`
- `TMessage`
#### Parameters
- `key`
- `options`
- `message`
##### Explanation
With `variant` you can validate if the input matches one of the given object `options`. The object schema to be used for the validation is determined by the discriminator `key`. If the input does not match a schema and cannot be clearly assigned to one of the options, you can use `message` to customize the error message.
> It is allowed to specify the exact same or a similar discriminator multiple times. However, in such cases `variant` will only return the output of the first untyped or typed variant option result. Typed results take precedence over untyped ones.
> For deeply nested `variant` schemas with several different discriminator keys, `variant` will return an issue for the first most likely object schemas on invalid input. The order of the discriminator keys and the presence of a discriminator in the input are taken into account.
#### Returns
- `Schema`
#### Examples
The following examples show how `variant` can be used.
##### Variant schema
Schema to validate an email, URL or date variant.
```ts
const VariantSchema = v.variant('type', [
v.object({
type: v.literal('email'),
email: v.pipe(v.string(), v.email()),
}),
v.object({
type: v.literal('url'),
url: v.pipe(v.string(), v.url()),
}),
v.object({
type: v.literal('date'),
date: v.pipe(v.string(), v.isoDate()),
}),
]);
```
##### Nested variant schema
You can also nest `variant` schemas.
```ts
const NestedVariantSchema = v.variant('type', [
VariantSchema,
v.object({
type: v.literal('color'),
date: v.pipe(v.string(), v.hexColor()),
}),
]);
```
##### Complex variant schema
You can also use `variant` to validate complex objects with multiple different discriminator keys.
```ts
const ComplexVariantSchema = v.variant('kind', [
v.variant('type', [
v.object({
kind: v.literal('fruit'),
type: v.literal('apple'),
item: v.object({ … }),
}),
v.object({
kind: v.literal('fruit'),
type: v.literal('banana'),
item: v.object({ … }),
}),
]),
v.variant('type', [
v.object({
kind: v.literal('vegetable'),
type: v.literal('carrot'),
item: v.object({ … }),
}),
v.object({
kind: v.literal('vegetable'),
type: v.literal('tomato'),
item: v.object({ … }),
}),
]),
]);
```
#### Related
The following APIs can be combined with `variant`.
##### Schemas
##### Methods
##### Actions
##### Utils
### void
Creates a void schema.
```ts
const Schema = v.void(message);
```
#### Generics
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `void` you can validate the data type of the input and if it is not `undefined`, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Related
The following APIs can be combined with `void`.
##### Schemas
##### Methods
##### Actions
## Methods
### assert
Checks if the input matches the scheme.
> As this is an assertion function, it can be used as a type guard.
```ts
v.assert(schema, input);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
- `input`
##### Explanation
`assert` does not modify the `input`. Therefore, transformations have no effect and unknown keys of an object are not removed. That is why this approach is not as safe and powerful as `parse` and `safeParse`.
#### Example
The following example show how `assert` can be used.
```ts
const EmailSchema = v.pipe(v.string(), v.email());
const data: unknown = 'jane@example.com';
v.assert(EmailSchema, data);
const email = data; // string
```
#### Related
The following APIs can be combined with `assert`.
##### Schemas
##### Methods
### config
Changes the local configuration of a schema.
```ts
const Schema = v.config(schema, config);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
- `config`
##### Explanation
This method overwrites the selected configuration properties by merging the previous configuration of the `schema` with the provided `config`.
#### Returns
- `Schema`
#### Examples
The following examples show how `config` can be used.
##### Same error message
Schema that uses the same error message for the entire pipeline.
```ts
const Schema = v.object({
email: v.config(
v.pipe(v.string(), v.trim(), v.email(), v.endsWith('@example.com')),
{ message: 'The email does not conform to the required format.' }
),
// ...
});
```
##### Abort pipeline early
Schema that aborts only a specific pipeline early.
```ts
const Schema = v.object({
url: v.config(
v.pipe(v.string(), v.trim(), v.url(), v.endsWith('@example.com')),
{ abortPipeEarly: true }
),
// ...
});
```
#### Related
The following APIs can be combined with `config`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### fallback
Returns a fallback value as output if the input does not match the schema.
```ts
const Schema = v.fallback(schema, fallback);
```
#### Generics
- `TSchema`
- `TFallback`
#### Parameters
- `schema`
- `fallback`
##### Explanation
`fallback` allows you to define a fallback value for the output that will be used if the validation of the input fails. This means that no issues will be returned when using `fallback` and the schema will always return an output.
> If you only want to set a default value for `null` or `undefined` inputs, you should use `optional`, `nullable` or `nullish` instead.
> The fallback value is not validated. Make sure that the fallback value matches your schema.
#### Returns
- `Schema`
#### Examples
The following examples show how `fallback` can be used.
##### Fallback string schema
Schema that will always return a string output.
```ts
const FallbackStringSchema = v.fallback(v.string(), "I'm the fallback!");
```
##### Fallback date schema
Schema that will always return a [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) output.
> By using a function as the `fallback` parameter, the schema will return a new [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance each time the input does not match the schema.
```ts
const FallbackDateSchema = v.fallback(v.date(), () => new Date());
```
#### Related
The following APIs can be combined with `fallback`.
##### Schemas
##### Methods
##### Actions
##### Utils
### flatten
Flatten the error messages of issues.
```ts
const errors = v.flatten(issues);
```
#### Generics
- `TSchema`
#### Parameters
- `issues`
##### Explanation
The error messages of issues without a path that belong to the root of the schema are added to the `.root` key.
The error messages of issues with a path that belong to the nested parts of the schema and can be converted to a dot path are added to the `.nested` key.
Some issue paths, for example for complex data types like `Set` and `Map`, have no key or a key that cannot be converted to a dot path. These error messages are added to the `.other` key.
#### Returns
- `errors`
#### Examples
The following example show how `flatten` can be used.
```ts
const Schema = v.object({
nested: v.object({
foo: v.string('Value of "nested.foo" is invalid.'),
}),
});
const result = v.safeParse(Schema, { nested: { foo: null } });
if (result.issues) {
const flatErrors = v.flatten(result.issues);
// ...
}
```
#### Related
The following APIs can be combined with `flatten`.
##### Methods
### forward
Forwards the issues of the passed validation action.
```ts
const Action = v.forward(action, path);
```
#### Generics
- `TInput`
- `TIssue`
- `TPath`
#### Parameters
- `action`
- `path`
##### Explanation
`forward` allows you to forward the issues of the passed validation `action` via `path` to a nested field of a schema.
#### Returns
- `Action`
#### Examples
The following examples show how `forward` can be used.
##### Register schema
Schema that ensures that the two passwords match.
```ts
const RegisterSchema = v.pipe(
v.object({
email: v.pipe(
v.string(),
v.nonEmpty('Please enter your email.'),
v.email('The email address is badly formatted.')
),
password1: v.pipe(
v.string(),
v.nonEmpty('Please enter your password.'),
v.minLength(8, 'Your password must have 8 characters or more.')
),
password2: v.string(),
}),
v.forward(
v.partialCheck(
[['password1'], ['password2']],
(input) => input.password1 === input.password2,
'The two passwords do not match.'
),
['password2']
)
);
```
#### Related
The following APIs can be combined with `forward`.
##### Schemas
##### Methods
##### Actions
##### Utils
### getDefault
Returns the default value of the schema.
```ts
const value = v.getDefault(schema, dataset, config);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
- `dataset`
- `config`
#### Returns
- `value`
#### Examples
The following examples show how `getDefault` can be used.
##### Optional string schema
Get the default value of an optional string schema.
```ts
const OptionalStringSchema = v.optional(v.string(), "I'm the default!");
const defaultValue = v.getDefault(OptionalStringSchema); // "I'm the default!"
```
#### Related
The following APIs can be combined with `getDefault`.
##### Schemas
##### Methods
##### Async
### getDefaults
Returns the default values of the schema.
> The difference to `getDefault` is that for object and tuple schemas this function recursively returns the default values of the subschemas instead of `undefined`.
```ts
const values = v.getDefaults(schema);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
#### Returns
- `values`
#### Examples
The following examples show how `getDefaults` can be used.
##### Object defaults
Get the default values of an object schema.
```ts
const ObjectSchema = v.object({
key: v.optional(v.string(), "I'm the default!"),
});
const defaultValues = v.getDefaults(ObjectSchema); // { key: "I'm the default!" }
```
##### Tuple defaults
Get the default values of a tuple schema.
```ts
const TupleSchema = v.tuple([v.nullable(v.number(), 100)]);
const defaultValues = v.getDefaults(TupleSchema); // [100]
```
#### Related
The following APIs can be combined with `getDefaults`.
##### Schemas
##### Methods
### getDescription
Returns the description of the schema.
> If multiple descriptions are defined, the last one of the highest level is returned. If no description is defined, `undefined` is returned.
```ts
const description = v.getDescription(schema);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
#### Returns
- `description`
#### Examples
The following examples show how `getDescription` can be used.
##### Get description of schema
Get the description of a username schema.
```ts
const UsernameSchema = v.pipe(
v.string(),
v.regex(/^[a-z0-9_-]{4,16}$/iu),
v.title('Username'),
v.description(
'A username must be between 4 and 16 characters long and can only contain letters, numbers, underscores and hyphens.'
)
);
const description = v.getDescription(UsernameSchema);
```
##### Overriding inherited descriptions
Get the description of a Gmail schema with an overridden description.
```ts
const EmailSchema = v.pipe(v.string(), v.email(), v.description('Email'));
const GmailSchema = v.pipe(
EmailSchema,
v.endsWith('@gmail.com'),
v.description('Gmail')
);
const description = v.getDescription(GmailSchema); // 'Gmail'
```
#### Related
The following APIs can be combined with `getDescription`.
##### Actions
### getFallback
Returns the fallback value of the schema.
```ts
const value = v.getFallback(schema, dataset, config);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
- `dataset`
- `config`
#### Returns
- `value`
#### Examples
The following examples show how `getFallback` can be used.
##### Fallback string schema
Get the fallback value of a string schema.
```ts
const FallbackStringSchema = v.fallback(v.string(), "I'm the fallback!");
const fallbackValue = v.getFallback(FallbackStringSchema); // "I'm the fallback!"
```
#### Related
The following APIs can be combined with `getFallback`.
##### Schemas
##### Methods
##### Async
### getFallbacks
Returns the fallback values of the schema.
> The difference to `getFallback` is that for object and tuple schemas this function recursively returns the fallback values of the subschemas instead of `undefined`.
```ts
const values = v.getFallbacks(schema);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
#### Returns
- `values`
#### Examples
The following examples show how `getFallbacks` can be used.
##### Object fallbacks
Get the fallback values of an object schema.
```ts
const ObjectSchema = v.object({
key: v.fallback(v.string(), "I'm the fallback!"),
});
const fallbackValues = v.getFallbacks(ObjectSchema); // { key: "I'm the fallback!" }
```
##### Tuple fallbacks
Get the fallback values of a tuple schema.
```ts
const TupleSchema = v.tuple([v.fallback(v.number(), 100)]);
const fallbackValues = v.getFallbacks(TupleSchema); // [100]
```
#### Related
The following APIs can be combined with `getFallbacks`.
##### Schemas
##### Methods
### getMetadata
Returns the metadata of the schema.
> If multiple metadata are defined, it shallowly merges them using depth-first search. If no metadata is defined, an empty object is returned.
```ts
const metadata = v.getMetadata(schema);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
#### Returns
- `metadata`
#### Examples
The following examples show how `getMetadata` can be used.
##### Get metadata of schema
Get the metadata of a username schema.
```ts
const UsernameSchema = v.pipe(
v.string(),
v.regex(/^[a-z0-9_-]{4,16}$/iu),
v.title('Username'),
v.metadata({
length: { min: 4, max: 16 },
chars: ['letters', 'numbers', 'underscores', 'hyphens'],
})
);
const metadata = v.getMetadata(UsernameSchema);
```
#### Related
The following APIs can be combined with `getMetadata`.
##### Actions
### getTitle
Returns the title of the schema.
> If multiple titles are defined, the last one of the highest level is returned. If no title is defined, `undefined` is returned.
```ts
const title = v.getTitle(schema);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
#### Returns
- `title`
#### Examples
The following examples show how `getTitle` can be used.
##### Get title of schema
Get the title of a username schema.
```ts
const UsernameSchema = v.pipe(
v.string(),
v.regex(/^[a-z0-9_-]{4,16}$/iu),
v.title('Username'),
v.description(
'A username must be between 4 and 16 characters long and can only contain letters, numbers, underscores and hyphens.'
)
);
const title = v.getTitle(UsernameSchema); // 'Username'
```
##### Overriding inherited titles
Get the title of a Gmail schema with an overridden title.
```ts
const EmailSchema = v.pipe(v.string(), v.email(), v.title('Email'));
const GmailSchema = v.pipe(
EmailSchema,
v.endsWith('@gmail.com'),
v.title('Gmail')
);
const title = v.getTitle(GmailSchema); // 'Gmail'
```
#### Related
The following APIs can be combined with `getTitle`.
##### Actions
### is
Checks if the input matches the scheme.
> By using a type predicate, this function can be used as a type guard.
```ts
const result = v.is(schema, input);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
- `input`
##### Explanation
`is` does not modify the `input`. Therefore, transformations have no effect and unknown keys of an object are not removed. That is why this approach is not as safe and powerful as `parse` and `safeParse`.
#### Returns
- `result`
#### Example
The following example show how `is` can be used.
```ts
const EmailSchema = v.pipe(v.string(), v.email());
const data: unknown = 'jane@example.com';
if (v.is(EmailSchema, data)) {
const email = data; // string
}
```
#### Related
The following APIs can be combined with `is`.
##### Schemas
##### Methods
### keyof
Creates a picklist schema of object keys.
```ts
const Schema = v.keyof(schema, message);
```
#### Generics
- `TSchema`
- `TMessage`
#### Parameters
- `schema`
- `message`
#### Returns
- `Schema`
#### Examples
The following examples show how `keyof` can be used.
##### Object key schema
Schema to validate the keys of an object.
```ts
const ObjectSchema = v.object({ key1: v.string(), key2: v.number() });
const ObjectKeySchema = v.keyof(ObjectSchema); // 'key1' | 'key2'
```
#### Related
The following APIs can be combined with `keyof`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### message
Changes the local message configuration of a schema.
```ts
const Schema = v.message(schema, message_);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
- `message_`
##### Explanation
This method overrides the local message configuration of the schema. In practice, it is typically used to specify a single error message for an entire pipeline.
#### Returns
- `Schema`
#### Examples
The following examples show how `message` can be used.
##### Email schema
Email schema that uses the same error message for the entire pipeline.
```ts
const EmailSchema = v.message(
v.pipe(v.string(), v.trim(), v.nonEmpty(), v.email(), v.maxLength(100)),
'The email is not in the required format.'
);
```
#### Related
The following APIs can be combined with `message`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### omit
Creates a modified copy of an object schema that does not contain the selected entries.
```ts
const Schema = v.omit(schema, keys);
```
#### Generics
- `TSchema`
- `TKeys`
#### Parameters
- `schema`
- `keys`
##### Explanation
`omit` creates a modified copy of the given object `schema` that does not contain the selected `keys`. It is similar to TypeScript's [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys) utility type.
> Because `omit` changes the data type of the input and output, it is not allowed to pass a schema that has been modified by the `pipe` method, as this may cause runtime errors. Please use the `pipe` method after you have modified the schema with `omit`.
#### Returns
- `Schema`
#### Examples
The following examples show how `omit` can be used.
##### Omit specific keys
Schema that does not contain the selected keys of an existing schema.
```ts
const OmittedSchema = v.omit(
v.object({
key1: v.string(),
key2: v.number(),
key3: v.boolean(),
}),
['key1', 'key3']
); // { key2: number }
```
#### Related
The following APIs can be combined with `omit`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### parse
Parses an unknown input based on a schema.
```ts
const output = v.parse(schema, input, config);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
- `input`
- `config`
##### Explanation
`parse` will throw a `ValiError` if the `input` does not match the `schema`. Therefore you should use a try/catch block to catch errors. If the input matches the schema, it is valid and the `output` of the schema will be returned typed.
#### Returns
- `output`
#### Example
The following example show how `parse` can be used.
```ts
try {
const EmailSchema = v.pipe(v.string(), v.email());
const email = v.parse(EmailSchema, 'jane@example.com');
// Handle errors if one occurs
} catch (error) {
console.log(error);
}
```
#### Related
The following APIs can be combined with `parse`.
##### Schemas
##### Methods
##### Utils
### parser
Returns a function that parses an unknown input based on a schema.
```ts
const parser = v.parser(schema, config);
```
#### Generics
- `TSchema`
- `TConfig`
#### Parameters
- `schema`
- `config`
#### Returns
- `parser`
#### Example
The following example show how `parser` can be used.
```ts
try {
const EmailSchema = v.pipe(v.string(), v.email());
const emailParser = v.parser(EmailSchema);
const email = emailParser('jane@example.com');
// Handle errors if one occurs
} catch (error) {
console.log(error);
}
```
#### Related
The following APIs can be combined with `parser`.
##### Schemas
##### Methods
##### Utils
### partial
Creates a modified copy of an object schema that marks all or only the selected entries as optional.
```ts
const Schema = v.partial(schema, keys);
```
#### Generics
- `TSchema`
- `TKeys`
#### Parameters
- `schema`
- `keys`
##### Explanation
`partial` creates a modified copy of the given object `schema` where all entries or only the selected `keys` are optional. It is similar to TypeScript's [`Partial`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype) utility type.
> Because `partial` changes the data type of the input and output, it is not allowed to pass a schema that has been modified by the `pipe` method, as this may cause runtime errors. Please use the `pipe` method after you have modified the schema with `partial`.
#### Returns
- `Schema`
#### Examples
The following examples show how `partial` can be used.
##### Partial object schema
Schema to validate an object with partial entries.
```ts
const PartialSchema = v.partial(
v.object({
key1: v.string(),
key2: v.number(),
})
); // { key1?: string; key2?: number }
```
##### With only specific keys
Schema to validate an object with only specific entries marked as optional.
```ts
const PartialSchema = v.partial(
v.object({
key1: v.string(),
key2: v.number(),
key3: v.boolean(),
}),
['key1', 'key3']
); // { key1?: string; key2: number; key3?: boolean }
```
#### Related
The following APIs can be combined with `partial`.
##### Schemas
##### Methods
##### Actions
##### Utils
### pick
Creates a modified copy of an object schema that contains only the selected entries.
```ts
const Schema = v.pick(schema, keys);
```
#### Generics
- `TSchema`
- `TKeys`
#### Parameters
- `schema`
- `keys`
##### Explanation
`pick` creates a modified copy of the given object `schema` that contains only the selected `keys`. It is similar to TypeScript's [`Pick`](https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys) utility type.
> Because `pick` changes the data type of the input and output, it is not allowed to pass a schema that has been modified by the `pipe` method, as this may cause runtime errors. Please use the `pipe` method after you have modified the schema with `pick`.
#### Returns
- `Schema`
#### Examples
The following examples show how `pick` can be used.
##### Pick specific keys
Schema that contains only the selected keys of an existing schema.
```ts
const PickedSchema = v.pick(
object({
key1: string(),
key2: number(),
key3: boolean(),
}),
['key1', 'key3']
); // { key1: string; key3: boolean }
```
#### Related
The following APIs can be combined with `pick`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### pipe
Adds a pipeline to a schema, that can validate and transform its input.
```ts
const Schema = v.pipe(schema, ...items);
```
#### Generics
- `TSchema`
- `TItems`
#### Parameters
- `schema`
- `items`
##### Explanation
`pipe` creates a modified copy of the given `schema`, containing a pipeline for detailed validations and transformations. It passes the input data synchronously through the `items` in the order they are provided and each item can examine and modify it.
> Since `pipe` returns a schema that can be used as the first argument of another pipeline, it is possible to nest multiple `pipe` calls to extend the validation and transformation further.
The `pipe` aborts early and marks the output as untyped if issues were collected before attempting to execute a schema or transformation action as the next item in the pipeline, to prevent unexpected behavior.
#### Returns
- `Schema`
#### Examples
The following examples show how `pipe` can be used. Please see the pipeline guide for more examples and explanations.
##### Email schema
Schema to validate an email.
```ts
const EmailSchema = v.pipe(
v.string(),
v.nonEmpty('Please enter your email.'),
v.email('The email is badly formatted.'),
v.maxLength(30, 'Your email is too long.')
);
```
##### String to number
Schema to convert a string to a number.
```ts
const NumberSchema = v.pipe(v.string(), v.transform(Number), v.number());
```
#### Related
The following APIs can be combined with `pipe`.
##### Schemas
##### Methods
##### Actions
##### Utils
### required
Creates a modified copy of an object schema that marks all or only the selected entries as required.
```ts
const AllKeysSchema = v.required(schema, message);
const SelectedKeysSchema = v.required(
schema,
keys,
message
);
```
#### Generics
- `TSchema`
- `TKeys`
- `TMessage`
#### Parameters
- `schema`
- `keys`
- `message`
##### Explanation
`required` creates a modified copy of the given object `schema` where all or only the selected `keys` are required. It is similar to TypeScript's [`Required`](https://www.typescriptlang.org/docs/handbook/utility-types.html#requiredtype) utility type.
> Because `required` changes the data type of the input and output, it is not allowed to pass a schema that has been modified by the `pipe` method, as this may cause runtime errors. Please use the `pipe` method after you have modified the schema with `required`.
#### Returns
- `AllKeysSchema`
- `SelectedKeysSchema`
#### Examples
The following examples show how `required` can be used.
##### Required object schema
Schema to validate an object with required entries.
```ts
const RequiredSchema = v.required(
v.object({
key1: v.optional(v.string()),
key2: v.optional(v.number()),
})
); // { key1: string; key2: number }
```
##### With only specific keys
Schema to validate an object with only specific entries marked as required.
```ts
const RequiredSchema = v.required(
v.object({
key1: v.optional(v.string()),
key2: v.optional(v.number()),
key3: v.optional(v.boolean()),
}),
['key1', 'key3']
); // { key1: string; key2?: number; key3: boolean }
```
#### Related
The following APIs can be combined with `required`.
##### Schemas
##### Methods
##### Actions
##### Utils
### safeParse
Parses an unknown input based on a schema.
```ts
const result = v.safeParse(schema, input, config);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
- `input`
- `config`
#### Returns
- `result`
#### Example
The following example show how `safeParse` can be used.
```ts
const EmailSchema = v.pipe(v.string(), v.email());
const result = v.safeParse(EmailSchema, 'jane@example.com');
if (result.success) {
const email = result.output;
} else {
console.log(result.issues);
}
```
#### Related
The following APIs can be combined with `safeParse`.
##### Schemas
##### Methods
##### Utils
### safeParser
Returns a function that parses an unknown input based on a schema.
```ts
const safeParser = v.safeParser(schema, config);
```
#### Generics
- `TSchema`
- `TConfig`
#### Parameters
- `schema`
- `config`
#### Returns
- `safeParser`
#### Example
The following example show how `safeParser` can be used.
```ts
const EmailSchema = v.pipe(v.string(), v.email());
const safeEmailParser = v.safeParser(EmailSchema);
const result = safeEmailParser('jane@example.com');
if (result.success) {
const email = result.output;
} else {
console.log(result.issues);
}
```
#### Related
The following APIs can be combined with `safeParser`.
##### Schemas
##### Methods
##### Utils
### summarize
Summarize the error messages of issues in a pretty-printable multi-line string.
```ts
const errors = v.summarize(issues);
```
#### Parameters
- `issues`
##### Explanation
If an issue in `issues` contains a path that can be converted to a dot path, the dot path will be displayed in the `errors` output just below the issue's error message.
#### Returns
- `errors`
#### Examples
The following example show how `summarize` can be used.
```ts
const Schema = v.object({
nested: v.object({
foo: v.string('Value of "nested.foo" is invalid.'),
}),
});
const result = v.safeParse(Schema, { nested: { foo: null } });
if (result.issues) {
console.log(v.summarize(result.issues));
}
```
#### Related
The following APIs can be combined with `summarize`.
##### Methods
### unwrap
Unwraps the wrapped schema.
```ts
const Schema = v.unwrap(schema);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
#### Returns
- `Schema`
#### Examples
The following examples show how `unwrap` can be used.
##### Unwrap string schema
Unwraps the wrapped string schema.
```ts
const OptionalStringSchema = v.optional(v.string());
const StringSchema = v.unwrap(OptionalStringSchema);
```
#### Related
The following APIs can be combined with `unwrap`.
##### Schemas
##### Methods
##### Utils
##### Async
## Actions
### args
Creates a function arguments transformation action.
```ts
const Action = v.args(schema);
```
#### Generics
- `TInput`
- `TSchema`
#### Parameters
- `schema`
##### Explanation
With `args` you can force the arguments of a function to match the given `schema`.
#### Returns
- `Action`
#### Examples
The following examples show how `args` can be used.
##### Function schema
Schema of a function that transforms a string to a number.
```ts
const FunctionSchema = v.pipe(
v.function(),
v.args(v.tuple([v.pipe(v.string(), v.decimal())])),
v.returns(v.number())
);
```
#### Related
The following APIs can be combined with `args`.
##### Schemas
##### Methods
##### Utils
### base64
Creates a [Base64](https://en.wikipedia.org/wiki/Base64) validation action.
```ts
const Action = v.base64(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `base64` you can validate the formatting of a string. If the input is not a Base64 string, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `base64` can be used.
##### Base64 schema
Schema to validate a Base64 string.
```ts
const Base64Schema = v.pipe(v.string(), v.base64('The data is badly encoded.'));
```
#### Related
The following APIs can be combined with `base64`.
##### Schemas
##### Methods
##### Utils
### bic
Creates a [BIC](https://en.wikipedia.org/wiki/ISO_9362) validation action.
```ts
const Action = v.bic(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `bic` you can validate the formatting of a string. If the input is not a BIC, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `bic` can be used.
##### BIC schema
Schema to validate a BIC.
```ts
const BicSchema = v.pipe(
v.string(),
v.toUpperCase(),
v.bic('The BIC is badly formatted.')
);
```
#### Related
The following APIs can be combined with `bic`.
##### Schemas
##### Methods
##### Utils
### brand
Creates a brand transformation action.
```ts
const Action = v.brand(name);
```
#### Generics
- `TInput`
- `TName`
#### Parameters
- `name`
##### Explanation
`brand` allows you to brand the output type of a schema with a `name`. This ensures that data can only be considered valid if it has been validated by a particular branded schema.
#### Returns
- `Action`
#### Examples
The following examples show how `brand` can be used.
##### Branded fruit schema
Schema to ensure that only a validated fruit is accepted.
```ts
// Create schema and infer output type
const FruitSchema = v.pipe(v.object({ name: v.string() }), v.brand('Fruit'));
type FruitOutput = v.InferOutput;
// This works because output is branded
const apple: FruitOutput = v.parse(FruitSchema, { name: 'apple' });
// But this will result in a type error
const banana: FruitOutput = { name: 'banana' };
```
#### Related
The following APIs can be combined with `brand`.
##### Schemas
##### Methods
##### Utils
### bytes
Creates a [bytes](https://en.wikipedia.org/wiki/Byte) validation action.
```ts
const Action = v.bytes(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `bytes` you can validate the bytes of a string. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `bytes` can be used.
##### Bytes schema
Schema to validate a string with 8 bytes.
```ts
const BytesSchema = v.pipe(
v.string(),
v.bytes(8, 'Exactly 8 bytes are required.')
);
```
#### Related
The following APIs can be combined with `bytes`.
##### Schemas
##### Methods
##### Utils
### check
Creates a check validation action.
```ts
const Action = v.check(requirement, message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `check` you can freely validate the input and return `true` if it is valid or `false` otherwise. If the input does not match your `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `check` can be used.
##### Check object properties
Schema to check the properties of an object.
```ts
const CustomObjectSchema = v.pipe(
v.object({
list: v.array(v.string()),
length: v.number(),
}),
v.check(
(input) => input.list.length === input.length,
'The list does not match the length.'
)
);
```
#### Related
The following APIs can be combined with `check`.
##### Schemas
##### Methods
##### Utils
### checkItems
Creates a check items validation action.
```ts
const Action = v.checkItems(requirement, message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `checkItems` you can freely validate the items of an array and return `true` if they are valid or `false` otherwise. If an item does not match your `requirement`, you can use `message` to customize the error message.
> The special thing about `checkItems` is that it automatically forwards each issue to the appropriate item.
#### Returns
- `Action`
#### Examples
The following examples show how `checkItems` can be used.
##### No duplicate items
Schema to validate that an array has no duplicate items.
```ts
const ArraySchema = v.pipe(
v.array(v.string()),
v.checkItems(
(item, index, array) => array.indexOf(item) === index,
'Duplicate items are not allowed.'
)
);
```
#### Related
The following APIs can be combined with `checkItems`.
##### Schemas
##### Methods
##### Utils
### creditCard
Creates a [credit card](https://en.wikipedia.org/wiki/Payment_card_number) validation action.
```ts
const Action = v.creditCard(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `creditCard` you can validate the formatting of a string. If the input is not a credit card, you can use `message` to customize the error message.
> The following credit card providers are currently supported: American Express, Diners Card, Discover, JCB, Union Pay, Master Card, and Visa.
#### Returns
- `Action`
#### Examples
The following examples show how `creditCard` can be used.
##### Credit Card schema
Schema to validate a credit card.
```ts
const CreditCardSchema = v.pipe(
v.string(),
v.creditCard('The credit card is badly formatted.')
);
```
#### Related
The following APIs can be combined with `creditCard`.
##### Schemas
##### Methods
##### Utils
### cuid2
Creates a [Cuid2](https://github.com/paralleldrive/cuid2) validation action.
```ts
const Action = v.cuid2(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `cuid2` you can validate the formatting of a string. If the input is not an Cuid2, you can use `message` to customize the error message.
> Since Cuid2s are not limited to a fixed length, it is recommended to combine `cuid2` with `length` to ensure the correct length.
#### Returns
- `Action`
#### Examples
The following examples show how `cuid2` can be used.
##### Cuid2 schema
Schema to validate an Cuid2.
```ts
const Cuid2Schema = v.pipe(
v.string(),
v.cuid2('The Cuid2 is badly formatted.'),
v.length(10, 'The Cuid2 must be 10 characters long.')
);
```
#### Related
The following APIs can be combined with `cuid2`.
##### Schemas
##### Methods
##### Utils
### decimal
Creates a [decimal](https://en.wikipedia.org/wiki/Decimal) validation action.
> The difference between `decimal` and `digits` is that `decimal` accepts floating point numbers and negative numbers, while `digits` accepts only the digits 0-9.
```ts
const Action = v.decimal(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `decimal` you can validate the formatting of a string. If the input is not a decimal, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `decimal` can be used.
##### Decimal schema
Schema to validate a decimal.
```ts
const DecimalSchema = v.pipe(
v.string(),
v.decimal('The decimal is badly formatted.')
);
```
#### Related
The following APIs can be combined with `decimal`.
##### Schemas
##### Methods
##### Utils
### description
Creates a description metadata action.
```ts
const Action = v.description(description_);
```
#### Generics
- `TInput`
- `TDescription`
#### Parameters
- `description_`
##### Explanation
With `description` you can describe the purpose of a schema. This can be useful when working with AI tools or for documentation purposes.
#### Returns
- `Action`
#### Examples
The following examples show how `description` can be used.
##### Username schema
Schema to validate a user name.
```ts
const UsernameSchema = v.pipe(
v.string(),
v.regex(/^[a-z0-9_-]{4,16}$/iu),
v.title('Username'),
v.description(
'A username must be between 4 and 16 characters long and can only contain letters, numbers, underscores and hyphens.'
)
);
```
#### Related
The following APIs can be combined with `description`.
##### Schemas
##### Methods
##### Utils
### digits
Creates a [digits](https://en.wikipedia.org/wiki/Numerical_digit) validation action.
> The difference between `digits` and `decimal` is that `digits` accepts only the digits 0-9, while `decimal` accepts floating point numbers and negative numbers.
```ts
const Action = v.digits(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `digits` you can validate the formatting of a string. If the input does not soley consist of numerical digits, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `digits` can be used.
##### Digits schema
Schema to validate a digits.
```ts
const DigitsSchema = v.pipe(
v.string(),
v.digits('The string contains something other than digits.')
);
```
#### Related
The following APIs can be combined with `digits`.
##### Schemas
##### Methods
##### Utils
### email
Creates an [email](https://en.wikipedia.org/wiki/Email_address) validation action.
```ts
const Action = v.email(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `email` you can validate the formatting of a string. If the input is not an email, you can use `message` to customize the error message.
> This validation action intentionally only validates common email addresses. If you are interested in an action that covers the entire specification, please use the `rfcEmail` action instead.
#### Returns
- `Action`
#### Examples
The following examples show how `email` can be used.
##### Email schema
Schema to validate an email.
```ts
const EmailSchema = v.pipe(
v.string(),
v.nonEmpty('Please enter your email.'),
v.email('The email is badly formatted.'),
v.maxLength(30, 'Your email is too long.')
);
```
#### Related
The following APIs can be combined with `email`.
##### Schemas
##### Methods
##### Utils
### emoji
Creates an [emoji](https://en.wikipedia.org/wiki/Emoji) validation action.
```ts
const Action = v.emoji(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `emoji` you can validate the formatting of a string. If the input is not an emoji, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `emoji` can be used.
##### Emoji schema
Schema to validate an emoji.
```ts
const EmojiSchema = v.pipe(
v.string(),
v.emoji('Please provide a valid emoji.')
);
```
#### Related
The following APIs can be combined with `emoji`.
##### Schemas
##### Methods
##### Utils
### empty
Creates an empty validation action.
```ts
const Action = v.empty(requirement, message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `empty` you can validate that a string or array is empty. If the input is not empty, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `empty` can be used.
##### String schema
Schema to validate that a string is empty.
```ts
const StringSchema = v.pipe(v.string(), v.empty('The string must be empty.'));
```
##### Array schema
Schema to validate that an array is empty.
```ts
const ArraySchema = v.pipe(
v.array(v.number()),
v.empty('The array must be empty.')
);
```
#### Related
The following APIs can be combined with `empty`.
##### Schemas
##### Methods
##### Utils
### endsWith
Creates an ends with validation action.
```ts
const Action = v.endsWith(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `endsWith` you can validate the end of a string. If the end does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `endsWith` can be used.
##### Email schema
Schema to validate an email with a specific domain.
```ts
const EmailSchema = v.pipe(v.string(), v.email(), v.endsWith('@example.com'));
```
#### Related
The following APIs can be combined with `endsWith`.
##### Schemas
##### Methods
##### Utils
### entries
Creates an entries validation action.
```ts
const Action = v.entries(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `entries` you can validate the number of entries of an object. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `entries` can be used.
##### Exact object entries
Schema to validate an object that does have 5 entries.
```ts
const EntriesSchema = v.pipe(
v.record(v.string(), v.number()),
v.entries(5, 'Object must have 5 entries')
);
```
#### Related
The following APIs can be combined with `entries`.
##### Schemas
##### Methods
##### Utils
### everyItem
Creates an every item validation action.
```ts
const Action = v.everyItem(requirement, message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `everyItem` you can freely validate the items of an array and return `true` if they are valid or `false` otherwise. If not every item matches your `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `everyItem` can be used.
##### Sorted array schema
Schema to validate that an array is sorted.
```ts
const SortedArraySchema = v.pipe(
v.array(v.number()),
v.everyItem(
(item, index, array) => index === 0 || item >= array[index - 1],
'The numbers must be sorted in ascending order.'
)
);
```
#### Related
The following APIs can be combined with `everyItem`.
##### Schemas
##### Methods
##### Utils
### excludes
Creates an excludes validation action.
```ts
const Action = v.excludes(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `excludes` you can validate the content of a string or array. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `excludes` can be used.
##### String schema
Schema to validate that a string does not contain a specific substring.
```ts
const StringSchema = v.pipe(
v.string(),
v.excludes('foo', 'The string must not contain "foo".')
);
```
##### Array schema
Schema to validate that an array does not contain a specific string.
```ts
const ArraySchema = v.pipe(
v.array(v.string()),
v.excludes('foo', 'The array must not contain "foo".')
);
```
#### Related
The following APIs can be combined with `excludes`.
##### Schemas
##### Methods
##### Utils
### filterItems
Creates a filter items transformation action.
```ts
const Action = v.filterItems(operation);
```
#### Generics
- `TInput`
#### Parameters
- `operation`
##### Explanation
With `filterItems` you can filter the items of an array. Returning `true` for an item will keep it in the array and returning `false` will remove it.
#### Returns
- `Action`
#### Examples
The following examples show how `filterItems` can be used.
##### Filter duplicate items
Schema to filter duplicate items from an array.
```ts
const FilteredArraySchema = v.pipe(
v.array(v.string()),
v.filterItems((item, index, array) => array.indexOf(item) === index)
);
```
#### Related
The following APIs can be combined with `filterItems`.
##### Schemas
##### Methods
##### Utils
### findItem
Creates a find item transformation action.
```ts
const Action = v.findItem(operation);
```
#### Generics
- `TInput`
#### Parameters
- `operation`
##### Explanation
With `findItem` you can extract the first item of an array that matches the given `operation`.
#### Returns
- `Action`
#### Examples
The following examples show how `findItem` can be used.
##### Find duplicate item
Schema to find the first duplicate item in an array.
```ts
const DuplicateItemSchema = v.pipe(
v.array(v.string()),
v.findItem((item, index, array) => array.indexOf(item) !== index)
);
```
#### Related
The following APIs can be combined with `findItem`.
##### Schemas
##### Methods
##### Utils
### finite
Creates a [finite](https://en.wikipedia.org/wiki/Finite) validation action.
```ts
const Action = v.finite(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `finite` you can validate the value of a number. If the input is not a finite number, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `finite` can be used.
##### Finite number schema
Schema to validate a finite number.
```ts
const FiniteNumberSchema = v.pipe(
v.number(),
v.finite('The number must be finite.')
);
```
#### Related
The following APIs can be combined with `finite`.
##### Schemas
##### Methods
##### Utils
### flavor
Creates a flavor transformation action.
```ts
const Action = v.flavor(name);
```
#### Generics
- `TInput`
- `TName`
#### Parameters
- `name`
##### Explanation
`flavor` is a less strict version of `brand` that allows you to flavor the output type of a schema with a `name`. Data is considered valid if it's type is unflavored or has been validated by a schema that has the same flavor.
> `falvor` can also be used as a TypeScript DX hack to improve the editor's autocompletion by displaying only literal types, but still allowing the unflavored root type to be passed.
#### Returns
- `Action`
#### Examples
The following examples show how `flavor` can be used.
##### Flavored ID schemas
Schema to ensure that different types of IDs are not mixed up.
```ts
// Create user ID and order ID schema
const UserIdSchema = v.pipe(v.string(), v.flavor('UserId'));
const OrderIdSchema = v.pipe(v.string(), v.flavor('OrderId'));
// Infer output types of both schemas
type UserId = v.InferOutput;
type OrderId = v.InferOutput;
// This works because output is flavored
const userId: UserId = v.parse(UserIdSchema, 'c28443ef...');
const orderId: OrderId = v.parse(OrderIdSchema, '4b717520...');
// You can also use unflavored strings
const newUserId1: UserId = '2d80cd94...';
// But this will result in a type error
const newUserId2: UserId = orderId;
```
#### Related
The following APIs can be combined with `flavor`.
##### Schemas
##### Methods
##### Utils
### graphemes
Creates a [graphemes](https://en.wikipedia.org/wiki/Grapheme) validation action.
```ts
const Action = v.graphemes(
requirement,
message
);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `graphemes` you can validate the graphemes of a string. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `graphemes` can be used.
##### Graphemes schema
Schema to validate a string with 8 graphemes.
```ts
const GraphemesSchema = v.pipe(
v.string(),
v.graphemes(8, 'Exactly 8 graphemes are required.')
);
```
#### Related
The following APIs can be combined with `graphemes`.
##### Schemas
##### Methods
##### Utils
### gtValue
Creates a greater than value validation action.
```ts
const Action = v.gtValue(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `gtValue` you can validate the value of a string, number, boolean or date. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `gtValue` can be used.
##### Number schema
Schema to validate a number with a greater than value.
```ts
const NumberSchema = v.pipe(
v.number(),
v.gtValue(100, 'The number must be greater than 100.')
);
```
##### Date schema
Schema to validate a date with a greater than year.
```ts
const DateSchema = v.pipe(
v.date(),
v.gtValue(
new Date('2000-01-01'),
'The date must be greater than 1st January 2000.'
)
);
```
#### Related
The following APIs can be combined with `gtValue`.
##### Schemas
##### Methods
##### Utils
### hash
Creates a [hash](https://en.wikipedia.org/wiki/Hash_function) validation action.
```ts
const Action = v.hash(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `types`
- `message`
##### Explanation
With `hash` you can validate the formatting of a string. If the input is not a hash, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `hash` can be used.
##### Hash schema
Schema to validate a hash.
```ts
const HashSchema = v.pipe(
v.string(),
v.hash(['md5', 'sha1'], 'The specified hash is invalid.')
);
```
#### Related
The following APIs can be combined with `hash`.
##### Schemas
##### Methods
##### Utils
### hexadecimal
Creates a [hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal) validation action.
```ts
const Action = v.hexadecimal(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `hexadecimal` you can validate the formatting of a string. If the input is not a hexadecimal, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `hexadecimal` can be used.
##### Hexadecimal schema
Schema to validate a Hexadecimal string.
```ts
const HexadecimalSchema = v.pipe(
v.string(),
v.hexadecimal('The hexadecimal is badly formatted.')
);
```
#### Related
The following APIs can be combined with `hexadecimal`.
##### Schemas
##### Methods
##### Utils
### hexColor
Creates a [hex color](https://en.wikipedia.org/wiki/Web_colors#Hex_triplet) validation action.
```ts
const Action = v.hexColor(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `hexColor` you can validate the formatting of a string. If the input is not a hex color, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `hexColor` can be used.
##### Hex color schema
Schema to validate a hex color.
```ts
const HexColorSchema = v.pipe(
v.string(),
v.hexColor('The hex color is badly formatted.')
);
```
#### Related
The following APIs can be combined with `hexColor`.
##### Schemas
##### Methods
##### Utils
### imei
Creates an [IMEI](https://en.wikipedia.org/wiki/International_Mobile_Equipment_Identity) validation action.
```ts
const Action = v.imei(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `imei` you can validate the formatting of a string. If the input is not an imei, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `imei` can be used.
##### IMEI schema
Schema to validate an IMEI.
```ts
const ImeiSchema = v.pipe(v.string(), v.imei('The imei is badly formatted.'));
```
#### Related
The following APIs can be combined with `imei`.
##### Schemas
##### Methods
##### Utils
### includes
Creates an includes validation action.
```ts
const Action = v.includes(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `includes` you can validate the content of a string or array. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `includes` can be used.
##### String schema
Schema to validate that a string contains a specific substring.
```ts
const StringSchema = v.pipe(
v.string(),
v.includes('foo', 'The string must contain "foo".')
);
```
##### Array schema
Schema to validate that an array contains a specific string.
```ts
const ArraySchema = v.pipe(
v.array(v.string()),
v.includes('foo', 'The array must contain "foo".')
);
```
#### Related
The following APIs can be combined with `includes`.
##### Schemas
##### Methods
##### Utils
### integer
Creates an [integer](https://en.wikipedia.org/wiki/Integer) validation action.
```ts
const Action = v.integer(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `integer` you can validate the value of a number. If the input is not an integer, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `integer` can be used.
##### Integer schema
Schema to validate an integer.
```ts
const IntegerSchema = v.pipe(
v.number(),
v.integer('The number must be an integer.')
);
```
#### Related
The following APIs can be combined with `integer`.
##### Schemas
##### Methods
##### Utils
### ip
Creates an [IP address](https://en.wikipedia.org/wiki/IP_address) validation action.
> This validation action accepts IPv4 and IPv6 addresses. For a more specific validation, you can also use `ipv4` or `ipv6`.
```ts
const Action = v.ip(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `ip` you can validate the formatting of a string. If the input is not an IP address, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `ip` can be used.
##### IP address schema
Schema to validate an IP address.
```ts
const IpAddressSchema = v.pipe(
v.string(),
v.ip('The IP address is badly formatted.')
);
```
#### Related
The following APIs can be combined with `ip`.
##### Schemas
##### Methods
##### Utils
### ipv4
Creates an [IPv4](https://en.wikipedia.org/wiki/IPv4) address validation action.
```ts
const Action = v.ipv4(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `ipv4` you can validate the formatting of a string. If the input is not an IPv4 address, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `ipv4` can be used.
##### IPv4 schema
Schema to validate an IPv4 address.
```ts
const Ipv4Schema = v.pipe(
v.string(),
v.ipv4('The IP address is badly formatted.')
);
```
#### Related
The following APIs can be combined with `ipv4`.
##### Schemas
##### Methods
##### Utils
### ipv6
Creates an [IPv6](https://en.wikipedia.org/wiki/IPv6) address validation action.
```ts
const Action = v.ipv6(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `ipv6` you can validate the formatting of a string. If the input is not an IPv6 address, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `ipv6` can be used.
##### IPv6 schema
Schema to validate an IPv6 address.
```ts
const Ipv6Schema = v.pipe(
v.string(),
v.ipv6('The IP address is badly formatted.')
);
```
#### Related
The following APIs can be combined with `ipv6`.
##### Schemas
##### Methods
##### Utils
### isoDate
Creates an [ISO date](https://en.wikipedia.org/wiki/ISO_8601) validation action.
Format: `yyyy-mm-dd`
> The regex used cannot validate the maximum number of days based on year and month. For example, "2023-06-31" is valid although June has only 30 days.
```ts
const Action = v.isoDate(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `isoDate` you can validate the formatting of a string. If the input is not an ISO date, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `isoDate` can be used.
##### ISO date schema
Schema to validate an ISO date.
```ts
const IsoDateSchema = v.pipe(
v.string(),
v.isoDate('The date is badly formatted.')
);
```
##### Minimum value schema
Schema to validate an ISO date is after a certain date.
```ts
const MinValueSchema = v.pipe(
v.string(),
v.isoDate(),
v.minValue('2000-01-01', 'The date must be after the year 1999.')
);
```
#### Related
The following APIs can be combined with `isoDate`.
##### Schemas
##### Methods
##### Utils
### isoDateTime
Creates an [ISO date time](https://en.wikipedia.org/wiki/ISO_8601) validation action.
Format: `yyyy-mm-ddThh:mm`
> The regex used cannot validate the maximum number of days based on year and month. For example, "2023-06-31T00:00" is valid although June has only 30 days.
> The regex also allows a space as a separator between the date and time parts instead of the "T" character.
```ts
const Action = v.isoDateTime(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `isoDateTime` you can validate the formatting of a string. If the input is not an ISO date time, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `isoDateTime` can be used.
##### ISO date time schema
Schema to validate an ISO date time.
```ts
const IsoDateTimeSchema = v.pipe(
v.string(),
v.isoDateTime('The date is badly formatted.')
);
```
#### Related
The following APIs can be combined with `isoDateTime`.
##### Schemas
##### Methods
##### Utils
### isoTime
Creates an [ISO time](https://en.wikipedia.org/wiki/ISO_8601) validation action.
Format: `hh:mm`
```ts
const Action = v.isoTime(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `isoTime` you can validate the formatting of a string. If the input is not an ISO time, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `isoTime` can be used.
##### ISO time schema
Schema to validate an ISO time.
```ts
const IsoTimeSchema = v.pipe(
v.string(),
v.isoTime('The time is badly formatted.')
);
```
#### Related
The following APIs can be combined with `isoTime`.
##### Schemas
##### Methods
##### Utils
### isoTimeSecond
Creates an [ISO time second](https://en.wikipedia.org/wiki/ISO_8601) validation action.
Format: `hh:mm:ss`
```ts
const Action = v.isoTimeSecond(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `isoTimeSecond` you can validate the formatting of a string. If the input is not an ISO time second, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `isoTimeSecond` can be used.
##### ISO time second schema
Schema to validate an ISO time second.
```ts
const IsoTimeSecondSchema = v.pipe(
v.string(),
v.isoTimeSecond('The time is badly formatted.')
);
```
#### Related
The following APIs can be combined with `isoTimeSecond`.
##### Schemas
##### Methods
##### Utils
### isoTimestamp
Creates an [ISO timestamp](https://en.wikipedia.org/wiki/ISO_8601) validation action.
Formats: `yyyy-mm-ddThh:mm:ss.sssZ`, `yyyy-mm-ddThh:mm:ss.sss±hh:mm`, `yyyy-mm-ddThh:mm:ss.sss±hhmm`
> To support timestamps with lower or higher accuracy, the millisecond specification can be removed or contain up to 9 digits.
> The regex used cannot validate the maximum number of days based on year and month. For example, "2023-06-31T00:00:00.000Z" is valid although June has only 30 days.
> The regex also allows a space as a separator between the date and time parts instead of the "T" character.
```ts
const Action = v.isoTimestamp(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `isoTimestamp` you can validate the formatting of a string. If the input is not an ISO timestamp, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `isoTimestamp` can be used.
##### ISO timestamp schema
Schema to validate an ISO timestamp.
```ts
const IsoTimestampSchema = v.pipe(
v.string(),
v.isoTimestamp('The timestamp is badly formatted.')
);
```
#### Related
The following APIs can be combined with `isoTimestamp`.
##### Schemas
##### Methods
##### Utils
### isoWeek
Creates an [ISO week](https://en.wikipedia.org/wiki/ISO_8601) validation action.
Format: `yyyy-Www`
> The regex used cannot validate the maximum number of weeks based on the year. For example, "2021W53" is valid although 2021 has only 52 weeks.
```ts
const Action = v.isoWeek(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `isoWeek` you can validate the formatting of a string. If the input is not an ISO week, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `isoWeek` can be used.
##### ISO week schema
Schema to validate an ISO week.
```ts
const IsoWeekSchema = v.pipe(
v.string(),
v.isoWeek('The week is badly formatted.')
);
```
#### Related
The following APIs can be combined with `isoWeek`.
##### Schemas
##### Methods
##### Utils
### length
Creates a length validation action.
```ts
const Action = v.length(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `length` you can validate the length of a string or array. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `length` can be used.
##### String schema
Schema to validate the length of a string.
```ts
const StringSchema = v.pipe(
v.string(),
v.length(8, 'The string must be 8 characters long.')
);
```
##### Array schema
Schema to validate the length of an array.
```ts
const ArraySchema = v.pipe(
v.array(v.number()),
v.length(100, 'The array must contain 100 numbers.')
);
```
#### Related
The following APIs can be combined with `length`.
##### Schemas
##### Methods
##### Utils
### mac
Creates a [MAC address](https://en.wikipedia.org/wiki/MAC_address) validation action.
> This validation action accepts 48-bit and 64-bit MAC addresses. For a more specific validation, you can also use `mac48` or `mac64`.
```ts
const Action = v.mac(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `mac` you can validate the formatting of a string. If the input is not a MAC address, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `mac` can be used.
##### MAC schema
Schema to validate a MAC address.
```ts
const MacSchema = v.pipe(
v.string(),
v.mac('The MAC address is badly formatted.')
);
```
#### Related
The following APIs can be combined with `mac`.
##### Schemas
##### Methods
##### Utils
### mac48
Creates a 48-bit [MAC address](https://en.wikipedia.org/wiki/MAC_address) validation action.
```ts
const Action = v.mac48(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `mac48` you can validate the formatting of a string. If the input is not a 48-bit MAC address, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `mac48` can be used.
##### 48-bit MAC schema
Schema to validate a 48-bit MAC address.
```ts
const Mac48Schema = v.pipe(
v.string(),
v.mac48('The MAC address is badly formatted.')
);
```
#### Related
The following APIs can be combined with `mac48`.
##### Schemas
##### Methods
##### Utils
### mac64
Creates a 64-bit [MAC address](https://en.wikipedia.org/wiki/MAC_address) validation action.
```ts
const Action = v.mac64(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `mac64` you can validate the formatting of a string. If the input is not a 64-bit MAC address, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `mac64` can be used.
##### 64-bit MAC schema
Schema to validate a 64-bit MAC address.
```ts
const Mac64Schema = v.pipe(
v.string(),
v.mac64('The MAC address is badly formatted.')
);
```
#### Related
The following APIs can be combined with `mac64`.
##### Schemas
##### Methods
##### Utils
### mapItems
Creates a map items transformation action.
```ts
const Action = v.mapItems(operation);
```
#### Generics
- `TInput`
- `TOutput`
#### Parameters
- `operation`
##### Explanation
With `mapItems` you can apply an `operation` to each item in an array to transform it.
#### Returns
- `Action`
#### Examples
The following examples show how `mapItems` can be used.
##### Mark duplicates
```ts
const MarkedArraySchema = v.pipe(
v.array(v.string()),
v.mapItems((item, index, array) => {
const isDuplicate = array.indexOf(item) !== index;
return { item, isDuplicate };
})
);
```
#### Related
The following APIs can be combined with `mapItems`.
##### Schemas
##### Methods
##### Utils
### maxBytes
Creates a max [bytes](https://en.wikipedia.org/wiki/Byte) validation action.
```ts
const Action = v.maxBytes(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `maxBytes` you can validate the bytes of a string. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `maxBytes` can be used.
##### Max bytes schema
Schema to validate a string with a maximum of 64 bytes.
```ts
const MaxBytesSchema = v.pipe(
v.string(),
v.maxBytes(64, 'The string must not exceed 64 bytes.')
);
```
#### Related
The following APIs can be combined with `maxBytes`.
##### Schemas
##### Methods
##### Utils
### maxEntries
Creates a max entries validation action.
```ts
const Action = v.maxEntries(
requirement,
message
);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `maxEntries` you can validate the number of entries of an object. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `maxEntries` can be used.
##### Maximum object entries
Schema to validate an object with a maximum of 5 entries.
```ts
const MaxEntriesSchema = v.pipe(
v.record(v.string(), v.number()),
v.maxEntries(5, 'Object must not exceed 5 entries.')
);
```
#### Related
The following APIs can be combined with `maxEntries`.
##### Schemas
##### Methods
##### Utils
### maxGraphemes
Creates a max [graphemes](https://en.wikipedia.org/wiki/Grapheme) validation action.
```ts
const Action = v.maxGraphemes(
requirement,
message
);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `maxGraphemes` you can validate the graphemes of a string. If the input does not match the `requirement`, you can use `message` to customize the error message.
> Hint: The number of characters per grapheme is not limited. You may want to consider combining `maxGraphemes` with `maxLength` or `maxBytes` to set a stricter limit.
#### Returns
- `Action`
#### Examples
The following examples show how `maxGraphemes` can be used.
##### Max graphemes schema
Schema to validate a string with a maximum of 8 graphemes.
```ts
const MaxGraphemesSchema = v.pipe(
v.string(),
v.maxGraphemes(8, 'The string must not exceed 8 graphemes.')
);
```
#### Related
The following APIs can be combined with `maxGraphemes`.
##### Schemas
##### Methods
##### Utils
### maxLength
Creates a max length validation action.
```ts
const Action = v.maxLength(
requirement,
message
);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `maxLength` you can validate the length of a string or array. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `maxLength` can be used.
##### Maximum string length
Schema to validate a string with a maximum length of 32 characters.
```ts
const MaxStringSchema = v.pipe(
v.string(),
v.maxLength(32, 'The string must not exceed 32 characters.')
);
```
##### Maximum array length
Schema to validate an array with a maximum length of 5 items.
```ts
const MaxArraySchema = v.pipe(
v.array(v.number()),
v.maxLength(5, 'The array must not exceed 5 numbers.')
);
```
#### Related
The following APIs can be combined with `maxLength`.
##### Schemas
##### Methods
##### Utils
### maxSize
Creates a max size validation action.
```ts
const Action = v.maxSize(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `maxSize` you can validate the size of a map, set or blob. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `maxSize` can be used.
##### Blob size schema
Schema to validate a blob with a maximum size of 10 MB.
```ts
const BlobSchema = v.pipe(
v.blob(),
v.maxSize(10 * 1024 * 1024, 'The blob must not exceed 10 MB.')
);
```
##### Set size schema
Schema to validate a set with a maximum of 8 numbers.
```ts
const SetSchema = v.pipe(
v.set(number()),
v.maxSize(8, 'The set must not exceed 8 numbers.')
);
```
#### Related
The following APIs can be combined with `maxSize`.
##### Schemas
##### Methods
##### Utils
### maxValue
Creates a max value validation action.
```ts
const Action = v.maxValue(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `maxValue` you can validate the value of a string, number, boolean or date. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `maxValue` can be used.
##### Number schema
Schema to validate a number with a maximum value.
```ts
const NumberSchema = v.pipe(
v.number(),
v.maxValue(100, 'The number must not exceed 100.')
);
```
##### Date schema
Schema to validate a date with a maximum year.
```ts
const DateSchema = v.pipe(
v.date(),
v.maxValue(new Date('1999-12-31'), 'The date must not exceed the year 1999.')
);
```
#### Related
The following APIs can be combined with `maxValue`.
##### Schemas
##### Methods
##### Utils
### maxWords
Creates a max [words](https://en.wikipedia.org/wiki/Word) validation action.
```ts
const Action = v.maxWords(
locales,
requirement,
message
);
```
#### Generics
- `TInput`
- `TLocales`
- `TRequirement`
- `TMessage`
#### Parameters
- `locales`
- `requirement`
- `message`
##### Explanation
With `maxWords` you can validate the words of a string based on the specified `locales`. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `maxWords` can be used.
##### Max words schema
Schema to validate a string with a maximum of 300 words.
```ts
const MaxWordsSchema = v.pipe(
v.string(),
v.maxWords('en', 300, 'The string must not exceed 300 words.')
);
```
#### Related
The following APIs can be combined with `maxWords`.
##### Schemas
##### Methods
##### Utils
### metadata
Creates a custom metadata action.
```ts
const Action = v.metadata(metadata_);
```
#### Generics
- `TInput`
- `TMetadata`
#### Parameters
- `metadata_`
##### Explanation
With `metadata` you can attach custom metadata to a schema. This can be useful when working with AI tools or for documentation purposes.
#### Returns
- `Action`
#### Examples
The following examples show how `metadata` can be used.
##### Profile table schema
Schema to describe a profile table.
```ts
const ProfileTableSchema = v.pipe(
v.object({
username: v.pipe(v.string(), v.nonEmpty()),
email: v.pipe(v.string(), v.email()),
avatar: v.pipe(v.string(), v.url()),
description: v.pipe(v.string(), v.maxLength(500)),
}),
v.metadata({
table: 'profiles',
primaryKey: 'username',
indexes: ['email'],
})
);
```
#### Related
The following APIs can be combined with `metadata`.
##### Schemas
##### Methods
##### Utils
### mimeType
Creates a [MIME type](https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types) validation action.
```ts
const Action = v.mimeType(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `mimeType` you can validate the MIME type of a blob. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `mimeType` can be used.
##### Image schema
Schema to validate an image file.
```ts
const ImageSchema = v.pipe(
v.blob(),
v.mimeType(['image/jpeg', 'image/png'], 'Please select a JPEG or PNG file.')
);
```
#### Related
The following APIs can be combined with `mimeType`.
##### Schemas
##### Methods
##### Utils
### minBytes
Creates a min [bytes](https://en.wikipedia.org/wiki/Byte) validation action.
```ts
const Action = v.minBytes(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `minBytes` you can validate the bytes of a string. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `minBytes` can be used.
##### Min bytes schema
Schema to validate a string with a minimum of 64 bytes.
```ts
const MinBytesSchema = v.pipe(
v.string(),
v.minBytes(64, 'The string must contain at least 64 bytes.')
);
```
#### Related
The following APIs can be combined with `minBytes`.
##### Schemas
##### Methods
##### Utils
### minEntries
Creates a min entries validation action.
```ts
const Action = v.minEntries(
requirement,
message
);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `minEntries` you can validate the number of entries of an object. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `minEntries` can be used.
##### Minimum object entries
Schema to validate an object with a minimum of 5 entries.
```ts
const MinEntriesSchema = v.pipe(
v.record(v.string(), v.number()),
v.minEntries(5, 'The object should have at least 5 entries.')
);
```
#### Related
The following APIs can be combined with `minEntries`.
##### Schemas
##### Methods
##### Utils
### minGraphemes
Creates a min [graphemes](https://en.wikipedia.org/wiki/Grapheme) validation action.
```ts
const Action = v.minGraphemes(
requirement,
message
);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `minGraphemes` you can validate the graphemes of a string. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `minGraphemes` can be used.
##### Min graphemes schema
Schema to validate a string with a minimum of 8 graphemes.
```ts
const MinGraphemesSchema = v.pipe(
v.string(),
v.minGraphemes(8, 'The string must contain at least 8 graphemes.')
);
```
#### Related
The following APIs can be combined with `minGraphemes`.
##### Schemas
##### Methods
##### Utils
### minLength
Creates a min length validation action.
```ts
const Action = v.minLength(
requirement,
message
);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `minLength` you can validate the length of a string or array. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `minLength` can be used.
##### Minimum string length
Schema to validate a string with a minimum length of 3 characters.
```ts
const MinStringSchema = v.pipe(
v.string(),
v.minLength(3, 'The string must be 3 or more characters long.')
);
```
##### Minimum array length
Schema to validate an array with a minimum length of 5 items.
```ts
const MinArraySchema = v.pipe(
v.array(v.number()),
v.minLength(5, 'The array must contain 5 numbers or more.')
);
```
#### Related
The following APIs can be combined with `minLength`.
##### Schemas
##### Methods
##### Utils
### minSize
Creates a min size validation action.
```ts
const Action = v.minSize(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `minSize` you can validate the size of a map, set or blob. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `minSize` can be used.
##### Blob size schema
Schema to validate a blob with a minimum size of 10 MB.
```ts
const BlobSchema = v.pipe(
v.blob(),
v.minSize(10 * 1024 * 1024, 'The blob must be at least 10 MB.')
);
```
##### Set size schema
Schema to validate a set with a minimum of 8 numbers.
```ts
const SetSchema = v.pipe(
v.set(number()),
v.minSize(8, 'The set must contain at least 8 numbers.')
);
```
#### Related
The following APIs can be combined with `minSize`.
##### Schemas
##### Methods
##### Utils
### minValue
Creates a min value validation action.
```ts
const Action = v.minValue(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `minValue` you can validate the value of a string, number, boolean or date. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `minValue` can be used.
##### Number schema
Schema to validate a number with a minimum value.
```ts
const NumberSchema = v.pipe(
v.number(),
v.minValue(100, 'The number must be at least 100.')
);
```
##### Date schema
Schema to validate a date with a minimum year.
```ts
const DateSchema = v.pipe(
v.date(),
v.minValue(new Date('2000-01-01'), 'The date must be after the year 1999.')
);
```
#### Related
The following APIs can be combined with `minValue`.
##### Schemas
##### Methods
##### Utils
### minWords
Creates a min [words](https://en.wikipedia.org/wiki/Word) validation action.
```ts
const Action = v.minWords(
locales,
requirement,
message
);
```
#### Generics
- `TInput`
- `TLocales`
- `TRequirement`
- `TMessage`
#### Parameters
- `locales`
- `requirement`
- `message`
##### Explanation
With `minWords` you can validate the words of a string based on the specified `locales`. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `minWords` can be used.
##### Min words schema
Schema to validate a string with a minimum of 50 words.
```ts
const MinWordsSchema = v.pipe(
v.string(),
v.minWords('en', 50, 'The string must contain at least 50 words.')
);
```
#### Related
The following APIs can be combined with `minWords`.
##### Schemas
##### Methods
##### Utils
### multipleOf
Creates a [multiple]() of validation action.
```ts
const Action = v.multipleOf(
requirement,
message
);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `multipleOf` you can validate the value of a number. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `multipleOf` can be used.
##### Even number schema
Schema to validate an even number.
```ts
const EvenNumberSchema = v.pipe(
v.number(),
v.multipleOf(2, 'The number must be even.')
);
```
#### Related
The following APIs can be combined with `multipleOf`.
##### Schemas
##### Methods
##### Utils
### nanoid
Creates a [Nano ID](https://github.com/ai/nanoid) validation action.
```ts
const Action = v.nanoid(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `nanoid` you can validate the formatting of a string. If the input is not an Nano ID, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `nanoid` can be used.
> Since Nano IDs are not limited to a fixed length, it is recommended to combine `nanoid` with `length` to ensure the correct length.
##### Nano ID schema
Schema to validate a Nano ID.
```ts
const NanoIdSchema = v.pipe(
v.string(),
v.nanoid('The Nano ID is badly formatted.'),
v.length(21, 'The Nano ID must be 21 characters long.')
);
```
#### Related
The following APIs can be combined with `nanoid`.
##### Schemas
##### Methods
##### Utils
### nonEmpty
Creates a non-empty validation action.
```ts
const Action = v.nonEmpty(requirement, message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `nonEmpty` you can validate that a string or array is non-empty. If the input is empty, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `nonEmpty` can be used.
##### String schema
Schema to validate that a string is non-empty.
```ts
const StringSchema = v.pipe(
v.string(),
v.nonEmpty('The string should contain at least one character.')
);
```
##### Array schema
Schema to validate that an array is non-empty.
```ts
const ArraySchema = v.pipe(
v.array(v.number()),
v.nonEmpty('The array should contain at least one item.')
);
```
#### Related
The following APIs can be combined with `nonEmpty`.
##### Schemas
##### Methods
##### Utils
### normalize
Creates a normalize transformation action.
```ts
const Action = v.normalize(form);
```
#### Generics
- `TForm`
#### Parameters
- `form`
#### Returns
- `Action`
#### Examples
The following examples show how `normalize` can be used.
##### Normalized string
Schema to normalize a string.
```ts
const StringSchema = v.pipe(v.string(), v.normalize());
```
#### Related
The following APIs can be combined with `normalize`.
##### Schemas
##### Methods
##### Utils
### notBytes
Creates a not [bytes](https://en.wikipedia.org/wiki/Byte) validation action.
```ts
const Action = v.notBytes(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `notBytes` you can validate the bytes of a string. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `notBytes` can be used.
##### Not bytes schema
Schema to validate a string with more or less than 8 bytes.
```ts
const NotBytesSchema = v.pipe(
v.string(),
v.notBytes(8, 'The string must not have 8 bytes.')
);
```
#### Related
The following APIs can be combined with `notBytes`.
##### Schemas
##### Methods
##### Utils
### notEntries
Creates a not entries validation action.
```ts
const Action = v.notEntries(
requirement,
message
);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `notEntries` you can validate the number of entries of an object. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `notEntries` can be used.
##### Not object entries
Schema to validate an object that does not have 5 entries.
```ts
const NotEntriesSchema = v.pipe(
v.record(v.string(), v.number()),
v.notEntries(5, 'Object must not have 5 entries')
);
```
#### Related
The following APIs can be combined with `notEntries`.
##### Schemas
##### Methods
##### Utils
### notGraphemes
Creates a not [graphemes](https://en.wikipedia.org/wiki/Grapheme) validation action.
```ts
const Action = v.notGraphemes(
requirement,
message
);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `notGraphemes` you can validate the graphemes of a string. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `notGraphemes` can be used.
##### Not graphemes schema
Schema to validate a string with more or less than 8 graphemes.
```ts
const NotGraphemesSchema = v.pipe(
v.string(),
v.notGraphemes(8, 'The string must not have 8 graphemes.')
);
```
#### Related
The following APIs can be combined with `notGraphemes`.
##### Schemas
##### Methods
##### Utils
### notLength
Creates a not length validation action.
```ts
const Action = v.notLength(
requirement,
message
);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `notLength` you can validate the length of a string or array. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `notLength` can be used.
##### String schema
Schema to validate the length of a string.
```ts
const StringSchema = v.pipe(
v.string(),
v.notLength(8, 'The string must not be 8 characters long.')
);
```
##### Array schema
Schema to validate the length of an array.
```ts
const ArraySchema = v.pipe(
v.array(number()),
v.notLength(10, 'The array must not contain 10 numbers.')
);
```
#### Related
The following APIs can be combined with `notLength`.
##### Schemas
##### Methods
##### Utils
### notSize
Creates a not size validation action.
```ts
const Action = v.notSize(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `notSize` you can validate the size of a map, set or blob. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `notSize` can be used.
##### Blob size schema
Schema to validate a blob with less ore more then 10 MB.
```ts
const BlobSchema = v.pipe(
v.blob(),
v.notSize(10 * 1024 * 1024, 'The blob must not be 10 MB in size.')
);
```
##### Set size schema
Schema to validate a set with less ore more then 8 numbers.
```ts
const SetSchema = v.pipe(
v.set(number()),
v.notSize(8, 'The set must not contain 8 numbers.')
);
```
#### Related
The following APIs can be combined with `notSize`.
##### Schemas
##### Methods
##### Utils
### notValue
Creates a not value validation action.
```ts
const Action = v.notValue(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `notValue` you can validate the value of a string, number, boolean or date. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `notValue` can be used.
##### Number schema
Schema to validate a number that is more or less than 100.
```ts
const NumberSchema = v.pipe(
v.number(),
v.notValue(100, 'The number must not be 100.')
);
```
##### Date schema
Schema to validate a date that is before or after the start of 2000.
```ts
const DateSchema = v.pipe(
v.date(),
v.notValue(new Date('2000-01-01'), 'The date must not be the start of 2000.')
);
```
#### Related
The following APIs can be combined with `notValue`.
##### Schemas
##### Methods
##### Utils
### notValues
Creates a not values validation action.
```ts
const Action = v.notValues(
requirement,
message
);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `notValues` you can validate the value of a string, number, boolean or date. If the input matches one of the values in the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `notValues` can be used.
##### Number schema
Schema to validate a number that is not 10, 11 or 12.
```ts
const NumberSchema = v.pipe(
v.number(),
v.notValues([10, 11, 12], 'The number must not be 10, 11 or 12.')
);
```
#### Related
The following APIs can be combined with `notValues`.
##### Schemas
##### Methods
##### Utils
### notWords
Creates a not [words](https://en.wikipedia.org/wiki/Word) validation action.
```ts
const Action = v.notWords(
locales,
requirement,
message
);
```
#### Generics
- `TInput`
- `TLocales`
- `TRequirement`
- `TMessage`
#### Parameters
- `locales`
- `requirement`
- `message`
##### Explanation
With `notWords` you can validate the words of a string based on the specified `locales`. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `notWords` can be used.
##### Not words schema
Schema to validate a string with more or less than 5 words.
```ts
const NotWordsSchema = v.pipe(
v.string(),
v.notWords('en', 5, 'The string must not have 5 words.')
);
```
#### Related
The following APIs can be combined with `notWords`.
##### Schemas
##### Methods
##### Utils
### octal
Creates an [octal](https://en.wikipedia.org/wiki/Octal) validation action.
```ts
const Action = v.octal(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `octal` you can validate the formatting of a string. If the input is not an octal, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `octal` can be used.
##### Octal schema
Schema to validate a octal string.
```ts
const OctalSchema = v.pipe(
v.string(),
v.octal('The octal is badly formatted.')
);
```
#### Related
The following APIs can be combined with `octal`.
##### Schemas
##### Methods
##### Utils
### parseJson
Creates a JSON parse transformation action.
```ts
const Action = v.parseJson(config, message);
```
#### Generics
- `TInput`
- `TConfig`
- `TMessage`
#### Parameters
- `config`
- `message`
##### Explanation
With `parseJson` you can parse a JSON string. If the input is not valid JSON, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `parseJson` can be used.
##### Parse and validate JSON
Parse a JSON string and validate the result.
```ts
const StringifiedObjectSchema = v.pipe(
v.string(),
v.parseJson(),
v.object({ key: v.string() })
);
```
##### Parse JSON with reviver
Parse a JSON string with a reviver function.
```ts
const StringifiedObjectSchema = v.pipe(
v.string(),
v.parseJson({
reviver: (key, value) =>
typeof value === 'string' ? value.toUpperCase() : value,
}),
v.object({ key: v.string() })
);
```
#### Related
The following APIs can be combined with `parseJson`.
##### Schemas
##### Methods
##### Utils
### partialCheck
Creates a partial check validation action.
```ts
const Action = v.partialCheck(
paths,
requirement,
message
);
```
#### Generics
- `TInput`
- `TPaths`
- `TSelection`
- `TMessage`
#### Parameters
- `paths`
- `requirement`
- `message`
##### Explanation
With `partialCheck` you can freely validate the selected input and return `true` if it is valid or `false` otherwise. If the input does not match your `requirement`, you can use `message` to customize the error message.
> The difference to `check` is that `partialCheck` can be executed whenever the selected part of the data is valid, while `check` is executed only when the entire dataset is typed. This can be an important advantage when working with forms.
#### Returns
- `Action`
#### Examples
The following examples show how `partialCheck` can be used.
##### Register schema
Schema that ensures that the two passwords match.
```ts
const RegisterSchema = v.pipe(
v.object({
email: v.pipe(
v.string(),
v.nonEmpty('Please enter your email.'),
v.email('The email address is badly formatted.')
),
password1: v.pipe(
v.string(),
v.nonEmpty('Please enter your password.'),
v.minLength(8, 'Your password must have 8 characters or more.')
),
password2: v.string(),
}),
v.forward(
v.partialCheck(
[['password1'], ['password2']],
(input) => input.password1 === input.password2,
'The two passwords do not match.'
),
['password2']
)
);
```
#### Related
The following APIs can be combined with `partialCheck`.
##### Schemas
##### Methods
##### Utils
### rawCheck
Creates a raw check validation action.
```ts
const Action = v.rawCheck(action);
```
#### Generics
- `TInput`
#### Parameters
- `action`
##### Explanation
With `rawCheck` you can freely validate the input with a custom `action` and add issues if necessary.
#### Returns
- `Action`
#### Examples
The following examples show how `rawCheck` can be used.
##### Emails schema
Object schema that ensures that the primary email is not the same as any of the other emails.
> This `rawCheck` validation action adds an issue for any invalid other email and forwards it via `path` to the appropriate nested field.
```ts
const EmailsSchema = v.pipe(
v.object({
primaryEmail: v.pipe(v.string(), v.email()),
otherEmails: v.array(v.pipe(v.string(), v.email())),
}),
v.rawCheck(({ dataset, addIssue }) => {
if (dataset.typed) {
dataset.value.otherEmails.forEach((otherEmail, index) => {
if (otherEmail === dataset.value.primaryEmail) {
addIssue({
message: 'This email is already being used as the primary email.',
path: [
{
type: 'object',
origin: 'value',
input: dataset.value,
key: 'otherEmails',
value: dataset.value.otherEmails,
},
{
type: 'array',
origin: 'value',
input: dataset.value.otherEmails,
key: index,
value: otherEmail,
},
],
});
}
});
}
})
);
```
#### Related
The following APIs can be combined with `rawCheck`.
##### Schemas
##### Methods
##### Utils
### rawTransform
Creates a raw transformation action.
```ts
const Action = v.rawTransform(action);
```
#### Generics
- `TInput`
- `TOutput`
#### Parameters
- `action`
##### Explanation
With `rawTransform` you can freely transform and validate the input with a custom `action` and add issues if necessary.
#### Returns
- `Action`
#### Examples
The following examples show how `rawTransform` can be used.
##### Calculate game result
Schema that calculates the total score of a game based on the scores and a multiplier.
> This `rawTransform` validation action adds an issue for points that exceed a certain maximum and forwards it via `path` to the appropriate nested score.
```ts
const GameResultSchema = v.pipe(
v.object({
scores: v.array(v.pipe(v.number(), v.integer())),
multiplier: v.number(),
}),
v.rawTransform(({ dataset, addIssue, NEVER }) => {
// Create total variable
let total = 0;
// Iterate over scores and check points
for (let index = 0; index < dataset.value.scores.length; index++) {
// Calculate points by multiplying score with multiplier
const score = dataset.value.scores[index];
const points = score * dataset.value.multiplier;
// Add issue if points exceed maximum of 1,000 points
if (points > 1_000) {
addIssue({
message:
'The score exceeds the maximum allowed value of 1,000 points.',
path: [
{
type: 'object',
origin: 'value',
input: dataset.value,
key: 'scores',
value: dataset.value.scores,
},
{
type: 'array',
origin: 'value',
input: dataset.value.scores,
key: index,
value: score,
},
],
});
// Abort transformation
return NEVER;
}
// Add points to total
total += points;
}
// Add calculated total to dataset
return { ...dataset.value, total };
})
);
```
#### Related
The following APIs can be combined with `rawTransform`.
##### Schemas
##### Methods
##### Utils
### readonly
Creates a readonly transformation action.
```ts
const Action = v.readonly();
```
#### Generics
- `TInput`
#### Returns
- `Action`
#### Examples
The following examples show how `readonly` can be used.
##### Readonly array
Schema for a readonly array of numbers.
```ts
const ArraySchema = v.pipe(v.array(v.number()), v.readonly());
```
##### Readonly entry
Object schema with an entry marked as readonly.
```ts
const ObjectSchema = v.object({
name: v.string(),
username: v.pipe(v.string(), v.readonly()),
age: v.number(),
});
```
#### Related
The following APIs can be combined with `readonly`.
##### Schemas
##### Methods
##### Utils
### reduceItems
Creates a reduce items transformation action.
```ts
const Action = v.reduceItems(operation, initial);
```
#### Generics
- `TInput`
- `TOutput`
#### Parameters
- `operation`
- `initial`
##### Explanation
With `reduceItems` you can apply an `operation` to each item in an array to reduce it to a single value.
#### Returns
- `Action`
#### Examples
The following examples show how `reduceItems` can be used.
##### Sum all numbers
Schema that sums all the numbers in an array.
```ts
const SumArraySchema = v.pipe(
v.array(v.number()),
v.reduceItems((sum, item) => sum + item, 0)
);
```
#### Related
The following APIs can be combined with `reduceItems`.
##### Schemas
##### Methods
##### Utils
### regex
Creates a [regex](https://en.wikipedia.org/wiki/Regular_expression) validation action.
```ts
const Action = v.regex(requirement, message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `regex` you can validate the formatting of a string. If the input does not match the `requirement`, you can use `message` to customize the error message.
> Hint: Be careful with the global flag `g` in your regex pattern, as it can lead to unexpected results. See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test#using_test_on_a_regex_with_the_global_flag) for more information.
#### Returns
- `Action`
#### Examples
The following examples show how `regex` can be used.
##### Pixel string schema
Schema to validate a pixel string.
```ts
const PixelStringSchema = v.pipe(
v.string(),
v.regex(/^\d+px$/, 'The pixel string is badly formatted.')
);
```
#### Related
The following APIs can be combined with `regex`.
##### Schemas
##### Methods
##### Utils
### returns
Creates a function return transformation action.
```ts
const Action = v.returns(schema);
```
#### Generics
- `TInput`
- `TSchema`
#### Parameters
- `schema`
##### Explanation
With `returns` you can force the returned value of a function to match the given `schema`.
#### Returns
- `Action`
#### Examples
The following examples show how `returns` can be used.
##### Function schema
Schema of a function that transforms a string to a number.
```ts
const FunctionSchema = v.pipe(
v.function(),
v.args(v.tuple([v.pipe(v.string(), v.decimal())])),
v.returns(v.number())
);
```
#### Related
The following APIs can be combined with `returns`.
##### Schemas
##### Methods
##### Utils
### rfcEmail
Creates a [RFC email](https://datatracker.ietf.org/doc/html/rfc5322#section-3.4.1) validation action.
```ts
const Action = v.rfcEmail(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `rfcEmail` you can validate the formatting of a string. If the input is not an email, you can use `message` to customize the error message.
> This validation action intentionally validates the entire RFC 5322 specification. If you are interested in an action that only covers common email addresses, please use the `email` action instead.
#### Returns
- `Action`
#### Examples
The following examples show how `rfcEmail` can be used.
##### Email schema
Schema to validate an email.
```ts
const EmailSchema = v.pipe(
v.string(),
v.nonEmpty('Please enter your email.'),
v.rfcEmail('The email is badly formatted.'),
v.maxLength(30, 'Your email is too long.')
);
```
#### Related
The following APIs can be combined with `rfcEmail`.
##### Schemas
##### Methods
##### Utils
### safeInteger
Creates a safe integer validation action.
```ts
const Action = v.safeInteger(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `safeInteger` you can validate the value of a number. If the input is not a safe integer, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `safeInteger` can be used.
##### Safe integer schema
Schema to validate an safe integer.
```ts
const SafeIntegerSchema = v.pipe(
v.number(),
v.safeInteger('The number must be a safe integer.')
);
```
#### Related
The following APIs can be combined with `safeInteger`.
##### Schemas
##### Methods
##### Utils
### size
Creates a size validation action.
```ts
const Action = v.size(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `size` you can validate the size of a map, set or blob. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `size` can be used.
##### Blob size schema
Schema to validate a blob with a size of 256 bytes.
```ts
const BlobSchema = v.pipe(
v.blob(),
v.size(256, 'The blob must be 256 bytes in size.')
);
```
##### Set size schema
Schema to validate a set of 8 numbers.
```ts
const SetSchema = v.pipe(
v.set(number()),
v.size(8, 'The set must contain 8 numbers.')
);
```
#### Related
The following APIs can be combined with `size`.
##### Schemas
##### Methods
##### Utils
### slug
Creates an [slug](https://en.wikipedia.org/wiki/Clean_URL#Slug) validation action.
```ts
const Action = v.slug(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `slug` you can validate the formatting of a string. If the input is not a URL slug, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `slug` can be used.
##### Slug schema
Schema to validate a slug.
```ts
const SlugSchema = v.pipe(
v.string(),
v.nonEmpty('Please provide a slug.'),
v.slug('The slug is badly formatted.'),
v.maxLength(100, 'Your slug is too long.')
);
```
#### Related
The following APIs can be combined with `slug`.
##### Schemas
##### Methods
##### Utils
### someItem
Creates a some item validation action.
```ts
const Action = v.someItem(requirement, message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `someItem` you can freely validate the items of an array and return `true` if they are valid or `false` otherwise. If not some item matches your `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `someItem` can be used.
##### Unsorted array schema
Schema to validate that an array is not sorted.
```ts
const UnsortedArraySchema = v.pipe(
v.array(v.number()),
v.someItem(
(item, index, array) => array.length === 1 || item < array[index - 1],
'The numbers must not be sorted in ascending order.'
)
);
```
#### Related
The following APIs can be combined with `someItem`.
##### Schemas
##### Methods
##### Utils
### sortItems
Creates a sort items transformation action.
```ts
const Action = v.sortItems(operation);
```
#### Generics
- `TInput`
#### Parameters
- `operation`
##### Explanation
With `sortItems` you can sort the items of an array based on a custom `operation`. This is a function that takes two items and returns a number. If the number is less than 0, the first item is sorted before the second item. If the number is greater than 0, the second item is sorted before the first. If the number is 0, the order of the items is not changed.
#### Returns
- `Action`
#### Examples
The following examples show how `sortItems` can be used.
##### Sort numbers
Schema that sorts the numbers in an array in ascending order.
```ts
const SortedArraySchema = v.pipe(v.array(v.number()), v.sortItems());
```
#### Related
The following APIs can be combined with `sortItems`.
##### Schemas
##### Methods
##### Utils
### startsWith
Creates a starts with validation action.
```ts
const Action = v.startsWith(
requirement,
message
);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `startsWith` you can validate the start of a string. If the start does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `startsWith` can be used.
##### HTTPS URL schema
Schema to validate a HTTPS URL.
```ts
const HttpsUrlSchema = v.pipe(v.string(), v.url(), v.startsWith('https://'));
```
#### Related
The following APIs can be combined with `startsWith`.
##### Schemas
##### Methods
##### Utils
### stringifyJson
Creates a JSON stringify transformation action.
```ts
const Action = v.stringifyJson(config, message);
```
#### Generics
- `TInput`
- `TConfig`
- `TMessage`
#### Parameters
- `config`
- `message`
##### Explanation
With `stringifyJson` you can stringify a JSON object. If the input is unable to be stringified, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `stringifyJson` can be used.
##### Stringify JSON
Stringify a JSON object.
```ts
const StringifiedObjectSchema = v.pipe(
v.object({ key: v.string() }),
v.stringifyJson()
);
```
##### Stringify JSON with replacer
Stringify a JSON object with a replacer function.
```ts
const StringifiedObjectSchema = v.pipe(
v.object({ key: v.string() }),
v.stringifyJson({
replacer: (key, value) =>
typeof value === 'string' ? value.toUpperCase() : value,
})
);
```
#### Related
The following APIs can be combined with `stringifyJson`.
##### Schemas
##### Methods
##### Utils
### title
Creates a title metadata action.
```ts
const Action = v.title(title_);
```
#### Generics
- `TInput`
- `TTitle`
#### Parameters
- `title_`
##### Explanation
With `title` you can give a title to a schema. This can be useful when working with AI tools or for documentation purposes.
#### Returns
- `Action`
#### Examples
The following examples show how `title` can be used.
##### Username schema
Schema to validate a user name.
```ts
const UsernameSchema = v.pipe(
v.string(),
v.regex(/^[a-z0-9_-]{4,16}$/iu),
v.title('Username'),
v.description(
'A username must be between 4 and 16 characters long and can only contain letters, numbers, underscores and hyphens.'
)
);
```
#### Related
The following APIs can be combined with `title`.
##### Schemas
##### Methods
##### Utils
### toLowerCase
Creates a to lower case transformation action.
```ts
const Action = v.toLowerCase();
```
#### Returns
- `Action`
#### Examples
The following examples show how `toLowerCase` can be used.
##### Lower case string
Schema that transforms a string to lower case.
```ts
const StringSchema = v.pipe(v.string(), v.toLowerCase());
```
#### Related
The following APIs can be combined with `toLowerCase`.
##### Schemas
##### Methods
##### Utils
### toMaxValue
Creates a to max value transformation action.
```ts
const Action = v.toMaxValue(requirement);
```
#### Generics
- `TInput`
- `TRequirement`
#### Parameters
- `requirement`
##### Explanation
With `toMaxValue` you can enforce a maximum value for a number, date or string. If the input does not meet the `requirement`, it will be changed to its value.
#### Returns
- `Action`
#### Examples
The following examples show how `toMaxValue` can be used.
##### Number schema
Schema to enforce a maximum value for a number.
```ts
const NumberSchema = v.pipe(v.number(), v.toMaxValue(100));
```
##### Date schema
Schema to enforce a maximum value for a date.
```ts
const DateSchema = v.pipe(v.date(), v.toMaxValue(new Date('1999-12-31')));
```
#### Related
The following APIs can be combined with `toMaxValue`.
##### Schemas
##### Methods
##### Utils
### toMinValue
Creates a to min value transformation action.
```ts
const Action = v.toMinValue(requirement);
```
#### Generics
- `TInput`
- `TRequirement`
#### Parameters
- `requirement`
##### Explanation
With `toMinValue` you can enforce a minimum value for a number, date or string. If the input does not meet the `requirement`, it will be changed to its value.
#### Returns
- `Action`
#### Examples
The following examples show how `toMinValue` can be used.
##### Number schema
Schema to enforce a minimum value for a number.
```ts
const NumberSchema = v.pipe(v.number(), v.toMinValue(100));
```
##### Date schema
Schema to enforce a minimum value for a date.
```ts
const DateSchema = v.pipe(v.date(), v.toMinValue(new Date('1999-12-31')));
```
#### Related
The following APIs can be combined with `toMinValue`.
##### Schemas
##### Methods
##### Utils
### toUpperCase
Creates a to upper case transformation action.
```ts
const Action = v.toUpperCase();
```
#### Returns
- `Action`
#### Examples
The following examples show how `toUpperCase` can be used.
##### Lower case string
Schema that transforms a string to upper case.
```ts
const StringSchema = v.pipe(v.string(), v.toUpperCase());
```
#### Related
The following APIs can be combined with `toUpperCase`.
##### Schemas
##### Methods
##### Utils
### transform
Creates a custom transformation action.
```ts
const Action = v.transform(action);
```
#### Generics
- `TInput`
- `TOutput`
#### Parameters
- `action`
##### Explanation
`transform` can be used to freely transform the input. The `action` parameter is a function that takes the input and returns the transformed output.
#### Returns
- `Action`
#### Examples
The following examples show how `transform` can be used.
##### Transform to length
Schema that transforms a string to its length.
```ts
const StringLengthSchema = v.pipe(
v.string(),
v.transform((input) => input.length)
);
```
##### Add object entry
Schema that transforms an object to add an entry.
```ts
const UserSchema = v.pipe(
v.object({ name: v.string(), age: v.number() }),
v.transform((input) => ({
...input,
created: new Date().toISOString(),
}))
);
```
#### Related
The following APIs can be combined with `transform`.
##### Schemas
##### Methods
##### Utils
### trim
Creates a trim transformation action.
```ts
const Action = v.trim();
```
#### Returns
- `Action`
#### Examples
The following examples show how `trim` can be used.
##### Trimmed string
Schema to trim the start and end of a string.
```ts
const StringSchema = v.pipe(v.string(), v.trim());
```
#### Related
The following APIs can be combined with `trim`.
##### Schemas
##### Methods
##### Utils
### trimEnd
Creates a trim end transformation action.
```ts
const Action = v.trimEnd();
```
#### Returns
- `Action`
#### Examples
The following examples show how `trimEnd` can be used.
##### Trimmed string
Schema to trimEnd the end of a string.
```ts
const StringSchema = v.pipe(v.string(), v.trimEnd());
```
#### Related
The following APIs can be combined with `trimEnd`.
##### Schemas
##### Methods
##### Utils
### trimStart
Creates a trim start transformation action.
```ts
const Action = v.trimStart();
```
#### Returns
- `Action`
#### Examples
The following examples show how `trimStart` can be used.
##### Trimmed string
Schema to trimStart the start of a string.
```ts
const StringSchema = v.pipe(v.string(), v.trimStart());
```
#### Related
The following APIs can be combined with `trimStart`.
##### Schemas
##### Methods
##### Utils
### ulid
Creates an [ULID](https://github.com/ulid/spec) validation action.
```ts
const Action = v.ulid(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `ulid` you can validate the formatting of a string. If the input is not an ULID, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `ulid` can be used.
##### ULID schema
Schema to validate an ULID.
```ts
const UlidSchema = v.pipe(v.string(), v.ulid('The ULID is badly formatted.'));
```
#### Related
The following APIs can be combined with `ulid`.
##### Schemas
##### Methods
##### Utils
### url
Creates an [URL](https://en.wikipedia.org/wiki/URL) validation action.
```ts
const Action = v.url(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `url` you can validate the formatting of a string. If the input is not an URL, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `url` can be used.
##### URL schema
Schema to validate an URL.
```ts
const UrlSchema = v.pipe(
v.string(),
v.nonEmpty('Please enter your url.'),
v.url('The url is badly formatted.'),
v.endsWith('.com', 'Only ".com" domains are allowed.')
);
```
#### Related
The following APIs can be combined with `url`.
##### Schemas
##### Methods
##### Utils
### uuid
Creates an [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier) validation action.
```ts
const Action = v.uuid(message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `message`
##### Explanation
With `uuid` you can validate the formatting of a string. If the input is not an UUID, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `uuid` can be used.
##### UUID schema
Schema to validate an UUID.
```ts
const UuidSchema = v.pipe(v.string(), v.uuid('The UUID is badly formatted.'));
```
#### Related
The following APIs can be combined with `uuid`.
##### Schemas
##### Methods
##### Utils
### value
Creates a value validation action.
```ts
const Action = v.value(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `value` you can validate the value of a string, number, boolean or date. If the input does not match the `requirement`, you can use `message` to customize the error message.
> This action does not change the type of the pipeline. Use the `literal` schema instead if you want the type to match a specific value.
#### Returns
- `Action`
#### Examples
The following examples show how `value` can be used.
##### Number schema
Schema to validate a number with a specific value.
```ts
const NumberSchema = v.pipe(
v.number(),
v.value(100, 'The number must be 100.')
);
```
##### Date schema
Schema to validate a date with a specific value.
```ts
const DateSchema = v.pipe(
v.date(),
v.value(new Date('2000-01-01'), 'The date must be the first day of 2000.')
);
```
#### Related
The following APIs can be combined with `value`.
##### Schemas
##### Methods
##### Utils
### values
Creates a values validation action.
```ts
const Action = v.values(requirement, message);
```
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `values` you can validate the value of a string, number, boolean or date. If the input does not match one of the values in the `requirement`, you can use `message` to customize the error message.
> This action does not change the type of the pipeline. Use the `picklist` schema instead if you want the type to match the union of specific values.
#### Returns
- `Action`
#### Examples
The following examples show how `values` can be used.
##### Number schema
Schema to validate a number with specific values.
```ts
const NumberSchema = v.pipe(
v.number(),
v.values([5, 15, 20], 'The number must be one of the allowed numbers.')
);
```
#### Related
The following APIs can be combined with `values`.
##### Schemas
##### Methods
##### Utils
### words
Creates a [words](https://en.wikipedia.org/wiki/Word) validation action.
```ts
const Action = v.words(
locales,
requirement,
message
);
```
#### Generics
- `TInput`
- `TLocales`
- `TRequirement`
- `TMessage`
#### Parameters
- `locales`
- `requirement`
- `message`
##### Explanation
With `words` you can validate the words of a string based on the specified `locales`. If the input does not match the `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `words` can be used.
##### Words schema
Schema to validate a string with 3 words.
```ts
const WordsSchema = v.pipe(
v.string(),
v.words('en', 3, 'Exactly 3 words are required.')
);
```
#### Related
The following APIs can be combined with `words`.
##### Schemas
##### Methods
##### Utils
## Storages
### deleteGlobalConfig
Deletes the global configuration.
```ts
v.deleteGlobalConfig();
```
### deleteGlobalMessage
Deletes a global error message.
```ts
v.deleteGlobalMessage(lang);
```
#### Parameters
- `lang`
### deleteSchemaMessage
Deletes a schema error message.
```ts
v.deleteSchemaMessage(lang);
```
#### Parameters
- `lang`
### deleteSpecificMessage
Deletes a specific error message.
```ts
v.deleteSpecificMessage(reference, lang);
```
#### Parameters
- `reference`
- `lang`
### getGlobalConfig
Returns the global configuration.
```ts
const config = v.getGlobalConfig(merge);
```
#### Generics
- `TIssue`
#### Parameters
- `merge`
##### Explanation
Properties that you want to explicitly override can be optionally specified with `merge`.
#### Returns
- `config`
### getGlobalMessage
Returns a global error message.
```ts
const message = v.getGlobalMessage(lang);
```
#### Parameters
- `lang`
#### Returns
- `message`
### getSchemaMessage
Returns a schema error message.
```ts
const message = v.getSchemaMessage(lang);
```
#### Parameters
- `lang`
#### Returns
- `message`
### getSpecificMessage
Returns a specific error message.
```ts
const message = v.getSpecificMessage(reference, lang);
```
#### Parameters
- `reference`
- `lang`
#### Returns
- `message`
### setGlobalConfig
Sets the global configuration.
```ts
v.setGlobalConfig(merge);
```
#### Parameters
- `config`
##### Explanation
The properties specified by `config` are merged with the existing global configuration. If a property is already set, it will be overwritten.
### setGlobalMessage
Sets a global error message.
```ts
v.setGlobalMessage(message, lang);
```
#### Parameters
- `message`
- `lang`
### setSchemaMessage
Sets a schema error message.
```ts
v.setSchemaMessage(message, lang);
```
#### Parameters
- `message`
- `lang`
### setSpecificMessage
Sets a specific error message.
```ts
v.setSpecificMessage(reference, message, lang);
```
#### Generics
- `TReference`
#### Parameters
- `reference`
- `message`
- `lang`
## Utils
### entriesFromList
Creates an object entries definition from a list of keys and a schema.
```ts
const entries = v.entriesFromList(list, schema);
```
#### Generics
- `TList`
- `TSchema`
#### Parameters
- `list`
- `schema`
#### Returns
- `entries`
#### Examples
The following example show how `entriesFromList` can be used.
```ts
const ObjectSchema = v.object(
v.entriesFromList(['foo', 'bar', 'baz'], v.string())
);
```
#### Related
The following APIs can be combined with `entriesFromList`.
##### Schemas
### entriesFromObjects
Creates a new object entries definition from existing object schemas.
```ts
const entries = v.entriesFromObjects(schemas);
```
#### Generics
- `TSchemas`
#### Parameters
- `schemas`
#### Returns
- `entries`
#### Examples
The following example show how `entriesFromObjects` can be used.
> Hint: The third schema of the list overwrites the `foo` and `baz` properties of the previous schemas.
```ts
const ObjectSchema = v.object(
v.entriesFromObjects([
v.object({ foo: v.string(), bar: v.string() });
v.object({ baz: v.number(), qux: v.number() });
v.object({ foo: v.boolean(), baz: v.boolean() });
])
);
```
#### Related
The following APIs can be combined with `entriesFromObjects`.
##### Schemas
### getDotPath
Creates and returns the dot path of an issue if possible.
```ts
const dotPath = v.getDotPath(issue);
```
#### Generics
- `TSchema`
#### Parameters
- `issue`
#### Returns
- `dotPath`
### isOfKind
A generic type guard to check the kind of an object.
```ts
const result = v.isOfKind(kind, object);
```
#### Generics
- `TKind`
- `TObject`
#### Parameters
- `kind`
- `object`
#### Returns
- `result`
### isOfType
A generic type guard to check the type of an object.
```ts
const result = v.isOfType(type, object);
```
#### Generics
- `TType`
- `TObject`
#### Parameters
- `type`
- `object`
#### Returns
- `result`
### isValiError
A type guard to check if an error is a ValiError.
```ts
const result = v.isValiError(error);
```
#### Generics
- `TSchema`
#### Parameters
- `error`
#### Returns
- `result`
### ValiError
Creates a Valibot error with useful information.
```ts
const error = new v.ValiError(issues);
```
#### Generics
- `TSchema`
#### Parameters
- `issues`
#### Returns
- `error`
## Async
### argsAsync
Creates a function arguments transformation action.
```ts
const Action = v.argsAsync(schema);
```
#### Generics
- `TInput`
- `TSchema`
#### Parameters
- `schema`
##### Explanation
With `argsAsync` you can force the arguments of a function to match the given `schema`.
#### Returns
- `Action`
#### Examples
The following examples show how `argsAsync` can be used.
##### Product function schema
Schema of a function that returns a product by its ID.
```ts
import { isValidProductId } from '~/api';
const ProductFunctionSchema = v.pipeAsync(
v.function(),
v.argsAsync(
v.tupleAsync([v.pipeAsync(v.string(), v.checkAsync(isValidProductId))])
),
v.returnsAsync(
v.pipeAsync(
v.promise(),
v.awaitAsync(),
v.object({
id: v.string(),
name: v.string(),
price: v.number(),
})
)
)
);
```
#### Related
The following APIs can be combined with `argsAsync`.
##### Schemas
##### Methods
##### Utils
##### Async
### arrayAsync
Creates an array schema.
```ts
const Schema = v.arrayAsync(item, message);
```
#### Generics
- `TItem`
- `TMessage`
#### Parameters
- `item`
- `message`
##### Explanation
With `arrayAsync` you can validate the data type of the input. If the input is not an array, you can use `message` to customize the error message.
> If your array has a fixed length, consider using `tupleAsync` for a more precise typing.
#### Returns
- `Schema`
#### Examples
The following examples show how `arrayAsync` can be used.
##### Stored emails schema
Schema to validate an array of stored emails.
```ts
import { isEmailPresent } from '~/api';
const StoredEmailsSchema = v.arrayAsync(
v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPresent, 'The email is not in the database.')
)
);
```
#### Related
The following APIs can be combined with `arrayAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### awaitAsync
Creates an await transformation action.
```ts
const Action = v.awaitAsync();
```
#### Generics
- `TInput`
##### Explanation
With `awaitAsync` you can transform a promise into its resolved value.
#### Returns
- `Action`
#### Examples
The following examples show how `awaitAsync` can be used.
##### Unique emails schema
Schema to check a set of emails wrapped in a promise object.
```ts
const UniqueEmailsSchema = v.pipeAsync(
v.promise(),
v.awaitAsync(),
v.set(v.pipe(v.string(), v.email()))
);
```
#### Related
The following APIs can be combined with `awaitAsync`.
##### Schemas
##### Utils
##### Async
### checkAsync
Creates a check validation action.
```ts
const Action = v.checkAsync(requirement, message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `checkAsync` you can freely validate the input and return `true` if it is valid or `false` otherwise. If the input does not match your `requirement`, you can use `message` to customize the error message.
#### Returns
- `Action`
#### Examples
The following examples show how `checkAsync` can be used.
##### Cart item schema
Schema to check a cart item object.
```ts
import { getProductItem } from '~/api';
const CartItemSchema = v.pipeAsync(
v.object({
itemId: v.pipe(v.string(), v.regex(/^[a-z0-9]{10}$/i)),
quantity: v.pipe(v.number(), v.minValue(1)),
}),
v.checkAsync(async (input) => {
const productItem = await getProductItem(input.itemId);
return productItem?.quantity >= input.quantity;
}, 'The required quantity is greater than available.')
);
```
#### Related
The following APIs can be combined with `checkAsync`.
##### Schemas
##### Utils
##### Async
### checkItemsAsync
Creates a check items validation action.
```ts
const Action = v.checkItemsAsync(requirement, message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `requirement`
- `message`
##### Explanation
With `checkItemsAsync` you can freely validate the items of an array and return `true` if they are valid or `false` otherwise. If an item does not match your `requirement`, you can use `message` to customize the error message.
> The special thing about `checkItemsAsync` is that it automatically forwards each issue to the appropriate item.
#### Returns
- `Action`
#### Examples
The following examples show how `checkItemsAsync` can be used.
##### Cart items schema
Schema to check an array of cart item objects.
```ts
import { getProductItem } from '~/api';
const CartItemsSchema = v.pipeAsync(
v.array(
v.object({
itemId: v.pipe(v.string(), v.uuid()),
quantity: v.pipe(v.number(), v.minValue(1)),
})
),
v.checkItemsAsync(async (input) => {
const productItem = await getProductItem(input.itemId);
return (productItem?.quantity ?? 0) >= input.quantity;
}, 'The required quantity is greater than available.')
);
```
#### Related
The following APIs can be combined with `checkItemsAsync`.
##### Schemas
##### Utils
##### Async
### customAsync
Creates a custom schema.
> This schema function allows you to define a schema that matches a value based on a custom function. Use it whenever you need to define a schema that cannot be expressed using any of the other schema functions.
```ts
const Schema = v.customAsync(check, message);
```
#### Generics
- `TInput`
- `TMessage`
#### Parameters
- `check`
- `message`
##### Explanation
With `customAsync` you can validate the data type of the input. If the input does not match the validation of `check`, you can use `message` to customize the error message.
> Make sure that the validation in `check` matches the data type of `TInput`.
#### Returns
- `Schema`
#### Examples
The following examples show how `customAsync` can be used.
##### Vacant seat schema
Schema to validate a vacant seat.
```ts
import { isSeatVacant } from '~/api';
type Group = 'A' | 'B' | 'C' | 'D' | 'E';
type DigitLessThanSix = '0' | '1' | '2' | '3' | '4' | '5';
type Digit = DigitLessThanSix | '6' | '7' | '8' | '9';
type Seat = `${Group}${DigitLessThanSix}${Digit}`;
function isSeat(possibleSeat: string): possibleSeat is Seat {
return /^[A-E][0-5]\d$/.test(possibleSeat);
}
const VacantSeatSchema = v.customAsync(
(input) => typeof input === 'string' && isSeat(input) && isSeatVacant(input),
'The input is not a valid vacant seat.'
);
```
#### Related
The following APIs can be combined with `customAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### exactOptionalAsync
Creates an exact optional schema.
```ts
const Schema = v.exactOptionalAsync(wrapped, default_);
```
#### Generics
- `TWrapped`
- `TDefault`
#### Parameters
- `wrapped`
- `default_` {/* prettier-ignore */}
##### Explanation
With `exactOptionalAsync` the validation of your schema will pass missing object entries, and if you specify a `default_` input value, the schema will use it if the object entry is missing. For this reason, the output type may differ from the input type of the schema.
> The difference to `optionalAsync` is that this schema function follows the implementation of TypeScript's [`exactOptionalPropertyTypes` configuration](https://www.typescriptlang.org/tsconfig/#exactOptionalPropertyTypes) and only allows missing but not undefined object entries.
#### Returns
- `Schema`
#### Examples
The following examples show how `exactOptionalAsync` can be used.
##### New user schema
Schema to validate new user details.
```ts
import { isEmailUnique, isUsernameUnique } from '~/api';
const NewUserSchema = v.objectAsync({
email: v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailUnique, 'The email is not unique.')
),
username: v.exactOptionalAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
)
),
password: v.pipe(v.string(), v.minLength(8)),
});
/*
The input and output types of the schema:
{
email: string;
password: string;
username?: string;
}
*/
```
##### Unwrap exact optional schema
Use `unwrap` to undo the effect of `exactOptionalAsync`.
```ts
import { isUsernameUnique } from '~/api';
const UsernameSchema = v.unwrap(
// Assume this schema is from a different file and is reused here
v.exactOptionalAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
)
)
);
```
#### Related
The following APIs can be combined with `exactOptionalAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### fallbackAsync
Returns a fallback value as output if the input does not match the schema.
```ts
const Schema = v.fallbackAsync(schema, fallback);
```
#### Generics
- `TSchema`
- `TFallback`
#### Parameters
- `schema`
- `fallback`
##### Explanation
`fallbackAsync` allows you to define a fallback value for the output that will be used if the validation of the input fails. This means that no issues will be returned when using `fallbackAsync` and the schema will always return an output.
> If you only want to set a default value for `null` or `undefined` inputs, you should use `optionalAsync`, `nullableAsync` or `nullishAsync` instead.
> The fallback value is not validated. Make sure that the fallback value matches your schema.
#### Returns
- `Schema`
#### Examples
The following examples show how `fallbackAsync` can be used.
##### Unique username schema
Schema that will always return a unique username.
> By using a function as the `fallbackAsync` parameter, the schema will return any unique username each time the input does not match the schema.
```ts
import { getAnyUniqueUsername, isUsernameUnique } from '~/api';
const UniqueUsernameSchema = v.fallbackAsync(
v.pipeAsync(v.string(), v.minLength(4), v.checkAsync(isUsernameUnique)),
getAnyUniqueUsername
);
```
#### Related
The following APIs can be combined with `fallbackAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### forwardAsync
Forwards the issues of the passed validation action.
```ts
const Action = v.forwardAsync(action, path);
```
#### Generics
- `TInput`
- `TIssue`
- `TPath`
#### Parameters
- `action`
- `path`
##### Explanation
`forwardAsync` allows you to forward the issues of the passed validation `action` via `path` to a nested field of a schema.
#### Returns
- `Action`
#### Examples
The following examples show how `forwardAsync` can be used.
##### Allowed action schema
Schema that checks if the user is allowed to complete an action.
```ts
import { isAllowedAction, isUsernamePresent } from '~/api';
const AllowedActionSchema = v.pipeAsync(
v.objectAsync({
username: v.pipeAsync(
v.string(),
v.minLength(3),
v.checkAsync(isUsernamePresent, 'The username is not in the database.')
),
action: v.picklist(['view', 'edit', 'delete']),
}),
v.forwardAsync(
v.checkAsync(
isAllowedAction,
'The user is not allowed to complete the action.'
),
['action']
)
);
```
#### Related
The following APIs can be combined with `forwardAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### getDefaultsAsync
Returns the default values of the schema.
> The difference to `getDefault` is that for object and tuple schemas this function recursively returns the default values of the subschemas instead of `undefined`.
```ts
const values = v.getDefaultsAsync(schema);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
#### Returns
- `values`
#### Examples
The following examples show how `getDefaultsAsync` can be used.
##### Donation schema defaults
Get the default values of a donation schema.
```ts
import { getRandomOrgId } from '~/api';
const DonationSchema = v.objectAsync({
timestamp: v.optional(v.date(), () => new Date()),
sponsor: v.optional(v.pipe(v.string(), v.nonEmpty()), 'anonymous'),
organizationId: v.optionalAsync(v.pipe(v.string(), v.uuid()), getRandomOrgId),
message: v.optional(v.pipe(v.string(), v.minLength(1))),
});
const defaultValues = await v.getDefaultsAsync(DonationSchema);
/*
{
timestamp: new Date(),
sponsor: "anonymous",
organizationId: "43775869-95f3-4e00-9f37-161ec8f9f7cd",
message: undefined
}
*/
```
#### Related
The following APIs can be combined with `getDefaultsAsync`.
##### Schemas
##### Methods
##### Async
### getFallbacksAsync
Returns the fallback values of the schema.
> The difference to `getFallback` is that for object and tuple schemas this function recursively returns the fallback values of the subschemas instead of `undefined`.
```ts
const values = v.getFallbacksAsync(schema);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
#### Returns
- `values`
#### Examples
The following examples show how `getFallbacksAsync` can be used.
##### New user fallbacks
Get the fallback values of a new user schema.
```ts
import { getAnyUniqueUsername, isUsernameUnique } from '~/api';
const NewUserSchema = v.objectAsync({
username: v.fallbackAsync(
v.pipeAsync(v.string(), v.minLength(3), v.checkAsync(isUsernameUnique)),
getAnyUniqueUsername
),
password: v.pipe(v.string(), v.minLength(8)),
});
const fallbackValues = await v.getFallbacksAsync(NewUserSchema);
/*
{
username: "cookieMonster07",
password: undefined
}
*/
```
#### Related
The following APIs can be combined with `getFallbacksAsync`.
##### Schemas
##### Methods
##### Async
### intersectAsync
Creates an intersect schema.
> I recommend to read the intersections guide before using this schema function.
```ts
const Schema = v.intersectAsync(options, message);
```
#### Generics
- `TOptions`
- `TMessage`
#### Parameters
- `options`
- `message`
##### Explanation
With `intersectAsync` you can validate if the input matches each of the given `options`. If the output of the intersection cannot be successfully merged, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `intersectAsync` can be used.
##### Donation schema
Schema that combines objects to validate donation details.
```ts
import { isOrganizationPresent } from '~/api';
const DonationSchema = v.intersectAsync([
v.objectAsync({
organizationId: v.pipeAsync(
v.string(),
v.uuid(),
v.checkAsync(
isOrganizationPresent,
'The organization is not in the database.'
)
),
}),
// Assume the schemas below are from different files and are reused here
v.object({
amount: v.pipe(v.number(), v.minValue(100)),
message: v.pipe(v.string(), v.nonEmpty()),
}),
v.object({
amount: v.pipe(v.number(), v.maxValue(1_000_000)),
message: v.pipe(v.string(), v.maxLength(500)),
}),
]);
```
#### Related
The following APIs can be combined with `intersectAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### lazyAsync
Creates a lazy schema.
```ts
const Schema = v.lazyAsync(getter);
```
#### Generics
- `TWrapped`
#### Parameters
- `getter`
##### Explanation
The `getter` function is called lazily to retrieve the schema. This is necessary to be able to access the input through the first argument of the `getter` function and to avoid a circular dependency for recursive schemas.
#### Returns
- `Schema`
#### Examples
The following examples show how `lazyAsync` can be used.
##### Transaction list schema
Recursive schema to validate transactions.
> Due to a TypeScript limitation, the input and output types of recursive schemas cannot be inferred automatically. Therefore, you must explicitly specify these types using `GenericSchemaAsync`.
```ts
import { isTransactionValid } from '~/api';
type Transaction = {
transactionId: string;
next: Transaction | null;
};
const TransactionSchema: v.GenericSchemaAsync = v.objectAsync({
transactionId: v.pipeAsync(
v.string(),
v.uuid(),
v.checkAsync(isTransactionValid, 'The transaction is not valid.')
),
next: v.nullableAsync(v.lazyAsync(() => TransactionSchema)),
});
```
##### Email or username schema
Schema to validate an object containing an email or username.
> In most cases, `unionAsync` and `variantAsync` are the better choices for creating such a schema. I recommend using `lazyAsync` only in special cases.
```ts
import { isEmailPresent, isUsernamePresent } from '~/api';
const EmailOrUsernameSchema = v.lazyAsync((input) => {
if (input && typeof input === 'object' && 'type' in input) {
switch (input.type) {
case 'email':
return v.objectAsync({
type: v.literal('email'),
email: v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(
isEmailPresent,
'The email is not present in the database.'
)
),
});
case 'username':
return v.objectAsync({
type: v.literal('username'),
username: v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(
isUsernamePresent,
'The username is not present in the database.'
)
),
});
}
}
return v.never();
});
```
#### Related
The following APIs can be combined with `lazyAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### looseObjectAsync
Creates a loose object schema.
```ts
const Schema = v.looseObjectAsync(entries, message);
```
#### Generics
- `TEntries`
- `TMessage`
#### Parameters
- `entries`
- `message`
##### Explanation
With `looseObjectAsync` you can validate the data type of the input and whether the content matches `entries`. If the input is not an object, you can use `message` to customize the error message.
> The difference to `objectAsync` is that this schema includes any unknown entries in the output. In addition, this schema filters certain entries from the unknown entries for security reasons.
#### Returns
- `Schema`
#### Examples
The following examples show how `looseObjectAsync` can be used. Please see the object guide for more examples and explanations.
##### New user schema
Schema to validate a loose object containing specific new user details.
```ts
import { isEmailPresent } from '~/api';
const NewUserSchema = v.looseObjectAsync({
firstName: v.pipe(v.string(), v.minLength(2), v.maxLength(45)),
lastName: v.pipe(v.string(), v.minLength(2), v.maxLength(45)),
email: v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPresent, 'The email is already in use by another user.')
),
password: v.pipe(v.string(), v.minLength(8)),
avatar: v.optional(v.pipe(v.string(), v.url())),
});
```
#### Related
The following APIs can be combined with `looseObjectAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### looseTupleAsync
Creates a loose tuple schema.
```ts
const Schema = v.looseTupleAsync(items, message);
```
#### Generics
- `TItems`
- `TMessage`
#### Parameters
- `items`
- `message`
##### Explanation
With `looseTuplAsynce` you can validate the data type of the input and whether the content matches `items`. If the input is not an array, you can use `message` to customize the error message.
> The difference to `tupleAsync` is that this schema does include unknown items into the output.
#### Returns
- `Schema`
#### Examples
The following examples show how `looseTupleAsync` can be used. Please see the arrays guide for more examples and explanations.
##### Number and email tuple
Schema to validate a loose tuple with one number and one stored email address.
```ts
import { isEmailPresent } from '~/api';
const TupleSchema = v.looseTupleAsync([
v.number(),
v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPresent, 'The email is not in the database.')
),
]);
```
#### Related
The following APIs can be combined with `looseTupleAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### mapAsync
Creates a map schema.
```ts
const Schema = v.mapAsync(key, value, message);
```
#### Generics
- `TKey`
- `TValue`
- `TMessage`
#### Parameters
- `key`
- `value`
- `message`
##### Explanation
With `mapAsync` you can validate the data type of the input and whether the entries match `key` and `value`. If the input is not a map, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `mapAsync` can be used.
##### Shopping items schema
Schema to validate a map with usernames that are allowed to shop as keys and the total items purchased as values.
```ts
import { isUserVerified } from '~/api';
const ShoppingItemsSchema = v.mapAsync(
v.pipeAsync(
v.string(),
v.checkAsync(isUserVerified, 'The username is not allowed to shop.')
),
v.pipe(v.number(), v.minValue(0))
);
```
#### Related
The following APIs can be combined with `mapAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### nonNullableAsync
Creates a non nullable schema.
> This schema function can be used to override the behavior of `nullableAsync`.
```ts
const Schema = v.nonNullableAsync(wrapped, message);
```
#### Generics
- `TWrapped`
- `TMessage`
#### Parameters
- `wrapped`
- `message`
##### Explanation
With `nonNullableAsync` the validation of your schema will not pass `null` inputs. If the input is `null`, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `nonNullableAsync` can be used.
##### Unique username schema
Schema to validate a non-null unique username.
```ts
import { isUsernameUnique } from '~/api';
const UniqueUsernameSchema = v.nonNullableAsync(
// Assume this schema is from a different file and reused here.
v.nullableAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
)
)
);
```
#### Related
The following APIs can be combined with `nonNullableAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### nonNullishAsync
Creates a non nullish schema.
> This schema function can be used to override the behavior of `nullishAsync`.
```ts
const Schema = v.nonNullishAsync(wrapped, message);
```
#### Generics
- `TWrapped`
- `TMessage`
#### Parameters
- `wrapped`
- `message`
##### Explanation
With `nonNullishAsync` the validation of your schema will not pass `null` and `undefined` inputs. If the input is `null` or `undefined`, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `nonNullishAsync` can be used.
##### Allowed country schema
Schema to check if a string matches one of the allowed country names.
```ts
import { isAllowedCountry } from '~/api';
const AllowedCountrySchema = v.nonNullishAsync(
// Assume this schema is from a different file and reused here.
v.nullishAsync(
v.pipeAsync(v.string(), v.nonEmpty(), v.checkAsync(isAllowedCountry))
)
);
```
#### Related
The following APIs can be combined with `nonNullishAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### nonOptionalAsync
Creates a non optional schema.
> This schema function can be used to override the behavior of `optionalAsync`.
```ts
const Schema = v.nonOptionalAsync(wrapped, message);
```
#### Generics
- `TWrapped`
- `TMessage`
#### Parameters
- `wrapped`
- `message`
##### Explanation
With `nonOptionalAsync` the validation of your schema will not pass `undefined` inputs. If the input is `undefined`, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `nonOptionalAsync` can be used.
##### Add user schema
Schema to validate an object containing details required to add a user to an existing group.
```ts
import { isGroupPresent } from '~/api';
const AddUserSchema = v.objectAsync({
groupId: v.nonOptionalAsync(
// Assume this schema is from a different file and reused here.
v.optionalAsync(
v.pipeAsync(
v.string(),
v.uuid(),
v.checkAsync(
isGroupPresent,
'The group is not present in the database.'
)
)
)
),
userEmail: v.pipe(v.string(), v.email()),
});
```
#### Related
The following APIs can be combined with `nonOptionalAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### nullableAsync
Creates a nullable schema.
```ts
const Schema = v.nullableAsync(wrapped, default_);
```
#### Generics
- `TWrapped`
- `TDefault`
#### Parameters
- `wrapped`
- `default_` {/* prettier-ignore */}
##### Explanation
With `nullableAsync` the validation of your schema will pass `null` inputs, and if you specify a `default_` input value, the schema will use it if the input is `null`. For this reason, the output type may differ from the input type of the schema.
> Note that `nullableAsync` does not accept `undefined` as an input. If you want to accept `undefined` inputs, use `optionalAsync`, and if you want to accept `null` and `undefined` inputs, use `nullishAsync` instead. Also, if you want to set a default output value for any invalid input, you should use `fallbackAsync` instead.
#### Returns
- `Schema`
#### Examples
The following examples show how `nullableAsync` can be used.
##### Nullable username schema
Schema that accepts a unique username or `null`.
> By using a function as the `default_` parameter, the schema will return a unique username from the function call each time the input is `null`.
```ts
import { getUniqueUsername, isUsernameUnique } from '~/api';
const NullableUsernameSchema = v.nullableAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
),
getUniqueUsername
);
```
##### Unwrap nullable schema
Use `unwrap` to undo the effect of `nullableAsync`.
```ts
import { isUsernameUnique } from '~/api';
const UsernameSchema = v.unwrap(
// Assume this schema is from a different file and is reused here
v.nullableAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
)
)
);
```
#### Related
The following APIs can be combined with `nullableAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### nullishAsync
Creates a nullish schema.
```ts
const Schema = v.nullishAsync(wrapped, default_);
```
#### Generics
- `TWrapped`
- `TDefault`
#### Parameters
- `wrapped`
- `default_` {/* prettier-ignore */}
##### Explanation
With `nullishAsync` the validation of your schema will pass `undefined` and `null` inputs, and if you specify a `default_` input value, the schema will use it if the input is `undefined` or `null`. For this reason, the output type may differ from the input type of the schema.
> Note that `nullishAsync` accepts `undefined` or `null` as an input. If you want to accept only `null` inputs, use `nullableAsync`, and if you want to accept only `undefined` inputs, use `optionalAsync` instead. Also, if you want to set a default output value for any invalid input, you should use `fallbackAsync` instead.
#### Returns
- `Schema`
#### Examples
The following examples show how `nullishAsync` can be used.
##### Nullish username schema
Schema that accepts a unique username, `undefined` or `null`.
> By using a function as the `default_` parameter, the schema will return a unique username from the function call each time the input is `undefined` or `null`.
```ts
import { getUniqueUsername, isUsernameUnique } from '~/api';
const NullishUsernameSchema = v.nullishAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
),
getUniqueUsername
);
```
##### New user schema
Schema to validate new user details.
```ts
import { isEmailUnique, isUsernameUnique } from '~/api';
const NewUserSchema = v.objectAsync({
email: v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailUnique, 'The email is not unique.')
),
username: v.nullishAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
)
),
password: v.pipe(v.string(), v.minLength(8)),
});
/*
The input and output types of the schema:
{
email: string;
password: string;
username?: string | null | undefined;
}
*/
```
##### Unwrap nullish schema
Use `unwrap` to undo the effect of `nullishAsync`.
```ts
import { isUsernameUnique } from '~/api';
const UsernameSchema = v.unwrap(
// Assume this schema is from a different file and is reused here
v.nullishAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
)
)
);
```
#### Related
The following APIs can be combined with `nullishAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### objectAsync
Creates an object schema.
```ts
const Schema = v.objectAsync(entries, message);
```
#### Generics
- `TEntries`
- `TMessage`
#### Parameters
- `entries`
- `message`
##### Explanation
With `objectAsync` you can validate the data type of the input and whether the content matches `entries`. If the input is not an object, you can use `message` to customize the error message.
> This schema removes unknown entries. The output will only include the entries you specify. To include unknown entries, use `looseObjectAsync`. To return an issue for unknown entries, use `strictObjectAsync`. To include and validate unknown entries, use `objectWithRestAsync`.
#### Returns
- `Schema`
#### Examples
The following examples show how `objectAsync` can be used. Please see the object guide for more examples and explanations.
##### New user schema
Schema to validate an object containing new user details.
```ts
import { isEmailPresent } from '~/api';
const NewUserSchema = v.objectAsync({
firstName: v.pipe(v.string(), v.minLength(2), v.maxLength(45)),
lastName: v.pipe(v.string(), v.minLength(2), v.maxLength(45)),
email: v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPresent, 'The email is already in use by another user.')
),
password: v.pipe(v.string(), v.minLength(8)),
avatar: v.optional(v.pipe(v.string(), v.url())),
});
```
#### Related
The following APIs can be combined with `objectAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### objectWithRestAsync
Creates an object with rest schema.
```ts
const Schema = v.objectWithRestAsync(
entries,
rest,
message
);
```
#### Generics
- `TEntries`
- `TRest`
- `TMessage`
#### Parameters
- `entries`
- `rest`
- `message`
##### Explanation
With `objectWithRestAsync` you can validate the data type of the input and whether the content matches `entries` and `rest`. If the input is not an object, you can use `message` to customize the error message.
> The difference to `objectAsync` is that this schema includes unknown entries in the output. In addition, this schema filters certain entries from the unknown entries for security reasons.
#### Returns
- `Schema`
#### Examples
The following examples show how `objectWithRestAsync` can be used. Please see the object guide for more examples and explanations.
##### Word map schema
Schema to validate an object with word map mutation details.
```ts
import { isUserAllowedToMutate } from '~/api';
// Assume the rest of the keys are always English words
const WordMapSchema = v.objectWithRestAsync(
{
$userId: v.pipeAsync(
v.string(),
v.regex(/^[a-z0-9]{12}$/i),
v.checkAsync(
isUserAllowedToMutate,
'The user is not allowed to change the word map.'
)
),
$targetLanguage: v.union([
v.literal('hindi'),
v.literal('spanish'),
v.literal('french'),
]),
},
v.string()
);
```
#### Related
The following APIs can be combined with `objectWithRestAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### optionalAsync
Creates an optional schema.
```ts
const Schema = v.optionalAsync(wrapped, default_);
```
#### Generics
- `TWrapped`
- `TDefault`
#### Parameters
- `wrapped`
- `default_` {/* prettier-ignore */}
##### Explanation
With `optionalAsync` the validation of your schema will pass `undefined` inputs, and if you specify a `default_` input value, the schema will use it if the input is `undefined`. For this reason, the output type may differ from the input type of the schema.
> Note that `optionalAsync` does not accept `null` as an input. If you want to accept `null` inputs, use `nullableAsync`, and if you want to accept `null` and `undefined` inputs, use `nullishAsync` instead. Also, if you want to set a default output value for any invalid input, you should use `fallbackAsync` instead.
#### Returns
- `Schema`
#### Examples
The following examples show how `optionalAsync` can be used.
##### Optional username schema
Schema that accepts a unique username or `undefined`.
> By using a function as the `default_` parameter, the schema will return a unique username from the function call each time the input is `undefined`.
```ts
import { getUniqueUsername, isUsernameUnique } from '~/api';
const OptionalUsernameSchema = v.optionalAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
),
getUniqueUsername
);
```
##### New user schema
Schema to validate new user details.
```ts
import { isEmailUnique, isUsernameUnique } from '~/api';
const NewUserSchema = v.objectAsync({
email: v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailUnique, 'The email is not unique.')
),
username: v.optionalAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
)
),
password: v.pipe(v.string(), v.minLength(8)),
});
/*
The input and output types of the schema:
{
email: string;
password: string;
username?: string | undefined;
}
*/
```
##### Unwrap optional schema
Use `unwrap` to undo the effect of `optionalAsync`.
```ts
import { isUsernameUnique } from '~/api';
const UsernameSchema = v.unwrap(
// Assume this schema is from a different file and is reused here
v.optionalAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
)
)
);
```
#### Related
The following APIs can be combined with `optionalAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### parseAsync
Parses an unknown input based on a schema.
```ts
const output = v.parseAsync(schema, input, config);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
- `input`
- `config`
##### Explanation
`parseAsync` will throw a `ValiError` if the `input` does not match the `schema`. Therefore you should use a try/catch block to catch errors. If the input matches the schema, it is valid and the `output` of the schema will be returned typed.
> If an asynchronous operation associated with the passed schema throws an error, the promise returned by `parseAsync` is rejected and the error thrown may not be a `ValiError`.
#### Returns
- `output`
#### Examples
The following examples show how `parseAsync` can be used.
```ts
import { isEmailPresent } from '~/api';
try {
const StoredEmailSchema = v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPresent, 'The email is not in the database.')
);
const storedEmail = await v.parseAsync(StoredEmailSchema, 'jane@example.com');
// Handle errors if one occurs
} catch (error) {
console.error(error);
}
```
#### Related
The following APIs can be combined with `parseAsync`.
##### Schemas
##### Methods
##### Utils
##### Async
### parserAsync
Returns a function that parses an unknown input based on a schema.
```ts
const parser = v.parserAsync(schema, config);
```
#### Generics
- `TSchema`
- `TConfig`
#### Parameters
- `schema`
- `config`
#### Returns
- `parser`
#### Examples
The following examples show how `parserAsync` can be used.
```ts
import { isEmailPresent } from '~/api';
try {
const StoredEmailSchema = v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPresent, 'The email is not in the database.')
);
const storedEmailParser = v.parserAsync(StoredEmailSchema);
const storedEmail = await storedEmailParser('jane@example.com');
// Handle errors if one occurs
} catch (error) {
console.error(error);
}
```
#### Related
The following APIs can be combined with `parserAsync`.
##### Schemas
##### Methods
##### Utils
##### Async
### partialAsync
Creates a modified copy of an object schema that marks all or only the selected entries as optional.
```ts
const Schema = v.partialAsync(schema, keys);
```
#### Generics
- `TSchema`
- `TKeys`
#### Parameters
- `schema`
- `keys`
##### Explanation
`partialAsync` creates a modified copy of the given object `schema` where all entries or only the selected `keys` are optional. It is similar to TypeScript's [`Partial`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype) utility type.
> Because `partialAsync` changes the data type of the input and output, it is not allowed to pass a schema that has been modified by the `pipeAsync` method, as this may cause runtime errors. Please use the `pipeAsync` method after you have modified the schema with `partialAsync`.
#### Returns
- `Schema`
#### Examples
The following examples show how `partialAsync` can be used.
##### Update user schema
Schema to update the user details.
```ts
import { isEmailAbsent, isUsernameAbsent } from '~/api';
const UserSchema = v.objectAsync({
email: v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailAbsent, 'The email is already in the database.')
),
username: v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameAbsent, 'The username is already in the database.')
),
password: v.pipe(v.string(), v.minLength(8)),
});
const UpdateUserSchema = v.partialAsync(UserSchema);
/*
{
email?: string;
username?: string;
password?: string;
}
*/
```
#### Related
The following APIs can be combined with `partialAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### partialCheckAsync
Creates a partial check validation action.
```ts
const Action = v.partialCheckAsync(
paths,
requirement,
message
);
```
#### Generics
- `TInput`
- `TPaths`
- `TSelection`
- `TMessage`
#### Parameters
- `paths`
- `requirement`
- `message`
##### Explanation
With `partialCheckAsync` you can freely validate the selected input and return `true` if it is valid or `false` otherwise. If the input does not match your `requirement`, you can use `message` to customize the error message.
> The difference to `checkAsync` is that `partialCheckAsync` can be executed whenever the selected part of the data is valid, while `checkAsync` is executed only when the entire dataset is typed. This can be an important advantage when working with forms.
#### Returns
- `Action`
#### Examples
The following examples show how `partialCheckAsync` can be used.
##### Message details schema
Schema to validate details associated with a message.
```ts
import { isSenderInTheGroup } from '~/api';
const MessageDetailsSchema = v.pipeAsync(
v.object({
sender: v.object({
name: v.pipe(v.string(), v.minLength(2), v.maxLength(45)),
email: v.pipe(v.string(), v.email()),
}),
groupId: v.pipe(v.string(), v.uuid()),
message: v.pipe(v.string(), v.nonEmpty(), v.maxLength(500)),
}),
v.forwardAsync(
v.partialCheckAsync(
[['sender', 'email'], ['groupId']],
(input) =>
isSenderInTheGroup({
senderEmail: input.sender.email,
groupId: input.groupId,
}),
'The sender is not in the group.'
),
['sender', 'email']
)
);
```
#### Related
The following APIs can be combined with `partialCheckAsync`.
##### Schemas
##### Utils
##### Async
### pipeAsync
Adds a pipeline to a schema, that can validate and transform its input.
```ts
const Schema = v.pipeAsync(schema, ...items);
```
#### Generics
- `TSchema`
- `TItems`
#### Parameters
- `schema`
- `items`
##### Explanation
`pipeAsync` creates a modified copy of the given `schema`, containing a pipeline for detailed validations and transformations. It passes the input data asynchronously through the `items` in the order they are provided and each item can examine and modify it.
> Since `pipeAsync` returns a schema that can be used as the first argument of another pipeline, it is possible to nest multiple `pipeAsync` calls to extend the validation and transformation further.
`pipeAsync` aborts early and marks the output as untyped if issues were collected before attempting to execute a schema or transformation action as the next item in the pipeline, to prevent unexpected behavior.
#### Returns
- `Schema`
#### Examples
The following examples show how `pipeAsync` can be used. Please see the pipeline guide for more examples and explanations.
##### Stored email schema
Schema to validate a stored email address.
```ts
import { isEmailPresent } from '~/api';
const StoredEmailSchema = v.pipeAsync(
v.string(),
v.nonEmpty('Please enter your email.'),
v.email('The email is badly formatted.'),
v.maxLength(30, 'Your email is too long.'),
v.checkAsync(isEmailPresent, 'The email is not in the database.')
);
```
##### New user schema
Schema to validate and transform new user details to a string.
```ts
import { isUsernameUnique } from '~/api';
const NewUserSchema = v.pipeAsync(
v.objectAsync({
firstName: v.pipe(v.string(), v.nonEmpty(), v.maxLength(30)),
lastName: v.pipe(v.string(), v.nonEmpty(), v.maxLength(30)),
username: v.pipeAsync(
v.string(),
v.nonEmpty(),
v.maxLength(30),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
),
}),
v.transform(
({ firstName, lastName, username }) =>
`${username} (${firstName} ${lastName})`
)
);
```
#### Related
The following APIs can be combined with `pipeAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### rawCheckAsync
Creates a raw check validation action.
```ts
const Action = v.rawCheckAsync(action);
```
#### Generics
- `TInput`
#### Parameters
- `action`
##### Explanation
With `rawCheckAsync` you can freely validate the input with a custom `action` and add issues if necessary.
#### Returns
- `Action`
#### Examples
The following examples show how `rawCheckAsync` can be used.
##### Add users schema
Object schema that ensures that only users not already in the group are included.
> This `rawCheckAsync` validation action adds an issue for any invalid username and forwards it via `path` to the appropriate nested field.
```ts
import { isAlreadyInGroup } from '~/api';
const AddUsersSchema = v.pipeAsync(
v.object({
groupId: v.pipe(v.string(), v.uuid()),
usernames: v.array(v.pipe(v.string(), v.nonEmpty())),
}),
v.rawCheckAsync(async ({ dataset, addIssue }) => {
if (dataset.typed) {
await Promise.all(
dataset.value.usernames.map(async (username, index) => {
if (await isAlreadyInGroup(username, dataset.value.groupId)) {
addIssue({
received: username,
message: 'The user is already in the group.',
path: [
{
type: 'object',
origin: 'value',
input: dataset.value,
key: 'usernames',
value: dataset.value.usernames,
},
{
type: 'array',
origin: 'value',
input: dataset.value.usernames,
key: index,
value: username,
},
],
});
}
})
);
}
})
);
```
#### Related
The following APIs can be combined with `rawCheckAsync`.
##### Schemas
##### Utils
##### Async
### rawTransformAsync
Creates a raw transformation action.
```ts
const Action = v.rawTransformAsync(action);
```
#### Generics
- `TInput`
- `TOutput`
#### Parameters
- `action`
##### Explanation
With `rawTransformAsync` you can freely transform and validate the input with a custom `action` and add issues if necessary.
#### Returns
- `Action`
#### Examples
The following examples show how `rawTransformAsync` can be used.
##### Order schema
Schema that rejects an order that does not meet a requirement when free delivery is expected.
```ts
import { getTotalAmount } from '~/api';
import { FREE_DELIVERY_MIN_AMOUNT } from '~/constants';
const OrderSchema = v.pipeAsync(
v.object({
cart: v.array(
v.object({
itemId: v.pipe(v.string(), v.uuid()),
quantity: v.pipe(v.number(), v.integer(), v.minValue(1)),
})
),
expectsFreeDelivery: v.optional(v.boolean(), false),
}),
v.rawTransformAsync(
async ({ dataset: { value: input }, addIssue, NEVER }) => {
const total = await getTotalAmount(input.cart);
if (input.expectsFreeDelivery && total < FREE_DELIVERY_MIN_AMOUNT) {
addIssue({
label: 'order',
expected: `>=${FREE_DELIVERY_MIN_AMOUNT}`,
received: `${total}`,
message: `The total amount must be at least $${FREE_DELIVERY_MIN_AMOUNT} for free delivery.`,
path: [
{
type: 'object',
origin: 'value',
input,
key: 'cart',
value: input.cart,
},
],
});
return NEVER;
}
return { ...input, total };
}
)
);
```
#### Related
The following APIs can be combined with `rawTransformAsync`.
##### Schemas
##### Utils
##### Async
### recordAsync
Creates a record schema.
```ts
const Schema = v.recordAsync(key, value, message);
```
#### Generics
- `TKey`
- `TValue`
- `TMessage`
#### Parameters
- `key`
- `value`
- `message`
##### Explanation
With `recordAsync` you can validate the data type of the input and whether the entries match `key` and `value`. If the input is not an object, you can use `message` to customize the error message.
> This schema filters certain entries from the record for security reasons.
> This schema marks an entry as optional if it detects that its key is a literal type. The reason for this is that it is not technically possible to detect missing literal keys without restricting the `key` schema to `string`, `enum` and `picklist`. However, if `enum` and `picklist` are used, it is better to use `objectAsync` with `entriesFromList` because it already covers the needed functionality. This decision also reduces the bundle size of `recordAsync`, because it only needs to check the entries of the input and not any missing keys.
#### Returns
- `Schema`
#### Examples
The following examples show how `recordAsync` can be used.
##### ID to email schema
Schema to validate a record that maps an ID to a public user email.
```ts
import { isEmailPublic } from '~/api';
const IdToEmailSchema = v.recordAsync(
v.pipe(v.string(), v.uuid()),
v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPublic, 'The email address is private.')
)
);
```
#### Related
The following APIs can be combined with `recordAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### requiredAsync
Creates a modified copy of an object schema that marks all or only the selected entries as required.
```ts
const AllKeysSchema = v.requiredAsync(schema, message);
const SelectedKeysSchema = v.requiredAsync(
schema,
keys,
message
);
```
#### Generics
- `TSchema`
- `TKeys`
- `TMessage`
#### Parameters
- `schema`
- `keys`
- `message`
##### Explanation
`requiredAsync` creates a modified copy of the given object `schema` where all or only the selected `keys` are required. It is similar to TypeScript's [`Required`](https://www.typescriptlang.org/docs/handbook/utility-types.html#requiredtype) utility type.
> Because `requiredAsync` changes the data type of the input and output, it is not allowed to pass a schema that has been modified by the `pipeAsync` method, as this may cause runtime errors. Please use the `pipeAsync` method after you have modified the schema with `requiredAsync`.
#### Returns
- `AllKeysSchema`
- `SelectedKeysSchema`
#### Examples
The following examples show how `requiredAsync` can be used.
##### New task schema
Schema to validate an object containing task details.
```ts
import { isOwnerPresent } from '~/api';
const UpdateTaskSchema = v.objectAsync({
owner: v.optionalAsync(
v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isOwnerPresent, 'The owner is not in the database.')
)
),
title: v.optional(v.pipe(v.string(), v.nonEmpty(), v.maxLength(255))),
description: v.optional(v.pipe(v.string(), v.nonEmpty())),
});
const NewTaskSchema = v.requiredAsync(UpdateTaskSchema);
/*
{
owner: string;
title: string;
description: string;
}
*/
```
#### Related
The following APIs can be combined with `requiredAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### returnsAsync
Creates a function return transformation action.
```ts
const Action = v.returnsAsync(schema);
```
#### Generics
- `TInput`
- `TSchema`
#### Parameters
- `schema`
##### Explanation
With `returnsAsync` you can force the returned value of a function to match the given `schema`.
#### Returns
- `Action`
#### Examples
The following examples show how `returnsAsync` can be used.
##### Product function schema
Schema of a function that returns a product by its ID.
```ts
import { isValidProductId } from '~/api';
const ProductFunctionSchema = v.pipeAsync(
v.function(),
v.argsAsync(
v.tupleAsync([v.pipeAsync(v.string(), v.checkAsync(isValidProductId))])
),
v.returnsAsync(
v.pipeAsync(
v.promise(),
v.awaitAsync(),
v.object({
id: v.string(),
name: v.string(),
price: v.number(),
})
)
)
);
```
#### Related
The following APIs can be combined with `returnsAsync`.
##### Schemas
##### Methods
##### Utils
##### Async
### safeParseAsync
Parses an unknown input based on a schema.
```ts
const result = v.safeParseAsync(schema, input, config);
```
#### Generics
- `TSchema`
#### Parameters
- `schema`
- `input`
- `config`
#### Returns
- `result`
#### Example
The following example shows how `safeParseAsync` can be used.
```ts
import { isEmailPresent } from '~/api';
const StoredEmailSchema = v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPresent, 'The email is not in the database.')
);
const result = await v.safeParseAsync(StoredEmailSchema, 'jane@example.com');
if (result.success) {
const storedEmail = result.output;
} else {
console.error(result.issues);
}
```
#### Related
The following APIs can be combined with `safeParseAsync`.
##### Schemas
##### Methods
##### Utils
##### Async
### safeParserAsync
Returns a function that parses an unknown input based on a schema.
```ts
const safeParser = v.safeParserAsync(schema, config);
```
#### Generics
- `TSchema`
- `TConfig`
#### Parameters
- `schema`
- `config`
#### Returns
- `safeParser`
#### Example
The following example shows how `safeParserAsync` can be used.
```ts
import { isEmailPresent } from '~/api';
const StoredEmailSchema = v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPresent, 'The email is not in the database.')
);
const safeStoredEmailParser = v.safeParserAsync(StoredEmailSchema);
const result = await safeStoredEmailParser('jane@example.com');
if (result.success) {
const storedEmail = result.output;
} else {
console.error(result.issues);
}
```
#### Related
The following APIs can be combined with `safeParserAsync`.
##### Schemas
##### Methods
##### Utils
##### Async
### setAsync
Creates a set schema.
```ts
const Schema = v.setAsync(value, message);
```
#### Generics
- `TValue`
- `TMessage`
#### Parameters
- `value`
- `message`
##### 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
- `Schema`
#### Examples
The following examples show how `setAsync` can be used.
##### Allowed IPs schema
Schema to validate a set of allowed IP addresses.
```ts
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
##### Methods
##### Actions
##### Utils
##### Async
### strictObjectAsync
Creates a strict object schema.
```ts
const Schema = v.strictObjectAsync(entries, message);
```
#### Generics
- `TEntries`
- `TMessage`
#### Parameters
- `entries`
- `message`
##### Explanation
With `strictObjectAsync` you can validate the data type of the input and whether the content matches `entries`. If the input is not an object or does include unknown entries, you can use `message` to customize the error message.
> The difference to `objectAsync` is that this schema returns an issue for unknown entries. It intentionally returns only one issue. Otherwise, attackers could send large objects to exhaust device resources. If you want an issue for every unknown key, use the `objectWithRestAsync` schema with `never` for the `rest` argument.
#### Returns
- `Schema`
#### Examples
The following examples show how `strictObjectAsync` can be used. Please see the object guide for more examples and explanations.
##### New user schema
Schema to validate a strict object containing only specific new user details.
```ts
import { isEmailPresent } from '~/api';
const NewUserSchema = v.strictObjectAsync({
firstName: v.pipe(v.string(), v.minLength(2), v.maxLength(45)),
lastName: v.pipe(v.string(), v.minLength(2), v.maxLength(45)),
email: v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPresent, 'The email is already in use by another user.')
),
password: v.pipe(v.string(), v.minLength(8)),
avatar: v.optional(v.pipe(v.string(), v.url())),
});
```
#### Related
The following APIs can be combined with `strictObjectAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### strictTupleAsync
Creates a strict tuple schema.
```ts
const Schema = v.strictTupleAsync(items, message);
```
#### Generics
- `TItems`
- `TMessage`
#### Parameters
- `items`
- `message`
##### Explanation
With `strictTupleAsync` you can validate the data type of the input and whether the content matches `items`. If the input is not an array or does include unknown items, you can use `message` to customize the error message.
> The difference to `tupleAsync` is that this schema returns an issue for unknown items. It intentionally returns only one issue. Otherwise, attackers could send large arrays to exhaust device resources. If you want an issue for every unknown item, use the `tupleWithRestAsync` schema with `never` for the `rest` argument.
#### Returns
- `Schema`
#### Examples
The following examples show how `strictTupleAsync` can be used. Please see the arrays guide for more examples and explanations.
##### Number and email tuple
Schema to validate a strict tuple with one number and one stored email address.
```ts
import { isEmailPresent } from '~/api';
const TupleSchema = v.strictTupleAsync([
v.number(),
v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPresent, 'The email is not in the database.')
),
]);
```
#### Related
The following APIs can be combined with `strictTupleAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### transformAsync
Creates a custom transformation action.
```ts
const Action = v.transformAsync(operation);
```
#### Generics
- `TInput`
- `TOutput`
#### Parameters
- `operation`
##### Explanation
`transformAsync` can be used to freely transform the input. The `operation` parameter is a function that takes the input and returns the transformed output.
#### Returns
- `Action`
#### Examples
The following examples show how `transformAsync` can be used.
##### Blob to string
Schema that transforms a blob to its string value.
```ts
const StringSchema = v.pipeAsync(
v.blob(),
v.transformAsync((value) => value.text())
);
```
#### Related
The following APIs can be combined with `transformAsync`.
##### Schemas
##### Utils
##### Async
### tupleAsync
Creates a tuple schema.
```ts
const Schema = v.tupleAsync(items, message);
```
#### Generics
- `TItems`
- `TMessage`
#### Parameters
- `items`
- `message`
##### Explanation
With `tupleAsync` you can validate the data type of the input and whether the content matches `items`. If the input is not an array, you can use `message` to customize the error message.
> This schema removes unknown items. The output will only include the items you specify. To include unknown items, use `looseTupleAsync`. To return an issue for unknown items, use `strictTupleAsync`. To include and validate unknown items, use `tupleWithRestAsync`.
#### Returns
- `Schema`
#### Examples
The following examples show how `tupleAsync` can be used. Please see the arrays guide for more examples and explanations.
##### Number and email tuple
Schema to validate a tuple with one number and one stored email address.
```ts
import { isEmailPresent } from '~/api';
const TupleSchema = v.tupleAsync([
v.number(),
v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPresent, 'The email is not in the database.')
),
]);
```
#### Related
The following APIs can be combined with `tupleAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### tupleWithRestAsync
Creates a tuple with rest schema.
```ts
const Schema = v.tupleWithRestAsync(
items,
rest,
message
);
```
#### Generics
- `TItems`
- `TRest`
- `TMessage`
#### Parameters
- `items`
- `rest`
- `message`
##### Explanation
With `tupleWithRestAsync` you can validate the data type of the input and whether the content matches `items` and `rest`. If the input is not an array, you can use `message` to customize the error message.
#### Returns
- `Schema`
#### Examples
The following examples show how `tupleWithRestAsync` can be used. Please see the arrays guide for more examples and explanations.
##### Tuple schema with rest
Schema to validate a tuple with generic rest items.
```ts
import { isEmailPresent } from '~/api';
const TupleSchemaWithRest = v.tupleWithRestAsync(
[
v.number(),
v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPresent, 'The email is not in the database.')
),
],
v.boolean()
);
```
#### Related
The following APIs can be combined with `tupleWithRestAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### undefinedableAsync
Creates an undefinedable schema.
```ts
const Schema = v.undefinedableAsync(wrapped, default_);
```
#### Generics
- `TWrapped`
- `TDefault`
#### Parameters
- `wrapped`
- `default_` {/* prettier-ignore */}
##### Explanation
With `undefinedableAsync` the validation of your schema will pass `undefined` inputs, and if you specify a `default_` input value, the schema will use it if the input is `undefined`. For this reason, the output type may differ from the input type of the schema.
> `undefinedableAsync` behaves exactly the same as `optionalAsync` at runtime. The only difference is the input and output type when used for object entries. While `optionalAsync` adds a question mark to the key, `undefinedableAsync` does not.
> Note that `undefinedableAsync` does not accept `null` as an input. If you want to accept `null` inputs, use `nullableAsync`, and if you want to accept `null` and `undefined` inputs, use `nullishAsync` instead. Also, if you want to set a default output value for any invalid input, you should use `fallbackAsync` instead.
#### Returns
- `Schema`
#### Examples
The following examples show how `undefinedableAsync` can be used.
##### Undefinedable username schema
Schema that accepts a unique username or `undefined`.
> By using a function as the `default_` parameter, the schema will return a unique username from the function call each time the input is `undefined`.
```ts
import { getUniqueUsername, isUsernameUnique } from '~/api';
const UndefinedableUsernameSchema = v.undefinedableAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
),
getUniqueUsername
);
```
##### New user schema
Schema to validate new user details.
```ts
import { isEmailUnique, isUsernameUnique } from '~/api';
const NewUserSchema = v.objectAsync({
email: v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailUnique, 'The email is not unique.')
),
username: v.undefinedableAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
)
),
password: v.pipe(v.string(), v.minLength(8)),
});
/*
The input and output types of the schema:
{
email: string;
password: string;
username: string | undefined;
}
*/
```
##### Unwrap undefinedable schema
Use `unwrap` to undo the effect of `undefinedableAsync`.
```ts
import { isUsernameUnique } from '~/api';
const UsernameSchema = v.unwrap(
// Assume this schema is from a different file and is reused here
v.undefinedableAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
)
)
);
```
#### Related
The following APIs can be combined with `undefinedableAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### unionAsync
Creates an union schema.
> I recommend that you read the unions guide before using this schema function.
```ts
const Schema = v.unionAsync(options, message);
```
#### Generics
- `TOptions`
- `TMessage`
#### Parameters
- `options`
- `message`
##### Explanation
With `unionAsync` you can validate if the input matches one of the given `options`. If the input does not match a schema and cannot be clearly assigned to one of the options, you can use `message` to customize the error message.
If a bad input can be uniquely assigned to one of the schemas based on the data type, the result of that schema is returned. Otherwise, a general issue is returned that contains the issues of each schema as subissues. This is a special case within the library, as the issues of `unionAsync` can contradict each other.
#### Returns
- `Schema`
#### Examples
The following examples show how `unionAsync` can be used.
##### User schema
Schema to validate a user's email or username.
```ts
import { isEmailPresent, isUsernamePresent } from '~/api';
const UserSchema = v.unionAsync([
v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPresent, 'The email is not in the database.')
),
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernamePresent, 'The username is not in the database.')
),
]);
```
#### Related
The following APIs can be combined with `unionAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
### variantAsync
Creates a variant schema.
```ts
const Schema = v.variantAsync(key, options, message);
```
#### Generics
- `TKey`
- `TOptions`
- `TMessage`
#### Parameters
- `key`
- `options`
- `message`
##### Explanation
With `variantAsync` you can validate if the input matches one of the given object `options`. The object schema to be used for the validation is determined by the discriminator `key`. If the input does not match a schema and cannot be clearly assigned to one of the options, you can use `message` to customize the error message.
> It is allowed to specify the exact same or a similar discriminator multiple times. However, in such cases `variantAsync` will only return the output of the first untyped or typed variant option result. Typed results take precedence over untyped ones.
> For deeply nested `variant` schemas with several different discriminator keys, `variant` will return an issue for the first most likely object schemas on invalid input. The order of the discriminator keys and the presence of a discriminator in the input are taken into account.
#### Returns
- `Schema`
#### Examples
The following examples show how `variantAsync` can be used.
##### Message schema
Schema to validate a message object.
```ts
import { isValidGroupReceiver, isValidUserReceiver } from '~/api';
const MessageSchema = v.objectAsync({
message: v.pipe(v.string(), v.nonEmpty()),
receiver: v.variantAsync('type', [
v.objectAsync({
type: v.literal('group'),
groupId: v.pipeAsync(
v.string(),
v.uuid(),
v.checkAsync(isValidGroupReceiver, 'The group cannot receive messages.')
),
}),
v.objectAsync({
type: v.literal('user'),
email: v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isValidUserReceiver, 'The user cannot receive messages.')
),
}),
]),
});
```
##### User schema
Schema to validate unique user details.
```ts
import { isRegisteredEmail, isRegisteredUsername, isValidUserId } from '~/api';
const UserSchema = v.variantAsync('type', [
// Assume this schema is from a different file and reused here.
v.variantAsync('type', [
v.objectAsync({
type: v.literal('email'),
email: v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isRegisteredEmail, 'The email is not registered.')
),
}),
v.objectAsync({
type: v.literal('username'),
username: v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isRegisteredUsername, 'The username is not registered.')
),
}),
]),
v.objectAsync({
type: v.literal('userId'),
userId: v.pipeAsync(
v.string(),
v.uuid(),
v.checkAsync(isValidUserId, 'The user id is not valid.')
),
}),
]);
```
#### Related
The following APIs can be combined with `variantAsync`.
##### Schemas
##### Methods
##### Actions
##### Utils
##### Async
## Types
### AnySchema
Any schema interface.
#### Definition
- `AnySchema`
- `type`
- `reference`
- `expects`
### ArgsAction
Args action interface.
#### Generics
- `TInput`
- `TSchema`
#### Definition
- `ArgsAction`
- `type`
- `reference`
- `schema`
### ArgsActionAsync
Args action interface.
#### Generics
- `TInput`
- `TSchema`
#### Definition
- `ArgsActionAsync`
- `type`
- `reference`
- `schema`
### ArrayInput
Array input type.
#### Definition
- `ArrayInput`
### ArrayIssue
Array issue interface.
#### Definition
- `ArrayIssue`
- `kind`
- `type`
- `expected`
### ArrayPathItem
Array path item interface.
#### Definition
- `ArrayPathItem`
- `type`
- `origin`
- `input`
- `key`
- `value`
The `input` of a path item may differ from the `input` of its issue. This is because path items are subsequently added by parent schemas and are related to their input. Transformations of child schemas are not taken into account.
### ArrayRequirement
Array requirement type.
#### Generics
- `TInput`
#### Definition
- `ArrayRequirement`
### ArrayRequirementAsync
Array requirement async type.
#### Generics
- `TInput`
#### Definition
- `ArrayRequirementAsync`
### ArraySchema
Array schema interface.
#### Generics
- `TItem`
- `TMessage`
#### Definition
- `ArraySchema`
- `type`
- `reference`
- `expects`
- `item`
- `message`
### ArraySchemaAsync
Array schema async interface.
#### Generics
- `TItem`
- `TMessage`
#### Definition
- `ArraySchemaAsync`
- `type`
- `reference`
- `expects`
- `item`
- `message`
### AwaitActionAsync
Await action async interface.
#### Generics
- `TInput`
#### Definition
- `AwaitActionAsync`
- `type`
- `reference`
### Base64Action
Base64 action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `Base64Action`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### Base64Issue
Base64 issue interface.
#### Generics
- `TInput`
#### Definition
- `Base64Issue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### BaseIssue
Schema issue interface.
#### Generics
- `TInput`
#### Definition
- `BaseIssue`
- `kind`
- `type`
- `input`
- `expected`
- `received`
- `message`
- `requirement`
- `path`
- `issues`
### BaseMetadata
Base metadata interface.
#### Generics
- `TInput`
#### Definition
- `BaseMetadata`
- `kind`
- `type`
- `reference`
- `~types`
### BaseSchema
Base schema interface.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `BaseSchema`
- `kind`
- `type`
- `reference`
- `expects`
- `async`
- `~standard`
- `~run`
- `~types`
### BaseSchemaAsync
Base schema async interface.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `BaseSchemaAsync`
- `reference`
- `async`
- `~run`
### BaseTransformation
Base transformation interface.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `BaseTransformation`
- `kind`
- `type`
- `reference`
- `async`
- `~run`
- `~types`
### BaseTransformationAsync
Base transformation async interface.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `BaseTransformationAsync`
- `reference`
- `async`
- `~run`
### BaseValidation
Base action interface.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `BaseValidation`
- `kind`
- `type`
- `reference`
- `expects`
- `async`
- `~run`
- `~types`
### BaseValidationAsync
Base validation async interface.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `BaseValidationAsync`
- `reference`
- `async`
- `~run`
### BicAction
BIC action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `BicAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### BicIssue
Bic issue interface.
#### Generics
- `TInput`
#### Definition
- `BicIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### BigintIssue
Bigint issue interface.
#### Definition
- `BigintIssue`
- `kind`
- `type`
- `expected`
### BigintSchema
Bigint schema interface.
#### Generics
- `TMessage`
#### Definition
- `BigintSchema`
- `type`
- `reference`
- `expects`
- `message`
### BlobIssue
Blob issue interface.
#### Definition
- `BlobIssue`
- `kind`
- `type`
- `expected`
### BlobSchema
Blob schema interface.
#### Generics
- `TMessage`
#### Definition
- `BlobSchema`
- `type`
- `reference`
- `expects`
- `message`
### BooleanIssue
Boolean issue interface.
#### Definition
- `BooleanIssue`
- `kind`
- `type`
- `expected`
### BooleanSchema
Boolean schema interface.
#### Generics
- `TMessage`
#### Definition
- `BooleanSchema`
- `type`
- `reference`
- `expects`
- `message`
### Brand
Brand interface.
#### Generics
- `TName`
#### Definition
- `Brand`
### BrandAction
Brand action interface.
#### Generics
- `TInput`
- `TName`
#### Definition
- `BrandAction`
- `type`
- `reference`
- `name`
### BrandName
Brand name type.
#### Definition
- `BrandName`
### BytesAction
Bytes action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `BytesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### BytesIssue
Bytes issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `BytesIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### CheckAction
Check action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `CheckAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### CheckActionAsync
Check action async interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `CheckActionAsync`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### CheckIssue
Check issue interface.
#### Generics
- `TInput`
#### Definition
- `CheckIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### CheckItemsAction
Check items action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `CheckItemsAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### CheckItemsActionAsync
Check items action async interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `CheckItemsActionAsync`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### CheckItemsIssue
Check items issue interface.
#### Generics
- `TInput`
#### Definition
- `CheckItemsIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### Class
Class type.
#### Definition
- `Class`
### Config
Config interface.
#### Generics
- `TIssue`
#### Definition
- `Config`
- `lang`
- `message`
- `abortEarly`
- `abortPipeEarly`
### ContentInput
Content input type.
#### Definition
- `ContentInput`
### ContentRequirement
Content requirement type.
#### Generics
- `TInput`
#### Definition
- `ContentRequirement`
### CreditCardAction
Credit card action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `CreditCardAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### CreditCardIssue
Credit card issue interface.
#### Generics
- `TInput`
#### Definition
- `CreditCardIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### Cuid2Action
Cuid2 action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `Cuid2Action`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### Cuid2Issue
Cuid2 issue interface.
#### Generics
- `TInput`
#### Definition
- `Cuid2Issue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### CustomIssue
Custom issue interface.
#### Definition
- `CustomIssue`
- `kind`
- `type`
- `expected`
### CustomSchema
Custom schema interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `CustomSchema`
- `type`
- `reference`
- `expects`
- `check`
- `message`
### CustomSchemaAsync
Custom schema async interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `CustomSchemaAsync`
- `type`
- `reference`
- `expects`
- `check`
- `message`
### DateIssue
Date issue interface.
#### Definition
- `DateIssue`
- `kind`
- `type`
- `expected`
### DateSchema
Date schema interface.
#### Generics
- `TMessage`
#### Definition
- `DateSchema`
- `type`
- `reference`
- `expects`
- `message`
### DecimalAction
Decimal action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `DecimalAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### DecimalIssue
Decimal issue interface.
#### Generics
- `TInput`
#### Definition
- `DecimalIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### DeepPickN
Deeply picks N specific keys.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/types/utils.ts).
### Default
Default type.
#### Generics
- `TWrapped`
- `TInput`
#### Definition
- `Default`
### DefaultAsync
Default async type.
#### Generics
- `TWrapped`
- `TInput`
#### Definition
- `DefaultAsync`
### DefaultValue
Default value type.
#### Generics
- `TDefault`
#### Definition
- `DefaultValue`
### DescriptionAction
Description action interface.
#### Generics
- `TInput`
- `TDescription`
#### Definition
- `DescriptionAction`
- `type`
- `reference`
- `description`
### DigitsAction
Digits action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `DigitsAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### DigitsIssue
Digits issue interface.
#### Generics
- `TInput`
#### Definition
- `DigitsIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### EmailAction
Email action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `EmailAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### EmailIssue
Email issue interface.
#### Generics
- `TInput`
#### Definition
- `EmailIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### EmojiAction
Emoji action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `EmojiAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### EmojiIssue
Emoji issue interface.
#### Generics
- `TInput`
#### Definition
- `EmojiIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### EmptyAction
Empty action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `EmptyAction`
- `type`
- `reference`
- `expects`
- `message`
### EmptyIssue
Empty issue interface.
#### Generics
- `TInput`
#### Definition
- `EmptyIssue`
- `kind`
- `type`
- `expected`
- `received`
### EndsWithAction
Ends with action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `EndsWithAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### EndsWithIssue
Ends with issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `EndsWithIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### EntriesAction
Entries action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `EntriesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### EntriesInput
Entries input type.
#### Definition
- `EntriesInput`
### EntriesIssue
Entries issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `EntriesIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### Enum
Enum interface.
#### Definition
- `Enum`
### EnumIssue
Enum issue interface.
#### Definition
- `EnumIssue`
- `kind`
- `type`
- `expected`
### EnumSchema
Enum schema interface.
#### Generics
- `TEnum`
- `TMessage`
#### Definition
- `EnumSchema`
- `type`
- `reference`
- `enum`
- `options`
- `message`
### ErrorMessage
Error message type.
#### Generics
- `TIssue`
#### Definition
- `ErrorMessage`
### EveryItemAction
Every action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `EveryItemAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### EveryItemIssue
Every item issue interface.
#### Generics
- `TInput`
#### Definition
- `EveryItemIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### ExactOptionalSchema
Exact optional schema interface.
#### Generics
- `TWrapped`
- `TDefault`
#### Definition
- `ExactOptionalSchema`
- `type`
- `reference`
- `expects`
- `wrapped`
- `default`
### ExactOptionalSchemaAsync
Exact optional schema async interface.
#### Generics
- `TWrapped`
- `TDefault`
#### Definition
- `ExactOptionalSchemaAsync`
- `type`
- `reference`
- `expects`
- `wrapped`
- `default`
### ExcludesAction
Excludes action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `ExcludesAction`
- `type`
- `referece`
- `expects`
- `requirement`
- `message`
### ExcludesIssue
Excludes issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `ExcludesIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### FailureDataset
Failure dataset interface.
#### Generics
- `TIssue`
#### Definition
- `UntypedDataset`
- `typed`
- `value`
- `issues`
### Fallback
Fallback type.
#### Generics
- `TSchema`
#### Definition
- `Fallback`
### FallbackAsync
Fallback async type.
#### Generics
- `TSchema`
#### Definition
- `FallbackAsync`
### FileIssue
File issue interface.
#### Definition
- `FileIssue`
- `kind`
- `type`
- `expected`
### FileSchema
File schema interface.
#### Generics
- `TMessage`
#### Definition
- `FileSchema`
- `type`
- `reference`
- `expects`
- `message`
### FilterItemsAction
Filter items action interface.
#### Generics
- `TInput`
#### Definition
- `FilterItemsAction`
- `type`
- `reference`
- `operation`
### FindItemAction
Find item action interface.
#### Generics
- `TInput`
#### Definition
- `FindItemAction`
- `type`
- `reference`
- `operation`
### FiniteAction
Finite action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `FiniteAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### FiniteIssue
Finite issue interface.
#### Generics
- `TInput`
#### Definition
- `FiniteIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### FirstTupleItem
Extracts first tuple item.
#### Generics
- `TTuple`
#### Definition
- `FirstTupleItem`
### FlatErrors
Flat errors type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/methods/flatten/flatten.ts).
### Flavor
Flavor interface.
#### Generics
- `TName`
#### Definition
- `Flavor`
### FlavorAction
Flavor action interface.
#### Generics
- `TInput`
- `TName`
#### Definition
- `FlavorAction`
- `type`
- `reference`
- `name`
### FlavorName
Flavor name type.
#### Definition
- `FlavorName`
### FunctionIssue
Function issue interface.
#### Definition
- `FunctionIssue`
- `kind`
- `type`
- `expected`
### FunctionSchema
Function schema interface.
#### Generics
- `TMessage`
#### Definition
- `FunctionSchema`
- `type`
- `reference`
- `expects`
- `message`
### GenericIssue
Generic issue type.
#### Generics
- `TInput`
#### Definition
- `GenericIssue`
### GenericMetadata
Generic metadata type.
#### Generics
- `TInput`
#### Definition
- `GenericMetadata`
### GenericPipeAction
Generic pipe action type.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `GenericPipeAction`
### GenericPipeActionAsync
Generic pipe action async type.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `GenericPipeActionAsync`
### GenericPipeItem
Generic pipe item type.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `GenericPipeItem`
### GenericPipeItemAsync
Generic pipe item async type.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `GenericPipeItemAsync`
### GenericSchema
Generic schema type.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `GenericSchema`
### GenericSchemaAsync
Generic schema async type.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `GenericSchemaAsync`
### GenericTransformation
Generic transformation type.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `GenericTransformation`
### GenericTransformationAsync
Generic transformation async type.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `GenericTransformationAsync`
### GenericValidation
Generic validation type.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `GenericValidation`
### GenericValidationAsync
Generic validation async type.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `GenericValidationAsync`
### GlobalConfig
The global config type.
#### Definition
- `GlobalConfig`
### GraphemesAction
Graphemes action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `GraphemesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### GraphemesIssue
Graphemes issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `GraphemesIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### GtValueAction
Greater than value action type.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `GtValueAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### GtValueIssue
Greater than value issue type.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `GtValueIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### HashAction
Hash action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `HashAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### HashIssue
Hash issue interface.
#### Generics
- `TInput`
#### Definition
- `HashIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### HashType
Hash type type.
#### Definition
- `HashType`
### HexadecimalAction
Hexadecimal action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `HexadecimalAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### HexadecimalIssue
Hexadecimal issue interface.
#### Generics
- `TInput`
#### Definition
- `HexadecimalIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### HexColorAction
Hex color action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `HexColorAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### HexColorIssue
HexColor issue interface.
#### Generics
- `TInput`
#### Definition
- `HexColorIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### ImeiAction
Imei action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `ImeiAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### ImeiIssue
IMEI issue interface.
#### Generics
- `TInput`
#### Definition
- `ImeiIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### IncludesAction
Includes action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `IncludesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### IncludesIssue
Includes issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `IncludesIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### InferDefault
Infer default type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/methods/getDefault/getDefault.ts).
### InferDefaults
Infer defaults type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/methods/getDefaults/types.ts).
### InferFallback
Infer fallback type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/methods/getFallback/getFallback.ts).
### InferFallbacks
Infer fallbacks type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/methods/getFallbacks/types.ts).
### InferInput
Infer input type.
#### Generics
- `TItem`
#### Definition
- `InferInput`
#### Example
```ts
// Create object schema
const ObjectSchema = v.object({
key: v.pipe(
v.string(),
v.transform((input) => input.length)
),
});
// Infer object input type
type ObjectInput = v.InferInput; // { key: string }
```
### InferIntersectInput
Infer intersect input type.
```ts
// Create object schemas
const ObjectSchemas = [
v.object({
key1: v.pipe(
v.string(),
v.transform((input) => input.length)
),
}),
v.object({
key2: v.pipe(
v.string(),
v.transform((input) => input.length)
),
}),
];
// Infer object intersect input type
type ObjectInput = v.InferIntersectInput; // { key1: string } & { key2: string }
```
### InferIntersectOutput
Infer intersect output type.
```ts
// Create object schemas
const ObjectSchemas = [
v.object({
key1: v.pipe(
v.string(),
v.transform((input) => input.length)
),
}),
v.object({
key2: v.pipe(
v.string(),
v.transform((input) => input.length)
),
}),
];
// Infer object intersect output type
type ObjectOutput = v.InferIntersectOutput; // { key1: number } & { key2: number }
```
### InferIssue
Infer issue type.
#### Generics
- `TItem`
#### Definition
- `InferIssue`
### InferMapInput
Infer map input type.
#### Generics
- `TKey`
- `TValue`
#### Definition
- `InferMapInput`
### InferMapOutput
Infer map output type.
#### Generics
- `TKey`
- `TValue`
#### Definition
- `InferMapOutput`
### InferMetadata
Infer fallbacks type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/methods/getMetadata/getMetadata.ts).
### InferNonNullableInput
Infer non nullable input type.
```ts
// Create nullable sting schema
const NullableStringSchema = v.nullable(
v.pipe(
v.string(),
v.transform((input) => input.length)
)
);
// Infer non nullable string input type
type NonNullableStringInput = v.InferNonNullableInput<
typeof NullableStringSchema
>; // string
```
### InferNonNullableIssue
Infer non nullable issue type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/schemas/nonNullable/types.ts).
### InferNonNullableOutput
Infer non nullable output type.
```ts
// Create nullable sting schema
const NullableStringSchema = v.nullable(
v.pipe(
v.string(),
v.transform((input) => input.length)
)
);
// Infer non nullable string output type
type NonNullableStringOutput = v.InferNonNullableOutput<
typeof NullableStringSchema
>; // number
```
### InferNonNullishInput
Infer non nullable input type.
```ts
// Create nullish sting schema
const NullishStringSchema = v.nullish(
v.pipe(
v.string(),
v.transform((input) => input.length)
)
);
// Infer non nullish string input type
type NonNullishStringInput = v.InferNonNullishInput; // string
```
### InferNonNullishIssue
Infer non nullish issue type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/schemas/nonNullish/types.ts).
### InferNonNullishOutput
Infer non nullable output type.
```ts
// Create nullish sting schema
const NullishStringSchema = v.nullish(
v.pipe(
v.string(),
v.transform((input) => input.length)
)
);
// Infer non nullish string output type
type NonNullishStringOutput = v.InferNonNullishOutput<
typeof NullishStringSchema
>; // number
```
### InferNonOptionalInput
Infer non optional input type.
```ts
// Create optional sting schema
const OptionalStringSchema = v.optional(
v.pipe(
v.string(),
v.transform((input) => input.length)
)
);
// Infer non optional string input type
type NonOptionalStringInput = v.InferNonOptionalInput<
typeof OptionalStringSchema
>; // string
```
### InferNonOptionalIssue
Infer non optional issue type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/schemas/nonOptional/types.ts).
### InferNonOptionalOutput
Infer non optional output type.
```ts
// Create optional sting schema
const OptionalStringSchema = v.optional(
v.pipe(
v.string(),
v.transform((input) => input.length)
)
);
// Infer non optional string output type
type NonOptionalStringOutput = v.InferNonOptionalOutput<
typeof OptionalStringSchema
>; // number
```
### InferNullableOutput
Infer nullable output type.
#### Generics
- `TWrapped`
- `TDefault`
#### Definition
- `InferNullableOutput`
### InferNullishOutput
Infer nullish output type.
#### Generics
- `TWrapped`
- `TDefault`
#### Definition
- `InferNullishOutput`
### InferObjectInput
Infer object input type.
```ts
// Create object entries
const entries = {
key: v.pipe(
v.string(),
v.transform((input) => input.length)
),
};
// Infer entries input type
type EntriesInput = v.InferObjectInput; // { key: string }
```
### InferObjectIssue
Infer object issue type.
#### Generics
- `TEntries`
#### Definition
- `InferObjectIssue`
### InferObjectOutput
Infer object output type.
```ts
// Create object entries
const entries = {
key: v.pipe(
v.string(),
v.transform((input) => input.length)
),
};
// Infer entries output type
type EntriesOutput = v.InferObjectOutput; // { key: number }
```
### InferOptionalOutput
Infer optional output type.
#### Generics
- `TWrapped`
- `TDefault`
#### Definition
- `InferOptionalOutput`
### InferOutput
Infer output type.
#### Generics
- `TItem`
#### Definition
- `InferIssue`
#### Example
```ts
// Create object schema
const ObjectSchema = v.object({
key: v.pipe(
v.string(),
v.transform((input) => input.length)
),
});
// Infer object output type
type ObjectOutput = v.InferOutput; // { key: number }
```
### InferRecordInput
Infer record input type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/schemas/record/types.ts).
### InferRecordOutput
Infer record output type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/schemas/record/types.ts).
### InferSetInput
Infer set input type.
#### Generics
- `TValue`
#### Definition
- `InferSetInput`
### InferSetOutput
Infer set output type.
#### Generics
- `TValue`
#### Definition
- `InferSetOutput`
### InferTupleInput
Infer tuple output type.
```ts
// Create tuple items
const items = [
v.pipe(
v.string(),
v.transform((input) => input.length)
),
];
// Infer items input type
type ItemsInput = v.InferTupleInput; // [string]
```
### InferTupleIssue
Infer tuple issue type.
#### Generics
- `TItems`
#### Definition
- `InferTupleIssue`
### InferTupleOutput
Infer tuple issue type.
```ts
const items = [
v.pipe(
v.string(),
v.transform((input) => input.length)
),
];
// Infer items output type
type ItemsOutput = v.InferTupleOutput; // [number]
```
### InferVariantIssue
Infer variant issue type.
#### Generics
- `TOptions`
#### Definition
- `InferVariantIssue`
### InstanceIssue
Instance issue interface.
#### Definition
- `InstanceIssue`
- `kind`
- `type`
- `expected`
### InstanceSchema
Instance schema interface.
#### Generics
- `TClass`
- `TMessage`
#### Definition
- `InstanceSchema`
- `type`
- `reference`
- `class`
- `message`
### IntegerAction
Integer action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `IntegerAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### IntegerIssue
Integer issue interface.
#### Generics
- `TInput`
#### Definition
- `IntegerIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### IntersectIssue
Intersect issue interface.
#### Definition
- `IntersectIssue`
- `kind`
- `type`
- `expected`
### IntersectOptions
Intersect options type.
#### Definition
- `IntersectOptions`
### IntersectOptionsAsync
Intersect options async type.
#### Definition
- `IntersectOptionsAsync`
### IntersectSchema
Intersect schema interface.
#### Generics
- `TOptions`
- `TMessage`
#### Definition
- `IntersectSchema`
- `type`
- `reference`
- `options`
- `message`
### IntersectSchemaAsync
Intersect schema async interface.
#### Generics
- `TOptions`
- `TMessage`
#### Definition
- `IntersectSchemaAsync`
- `type`
- `reference`
- `options`
- `message`
### IpAction
IP action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `IpAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### IpIssue
IP issue interface.
#### Generics
- `TInput`
#### Definition
- `IpIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### Ipv4Action
IPv4 action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `Ipv4Action`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### Ipv4Issue
IPv4 issue interface.
#### Generics
- `TInput`
#### Definition
- `Ipv4Issue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### Ipv6Action
IPv6 action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `Ipv6Action`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### Ipv6Issue
IPv6 issue interface.
#### Generics
- `TInput`
#### Definition
- `Ipv6Issue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### IsoDateAction
ISO date action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `IsoDateAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### IsoDateIssue
ISO date issue interface.
#### Generics
- `TInput`
#### Definition
- `IsoDateIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### IsoDateTimeAction
ISO date time action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `IsoDateTimeAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### IsoDateTimeIssue
ISO date time issue interface.
#### Generics
- `TInput`
#### Definition
- `IsoDateTimeIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### IsoTimeAction
ISO time action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `IsoTimeAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### IsoTimeIssue
ISO time issue interface.
#### Generics
- `TInput`
#### Definition
- `IsoTimeIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### IsoTimeSecondAction
ISO time second action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `IsoTimeSecondAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### IsoTimeSecondIssue
ISO time second issue interface.
#### Generics
- `TInput`
#### Definition
- `IsoTimeSecondIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### IsoTimestampAction
ISO timestamp action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `IsoTimestampAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### IsoTimestampIssue
ISO timestamp issue interface.
#### Generics
- `TInput`
#### Definition
- `IsoTimestampIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### IsoWeekAction
ISO week action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `IsoWeekAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### IsoWeekIssue
ISO week issue interface.
#### Generics
- `TInput`
#### Definition
- `IsoWeekIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### IssueDotPath
Issue dot path type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/types/issue.ts).
### IssuePathItem
Path item type.
#### Definition
- `IssuePathItem`
### LazySchema
Lazy schema interface.
#### Generics
- `TWrapped`
#### Definition
- `LazySchema`
- `type`
- `reference`
- `expects`
- `getter`
### LazySchemaAsync
Lazy schema async interface.
#### Generics
- `TWrapped`
#### Definition
- `LazySchemaAsync`
- `type`
- `reference`
- `expects`
- `getter`
### LengthAction
Length action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `LengthAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### LengthInput
Length input type.
#### Definition
- `LengthInput`
### LengthIssue
Length issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `LengthIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### Literal
Literal type.
#### Definition
- `Literal`
### LiteralIssue
Literal issue interface.
#### Definition
- `LiteralIssue`
- `kind`
- `type`
- `expected`
### LooseObjectIssue
Loose object issue interface.
#### Definition
- `LooseObjectIssue`
- `kind`
- `type`
- `expected`
### LooseObjectSchema
Loose object schema interface.
#### Generics
- `TEntries`
- `TMessage`
#### Definition
- `LooseObjectSchema`
- `type`
- `reference`
- `expects`
- `entries`
- `message`
### LooseObjectSchemaAsync
Loose object schema async interface.
#### Generics
- `TEntries`
- `TMessage`
#### Definition
- `LooseObjectSchemaAsync`
- `type`
- `reference`
- `expects`
- `entries`
- `message`
### LooseTupleIssue
Loose tuple issue interface.
#### Definition
- `LooseTupleIssue`
- `kind`
- `type`
- `expected`
### LooseTupleSchema
Loose tuple schema interface.
#### Generics
- `TItems`
- `TMessage`
#### Definition
- `LooseTupleSchema`
- `type`
- `reference`
- `expects`
- `items`
- `message`
### LooseTupleSchemaAsync
Loose tuple schema async interface.
#### Generics
- `TItems`
- `TMessage`
#### Definition
- `LooseTupleSchemaAsync`
- `type`
- `reference`
- `expects`
- `items`
- `message`
### LiteralSchema
Literal schema interface.
#### Generics
- `TLiteral`
- `TMessage`
#### Definition
- `LiteralSchema`
- `type`
- `reference`
- `literal`
- `message`
### LtValueAction
Less than value action type.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `LtValueAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### LtValueIssue
Less than value issue type.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `LtValueIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### Mac48Action
48-bit MAC action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `Mac48Action`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### Mac48Issue
48-bit MAC issue interface.
#### Generics
- `TInput`
#### Definition
- `Mac48Issue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### Mac64Action
64-bit MAC action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `Mac64Action`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### Mac64Issue
64-bit MAC issue interface.
#### Generics
- `TInput`
#### Definition
- `Mac64Issue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MacAction
MAC action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `MacAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### MacIssue
MAC issue interface.
#### Generics
- `TInput`
#### Definition
- `MacIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MapIssue
Map issue interface.
#### Definition
- `MapIssue`
- `kind`
- `type`
- `expected`
### MapItemsAction
Map items action interface.
#### Generics
- `TInput`
- `TOutput`
#### Definition
- `MapItemsAction`
- `type`
- `reference`
- `operation`
### MapPathItem
Map path item interface.
#### Definition
- `MapPathItem`
- `type`
- `origin`
- `input`
- `key`
- `value`
The `input` of a path item may differ from the `input` of its issue. This is because path items are subsequently added by parent schemas and are related to their input. Transformations of child schemas are not taken into account.
### MapSchema
Map schema interface.
#### Generics
- `TKey`
- `TValue`
- `TMessage`
#### Definition
- `MapSchema`
- `type`
- `reference`
- `expects`
- `key`
- `value`
- `message`
### MapSchemaAsync
Map schema async interface.
#### Generics
- `TKey`
- `TValue`
- `TMessage`
#### Definition
- `MapSchemaAsync`
- `type`
- `reference`
- `expects`
- `key`
- `value`
- `message`
### MaxBytesAction
Max bytes action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `MaxBytesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### MaxBytesIssue
Max bytes issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MaxBytesIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MaxEntriesAction
Max entries action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `MaxEntriesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### MaxEntriesIssue
Max entries issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MaxEntriesIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MaxGraphemesAction
Max graphemes action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `MaxGraphemesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### MaxGraphemesIssue
Max graphemes issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MaxGraphemesIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MaxLengthAction
Max length action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `MaxLengthAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### MaxLengthIssue
Max length issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MaxLengthIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MaxSizeAction
Max size action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `MaxSizeAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### MaxSizeIssue
Max size issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MaxSizeIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MaxValueAction
Max value action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `MaxValueAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### MaxValueIssue
Max value issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MaxValueIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### MaxWordsAction
Max words action interface.
#### Generics
- `TInput`
- `TLocales`
- `TRequirement`
- `TMessage`
#### Definition
- `MaxWordsAction`
- `type`
- `reference`
- `expects`
- `locales`
- `requirement`
- `message`
### MaxWordsIssue
Max words issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MaxWordsIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MaybePromise
Maybe promise type.
#### Generics
- `TValue`
#### Definition
- `MaybePromise`
### MaybeReadonly
Maybe readonly type.
#### Generics
- `TValue`
#### Definition
- `MaybeReadonly`
### MetadataAction
Metadata action interface.
#### Generics
- `TInput`
- `TMetadata`
#### Definition
- `MetadataAction`
- `type`
- `reference`
- `metadata_`
### MimeTypeAction
MIME type action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `MimeTypeAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### MimeTypeIssue
Mime type issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MimeTypeIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MinBytesAction
Min bytes action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `MinBytesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### MinBytesIssue
Min bytes issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MinBytesIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MinEntriesAction
Min entries action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `MinEntriesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### MinEntriesIssue
Min entries issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MinEntriesIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MinGraphemesAction
Min graphemes action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `MinGraphemesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### MinGraphemesIssue
Min graphemes issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MinGraphemesIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MinLengthAction
Min length action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `MinLengthAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### MinLengthIssue
Min length issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MinLengthIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MinSizeAction
Min size action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `MinSizeAction`
- `type`
- `referece`
- `expects`
- `requirement`
- `message`
### MinSizeIssue
Min size issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MinSizeIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MinValueAction
Min value action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `MinValueAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### MinValueIssue
Min value issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MinValueIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### MinWordsAction
Min words action interface.
#### Generics
- `TInput`
- `TLocales`
- `TRequirement`
- `TMessage`
#### Definition
- `MinWordsAction`
- `type`
- `reference`
- `expects`
- `locales`
- `requirement`
- `message`
### MinWordsIssue
Min words issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MinWordsIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### MultipleOfAction
Multiple of action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `MultipleOfAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### MultipleOfIssue
Multiple of issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `MultipleOfIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### NanIssue
NaN issue interface.
#### Definition
- `NanIssue`
- `kind`
- `type`
- `expected`
### NanSchema
NaN schema interface.
#### Generics
- `TMessage`
#### Definition
- `NanSchema`
- `type`
- `reference`
- `expects`
- `message`
### NeverIssue
Never issue interface.
#### Definition
- `NeverIssue`
- `kind`
- `type`
- `expected`
### NeverSchema
Never schema interface.
#### Generics
- `TMessage`
#### Definition
- `NeverSchema`
- `type`
- `reference`
- `expects`
- `message`
### NonEmptyAction
Non empty action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `NonEmptyAction`
- `type`
- `reference`
- `expects`
- `message`
### NonEmptyIssue
Non empty issue interface.
#### Generics
- `TInput`
#### Definition
- `NonEmptyIssue`
- `kind`
- `type`
- `expected`
- `received`
### NonNullable
Extracts `null` from a type.
#### Generics
- `TValue`
#### Definition
- `NonNullable`
### NonNullableIssue
Non nullable issue interface.
#### Definition
- `NonNullableIssue`
- `kind`
- `type`
- `expected`
### NonNullableSchema
Non nullable schema interface.
#### Generics
- `TWrapped`
- `TMessage`
#### Definition
- `NonNullableSchema`
- `type`
- `reference`
- `expects`
- `wrapped`
- `message`
### NonNullableSchemaAsync
Non nullable schema async interface.
#### Generics
- `TWrapped`
- `TMessage`
#### Definition
- `NonNullableSchemaAsync`
- `type`
- `reference`
- `expects`
- `wrapped`
- `message`
### NonNullish
Extracts `null` and `undefined` from a type.
#### Generics
- `TValue`
#### Definition
- `NonNullish`
### NonNullishIssue
Non nullish issue interface.
#### Definition
- `NonNullishIssue`
- `kind`
- `type`
- `expected`
### NonNullishSchema
Non nullish schema interface.
#### Generics
- `TWrapped`
- `TMessage`
#### Definition
- `NonNullishSchema`
- `type`
- `reference`
- `expects`
- `wrapped`
- `message`
### NonNullishSchemaAsync
Non nullish schema async interface.
#### Generics
- `TWrapped`
- `TMessage`
#### Definition
- `NonNullishSchemaAsync`
- `type`
- `reference`
- `expects`
- `wrapped`
- `message`
### NonOptional
Extracts `undefined` from a type.
#### Generics
- `TValue`
#### Definition
- `NonOptional`
### NonOptionalIssue
Non optional issue interface.
#### Definition
- `NonOptionalIssue`
- `kind`
- `type`
- `expected`
### NonOptionalSchema
Non optional schema interface.
#### Generics
- `TWrapped`
- `TMessage`
#### Definition
- `NonOptionalSchema`
- `type`
- `reference`
- `expects`
- `wrapped`
- `message`
### NonOptionalSchemaAsync
Non optional schema async interface.
#### Generics
- `TWrapped`
- `TMessage`
#### Definition
- `NonOptionalSchemaAsync`
- `type`
- `reference`
- `expects`
- `wrapped`
- `message`
### NormalizeAction
Normalize action interface.
#### Generics
- `TForm`
#### Definition
- `NormalizeAction`
- `type`
- `reference`
- `form`
### NormalizeForm
Normalize form type.
#### Definition
- `NormalizeForm`
### NotBytesAction
Not bytes action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `NotBytesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### NotBytesIssue
Not bytes issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `NotBytesIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### NotEntriesAction
Not entries action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `NotEntriesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### NotEntriesIssue
Not entries issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `NotEntriesIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### NotGraphemesAction
Not graphemes action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `NotGraphemesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### NotGraphemesIssue
Not graphemes issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `NotGraphemesIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### NotLengthAction
Not length action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `NotLengthAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### NotLengthIssue
Not length issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `NotLengthIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### NotSizeAction
Not size action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `NotSizeAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### NotSizeIssue
Not size issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `NotSizeIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### NotValueAction
Not value action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `NotValueAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### NotValuesAction
Not values action type.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `NotValuesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### NotValueIssue
Not value issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `NotValueIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### NotValuesIssue
Not values issue type.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `NotValuesIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### NotWordsAction
Not words action interface.
#### Generics
- `TInput`
- `TLocales`
- `TRequirement`
- `TMessage`
#### Definition
- `NotWordsAction`
- `type`
- `reference`
- `expects`
- `locales`
- `requirement`
- `message`
### NotWordsIssue
Not words issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `NotWordsIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### NullableSchema
Nullable schema interface.
#### Generics
- `TWrapped`
- `TDefault`
#### Definition
- `NullableSchema`
- `type`
- `reference`
- `expects`
- `wrapped`
- `default`
### NullableSchemaAsync
Nullable schema async interface.
#### Generics
- `TWrapped`
- `TDefault`
#### Definition
- `NullableSchemaAsync`
- `type`
- `reference`
- `expects`
- `wrapped`
- `default`
### NullishSchema
Nullish schema interface.
#### Generics
- `TWrapped`
- `TDefault`
#### Definition
- `Nullish`
- `type`
- `reference`
- `expects`
- `wrapped`
- `default`
### NullishSchemaAsync
Nullish schema async interface.
#### Generics
- `TWrapped`
- `TDefault`
#### Definition
- `Nullish`
- `type`
- `reference`
- `expects`
- `wrapped`
- `default`
### NullIssue
Null issue interface.
#### Definition
- `NullIssue`
- `kind`
- `type`
- `expected`
### NullSchema
Null schema interface.
#### Generics
- `TMessage`
#### Definition
- `NullSchema`
- `type`
- `reference`
- `expects`
- `message`
### NumberIssue
Number issue interface.
#### Definition
- `NumberIssue`
- `kind`
- `type`
- `expected`
### NumberSchema
Number schema interface.
#### Generics
- `TMessage`
#### Definition
- `NumberSchema`
- `type`
- `reference`
- `expects`
- `message`
### ObjectEntries
Object entries interface.
#### Definition
- `ObjectEntries`
### ObjectEntriesAsync
Object entries async interface.
#### Definition
- `ObjectEntriesAsync`
### ObjectIssue
Object issue interface.
#### Definition
- `ObjectIssue`
- `kind`
- `type`
- `expected`
### ObjectKeys
Object keys type.
#### Generics
- `TSchema`
#### Definition
- `ObjectKeys`
### ObjectPathItem
Object path item interface.
#### Definition
- `ObjectPathItem`
- `type`
- `origin`
- `input`
- `key`
- `value`
The `input` of a path item may differ from the `input` of its issue. This is because path items are subsequently added by parent schemas and are related to their input. Transformations of child schemas are not taken into account.
### ObjectSchema
Object schema interface.
#### Generics
- `TEntries`
- `TMessage`
#### Definition
- `ObjectSchema`
- `type`
- `reference`
- `expects`
- `entries`
- `message`
### ObjectSchemaAsync
Object schema async interface.
#### Generics
- `TEntries`
- `TMessage`
#### Definition
- `ObjectSchemaAsync`
- `type`
- `reference`
- `expects`
- `entries`
- `message`
### ObjectWithRestIssue
Object with rest issue interface.
#### Definition
- `ObjectWithRestIssue`
- `kind`
- `type`
- `expected`
### ObjectWithRestSchema
Object with rest schema interface.
#### Generics
- `TEntries`
- `TRest`
- `TMessage`
#### Definition
- `ObjectWithRestSchema`
- `type`
- `reference`
- `expects`
- `entries`
- `rest`
- `message`
### ObjectWithRestSchemaAsync
Object schema async interface.
#### Generics
- `TEntries`
- `TRest`
- `TMessage`
#### Definition
- `ObjectWithRestSchemaAsync`
- `type`
- `reference`
- `expects`
- `entries`
- `rest`
- `message`
### OctalAction
Octal action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `OctalAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### OctalIssue
Octal issue interface.
#### Generics
- `TInput`
#### Definition
- `OctalIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### OptionalSchema
Optional schema interface.
#### Generics
- `TWrapped`
- `TDefault`
#### Definition
- `OptionalSchema`
- `type`
- `reference`
- `expects`
- `wrapped`
- `default`
### OptionalSchemaAsync
Optional schema async interface.
#### Generics
- `TWrapped`
- `TDefault`
#### Definition
- `OptionalSchemaAsync`
- `type`
- `reference`
- `expects`
- `wrapped`
- `default`
### OutputDataset
Output dataset interface.
#### Generics
- `TValue`
- `TIssue`
#### Definition
- `OutputDataset`
### ParseJsonAction
JSON parse action interface.
#### Generics
- `TInput`
- `TConfig`
- `TMessage`
#### Definition
- `ParseJsonAction`
- `type`
- `reference`
- `config`
- `message`
### ParseJsonConfig
JSON parse config interface.
#### Definition
- `ParseJsonConfig`
- `reviver`
### ParseJsonIssue
JSON parse issue interface.
#### Generics
- `TInput`
#### Definition
- `ParseJsonIssue`
- `kind`
- `type`
- `expected`
- `received`
### Parser
The parser interface.
#### Generics
- `TSchema`
- `TConfig`
#### Definition
- `Parser`
-
- `schema`
- `config`
### ParserAsync
The parser async interface.
#### Generics
- `TSchema`
- `TConfig`
#### Definition
- `ParserAsync`
-
- `schema`
- `config`
### PartialCheckAction
Partial check action interface.
#### Generics
- `TInput`
- `TPaths`
- `TSelection`
- `TMessage`
#### Definition
- `PartialCheckAction`
- `type`
- `reference`
- `expects`
- `paths`
- `requirement`
- `message`
### PartialCheckActionAsync
Partial check action async interface.
#### Generics
- `TInput`
- `TPaths`
- `TSelection`
- `TMessage`
#### Definition
- `PartialCheckActionAsync`
- `type`
- `reference`
- `expects`
- `paths`
- `requirement`
- `message`
### PartialCheckIssue
Partial check issue interface.
#### Generics
- `TInput`
#### Definition
- `PartialCheckIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### PartialDataset
Partial dataset interface.
#### Generics
- `TValue`
- `TIssue`
#### Definition
- `UntypedDataset`
- `typed`
- `value`
- `issues`
### PartialInput
Partial input type.
#### Definition
- `PartialInput`
### PicklistOptions
Picklist options type.
#### Definition
- `PicklistOptions`
### PicklistIssue
Picklist issue interface.
#### Definition
- `PicklistIssue`
- `kind`
- `type`
- `expected`
### PicklistSchema
Picklist schema interface.
#### Generics
- `TOptions`
- `TMessage`
#### Definition
- `PicklistSchema`
- `type`
- `reference`
- `options`
- `message`
### PipeAction
Pipe action interface.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `PipeAction`
### PipeActionAsync
Pipe action async interface.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `PipeActionAsync`
### PipeItem
Pipe item type.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `PipeItem`
### PipeItemAsync
Pipe item async type.
#### Generics
- `TInput`
- `TOutput`
- `TIssue`
#### Definition
- `PipeItemAsync`
### PromiseIssue
Promise issue interface.
#### Definition
- `PromiseIssue`
- `kind`
- `type`
- `expected`
### PromiseSchema
Promise schema interface.
#### Generics
- `TMessage`
#### Definition
- `PromiseSchema`
- `type`
- `reference`
- `expects`
- `message`
### RawCheckAction
Raw check action interface.
#### Generics
- `TInput`
#### Definition
- `RawCheckAction`
- `type`
- `reference`
### RawCheckActionAsync
Raw check action async interface.
#### Generics
- `TInput`
#### Definition
- `RawCheckActionAsync`
- `type`
- `reference`
- `expects`
### RawCheckIssue
Raw check issue interface.
#### Generics
- `TInput`
#### Definition
- `RawCheckIssue`
- `kind`
- `type`
### RawTransformAction
Raw transform action interface.
#### Generics
- `TInput`
- `TOutput`
#### Definition
- `RawTransformAction`
- `type`
- `reference`
### RawTransformActionAsync
Raw transform action async interface.
#### Generics
- `TInput`
- `TOutput`
#### Definition
- `RawTransformActionAsync`
- `type`
- `reference`
### RawTransformIssue
Raw transform issue interface.
#### Generics
- `TInput`
#### Definition
- `RawTransformIssue`
- `kind`
- `type`
### ReadonlyAction
Readonly action interface.
#### Generics
- `TInput`
#### Definition
- `ReadonlyAction`
- `type`
- `reference`
### RecordIssue
Record issue interface.
#### Definition
- `RecordIssue`
- `kind`
- `type`
- `expected`
### RecordSchema
Record schema interface.
#### Generics
- `TKey`
- `TValue`
- `TMessage`
#### Definition
- `RecordSchema`
- `type`
- `reference`
- `expects`
- `key`
- `value`
- `message`
### RecordSchemaAsync
Record schema async interface.
#### Generics
- `TKey`
- `TValue`
- `TMessage`
#### Definition
- `RecordSchemaAsync`
- `type`
- `reference`
- `expects`
- `key`
- `value`
- `message`
### ReduceItemsAction
Reduce items action interface.
#### Generics
- `TInput`
- `TOutput`
#### Definition
- `ReduceItemsAction`
- `type`
- `reference`
- `operation`
- `initial`
### RegexAction
Regex action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `RegexAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### RegexIssue
Regex issue interface.
#### Generics
- `TInput`
#### Definition
- `RegexIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### ReturnsAction
Returns action interface.
#### Generics
- `TInput`
- `TSchema`
#### Definition
- `ReturnsAction`
- `type`
- `reference`
- `schema`
### ReturnsActionAsync
Returns action interface.
#### Generics
- `TInput`
- `TSchema`
#### Definition
- `ReturnsActionAsync`
- `type`
- `reference`
- `schema`
### RfcEmailAction
RFC email action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `EmailAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### RfcEmailIssue
RFC email issue interface.
#### Generics
- `TInput`
#### Definition
- `EmailIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### SafeIntegerAction
Safe integer action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `SafeIntegerAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### SafeIntegerIssue
Safe integer issue interface.
#### Generics
- `TInput`
#### Definition
- `SafeIntegerIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### SafeParser
The safe parser interface.
#### Generics
- `TSchema`
- `TConfig`
#### Definition
- `SafeParser`
-
- `schema`
- `config`
### SafeParserAsync
The safe parser async interface.
#### Generics
- `TSchema`
- `TConfig`
#### Definition
- `SafeParserAsync`
-
- `schema`
- `config`
### SafeParseResult
Safe parse result type.
#### Generics
- `TSchema`
#### Definition
- `SafeParseResult`
- `typed`
- `success`
- `output`
- `issues`
### SchemaWithFallback
Schema with fallback type.
#### Generics
- `TSchema`
- `TFallback`
#### Definition
- `SchemaWithFallback`
- `fallback`
### SchemaWithFallbackAsync
Schema with fallback async type.
#### Generics
- `TSchema`
- `TFallback`
#### Definition
- `SchemaWithFallbackAsync`
- `fallback`
- `async`
- `~run`
### SchemaWithoutPipe
Schema without pipe type.
#### Generics
- `TSchema`
#### Definition
- `SchemaWithoutPipe`
### SchemaWithPartial
Schema with partial type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/methods/partial/partial.ts).
### SchemaWithPartialAsync
Schema with partial async type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/methods/partial/partialAsync.ts).
### SchemaWithPipe
Schema with pipe type.
#### Generics
- `TPipe`
#### Definition
- `SchemaWithPipe`
- `pipe`
- `~types`
- `~run`
### SchemaWithPipeAsync
Schema with pipe async type.
#### Generics
- `TPipe`
#### Definition
- `SchemaWithPipeAsync`
- `pipe`
- `async`
- `~types`
- `~run`
### SchemaWithRequired
Schema with required type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/methods/required/required.ts).
### SchemaWithRequiredAsync
Schema with required async type.
> This type is too complex to display. Please refer to the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/methods/required/requiredAsync.ts).
### SetPathItem
Set path item interface.
#### Definition
- `SetPathItem`
- `type`
- `origin`
- `input`
- `value`
The `input` of a path item may differ from the `input` of its issue. This is because path items are subsequently added by parent schemas and are related to their input. Transformations of child schemas are not taken into account.
### RecordIssue
Record issue interface.
#### Definition
- `RecordIssue`
- `kind`
- `type`
- `expected`
### SetSchema
Set schema interface.
#### Generics
- `TValue`
- `TMessage`
#### Definition
- `SetSchema`
- `type`
- `reference`
- `expects`
- `value`
- `message`
### SetSchemaAsync
Set schema async interface.
#### Generics
- `TValue`
- `TMessage`
#### Definition
- `SetSchemaAsync`
- `type`
- `reference`
- `expects`
- `value`
- `message`
### SizeAction
Size action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `SizeAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### SizeInput
Size input type.
#### Definition
- `SizeInput`
### SizeIssue
Size issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `SizeIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### SlugAction
Slug action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `SlugAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### SlugIssue
Slug issue interface.
#### Generics
- `TInput`
#### Definition
- `SlugIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### SomeItemAction
Some action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `SomeItemAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### SomeItemIssue
Some item issue interface.
#### Generics
- `TInput`
#### Definition
- `SomeItemIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### SortItemsAction
Sort items action interface.
#### Generics
- `TInput`
#### Definition
- `SortItemsAction`
- `type`
- `reference`
- `operation`
### StandardFailureResult
The result interface if validation fails.
#### Definition
- `StandardFailureResult`
- `issues`
### StandardIssue
The issue interface of the failure output.
#### Definition
- `StandardIssue`
- `message`
- `path`
### StandardPathItem
The path item interface of the issue.
#### Definition
- `StandardPathItem`
- `key`
### StandardProps
The Standard Schema properties interface.
#### Generics
- `TInput`
- `TOutput`
#### Definition
- `StandardProps`
- `version`
- `vendor`
- `validate`
- `types`
### StandardResult
The result interface of the validate function.
#### Generics
- `TOutput`
#### Definition
- `StandardResult`
### StandardSuccessResult
The result interface if validation succeeds.
#### Generics
- `TOutput`
#### Definition
- `StandardSuccessResult`
- `value`
- `issues`
### StandardTypes
The Standard Schema types interface.
#### Generics
- `TInput`
- `TOutput`
#### Definition
- `StandardTypes`
- `input`
- `output`
### StartsWithAction
Starts with action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `StartsWithAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### StartsWithIssue
Starts with issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `StartsWithIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### StrictObjectIssue
Strict object issue interface.
#### Definition
- `StrictObjectIssue`
- `kind`
- `type`
- `expected`
### StrictObjectSchema
Strict object schema interface.
#### Generics
- `TEntries`
- `TMessage`
#### Definition
- `StrictObjectSchema`
- `type`
- `reference`
- `expects`
- `entries`
- `message`
### StrictObjectSchemaAsync
Strict object schema async interface.
#### Generics
- `TEntries`
- `TMessage`
#### Definition
- `StrictObjectSchemaAsync`
- `type`
- `reference`
- `expects`
- `entries`
- `message`
### StrictTupleIssue
Strict tuple issue interface.
#### Definition
- `StrictTupleIssue`
- `kind`
- `type`
- `expected`
### StrictTupleSchema
Strict tuple schema interface.
#### Generics
- `TItems`
- `TMessage`
#### Definition
- `StrictTupleSchema`
- `type`
- `reference`
- `expects`
- `items`
- `message`
### StrictTupleSchemaAsync
Strict tuple schema async interface.
#### Generics
- `TItems`
- `TMessage`
#### Definition
- `StrictTupleSchemaAsync`
- `type`
- `reference`
- `expects`
- `items`
- `message`
### RecordIssue
Record issue interface.
#### Definition
- `RecordIssue`
- `kind`
- `type`
- `expected`
### StringSchema
String schema interface.
#### Generics
- `TMessage`
#### Definition
- `StringSchema`
- `type`
- `reference`
- `expects`
- `message`
### StringifyJsonAction
JSON stringify action interface.
#### Generics
- `TInput`
- `TConfig`
- `TMessage`
#### Definition
- `StringifyJsonAction`
- `type`
- `reference`
- `config`
- `message`
### StringifyJsonConfig
JSON stringify config interface.
#### Definition
- `StringifyJsonConfig`
- `replacer`
- `space`
### StringifyJsonIssue
JSON stringify issue interface.
#### Generics
- `TInput`
#### Definition
- `StringifyJsonIssue`
- `kind`
- `type`
- `expected`
- `received`
### SuccessDataset
Success dataset interface.
#### Generics
- `TValue`
#### Definition
- `TypedDataset`
- `typed`
- `value`
- `issues`
### SymbolIssue
Symbol issue interface.
#### Definition
- `SymbolIssue`
- `kind`
- `type`
- `expected`
### SymbolSchema
Symbol schema interface.
#### Generics
- `TMessage`
#### Definition
- `SymbolSchema`
- `type`
- `reference`
- `expects`
- `message`
### TitleAction
Title action interface.
#### Generics
- `TInput`
- `TTitle`
#### Definition
- `TitleAction`
- `type`
- `reference`
- `title`
### ToLowerCaseAction
To lower case action interface.
#### Definition
- `ToLowerCaseAction`
- `type`
- `reference`
### ToMinValueAction
To min value action interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `ToMinValueAction`
- `type`
- `reference`
- `requirement`
### ToMaxValueAction
To max value action interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `ToMaxValueAction`
- `type`
- `reference`
- `requirement`
### ToUpperCaseAction
To upper case action interface.
#### Definition
- `ToUpperCaseAction`
- `type`
- `reference`
### TransformAction
Transform action interface.
#### Generics
- `TInput`
- `TOutput`
#### Definition
- `TransformAction`
- `type`
- `reference`
- `operation`
### TransformActionAsync
Transform action async interface.
#### Generics
- `TInput`
- `TOutput`
#### Definition
- `TransformActionAsync`
- `type`
- `reference`
- `operation`
### TrimAction
Trim action interface.
#### Definition
- `TrimAction`
- `type`
- `reference`
### TrimEndAction
Trim end action interface.
#### Definition
- `TrimEndAction`
- `type`
- `reference`
### TrimStartAction
Trim start action interface.
#### Definition
- `TrimStartAction`
- `type`
- `reference`
### TupleIssue
Tuple issue interface.
#### Definition
- `TupleIssue`
- `kind`
- `type`
- `expected`
### TupleItems
Tuple items type.
#### Definition
- `TupleItems`
### TupleItemsAsync
Tuple items async type.
#### Definition
- `TupleItemsAsync`
### TupleSchema
Tuple schema interface.
#### Generics
- `TItems`
- `TMessage`
#### Definition
- `TupleSchema`
- `type`
- `reference`
- `expects`
- `items`
- `message`
### TupleSchemaAsync
Tuple schema async interface.
#### Generics
- `TItems`
- `TMessage`
#### Definition
- `TupleSchemaAsync`
- `type`
- `reference`
- `expects`
- `items`
- `message`
### TupleWithRestIssue
Tuple with rest issue interface.
#### Definition
- `TupleWithRestIssue`
- `kind`
- `type`
- `expected`
### TupleWithRestSchema
Tuple with rest schema interface.
#### Generics
- `TItems`
- `TRest`
- `TMessage`
#### Definition
- `TupleWithRestSchema`
- `type`
- `reference`
- `expects`
- `items`
- `rest`
- `message`
### TupleWithRestSchemaAsync
Tuple with rest schema async interface.
#### Generics
- `TItems`
- `TRest`
- `TMessage`
#### Definition
- `TupleWithRestSchemaAsync`
- `type`
- `reference`
- `expects`
- `items`
- `rest`
- `message`
### UlidAction
ULID action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `UlidAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### UlidIssue
ULID issue interface.
#### Generics
- `TInput`
#### Definition
- `UlidIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### UndefinedableSchema
Undefinedable schema interface.
#### Generics
- `TWrapped`
- `TDefault`
#### Definition
- `UndefinedableSchema`
- `type`
- `reference`
- `expects`
- `wrapped`
- `default`
### UndefinedableSchemaAsync
Undefinedable schema async interface.
#### Generics
- `TWrapped`
- `TDefault`
#### Definition
- `UndefinedableSchemaAsync`
- `type`
- `reference`
- `expects`
- `wrapped`
- `default`
### UndefinedIssue
Undefined issue interface.
#### Definition
- `UndefinedIssue`
- `kind`
- `type`
- `expected`
### UndefinedSchema
Undefined schema interface.
#### Generics
- `TMessage`
#### Definition
- `UndefinedSchema`
- `type`
- `reference`
- `expects`
- `message`
### UnionOptions
Union options type.
#### Definition
- `UnionOptions`
### UnionOptionsAsync
Union options async type.
#### Definition
- `UnionOptionsAsync`
### UnionIssue
Union issue interface.
#### Generics
- `TSubIssue`
#### Definition
- `UnionIssue`
- `kind`
- `type`
- `expected`
- `issues`
### UnionSchema
Union schema interface.
#### Generics
- `TOptions`
- `TMessage`
#### Definition
- `UnionSchema`
- `type`
- `reference`
- `options`
- `message`
### UnionSchemaAsync
Union schema async interface.
#### Generics
- `TOptions`
- `TMessage`
#### Definition
- `UnionSchemaAsync`
- `type`
- `reference`
- `options`
- `message`
### UnknownDataset
Unknown dataset interface.
#### Definition
- `TypedDataset`
- `typed`
- `value`
- `issues`
### UnknownPathItem
Unknown path item interface.
#### Definition
- `UnknownPathItem`
- `type`
- `origin`
- `input`
- `key`
- `value`
The `input` of a path item may differ from the `input` of its issue. This is because path items are subsequently added by parent schemas and are related to their input. Transformations of child schemas are not taken into account.
### UnknownSchema
Unknown schema interface.
#### Definition
- `UnknownSchema`
- `type`
- `reference`
- `expects`
### UrlAction
URL action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `UrlAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### UrlIssue
URL issue interface.
#### Generics
- `TInput`
#### Definition
- `UrlIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### UuidAction
UUID action interface.
#### Generics
- `TInput`
- `TMessage`
#### Definition
- `UuidAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### UuidIssue
UUID issue interface.
#### Generics
- `TInput`
#### Definition
- `UuidIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`
### ValueAction
Value action interface.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `ValueAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### ValuesAction
Values action type.
#### Generics
- `TInput`
- `TRequirement`
- `TMessage`
#### Definition
- `ValuesAction`
- `type`
- `reference`
- `expects`
- `requirement`
- `message`
### ValueInput
Value input type.
#### Definition
- `ValueInput`
### ValueIssue
Value issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `ValueIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### ValuesIssue
Values issue type.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `ValuesIssue`
- `kind`
- `type`
- `expected`
- `requirement`
### VariantIssue
Variant issue interface.
#### Definition
- `VariantIssue`
- `kind`
- `type`
- `expected`
### VariantOptions
Variant options type.
#### Generics
- `TKey`
#### Definition
- `VariantOptions`
### VariantOptionsAsync
Variant options async type.
#### Generics
- `TKey`
#### Definition
- `VariantOptionsAsync`
### VariantSchema
Variant schema interface.
#### Generics
- `TKey`
- `TOptions`
- `TMessage`
#### Definition
- `VariantSchema`
- `type`
- `reference`
- `expects`
- `key`
- `options`
- `message`
### VariantSchemaAsync
Variant schema async interface.
#### Generics
- `TKey`
- `TOptions`
- `TMessage`
#### Definition
- `VariantSchemaAsync`
- `type`
- `reference`
- `expects`
- `key`
- `options`
- `message`
### VoidIssue
Void issue interface.
#### Definition
- `VoidIssue`
- `kind`
- `type`
- `expected`
### VoidSchema
Void schema interface.
#### Generics
- `TMessage`
#### Definition
- `VoidSchema`
- `type`
- `reference`
- `expects`
- `message`
### WordsAction
Words action interface.
#### Generics
- `TInput`
- `TLocales`
- `TRequirement`
- `TMessage`
#### Definition
- `WordsAction`
- `type`
- `reference`
- `expects`
- `locales`
- `requirement`
- `message`
### WordsIssue
Words issue interface.
#### Generics
- `TInput`
- `TRequirement`
#### Definition
- `WordsIssue`
- `kind`
- `type`
- `expected`
- `received`
- `requirement`