# Valibot > The modular and type safe schema library for validating structural data. ## Get started (guides) ### Introduction Valibot is a modular and type-safe schema library that helps you validate data easily. No matter if it is incoming data on a server, a form or even configuration files. Valibot has no dependencies and can run in any JavaScript environment. > We highly recommend you read the [announcement post](https://www.builder.io/blog/introducing-valibot), and if you are a nerd, the [bachelor's thesis](/thesis.pdf) that Valibot is based on. #### Highlights - Fully type safe with static type inference - Small bundle size starting at less than 700 bytes - Validate everything from strings to complex objects - Open source and fully tested with 100 % coverage - Many transformation and validation actions included - Well structured source code without dependencies - Minimal, readable and well thought out API #### Example First you create a schema that describes a structured data set. A schema can be compared to a type definition in TypeScript. The big difference is that TypeScript types are "not executed" and are more or less a DX feature. A schema on the other hand, apart from the inferred type definition, can also be executed at runtime to guarantee type safety of unknown data. ```ts import * as v from 'valibot'; // 1.31 kB // Create login schema with email and password const LoginSchema = v.object({ email: v.pipe(v.string(), v.email()), password: v.pipe(v.string(), v.minLength(8)), }); // Infer output TypeScript type of login schema as // { email: string; password: string } type LoginData = v.InferOutput; // Throws error for email and password const output1 = v.parse(LoginSchema, { email: '', password: '' }); // Returns data as { email: string; password: string } const output2 = v.parse(LoginSchema, { email: 'jane@example.com', password: '12345678', }); ``` Apart from [`parse`](/api/parse.md), Valibot also offers a non-exception-based API with [`safeParse`](/api/safeParse.md) and a type guard function with [`is`](/api/is.md). You can read more about it [here](/guides/parse-data.md). #### Comparison Instead of relying on a few large functions with many methods, Valibot's API design and source code is based on many small and independent functions, each with just a single task. This modular design has several advantages. For example, this allows a bundler to use the import statements to remove code that is not needed. This way, only the code that is actually used gets into your production build. This can reduce the bundle size by up to 95 % compared to [Zod](https://zod.dev/). In addition, it allows you to easily extend Valibot's functionality with external code and makes the source code more robust and secure because the functionality of the individual functions can be tested much more easily through unit tests. > Coming from [Zod](https://zod.dev/)? Read our [migration article](/blog/why-migrate-to-valibot.md) to see the benefits of Valibot, and use our [migration guide](/guides/migrate-from-zod.md) to migrate your schemas with confidence. #### Credits Valibot was created by [Fabian Hiller](https://github.com/fabian-hiller) as part of his bachelor thesis at [Stuttgart Media University](https://www.hdm-stuttgart.de/en/), supervised by Walter Kriha, [Miško Hevery](https://github.com/mhevery) and [Ryan Carniato](https://github.com/ryansolid). The library's design was also influenced by [Colin McDonnell](https://github.com/colinhacks), whose work on [Zod](https://zod.dev/) had a big impact on Valibot's API design. #### Feedback Find a bug or have an idea how to improve the code? Please fill out an [issue](https://github.com/open-circle/valibot/issues/new). Together we can make the library even better! #### License Valibot is completely free and licensed under the [MIT license](https://github.com/open-circle/valibot/blob/main/LICENSE.md). But if you like, you can support the project with a star on [GitHub](https://github.com/open-circle/valibot). ### Installation Valibot is currently available for Node, Bun and Deno. Below you will learn how to add the library to your project. #### General Except for this guide, the rest of this documentation assumes that you are using npm for the import statements in the code examples. It does not make a difference whether you use individual imports or a wildcard import. Tree shaking and code splitting should work in both cases. Valibot's distributed files target **ES2020**. Make sure your bundler or transpiler supports ES2020 syntax. If you are using TypeScript, we recommend that you enable strict mode in your `tsconfig.json` so that all types are calculated correctly. > The minimum required TypeScript version is v5.0.2. ```json { "compilerOptions": { "strict": true // ... } } ``` #### For AI Agents We provide an agent skill that teaches AI agents the correct patterns for generating Valibot schemas. You can install it by running the following command in your terminal: ```bash npx skills add open-circle/agent-skills --skill valibot ``` You can learn more about the Valibot agent skill [here](https://github.com/open-circle/agent-skills). #### From npm For Node and Bun, you can add the library to your project with a single command using your favorite package manager. ```bash npm install valibot # npm yarn add valibot # yarn pnpm add valibot # pnpm bun add valibot # bun ``` Then you can import it into any JavaScript or TypeScript file. ```ts // With individual imports import { … } from 'valibot'; // With a wildcard import import * as v from 'valibot'; ``` #### From JSR For Node, Deno and Bun, you can add the library to your project with a single command using your favorite package manager. ```bash deno add jsr:@valibot/valibot # deno npx jsr add @valibot/valibot # npm yarn dlx jsr add @valibot/valibot # yarn pnpm dlx jsr add @valibot/valibot # pnpm bunx jsr add @valibot/valibot # bun ``` Then you can import it into any JavaScript or TypeScript file. ```ts // With individual imports import { … } from '@valibot/valibot'; // With a wildcard import import * as v from '@valibot/valibot'; ``` In Deno, you can also directly reference me using `jsr:` specifiers. ```ts // With individual imports import { … } from 'jsr:@valibot/valibot'; // With a wildcard import import * as v from 'jsr:@valibot/valibot'; ``` #### From Deno With Deno, you can reference the library directly through our deno.land/x URL. ```ts // With individual imports import { … } from 'https://deno.land/x/valibot/mod.ts'; // With a wildcard import import * as v from 'https://deno.land/x/valibot/mod.ts'; ``` ### Coding agents If you are using AI to generate Valibot schemas, our documentation provides several resources to help coding agents better understand the library. This page gives an overview of the available resources and how to use them. #### Agent skill Our [`SKILL.md`](https://github.com/open-circle/agent-skills/blob/main/skills/valibot/SKILL.md) contains specialized instructions for AI agents to write, migrate, and optimize Valibot schemas according to the latest best practices. You can install it by running the following command in your terminal. ```bash npx skills add open-circle/agent-skills --skill valibot ``` The skill is also published at [`/.well-known/agent-skills/valibot/SKILL.md`](/.well-known/agent-skills/valibot/SKILL.md) and discoverable via [`/.well-known/agent-skills/index.json`](/.well-known/agent-skills/index.json). #### MCP server Our MCP server (Model Context Protocol) provides tools to search and read this documentation. Instead of crawling the website, coding agents can look up the right schema, method, or action in a single tool call. The server is available at `https://valibot.dev/mcp` and provides the following tools. - `search_docs` searches the guides, API reference and blog posts and returns the most relevant pages - `get_doc` reads a documentation page or blog post and returns its full content as Markdown - `list_docs` lists all documentation pages and blog posts grouped by area and category The server is free to use, requires no authentication, and its metadata is published at [`/.well-known/mcp/server-card.json`](/.well-known/mcp/server-card.json). To add it to Claude Code, run the following command. ```bash claude mcp add --transport http valibot https://valibot.dev/mcp ``` For Cursor and other tools that use a JSON configuration file, add the following entry. ```json { "mcpServers": { "valibot": { "url": "https://valibot.dev/mcp" } } } ``` #### LLMs.txt An [LLMs.txt](https://llmstxt.org/) file is a plain text file that provides instructions or metadata for large language models (LLMs). It often specifies how the LLMs should process or interact with content. It is similar to a robots.txt file, but is tailored for AI models. We provide several LLMs.txt routes. Use the route that works best with your AI tool. - [`llms.txt`](/llms.txt) contains a table of contents with links to Markdown files - [`llms-full.txt`](/llms-full.txt) contains the Markdown content of the entire docs - [`llms-guides.txt`](/llms-guides.txt) contains the Markdown content of the guides - [`llms-api.txt`](/llms-api.txt) contains the Markdown content of the API reference - [`llms-blog.txt`](/llms-blog.txt) contains the Markdown content of the blog posts #### Markdown for agents We provide a Markdown version of every documentation page and blog post. You can access it by replacing the trailing slash (`/`) in the URL with `.md`. For example, `/guides/installation/` becomes `/guides/installation.md`. Alternatively, our server supports content negotiation. If a request to a documentation page contains the `Accept: text/markdown` header, the server responds with the Markdown version of the page instead of HTML. ### Quick start A Valibot schema can be compared to a type definition in TypeScript. The big difference is that TypeScript types are "not executed" and are more or less a DX feature. A schema on the other hand, apart from the inferred type definition, can also be executed at runtime to truly guarantee type safety of unknown data. #### Basic concept Similar to how types can be defined in TypeScript, Valibot allows you to define a schema with various small functions. This applies to primitive values like strings as well as more complex data sets like objects. ```ts import * as v from 'valibot'; // TypeScript type LoginData = { email: string; password: string; }; // Valibot const LoginSchema = v.object({ email: v.string(), password: v.string(), }); ``` #### Pipelines In addition, pipelines enable you to perform more detailed validations and transformations with the [`pipe`](/api/pipe.md) method. Thus, for example, it can be ensured that a string is an email that ends with a certain domain. ```ts import * as v from 'valibot'; const EmailSchema = v.pipe(v.string(), v.email(), v.endsWith('@example.com')); ``` A pipeline must always start with a schema, followed by up to 19 validation or transformation actions. They are executed in sequence, and the result of the previous action is passed to the next. More details about pipelines can be found in [this guide](/guides/pipelines.md). #### Error messages If an issue is detected during validation, the library emits a specific issue object that includes various details and an error message. This error message can be overridden via the first optional argument of a schema or validation action. ```ts import * as v from 'valibot'; const LoginSchema = v.object({ email: v.pipe( v.string('Your email must be a string.'), v.nonEmpty('Please enter your email.'), v.email('The email address is badly formatted.') ), password: v.pipe( v.string('Your password must be a string.'), v.nonEmpty('Please enter your password.'), v.minLength(8, 'Your password must have 8 characters or more.') ), }); ``` Custom error messages allow you to improve the usability of your software by providing specific troubleshooting information and returning error messages in a language other than English. See the [i18n guide](/guides/internationalization.md) for more information. #### Usage Finally, you can use your schema to infer its input and output types and to parse unknown data. This way, your schema is the single source of truth. This concept simplifies your development process and makes your code more robust in the long run. ```ts import * as v from 'valibot'; const LoginSchema = v.object({…}); type LoginData = v.InferOutput; function getLoginData(data: unknown): LoginData { return v.parse(LoginSchema, data); } ``` ### Use cases Next, we would like to point out some use cases for which Valibot is particularly well suited. We welcome [ideas](https://github.com/open-circle/valibot/issues/new) for other use cases that we may not have thought of yet. #### Server requests Since most API endpoints can be reached via the Internet, basically anyone can send a request and transmit data. It is therefore important to apply zero trust security and to check request data thoroughly before processing it further. This works particularly well with a schema, compared to if/else conditions, as even complex structures can be easily mapped. In addition, the library automatically type the parsed data according to the schema, which improves type safety and thus makes your code more secure. #### Form validation A schema can also be used for form validation. Due to Valibot's small bundle size and the possibility to individualize the error messages, the library is particularly well suited for this. Also, fullstack frameworks like Next.js, Remix, and Nuxt allow the same schema to be used for validation in the browser as well as on the server, which reduces your code to the minimum. [Formisch](https://formisch.dev/react/guides/introduction/), for example, offers validation based on a schema at form and field level. In addition, the form can be made type-safe using the schema, which also enables autocompletion during development. In combination with the right framework, a fully type-safe and progressively enhanced form can be created with few lines of code and a great experience for developers and end-users. #### Browser state The browser state, which is stored using cookies, search parameters or the local storage, can be accidentally or intentionally manipulated by the user. To ensure the functionality of an application, it can help to validate this data before processing. Valibot can be used for this, which also improves type safety. #### Config files Library authors can also make use of Valibot, for example, to match configuration files with a schema and, in the event of an error, provide clear indications of the cause and how to fix the problem. The same applies to environment variables to quickly detect configuration errors. #### Schema builder Our schemas are plain JavaScript objects with a well-defined and fully type-safe structure. This makes Valibot a great choice for defining data structures that can be further processed by third-party code. For example, it is possible to build an ORM with custom metadata actions on top of Valibot to generate database schemas. Another example is our official `toJsonSchema` function, which uses Valibot's object API to output a JSON Schema that can be used for documentation purposes or to generate structured output with LLMs. #### Data migration Valibot can also be used to migrate data from one form to another in a type-safe way. The advantage of a schema library like Valibot is that transformations can be defined for individual properties instead of for the entire dataset. This can make data migrations more readable and maintainable. In addition, the schema can be used to validate the data before the migration, which increases the reliability of the migration process. ### Comparison with Zod and others Even though Valibot's API resembles other solutions like Zod and Yup at first glance, the implementation and structure of the source code are very different. In the following, we would like to highlight the differences that can be beneficial for both you and your users. #### Modular design Instead of relying on a few large functions with many methods, Valibot's API design and source code is based on many small and independent functions, each with just a single task. This modular design has several advantages. On one hand, the functionality of Valibot can be easily extended with external code. On the other, it makes the source code more robust and secure because the functionality of the individual functions as well as special edge cases can be tested much easier through unit tests. However, perhaps the biggest advantage is that a bundler can use the static import statements to remove any code that is not needed. Thus, only the code that is actually used ends up in the production build. This allows us to extend the functionality of the library with additional functions without increasing the bundle size for all users. This can make a big difference, especially for client-side validation, as it reduces the bundle size and, depending on the framework, speeds up the startup time. ```ts import * as v from 'valibot'; // 1.37 kB const LoginSchema = v.object({ email: v.pipe( v.string(), v.nonEmpty('Please enter your email.'), v.email('The email address is badly formatted.') ), password: v.pipe( v.string(), v.nonEmpty('Please enter your password.'), v.minLength(8, 'Your password must have 8 characters or more.') ), }); ``` ##### Comparison with Zod For example, to validate a simple login form, [Zod](https://zod.dev/) requires [17.7 kB with esbuild](https://bundlejs.com/?q=zod&treeshake=%5B%7B+object%2Cstring+%7D%5D) and 15.18 kB with Rolldown, whereas Valibot requires only [1.37 kB](https://bundlejs.com/?q=valibot&treeshake=%5B%7B+email%2CminLength%2CnonEmpty%2Cobject%2Cstring%2Cpipe+%7D%5D). That's a 90 % reduction in bundle size. This is due to the fact that Zod's functions have several methods with additional functionalities, that cannot be easily removed by current bundlers when they are not executed in your source code. ```ts // 17.7 kB with esbuild and 15.18 kB with Rolldown import * as z from 'zod'; const LoginSchema = z.object({ email: z.string() .min(1, 'Please enter your email.') .email('The email address is badly formatted.'), password: z.string() .min(1, 'Please enter your password.') .min(8, 'Your password must have 8 characters or more.'), }); ``` Zod v4 also introduces Zod Mini, a tree-shakable, functional variant aimed at reducing bundle size. For the same login form, Zod Mini requires approximately [6.88 kB with esbuild](https://bundlejs.com/?q=zod%2Fmini&treeshake=%5B%7B+check%2Cemail%2CminLength%2Cobject%2Cstring+%7D%5D) and 3.94 kB with Rolldown, still about 3 to 5x larger than Valibot's [1.37 kB](https://bundlejs.com/?q=valibot&treeshake=%5B%7B+email%2CminLength%2CnonEmpty%2Cobject%2Cstring%2Cpipe+%7D%5D), representing a ~73 % reduction when using Valibot over Zod Mini. ```ts // 6.88 kB with esbuild and 3.94 kB with Rolldown import * as z from 'zod/mini'; const LoginSchema = z.object({ email: z.check( z.string(), z.minLength(1, 'Please enter your email.'), z.email('The email address is badly formatted.') ), password: z.check( z.string(), z.minLength(1, 'Please enter your password.'), z.minLength(8, 'Your password must have 8 characters or more.') ), }); ``` > Coming from [Zod](https://zod.dev/)? Read our [migration article](/blog/why-migrate-to-valibot.md) to see the benefits of Valibot, and use our [migration guide](/guides/migrate-from-zod.md) to migrate your schemas with confidence. #### Performance With a schema library, a distinction must be made between startup performance and runtime performance. Startup performance describes the time required to load and initialize the library. This benchmark is mainly influenced by the bundle size and the amount of work required to create a schema. Runtime performance describes the time required to validate unknown data using a schema. Since Valibot's implementation is optimized to minimize the bundle size and the effort of initialization, there is hardly any library that performs better in a [TTI](https://web.dev/articles/tti) benchmark. In terms of runtime performance, Valibot is in the midfield. Roughly speaking, the library is about twice as fast as [Zod](https://zod.dev/) v3, and has similar runtime performance to Zod v4 (including Zod Mini), but is much slower than [Typia](https://typia.io/) and [TypeBox](https://github.com/sinclairzx81/typebox), because we don't yet use a compiler that can generate highly optimized runtime code, and our implementation doesn't allow the use of the [`Function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Function) constructor. > Further details on performance can be found in the [bachelor's thesis](/thesis.pdf) Valibot is based on. ### Ecosystem This page is for you if you are looking for frameworks or libraries that support Valibot. > Use the button at the bottom left of this page to add your project to this ecosystem page. Please make sure to add your project to an appropriate existing category in alphabetical order or create a new category if necessary. #### Frameworks - [Better Auth](https://www.better-auth.com/): The most comprehensive authentication framework for TypeScript - [Elysia](https://elysiajs.com/): Ergonomic framework for humans with end-to-end type safety - [EviKit](https://codeberg.org/nykula/evikit): Preact SSR framework using Valibot to let you define node:sqlite ORM schemas and validate OpenAPI (Swagger) inputs and outputs - [NestJS](https://docs.nestjs.com): A progressive Node.js framework for building efficient, reliable and scalable server-side applications - [Qwik](https://qwik.dev): A web framework which helps you build instantly-interactive web apps at any scale without effort. #### API libraries - [Drizzle ORM](https://orm.drizzle.team/): TypeScript ORM that feels like writing SQL - [GQLoom](https://gqloom.dev/): Weave GraphQL schema and resolvers using Valibot - [Hono](https://hono.dev/): Ultrafast web framework for the Edges - [next-safe-action](https://next-safe-action.dev) Type safe and validated Server Actions for Next.js - [oRPC](https://orpc.unnoq.com/): Typesafe APIs Made Simple - [piying-orm](https://github.com/piying-org/piying-orm): ORM for Valibot; Supports TypeORM, with more to come. - [tRPC](https://trpc.io/): Move Fast and Break Nothing. End-to-end typesafe APIs made easy - [upfetch](https://github.com/L-Blondy/up-fetch): Advanced fetch client builder - [valifetch](https://github.com/haihv/valifetch): Type-safe HTTP client with Valibot schema validation #### AI libraries - [AI SDK](https://sdk.vercel.ai/): Build AI-powered applications with React, Svelte, Vue, and Solid - [Flue](https://flueframework.com/): Open agent framework that uses Valibot for tool inputs and structured output - [LangChain](https://js.langchain.com/): Framework for developing applications powered by large language models - [Mastra](https://mastra.ai/): TypeScript agent framework to build AI applications and features - [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk): The official TypeScript SDK for the Model Context Protocol #### Form libraries - [@rvf/valibot](https://github.com/airjp73/rvf/tree/main/packages/valibot): Valibot schema parser for [RVF](https://rvf-js.io/) - [conform](https://conform.guide/): A type-safe form validation library utilizing web fundamentals to progressively enhance HTML Forms with full support for server frameworks like Remix and Next.js. - [Formisch](https://formisch.dev/): The headless, modular and type-safe form library for any framework - [mantine-form-valibot-resolver](https://github.com/Songkeys/mantine-form-valibot-resolver): Valibot schema resolver for [@mantine/form](https://mantine.dev/form/use-form/) - [maz-ui](https://maz-ui.com/composables/use-form-validator): Vue3 flexible and typed composable to manage forms simply with multiple modes and advanced features - [piying-view](https://github.com/piying-org/piying-view): Frontend Form Solution; Supports Angular, Vue, React, Solid, Svelte. - [React Hook Form](https://react-hook-form.com/): React Hooks for form state management and validation - [regle](https://github.com/victorgarciaesgi/regle): Headless form validation library for Vue.js - [Superforms](https://superforms.rocks): A comprehensive SvelteKit form library for server and client validation - [svelte-jsonschema-form](https://x0k.dev/svelte-jsonschema-form/validators/valibot/): Svelte 5 library for creating forms based on JSON schema - [TanStack Form](https://tanstack.com/form): Powerful and type-safe form state management for the web - [VeeValidate](https://vee-validate.logaretm.com/v4/): Painless Vue.js forms - [vue-valibot-form](https://github.com/IlyaSemenov/vue-valibot-form): Minimalistic Vue3 composable for handling form submit #### Component libraries - [Nuxt UI](https://ui.nuxt.com/): Fully styled and customizable components for Nuxt #### Valibot to X - [@gcornut/cli-valibot-to-json-schema](https://github.com/gcornut/cli-valibot-to-json-schema): CLI wrapper for @valibot/to-json-schema - [@valibot/to-json-schema](https://github.com/open-circle/valibot/tree/main/packages/to-json-schema): The official JSON schema converter for Valibot - [Hono OpenAPI](https://github.com/rhinobase/hono-openapi): A plugin for Hono to generate OpenAPI Swagger documentation - [TypeMap](https://github.com/sinclairzx81/typemap/): Uniform Syntax, Mapping and Compiler Library for TypeBox, Valibot and Zod - [TypeSchema](https://typeschema.com/): Universal adapter for schema validation - [Valibot-Fast-Check](https://github.com/Eronmmer/valibot-fast-check): A library to generate [fast-check](https://fast-check.dev) arbitraries from Valibot schemas for property-based testing - [valibot-serialize](https://github.com/gadicc/valibot-serialize): Serialize a schema to JSON and back again, or to (tree-shaking safe) static code - [vscode-toolkit](https://github.com/wszgrcy/vscode-toolkit): Convert Valibot schemas to VSCode configuration formats with responsive read/write capabilities #### X to Valibot - [@hey-api/openapi-ts](https://heyapi.dev/openapi-ts/plugins/valibot): OpenAPI to TypeScript codegen. Production-ready SDKs, Zod schemas, TanStack Query hooks, and 20+ plugins. Used by Vercel, OpenCode, and PayPal. - [@traversable/valibot](https://github.com/traversable/schema/tree/main/packages/valibot): Build your own "Valibot to X" library, or pick one of 10+ off-the-shelf transformers - [DRZL](https://github.com/use-drzl/drzl): Analyze Drizzle ORM schema(s) and auto-generate Valibot validators, typed services, and strongly typed routers (oRPC/tRPC/etc) via a modular pipeline. - [graphql-codegen-typescript-validation-schema](https://github.com/Code-Hex/graphql-codegen-typescript-validation-schema): GraphQL Code Generator plugin to generate form validation schema from your GraphQL schema. - [Prisma Valibot Generator](https://github.com/omar-dulaimi/prisma-valibot-generator): Generate Valibot validators from your Prisma schema so types and runtime stay in sync. - [TypeBox-Codegen](https://sinclairzx81.github.io/typebox-workbench/): Code generation for schema libraries - [TypeMap](https://github.com/sinclairzx81/typemap/): Uniform Syntax, Mapping and Compiler Library for TypeBox, Valibot and Zod - [valibot-serialize](https://github.com/gadicc/valibot-serialize): From serialized JSON back to a schema instance or the (tree-shaking safe) code to create that instance #### Utilities - [@camflan/valibot-openapi-generator](https://github.com/camflan/valibot-openapi-generator): Functions to help build OpenAPI documentation using Valibot schemas - [@nest-lab/typeschema](https://github.com/jmcdo29/nest-lab/tree/main/packages/typeschema): A ValidationPipe that handles many schema validators in a class-based fashion for NestJS's input validation - [@traversable/valibot-test](https://github.com/traversable/schema/tree/main/packages/valibot-test): Random Valibot schema generator built for fuzz testing, includes generators for both valid and invalid data - [@valibot/i18n](https://github.com/open-circle/valibot/tree/main/packages/i18n): The official i18n translations for Valibot - [ArkEnv](https://github.com/yamcodes/arkenv): Environment variable validation from editor to runtime, for Next.js, Nuxt, Node.js, Vite, Bun, and more - [fastify-type-provider-valibot](https://github.com/qlaffont/fastify-type-provider-valibot): Fastify Type Provider with Valibot - [shorn](https://shorn.dev): Compact binary serialization that uses your Valibot schema as the wire format, with no IDL or code generation - [valibot-env](https://y-hiraoka.github.io/valibot-env): Environment variables validator with Valibot - [valibotx](https://github.com/IlyaSemenov/valibotx): A collection of extensions and shortcuts to core Valibot functions - [valiload](https://github.com/JuerGenie/valiload): A simple and lightweight library for overloading functions in TypeScript - [valimock](https://github.com/saeris/valimock): Generate mock data using your Valibot schemas using [Faker](https://github.com/faker-js/faker) - [valipass](https://github.com/Saeris/valipass): Collection of password validation actions for Valibot schemas ## Main concepts (guides) ### Mental model Valibot's mental model is mainly divided between **schemas**, **methods**, and **actions**. Since each functionality is imported as its own function, it is crucial to understand this concept as it makes working with the modular API design much easier. > The [API reference](/api/) gives you a great overview of all schemas, methods, and actions. For each one, the corresponding reference page also lists down other related schemas, methods, and actions for better discoverability. #### Schemas Schemas are the starting point for using Valibot. They allow you to validate **a specific data type**, like a string, object, or date. Each schema is independent. They can be reused or even nested to reflect more complex data structures. ```ts import * as v from 'valibot'; const BookSchema = v.object({ title: v.string(), numberOfPages: v.number(), publication: v.date(), tags: v.array(v.string()), }); ``` Every schema function returns an accessible object that contains all its properties. However, in most cases you don't need to access them directly. Instead, you use methods that help you modify or use a schema. #### Methods Methods help you either **modify or use a schema**. For example, the [`parse`](/api/parse.md) method helps you parse unknown data based on a schema. When you use a method, you always pass the schema as the first argument. ```ts import * as v from 'valibot'; const BookSchema = v.object({…}); function createBook(data: unknown) { return v.parse(BookSchema, data); } ``` > Most methods are used with schemas. However, there are a few exceptions, such as [`forward`](/api/forward.md) and [`flatten`](/api/flatten.md), which are used with actions or issues. #### Actions Actions help you to **further validate, transform, or annotate** a specific data type. They are used exclusively in conjunction with the [`pipe`](/api/pipe.md) method, which extends the functionality of a schema by adding additional validation, transformation, and metadata rules. For example, the following schema can be used to trim a string and check if it is a valid email address. ```ts import * as v from 'valibot'; const EmailSchema = v.pipe(v.string(), v.trim(), v.email()); ``` Actions are very powerful. There are basically no limits to what you can do with them. Besides validations and transformations, pipelines can also carry metadata with actions like [`title`](/api/title.md), [`description`](/api/description.md), [`examples`](/api/examples.md), and [`metadata`](/api/metadata.md). This can be useful for documentation, AI tools, and other integrations. Actions can also modify the output type with transformations like [`readonly`](/api/readonly.md) and [`brand`](/api/brand.md). ### Schemas Schemas allow you to validate a specific data type. They are similar to type definitions in TypeScript. Besides primitive values like strings and complex values like objects, Valibot also supports special cases like literals, unions and custom types. #### Primitive values Valibot supports the creation of schemas for any primitive data type. These are immutable values that are stored directly in the stack, unlike objects where only a reference to the heap is stored. Primitive schemas: [`bigint`](/api/bigint.md), [`boolean`](/api/boolean.md), [`null`](/api/null.md), [`number`](/api/number.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`undefined`](/api/undefined.md) ```ts import * as v from 'valibot'; const BigintSchema = v.bigint(); // bigint const BooleanSchema = v.boolean(); // boolean const NullSchema = v.null(); // null const NumberSchema = v.number(); // number const StringSchema = v.string(); // string const SymbolSchema = v.symbol(); // symbol const UndefinedSchema = v.undefined(); // undefined ``` #### Complex values Among complex values, Valibot supports objects, records, arrays, tuples, and several other classes. > There are various methods for objects such as [`pick`](/api/pick.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md) and [`required`](/api/required.md). Learn more about them [here](/guides/methods.md#object-methods). Complex schemas: [`array`](/api/array.md), [`blob`](/api/blob.md), [`date`](/api/date.md), [`file`](/api/file.md), [`function`](/api/function.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md) ```ts import * as v from 'valibot'; const ArraySchema = v.array(v.string()); // string[] const BlobSchema = v.blob(); // Blob const DateSchema = v.date(); // Date const FileSchema = v.file(); // File const FunctionSchema = v.function(); // (...args: unknown[]) => unknown const LooseObjectSchema = v.looseObject({ key: v.string() }); // { key: string } const LooseTupleSchema = v.looseTuple([v.string(), v.number()]); // [string, number] const MapSchema = v.map(v.string(), v.number()); // Map const ObjectSchema = v.object({ key: v.string() }); // { key: string } const ObjectWithRestSchema = v.objectWithRest({ key: v.string() }, v.null()); // { key: string } & { [key: string]: null } const PromiseSchema = v.promise(); // Promise const RecordSchema = v.record(v.string(), v.number()); // Record const SetSchema = v.set(v.number()); // Set const StrictObjectSchema = v.strictObject({ key: v.string() }); // { key: string } const StrictTupleSchema = v.strictTuple([v.string(), v.number()]); // [string, number] const TupleSchema = v.tuple([v.string(), v.number()]); // [string, number] const TupleWithRestSchema = v.tupleWithRest([v.string(), v.number()], v.null()); // [string, number, ...null[]] ``` #### Special cases Beyond primitive and complex values, there are also schema functions for more special cases. Special schemas: [`any`](/api/any.md), [`custom`](/api/custom.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ```ts import * as v from 'valibot'; const AnySchema = v.any(); // any const CustomSchema = v.custom<`${number}px`>(isPixelString); // `${number}px` const EnumSchema = v.enum(Direction); // Direction const ExactOptionalSchema = v.exactOptional(v.string()); // string const InstanceSchema = v.instance(Error); // Error const LazySchema = v.lazy(() => v.string()); // string const IntersectSchema = v.intersect([v.string(), v.literal('a')]); // string & 'a' const LiteralSchema = v.literal('foo'); // 'foo' const NanSchema = v.nan(); // NaN const NeverSchema = v.never(); // never const NonNullableSchema = v.nonNullable(v.nullable(v.string())); // string const NonNullishSchema = v.nonNullish(v.nullish(v.string())); // string const NonOptionalSchema = v.nonOptional(v.optional(v.string())); // string const NullableSchema = v.nullable(v.string()); // string | null const NullishSchema = v.nullish(v.string()); // string | null | undefined const OptionalSchema = v.optional(v.string()); // string | undefined const PicklistSchema = v.picklist(['a', 'b']); // 'a' | 'b' const UndefinedableSchema = v.undefinedable(v.string()); // string | undefined const UnionSchema = v.union([v.string(), v.number()]); // string | number const UnknownSchema = v.unknown(); // unknown const VariantSchema = v.variant('type', [ v.object({ type: v.literal('a'), foo: v.string() }), v.object({ type: v.literal('b'), bar: v.number() }), ]); // { type: 'a'; foo: string } | { type: 'b'; bar: number } const VoidSchema = v.void(); // void ``` ### Pipelines For detailed validations and transformations, a schema can be wrapped in a pipeline. Especially for schema functions like [`string`](/api/string.md), [`number`](/api/number.md), [`date`](/api/date.md), [`object`](/api/object.md), and [`array`](/api/array.md), this feature is useful for validating properties beyond the raw data type. #### How it works In simple words, a pipeline is a list of schemas and actions that synchronously passes through the input data. It must always start with a schema, followed by up to 19 schemas or actions. Each schema and action can examine and modify the input. The pipeline is therefore perfect for detailed validations and transformations. ##### Example For example, the pipeline feature can be used to trim a string and make sure that it is an email that ends with a specific domain. ```ts import * as v from 'valibot'; const EmailSchema = v.pipe( v.string(), v.trim(), v.email(), v.endsWith('@example.com') ); ``` #### Validations Pipeline validation actions examine the input and, if the input does not meet a certain condition, return an issue. If the input is valid, it is returned as the output and, if present, picked up by the next action in the pipeline. > Whenever possible, pipelines are run completely, even if an issue has occurred, to collect all possible issues. If you want to abort the pipeline early after the first issue, you need to set the `abortPipeEarly` option to `true`. Learn more about [parsing configuration](/guides/parse-data.md#configuration), or use the [`config`](/api/config.md) method for more granular control over individual pipelines. Validation actions: [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`finite`](/api/finite.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`regex`](/api/regex.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`startsWith`](/api/startsWith.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) Some of these actions can be combined with different schemas. For example, [`minValue`](/api/minValue.md) can be used to validate the minimum value of [`string`](/api/string.md), [`number`](/api/number.md), [`bigint`](/api/bigint.md), and [`date`](/api/date.md). ```ts import * as v from 'valibot'; const StringSchema = v.pipe(v.string(), v.minValue('foo')); const NumberSchema = v.pipe(v.number(), v.minValue(1234)); const BigintSchema = v.pipe(v.bigint(), v.minValue(1234n)); const DateSchema = v.pipe(v.date(), v.minValue(new Date())); ``` ##### Custom validation For custom validations, [`check`](/api/check.md) can be used. If the function passed as the first argument returns `false`, an issue is returned. Otherwise, the input is considered valid. ```ts import * as v from 'valibot'; import { isValidUsername } from '~/utils'; const UsernameSchema = v.pipe( v.string(), v.check(isValidUsername, 'This username is invalid.') ); ``` > You can forward the issues of a pipeline validation to a child. See the [methods](/guides/methods.md#forward) guide for more information. #### Transformations Pipeline transformation actions allow to change the value and data type of the input data. This can be useful for example to remove spaces at the beginning or end of a string or to force a minimum or maximum value. Transformation actions: [`brand`](/api/brand.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`mapItems`](/api/mapItems.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`sortItems`](/api/sortItems.md), [`toBigint`](/api/toBigint.md), [`toBoolean`](/api/toBoolean.md), [`toCamelCase`](/api/toCamelCase.md), [`toDate`](/api/toDate.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toNumber`](/api/toNumber.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toString`](/api/toString.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md) For example, the pipeline of the following schema enforces a minimum value of 10. If the input is less than 10, it is replaced with the specified minimum value. ```ts import * as v from 'valibot'; const NumberSchema = v.pipe(v.number(), v.toMinValue(10)); ``` ##### Custom transformation For custom transformations, [`transform`](/api/transform.md) can be used. The function passed as the first argument is called with the input data and the return value defines the output. The following transformation changes the output of the schema to `null` for any number less than 10. ```ts import * as v from 'valibot'; const NumberSchema = v.pipe( v.number(), v.transform((input) => (input < 10 ? null : input)) ); ``` #### Metadata In addition to the validation and transformation actions, a pipeline can also be used to add metadata to a schema. This can be useful when working with AI tools or for documentation purposes. Metadata actions: [`description`](/api/description.md), [`metadata`](/api/metadata.md), [`title`](/api/title.md) ```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.' ) ); ``` ### Parse data Now that you've learned how to create a schema, let's look at how you can use it to validate unknown data and make it type-safe. There are three different ways to do this. > Each schema has a `~run` method. However, this is an internal API and should only be used if you know what you are doing. #### Parse and throw The [`parse`](/api/parse.md) method will throw a [`ValiError`](/api/ValiError.md) 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 with the correct TypeScript type. ```ts import * as v from 'valibot'; 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); } ``` #### Parse and return If you want issues to be returned instead of thrown, you can use [`safeParse`](/api/safeParse.md). The returned value then contains the `.success` property, which is `true` if the input is valid or `false` otherwise. If the input is valid, you can use `.output` to get the output of the schema validation. Otherwise, if the input was invalid, the issues found can be accessed via `.issues`. ```ts import * as v from 'valibot'; 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); } ``` #### Type guards Another way to validate data that can be useful in individual cases is to use a type guard. You can use either a type predicate with the [`is`](/api/is.md) method or an assertion function with the [`assert`](/api/assert.md) method. If a type guard is used, the issues of the validation cannot be accessed. Also, transformations have no effect and unknown keys of an object are not removed. Therefore, this approach is not as safe and powerful as the two previous ways. Also, due to a TypeScript limitation, it can currently only be used with synchronous schemas. ```ts import * as v from 'valibot'; const EmailSchema = v.pipe(v.string(), v.email()); const data: unknown = 'jane@example.com'; if (v.is(EmailSchema, data)) { const email = data; // string } ``` #### Configuration By default, Valibot exhaustively collects every issue during validation to give you detailed feedback on why the input does not match the schema. If this is not required for your use case, you can control this behavior with `abortEarly` and `abortPipeEarly` to improve the performance of validation. ##### Abort validation If you set `abortEarly` to `true`, data validation immediately aborts upon finding the first issue. If you just want to know if some data matches a schema, but you don't care about the details, this can improve performance. ```ts import * as v from 'valibot'; try { const ProfileSchema = v.object({ name: v.string(), bio: v.string(), }); const profile = v.parse( ProfileSchema, { name: 'Jane', bio: '' }, { abortEarly: true } ); // Handle errors if one occurs } catch (error) { console.log(error); } ``` ##### Abort pipeline If you only set `abortPipeEarly` to `true`, the validation within a pipeline will only abort after finding the first issue. For example, if you only want to show the first error of a field when validating a form, you can use this option to improve performance. ```ts import * as v from 'valibot'; try { const EmailSchema = v.pipe(v.string(), v.email(), v.endsWith('@example.com')); const email = v.parse(EmailSchema, 'jane@example.com', { abortPipeEarly: true, }); // Handle errors if one occurs } catch (error) { console.log(error); } ``` ### Infer types Another cool feature of schemas is the ability to infer input and output types. This makes your work even easier because you don't have to write the type definition yourself. #### Infer input types The input type of a schema corresponds to the TypeScript type that the incoming data of a schema must match to be valid. To extract this type you use the utility type [`InferInput`](/api/InferInput.md). > You are probably interested in the input type only in special cases. In most cases, the output type should be sufficient. ```ts import * as v from 'valibot'; const LoginSchema = v.object({ email: v.string(), password: v.string(), }); type LoginInput = v.InferInput; // { email: string; password: string } ``` #### Infer output types The output type differs from the input type only if you use [`optional`](/api/optional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md) or [`undefinedable`](/api/undefinedable.md) with a default value or [`brand`](/api/brand.md), [`readonly`](/api/readonly.md) or [`transform`](/api/transform.md) to transform the input or data type of a schema after validation. The output type corresponds to the output of [`parse`](/api/parse.md) and [`safeParse`](/api/safeParse.md). To infer it, you use the utility type [`InferOutput`](/api/InferOutput.md). ```ts import * as v from 'valibot'; import { hashPassword } from '~/utils'; const LoginSchema = v.pipe( v.object({ email: v.string(), password: v.pipe(v.string(), v.transform(hashPassword)), }), v.transform((input) => { return { ...input, timestamp: new Date().toISOString(), }; }) ); type LoginOutput = v.InferOutput; // { email: string; password: string; timestamp: string } ``` #### Infer issue types You can also infer the possible issues of a schema. This can be useful if you want to handle the issues in a particular way. To extract this information from a schema you use the utility type [`InferIssue`](/api/InferIssue.md). ```ts import * as v from 'valibot'; const LoginSchema = v.object({ email: v.pipe(v.string(), v.email()), password: v.pipe(v.string(), v.minLength(8)), }); type Issue = v.InferIssue; // v.ObjectIssue | v.StringIssue | v.EmailIssue | v.MinLengthIssue ``` ### Methods Apart from [`parse`](/api/parse.md) and [`safeParse`](/api/safeParse.md), Valibot offers some more methods to make working with your schemas easier. In the following we distinguish between schema, object and pipeline methods. #### Schema methods Schema methods add functionality, simplify ergonomics, and help you use schemas for validation and data extraction. Schema methods: [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`flatten`](/api/flatten.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getDescription`](/api/getDescription.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`getMetadata`](/api/getMetadata.md), [`getTitle`](/api/getTitle.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`safeParse`](/api/safeParse.md), [`summarize`](/api/summarize.md), [`pipe`](/api/pipe.md), [`unwrap`](/api/unwrap.md) > For more information on [`pipe`](/api/pipe.md), see the [pipelines](/guides/pipelines.md) guide. For more information on validation methods, see the [parse data](/guides/parse-data.md) guide. For more information on [`flatten`](/api/flatten.md), see the [issues](/guides/issues.md#formatting) guide. ##### Fallback If an issue occurs while validating your schema, you can catch it with [`fallback`](/api/fallback.md) to return a predefined value instead. ```ts import * as v from 'valibot'; const StringSchema = v.fallback(v.string(), 'hello'); const stringOutput = v.parse(StringSchema, 123); // 'hello' ``` #### Object methods Object methods make it easier for you to work with object schemas. They are strongly oriented towards TypeScript's utility types. Object methods: [`keyof`](/api/keyof.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`required`](/api/required.md) ##### TypeScript similarities Like in TypeScript, you can make the values of an object optional with [`partial`](/api/partial.md), make them required with [`required`](/api/required.md), and even include/exclude certain values from an existing schema with [`pick`](/api/pick.md) and [`omit`](/api/omit.md). ```ts import * as v from 'valibot'; // TypeScript type Object1 = Partial<{ key1: string; key2: number }>; // Valibot const object1 = v.partial(v.object({ key1: v.string(), key2: v.number() })); // TypeScript type Object2 = Pick; // Valibot const object2 = v.pick(object1, ['key1']); ``` #### Pipeline methods Pipeline methods modify the results of validations and transformations within a pipeline. Pipeline methods: [`forward`](/api/forward.md) > For more info about our pipeline feature, see the [pipelines](/guides/pipelines.md) guide. ##### Forward ‎[`forward`](/api/forward.md) allows you to associate an issue with a nested schema. For example, if you want to check that both password entries in a registration form match, you can use it to forward the issue to the second password field in case of an error. This allows you to display the error message in the correct place. ```ts import * as v from 'valibot'; 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'] ) ); ``` ### Issues When validating unknown data against a schema, Valibot collects information about each issue. If there is at least one issue, these are returned in an array. Each issue provides detailed information for you or your users to fix the problem. #### Issue info A single issue conforms to the TypeScript type definition below. ```ts type BaseIssue = { // Required info kind: 'schema' | 'validation' | 'transformation'; type: string; input: unknown; expected: string | null; received: string; message: string; // Optional info requirement?: unknown; path?: IssuePath; issues?: Issues; lang?: string; abortEarly?: boolean; abortPipeEarly?: boolean; skipPipe?: boolean; }; ``` ##### Required info Each issue contains the following required information. ###### Kind `kind` describes the kind of the problem. If an input does not match the data type, for example a number was passed instead of a string, `kind` has the value `'schema'`. In all other cases, the reason is not the data type but the actual content of the data. For example, if a string is invalid because it does not match a regex, `kind` has the value `'validation'`. ###### Type `type` describes which function did the validation. If the schema function [`array`](/api/array.md) detects that the input is not an array, `type` has the value `'array'`. If the [`minLength`](/api/minLength.md) validation function detects that an array is too short, `type` has the value `'min_length'`. ###### Input `input` contains the input data where the issue was found. For complex data, for example objects, `input` contains the value of the respective key that does not match the schema. ###### Expected `expected` is a language-neutral string that describes the data property that was expected. It can be used to create useful error messages. If your users aren't developers, you can replace the language-neutral symbols with language-specific words. ###### Received `received` is a language-neutral string that describes the data property that was received. It can be used to create useful error messages. If your users aren't developers, you can replace the language-neutral symbols with language-specific words. ###### Message `message` contains a human-understandable error message that can be fully customized as described in our [quick start](/guides/quick-start.md#error-messages) and [internationalization](/guides/internationalization.md) guide. ##### Optional info Some issues contain further optional information. ###### Requirement `requirement` can contain further validation information. For example, if the [`minLength`](/api/minLength.md) validation function detects that a string is too short, `requirement` contains the minimum length that the string should have. ###### Path `path` is an array of objects that describes where an issue is located within complex data. Each path item contains the following information. > 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. ```ts type PathItem = { type: string; origin: 'key' | 'value'; input: unknown; key?: unknown; value: unknown; }; ``` For example, you can use the following code to create a dot path. ```ts import * as v from 'valibot'; const dotPath = v.getDotPath(issue); ``` ###### Issues `issues` currently only occur when using [`union`](/api/union.md) and contains all issues of the schemas of an union type. ###### Config `lang` can be used as part of our [i18n feature](/guides/internationalization.md) to define the required language. `abortEarly` and `abortPipeEarly` gives you an info that the validation was aborted prematurely. You can find more info about this in the [parse data](/guides/parse-data.md#configuration) guide. These are all configurations that you can control yourself. #### Formatting For common use cases such as form validation, Valibot includes small built-in functions for formatting issues. However, once you understand how they work, you can easily format them yourself and put them in the right form for your use case. ##### Flatten errors If you are only interested in the error messages of each issue to show them to your users, you can convert an array of issues to a flat object with [`flatten`](/api/flatten.md). Below is an example. ```ts import * as v from 'valibot'; const ObjectSchema = v.object({ foo: v.string('Value of "foo" is missing.'), bar: v.object({ baz: v.string('Value of "bar.baz" is missing.'), }), }); const result = v.safeParse(ObjectSchema, { bar: {} }); if (result.issues) { console.log(v.flatten(result.issues)); } ``` The `result` returned in the code sample above this text contains the following issues. ```ts [ { kind: 'schema', type: 'string', input: undefined, expected: 'string', received: 'undefined', message: 'Value of "foo" is missing.', path: [ { type: 'object', origin: 'value', input: { bar: {}, }, key: 'foo', value: undefined, }, ], }, { kind: 'schema', type: 'string', input: undefined, expected: 'string', received: 'undefined', message: 'Value of "bar.baz" is missing.', path: [ { type: 'object', origin: 'value', input: { bar: {}, }, key: 'bar', value: {}, }, { type: 'object', origin: 'value', input: {}, key: 'baz', value: undefined, }, ], }, ]; ``` However, with the help of [`flatten`](/api/flatten.md) the issues were converted to the following object. ```ts { nested: { foo: ['Value of "foo" is missing.'], 'bar.baz': ['Value of "bar.baz" is missing.'], }, }; ``` ## Schemas (guides) ### Objects To validate objects with a schema, you can use [`object`](/api/object.md) or [`record`](/api/record.md). You use [`object`](/api/object.md) for an object with a specific shape and [`record`](/api/record.md) for objects with any number of uniform entries. #### Object schema The first argument is used to define the specific structure of the object. Each entry consists of a key and a schema as the value. The entries of the input are then validated against these schemas. ```ts import * as v from 'valibot'; const ObjectSchema = v.object({ key1: v.string(), key2: v.number(), }); ``` ##### Loose and strict objects The [`object`](/api/object.md) schema removes unknown entries. This means that entries that you have not defined in the first argument are neither validated nor added to the output. You can change this behavior by using the [`looseObject`](/api/looseObject.md) or [`strictObject`](/api/strictObject.md) schema instead. The [`looseObject`](/api/looseObject.md) schema allows unknown entries and adds them to the output. The [`strictObject`](/api/strictObject.md) schema forbids unknown entries and returns an issue for the first unknown entry found. ##### Object with specific rest Alternatively, you can also use the [`objectWithRest`](/api/objectWithRest.md) schema to define a specific schema for unknown entries. Any entries not defined in the first argument are then validated against the schema of the second argument. ```ts import * as v from 'valibot'; const ObjectSchema = v.objectWithRest( { key1: v.string(), key2: v.number(), }, v.null() ); ``` ##### Pipeline validation To validate the value of an entry based on another entry, you can wrap you schema with the [`check`](/api/check.md) validation action in a pipeline. You can also use [`forward`](/api/forward.md) to assign the issue to a specific object key in the event of an error. > If you only want to validate specific entries, we recommend using [`partialCheck`](/api/partialCheck.md) instead as [`check`](/api/check.md) can only be executed if the input is fully typed. ```ts import * as v from 'valibot'; const CalculationSchema = v.pipe( v.object({ a: v.number(), b: v.number(), sum: v.number(), }), v.forward( v.check(({ a, b, sum }) => a + b === sum, 'The calculation is incorrect.'), ['sum'] ) ); ``` #### Record schema For an object with any number of uniform entries, [`record`](/api/record.md) is the right choice. The schema passed as the first argument validates the keys of your record, and the schema passed as the second argument validates the values. ```ts import * as v from 'valibot'; const RecordSchema = v.record(v.string(), v.number()); // Record ``` ##### Specific record keys Instead of [`string`](/api/string.md), you can also use [`custom`](/api/custom.md), [`enum`](/api/enum.md), [`literal`](/api/literal.md), [`picklist`](/api/picklist.md) or [`union`](/api/union.md) to validate the keys. ```ts import * as v from 'valibot'; const RecordSchema = v.record(v.picklist(['key1', 'key2']), v.number()); // { key1?: number; key2?: number } ``` Note that [`record`](/api/record.md) marks all literal keys as optional in this case. If you want to make them required, you can use the [`object`](/api/object.md) schema with the [`entriesFromList`](/api/entriesFromList.md) util instead. ```ts import * as v from 'valibot'; const RecordSchema = v.object(v.entriesFromList(['key1', 'key2'], v.number())); // { key1: number; key2: number } ``` ##### Pipeline validation To validate the value of an entry based on another entry, you can wrap you schema with the [`check`](/api/check.md) validation action in a pipeline. You can also use [`forward`](/api/forward.md) to assign the issue to a specific record key in the event of an error. ```ts import * as v from 'valibot'; const CalculationSchema = v.pipe( v.record(v.picklist(['a', 'b', 'sum']), v.number()), v.forward( v.check( ({ a, b, sum }) => (a || 0) + (b || 0) === (sum || 0), 'The calculation is incorrect.' ), ['sum'] ) ); ``` ### Arrays To validate arrays with a schema you can use [`array`](/api/array.md) or [`tuple`](/api/tuple.md). You use [`tuple`](/api/tuple.md) if your array has a specific shape and [`array`](/api/array.md) if it has any number of uniform items. #### Array schema The first argument you pass to [`array`](/api/array.md) is a schema, which is used to validate the items of the array. ```ts import * as v from 'valibot'; const ArraySchema = v.array(v.number()); // number[] ``` ##### Pipeline validation To validate the length or contents of the array, you can use a pipeline. ```ts import * as v from 'valibot'; const ArraySchema = v.pipe( v.array(v.string()), v.minLength(1), v.maxLength(5), v.includes('foo'), v.excludes('bar') ); ``` #### Tuple schema A [`tuple`](/api/tuple.md) is an array with a specific shape. The first argument that you pass to the function is a tuple of schemas that defines its shape. ```ts import * as v from 'valibot'; const TupleSchema = v.tuple([v.string(), v.number()]); // [string, number] ``` ##### Loose and strict tuples The [`tuple`](/api/tuple.md) schema removes unknown items. This means that items that you have not defined in the first argument are not validated and added to the output. You can change this behavior by using the [`looseTuple`](/api/looseTuple.md) or [`strictTuple`](/api/strictTuple.md) schema instead. The [`looseTuple`](/api/looseTuple.md) schema allows unknown items and adds them to the output. The [`strictTuple`](/api/strictTuple.md) schema forbids unknown items and returns an issue for the first unknown item found. ##### Tuple with specific rest Alternatively, you can also use the [`tupleWithRest`](/api/tupleWithRest.md) schema to define a specific schema for unknown items. Any items not defined in the first argument are then validated against the schema of the second argument. ```ts import * as v from 'valibot'; const TupleSchema = v.tupleWithRest([v.string(), v.number()], v.null()); ``` ##### Pipeline validation Similar to arrays, you can use a pipeline to validate the length and contents of a tuple. ```ts import * as v from 'valibot'; const TupleSchema = v.pipe( v.tupleWithRest([v.string()], v.string()), v.maxLength(5), v.includes('foo'), v.excludes('bar') ); ``` ### Optionals It often happens that `undefined` or `null` should also be accepted instead of the value. To make the API more readable for this and to reduce boilerplate, Valibot offers a shortcut for this functionality with [`optional`](/api/optional.md), [`exactOptional`](/api/exactOptional.md), [`undefinedable`](/api/undefinedable.md), [`nullable`](/api/nullable.md) and [`nullish`](/api/nullish.md). #### How it works To accept `undefined` and/or `null` besides your actual value, you just have to wrap the schema in [`optional`](/api/optional.md), [`exactOptional`](/api/exactOptional.md), [`undefinedable`](/api/undefinedable.md), [`nullable`](/api/nullable.md) or [`nullish`](/api/nullish.md). > Note: [`exactOptional`](/api/exactOptional.md) allows missing entries in objects, but does not allow `undefined` as a specified value. ```ts import * as v from 'valibot'; const OptionalStringSchema = v.optional(v.string()); // string | undefined const ExactOptionalStringSchema = v.exactOptional(v.string()); // string const UndefinedableStringSchema = v.undefinedable(v.string()); // string | undefined const NullableStringSchema = v.nullable(v.string()); // string | null const NullishStringSchema = v.nullish(v.string()); // string | null | undefined ``` ##### Use in objects When used inside objects, [`optional`](/api/optional.md), [`exactOptional`](/api/exactOptional.md), and [`nullish`](/api/nullish.md) are a special case, as they also mark the key as optional in TypeScript with a question mark. ```ts import * as v from 'valibot'; const OptionalKeySchema = v.object({ key: v.optional(v.string()) }); // { key?: string | undefined } ``` #### Default values What makes [`optional`](/api/optional.md), [`exactOptional`](/api/exactOptional.md), [`undefinedable`](/api/undefinedable.md), [`nullable`](/api/nullable.md) and [`nullish`](/api/nullish.md) unique is that the schema functions accept a default value as the second argument. Depending on the schema function, this default value is always used if the input is missing, `undefined` or `null`. ```ts import * as v from 'valibot'; const OptionalStringSchema = v.optional(v.string(), "I'm the default!"); type OptionalStringInput = v.InferInput; // string | undefined type OptionalStringOutput = v.InferOutput; // string ``` By providing a default value, the input type of the schema now differs from the output type. The schema in the example now accepts `string` and `undefined` as input, but returns a string as output in both cases. ##### Dynamic default values In some cases it is necessary to generate the default value dynamically. For this purpose, a function that generates and returns the default value can also be passed as the second argument. ```ts import * as v from 'valibot'; const NullableDateSchema = v.nullable(v.date(), () => new Date()); ``` The previous example thus creates a new instance of the [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) class for each validation with `null` as input, which is then used as the default value. > If you want missing object entries to default to an `undefined` value, pass a function that returns `undefined` as the second argument: `v.optional(v.string(), () => undefined)`. This ensures the key is always included in the output, since omitting the default would cause missing keys to be skipped entirely. ##### Dependent default values In rare cases, a default value for an optional entry may depend on the values of another entries in the same object. This can be achieved by using [`transform`](/api/transform.md) in the [`pipe`](/api/pipe.md) of the object. ```ts import * as v from 'valibot'; const CalculationSchema = v.pipe( v.object({ a: v.number(), b: v.number(), sum: v.optional(v.number()), }), v.transform((input) => ({ ...input, sum: input.sum === undefined ? input.a + input.b : input.sum, })) ); ``` #### Pipe execution behavior When an object entry uses [`optional`](/api/optional.md), [`exactOptional`](/api/exactOptional.md), or [`nullish`](/api/nullish.md) inside a [`pipe`](/api/pipe.md), it is important to understand when the pipe executes. ##### Without default values If no `default_` value is provided, missing object keys are completely ignored and their pipes will **not** be executed. If the key is present with `undefined` or `null`, the pipe still runs (but it may return an issue depending on the schema used). ```ts import * as v from 'valibot'; const Schema = v.object({ value: v.pipe( v.optional(v.string()), v.transform((input) => input.toUpperCase()) // Does not run for missing keys ), }); const result = v.parse(Schema, {}); // Output: {} ``` ##### With default values When a `default_` value is provided, the pipe will execute for missing keys using the default value. ```ts import * as v from 'valibot'; const Schema = v.object({ value: v.pipe( v.optional(v.string(), 'hello'), // Default value provided v.transform((input) => input.toUpperCase()) // Runs with 'hello' for missing keys too ), }); const result = v.parse(Schema, {}); // Output: { value: 'HELLO' } ``` This behavior ensures that the output type is consistent and transforms can reliably process values. ### Enums An enumerated type is a data type that consists of a set of values. They can be represented by either an object, a TypeScript enum or, to keep things simple, an array. You use [`enum`](/api/enum.md) for objects and TypeScript enums and [`picklist`](/api/picklist.md) for arrays. #### Enum schema Since TypeScript enums are transpiled to JavaScript objects by the TypeScript compiler, you can use the [`enum`](/api/enum.md) schema function for both. Just pass your enumerated data type as the first argument to the schema function. On validation, the schema checks whether the input matches one of the values in the enum. ```ts import * as v from 'valibot'; // As JavaScript object const Direction = { Left: 'LEFT', Right: 'RIGHT', } as const; // As TypeScript enum enum Direction { Left = 'LEFT', Right = 'RIGHT', } const DirectionSchema = v.enum(Direction); ``` #### Picklist schema For a set of values represented by an array, you can use the [`picklist`](/api/picklist.md) schema function. Just pass your array as the first argument to the schema function. On validation, the schema checks whether the input matches one of the items in the array. ```ts import * as v from 'valibot'; const Direction = ['LEFT', 'RIGHT'] as const; const DirectionSchema = v.picklist(Direction); ``` ##### Format array In some cases, the array may not be in the correct format. In this case, simply use the [`.map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) method to bring it into the required format. ```ts import * as v from 'valibot'; 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)); ``` ### Unions An union represents a logical OR relationship. You can apply this concept to your schemas with [`union`](/api/union.md) and [`variant`](/api/variant.md). For [discriminated unions](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-func.html#discriminated-unions) you use [`variant`](/api/variant.md) and in all other cases you use [`union`](/api/union.md). #### Union schema The schema function [`union`](/api/union.md) creates an OR relationship between any number of schemas that you pass as the first argument in the form of an array. On validation, the schema returns the result of the first schema that was successfully validated. ```ts import * as v from 'valibot'; // TypeScript type Union = string | number; // Valibot const UnionSchema = v.union([v.string(), v.number()]); ``` 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`](/api/union.md) can contradict each other. The following issues are returned if the input is `null` instead of a string or number. Since the input cannot be associated with a schema in this case, the issues of both schemas are returned as subissues. ```ts [ { kind: 'schema', type: 'union', input: null, expected: 'string | number', received: 'null', message: 'Invalid type: Expected string | number but received null', issues: [ { kind: 'schema', type: 'string', input: null, expected: 'string', received: 'null', message: 'Invalid type: Expected string but received null', }, { kind: 'schema', type: 'number', input: null, expected: 'number', received: 'null', message: 'Invalid type: Expected number but received null', }, ], }, ]; ``` #### Variant schema For better performance, more type safety, and a more targeted output of issues, you can use [`variant`](/api/variant.md) for discriminated unions. Therefore, we recommend using [`variant`](/api/variant.md) over [`union`](/api/union.md) whenever possible. A discriminated union is an OR relationship between objects that can be distinguished by a specific key. When you call the schema function, you first specify the discriminator key. This is used to determine the schema to use for validation based on the input. The object schemas, in the form of an array, follow as the second argument. ```ts import * as v from 'valibot'; const VariantScheme = v.variant('type', [ v.object({ type: v.literal('foo'), foo: v.string(), }), v.object({ type: v.literal('bar'), bar: v.number(), }), ]); ``` For very complex datasets, multiple [`variant`](/api/variant.md) schemas can also be deeply nested within one another. ### Intersections An intersection represents a logical AND relationship. You can apply this concept to your schemas with [`intersect`](/api/intersect.md) and partially by merging multiple object schemas into a new one. We recommend this approach for simple object schemas, and [`intersect`](/api/intersect.md) for all other cases. #### Intersect schema The schema function [`intersect`](/api/intersect.md) creates an AND relationship between any number of schemas that you pass as the first argument in the form of an array. To pass the validation, the validation of each schema passed must be successful. If this is the case, the schema merges the output of the individual schemas and returns the result. If the validation fails, the schema returns any issues that occurred. ```ts import * as v from 'valibot'; // TypeScript type Intersect = { foo: string } & { bar: number }; // Valibot const IntersectSchema = v.intersect([ v.object({ foo: v.string() }), v.object({ bar: v.number() }), ]); ``` #### Merge objects Technically, there is a big difference between [`intersect`](/api/intersect.md) and object merging. [`intersect`](/api/intersect.md) is a schema function that executes the passed schemas during validation. In contrast, object merging is done during initialization to create a new object schema. As a result, object merging usually has much better performance than [`intersect`](/api/intersect.md) when validating unknown data. Also, subsequent object properties overwrite the previous ones. This is not the case with [`intersect`](/api/intersect.md), since the validation would fail if two properties with the same name are fundamentally different. ```ts import * as v from 'valibot'; const ObjectSchema1 = v.object({ foo: v.string(), baz: v.number() }); const ObjectSchema2 = v.object({ bar: v.string(), baz: v.boolean() }); const MergedSchema = v.object({ ...ObjectSchema1.entries, ...ObjectSchema2.entries, }); // { foo: string; bar: string; baz: boolean } ``` In the previous code example, the `baz` property of the first object schema is overwritten by the `baz` property of the second object schema. ### Other This guide explains other special schema functions such as [`literal`](/api/literal.md), [`instance`](/api/instance.md), [`custom`](/api/custom.md) and [`lazy`](/api/lazy.md) that are not covered in the other guides. #### Literal schema You can use [`literal`](/api/literal.md) to define a schema that matches a specific string, number or boolean value. Therefore, this schema is perfect for representing [literal types](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types). Usage is simple, just pass the value you want to match as the first argument. ```ts import * as v from 'valibot'; const StringLiteralSchema = v.literal('foo'); // 'foo' const NumberLiteralSchema = v.literal(12345); // 12345 const BooleanLiteralSchema = v.literal(true); // true ``` #### Instance schema With schema functions like [`blob`](/api/blob.md), [`date`](/api/date.md), [`map`](/api/map.md) and [`set`](/api/set.md) Valibot already covers the most common JavaScript classes. However, there are many more classes that you may want to validate. For this purpose, you can use the [`instance`](/api/instance.md) schema function. It takes a class as its first argument and returns a schema that matches only instances of that class. ```ts import * as v from 'valibot'; const ErrorSchema = v.instance(Error); // Error const UrlSchema = v.instance(URL); // URL ``` #### Custom schema The [`custom`](/api/custom.md) schema function is a bit more advanced. It 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. The function receives the value to validate as its first argument and must return a boolean value. If the function returns `true`, the value is considered valid. Otherwise, it is considered invalid. ```ts import * as v from 'valibot'; const PixelStringSchema = v.custom<`${number}px`>((input) => typeof input === 'string' ? /^\d+px$/.test(input) : false ); ``` #### Lazy schema The [`lazy`](/api/lazy.md) schema function allows you to define recursive schemas. A recursive schema is a schema that references itself. For example, you can use it to define a schema for a tree-like data structure. > Due to a TypeScript limitation, the input and output types cannot be inferred automatically in this case. Therefore, you must explicitly specify these types using the [`GenericSchema`](/api/GenericSchema.md) type. ```ts import * as v from 'valibot'; 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 schema Another practical use case for `lazy` is a schema for all possible `JSON` values. These are all values that can be serialized and deserialized using `JSON.stringify()` and `JSON.parse()`. ```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), ]) ); ``` ## Advanced (guides) ### Naming convention In many cases a schema is created and exported together with the inferred type. There are two naming conventions for this procedure that we recommend you to use when working with Valibot. In this guide we will explain both of them and share why we think they might make sense. > You don't have to follow any of these conventions. They are only recommendations. #### Convention 1 The first naming convention exports the schema and type with the same name. The advantage of this is that the names are short and the boilerplate is low, since the schema and type can be imported together. We also recommend to follow the [PascalCase]() naming convention. This means that each word starts with an uppercase letter. This is a common convention for TypeScript types, and since schemas basically provide runtime validation of types, it makes sense to use this convention for schemas as well. ##### Example In the following example, a schema is created for a user object. In order to follow the naming convention, the schema and the type are exported with the same name. ```ts import * as v from 'valibot'; export const PublicUser = v.object({ name: v.pipe(v.string(), v.maxLength(30)), email: v.pipe(v.string(), v.email()), avatar: v.nullable(v.file()), bio: v.pipe(v.string(), v.maxLength(1000)), }); export type PublicUser = v.InferOutput; ``` The schema and type can then be imported and used together. ```ts import * as v from 'valibot'; import { PublicUser } from './types'; // Use `PublicUser` as a type const publicUsers: PublicUser[] = []; publicUsers.push( // Use `PublicUser` as a schema v.parse(PublicUser, { name: 'Jane Doe', email: 'jane@example.com', avatar: null, bio: 'Lorem ipsum ...', }) ); ``` #### Convention 2 The first naming convention can cause naming conflicts with other classes and types. It also causes a problem when you need to export both the input and output types of a schema. The second naming convention provides a solution. It also follows the [PascalCase]() naming convention, but adds an appropriate suffix to each export. Schemas get the suffix `Schema`, input types get the suffix `Input` and output types get the suffix `Output`. > If there is no difference between the input and output type, the suffix `Data` can optionally be used to indicate this. This requires the schema and types to be imported separately, which increases the overhead. However, the naming convention is more precise, flexible, and works in any use case. ##### Example In the following example, a schema is created for an image object. In order to follow the naming convention, the schema and the types are exported with different names. ```ts import * as v from 'valibot'; export const ImageSchema = v.object({ status: v.optional(v.picklist(['public', 'private']), 'private'), created: v.optional(v.date(), () => new Date()), title: v.pipe(v.string(), v.maxLength(100)), source: v.pipe(v.string(), v.url()), size: v.pipe(v.number(), v.minValue(0)), }); export type ImageInput = v.InferInput; export type ImageOutput = v.InferOutput; ``` The schema and the input and output types can then be imported and used separately. ```ts import * as v from 'valibot'; import { ImageInput, ImageOutput, ImageSchema } from './types'; export function createImage(input: ImageInput): ImageOutput { return v.parse(ImageSchema, input); } ``` > Do you have ideas for improving these conventions? We welcome your feedback and suggestions. Feel free to create an [issue](https://github.com/open-circle/valibot/issues/new) on GitHub. ### Async validation By default, Valibot validates each schema synchronously. This is usually the fastest way to validate unknown data, but sometimes you need to validate something asynchronously. For example, you might want to check if a username already exists in your database. #### How it works To be able to do this, Valibot provides an asynchronous implementation when necessary. The only difference is that the asynchronous implementation is promise-based. Otherwise, the API and functionality is exactly the same. ##### Naming The asynchronous implementation starts with the same name as the synchronous one, but adds the suffix `Async` to the end. For example, the asynchronous implementation of [`pipe`](/api/pipe.md) is called [`pipeAsync`](/api/pipeAsync.md) and the asynchronous implementation of [`object`](/api/object.md) is called [`objectAsync`](/api/objectAsync.md). ##### Nesting Asynchronous functions can only be nested inside other asynchronous functions. This means that if you need to validate a string within an object asynchronously, you must also switch the object validation to the asynchronous implementation. This is not necessary in the other direction. You can nest synchronous functions within asynchronous functions, and we recommend that you do so in most cases to keep complexity and bundle size to a minimum. ###### Rule of thumb We recommend that you always start with the synchronous implementation, and only move the necessary parts to the asynchronous implementation as needed. If you are using TypeScript, it is not possible to make a mistake here, as our API is completely type-safe and will notify you when you embed an asynchronous function into a synchronous function. ##### Example Let's say you want to validate a profile object and the username should be checked asynchronously against your database. Only the object and username validation needs to be asynchronous, the rest can stay synchronous. ```ts import * as v from 'valibot'; import { isUsernameAvailable } from '~/api'; const ProfileSchema = v.objectAsync({ username: v.pipeAsync(v.string(), v.checkAsync(isUsernameAvailable)), avatar: v.pipe(v.string(), v.url()), description: v.pipe(v.string(), v.maxLength(1000)), }); ``` ### Internationalization Providing error messages in the native language of your users can improve the user experience and adoption rate of your software. That is why we offer several flexible ways to easily implement i18n. #### Official translations The fastest way to get started with i18n is to use Valibot's official translations. They are provided in a separate package called [`@valibot/i18n`](https://github.com/open-circle/valibot/tree/main/packages/i18n). > If you are missing a translation, feel free to open an [issue](https://github.com/open-circle/valibot/issues/new) or pull request on GitHub. ##### Import translations Each translation in this package is implemented modularly and exported as a submodule. This allows you to import only the translations you actually need to keep your bundle size small. ```ts // Import every translation (not recommended) import '@valibot/i18n'; // Import every translation for a specific language import '@valibot/i18n/de'; // Import only the translation for schema functions import '@valibot/i18n/de/schema'; // Import only the translation for a specific pipeline function import '@valibot/i18n/de/minLength'; ``` The submodules use sideeffects to load the translations into a global storage that the schema and validation functions access when adding the error message to an issue. ##### Select language The language used is then selected by the `lang` configuration. You can set it globally with [`setGlobalConfig`](/api/setGlobalConfig.md) or locally when parsing unknown data via [`parse`](/api/parse.md) or [`safeParse`](/api/safeParse.md). ```ts import * as v from 'valibot'; // Set the language configuration globally v.setGlobalConfig({ lang: 'de' }); // Set the language configuration locally v.parse(Schema, input, { lang: 'de' }); ``` #### Custom translations You can use the same APIs as [`@valibot/i18n`](https://github.com/open-circle/valibot/tree/main/packages/i18n) to add your own translations to the global storage. Alternatively, you can also pass them directly to a specific schema or validation function as the first optional argument. This can be useful if you want to customize an existing language or define a completely custom language yourself. > You can either enter the translations manually or use an i18n library like [Paraglide JS](https://inlang.com/m/gerre34r/library-inlang-paraglideJs). ##### Set translations globally You can add translations with [`setGlobalMessage`](/api/setGlobalMessage.md), [`setSchemaMessage`](/api/setSchemaMessage.md) and [`setSpecificMessage`](/api/setSpecificMessage.md) in three different hierarchy levels. When creating an issue, Valibot first checks if a specific translation is available, then the translation for schema functions, and finally the global translation. Unlike the official translations, you do not need to import an `@valibot/i18n` submodule for this. The `lang` value is just a key that Valibot uses to look up the registered translations. Therefore, it can be any string you want. ```ts import * as v from 'valibot'; // Set the translation globally (can be used as a fallback) v.setGlobalMessage((issue) => `Invalid input: ...`, 'custom'); // Set the translation globally for every schema functions v.setSchemaMessage((issue) => `Invalid type: ...`, 'custom'); // Set the translation globally for a specific function v.setSpecificMessage(v.minLength, (issue) => `Invalid length: ...`, 'custom'); // Use the registered translations v.setGlobalConfig({ lang: 'custom' }); ``` ##### Set translations locally If you prefer to define the translations individually, you can pass them as the first optional argument to schema and validation functions. We recommend using an i18n library like [Paraglide JS](https://inlang.com/m/gerre34r/library-inlang-paraglideJs) in this case. ```ts import * as v from 'valibot'; import * as m from './paraglide/messages.js'; const LoginSchema = v.object({ email: v.pipe( v.string(), v.nonEmpty(m.emailRequired), v.email(m.emailInvalid) ), password: v.pipe( v.string(), v.nonEmpty(m.passwordRequired), v.minLength(8, m.passwordInvalid) ), }); ``` ### JSON Schema In favor of a larger feature set and smaller bundle size, Valibot is not implemented with JSON Schema in mind. However, in some use cases, you may still need a JSON Schema. This guide will show you how to convert Valibot schemas to JSON Schema format. #### Valibot to JSON Schema A large part of Valibot's schemas are JSON Schema compatible and can be easily converted to the JSON Schema format using the official `toJsonSchema` function. This function is provided via a separate package called [`@valibot/to-json-schema`](https://github.com/open-circle/valibot/tree/main/packages/to-json-schema). > See the [README](https://github.com/open-circle/valibot/blob/main/packages/to-json-schema/README.md) of the `@valibot/to-json-schema` package for more details. It is also recommended that you take a look at [this blog post](/blog/json-schema-package-upgrade.md), which highlights recent improvements. ```ts import { toJsonSchema } from '@valibot/to-json-schema'; import * as v from 'valibot'; const ValibotEmailSchema = v.pipe(v.string(), v.email()); const JsonEmailSchema = toJsonSchema(ValibotEmailSchema); // -> { type: 'string', format: 'email' } ``` #### Cons of JSON Schema Valibot schemas intentionally do not output JSON Schema natively. This is because JSON Schema is limited to JSON-compliant data structures. In addition, more advanced features like transformations are not supported. Since we want to leverage the full power of TypeScript, we output a custom format instead. Another drawback of JSON Schema is that JSON Schema itself does not contain any validation logic. Therefore, an additional function is required that can validate the entire JSON Schema specification. This approach is usually not tree-shakable and results in a large bundle size. In contrast, Valibot's API design and implementation is completely modular. Every schema is independent and contains its own validation logic. This allows the schemas to be plugged together like LEGO bricks, resulting in a much smaller bundle size due to tree shaking. #### Pros of JSON Schema Despite these drawbacks, JSON Schema is still widely used in the industry because it also has many advantages. For example, JSON Schemas can be used across programming languages and tools. In addition, JSON Schemas are serializable and can be easily stored in a database or transmitted over a network. ### Internal Architecture This guide targets library authors and advanced users who want to understand how Valibot works under the hood. It covers the internal object model — schemas, actions, datasets, issues, and config — and how they fit together in the pipeline execution engine. Valibot is built around a simple modularity principle: every schema and action is an independent, interchangeable building block. Like Lego bricks, they each expose a standard connector — a shared interface contract — and can be freely combined, nested, and replaced without any central registry or shared state. Valibot's built-in schemas and actions follow the exact same rules as any custom ones you write yourself, which means the library can be extended or partially replaced without special privileges. This design is backed by a concrete technical choice: Every schema and action is a plain object literal returned by a pure factory function. There are no classes, no prototypes beyond `Object`, and no shared mutable state. Because each factory is a pure function with no side effects, it is annotated with `// @__NO_SIDE_EFFECTS__`, which allows bundlers to eliminate every unused schema and action from the final bundle. #### Schemas Schemas are the starting point for using Valibot. They validate a specific data type, like a string, object, or date, and can be reused or nested to reflect more complex data structures. Every schema is a plain object that satisfies [`BaseSchema`](/api/BaseSchema.md): | Property | Type | Description | | ------------- | --------------- | --------------------------------------------------------------------------- | | `kind` | `'schema'` | Identifies this object as a schema | | `type` | `string` | snake_case name, e.g. `'string'`, `'loose_object'` | | `reference` | `Function` | The factory function itself (for identity checks) | | `expects` | `string` | Human-readable expected type, e.g. `'string'` | | `async` | `false` | `true` on async variants | | `'~standard'` | `StandardProps` | Standard Schema v1 properties (lazy getter) | | `'~run'` | `Function` | Parses an `UnknownDataset` and returns an output dataset | | `'~types'` | `undefined` | Phantom field for TypeScript inference only — always `undefined` at runtime | Validation logic beyond the base type check lives in a `pipe` array added by the [`pipe`](/api/pipe.md) method and some schemas expose additional schema-specific properties. See [Runtime properties](/guides/integrate-valibot.md#runtime-properties) for a full breakdown. Any object that satisfies the `BaseSchema` interface is a valid schema — whether it comes from Valibot's built-ins, a third-party package, or your own code. The guide [Extend Valibot](/guides/extend-valibot.md) walks through building one from scratch. #### Actions Actions come in three kinds. The first and probably most important one are validation actions. They check an already-typed value and may add issues. Every validation action is a plain object that satisfies [`BaseValidation`](/api/BaseValidation.md): | Property | Type | Description | | ----------- | ---------------- | --------------------------------------------------------------------------- | | `kind` | `'validation'` | Identifies this object as a validation action | | `type` | `string` | snake_case name, e.g. `'min_length'`, `'email'` | | `reference` | `Function` | The factory function itself (for identity checks) | | `expects` | `string \| null` | Human-readable expected value description; used in issue messages | | `async` | `false` | `true` on async variants | | `'~run'` | `Function` | Validates the current dataset value | | `'~types'` | `undefined` | Phantom field for TypeScript inference only — always `undefined` at runtime | The second one are transformation actions. They convert the value to a new type and/or value. Every transformation action is a plain object that satisfies [`BaseTransformation`](/api/BaseTransformation.md): | Property | Type | Description | | ----------- | ------------------ | --------------------------------------------------------------------------- | | `kind` | `'transformation'` | Identifies this object as a transformation action | | `type` | `string` | snake_case name, e.g. `'trim'`, `'to_lower_case'` | | `reference` | `Function` | The factory function itself (for identity checks) | | `async` | `false` | `true` on async variants | | `'~run'` | `Function` | Transforms the current dataset value | | `'~types'` | `undefined` | Phantom field for TypeScript inference only — always `undefined` at runtime | The third one are metadata actions. They carry static annotations and are always skipped during pipeline execution. Every metadata action is a plain object that satisfies [`BaseMetadata`](/api/BaseMetadata.md): | Property | Type | Description | | ----------- | ------------ | ------------------------------------------------- | | `kind` | `'metadata'` | Identifies this object as a metadata action | | `type` | `string` | snake_case name, e.g. `'title'`, `'description'` | | `reference` | `Function` | The factory function itself (for identity checks) | Just like schemas, any object that satisfies one of these action interfaces is a valid action that can be dropped into any pipeline. #### Datasets A dataset is the container that carries a value through the validation pipeline. It is passed to each `'~run'` method in sequence, and as the pipeline executes, the dataset's `typed` flag and `issues` array are updated to reflect the current state of validation. Datasets are **mutable by design** for performance reasons. `'~run'` implementations modify `dataset.value` and `dataset.typed` in place rather than returning new objects. | Type | `typed` | `issues` | Description | | -------------------------- | ----------- | --------------------- | ---------------------------------------- | | `UnknownDataset` | `undefined` | `undefined` | Raw input, not yet validated | | `SuccessDataset` | `true` | `undefined` | Fully typed, no issues | | `PartialDataset` | `true` | `[Issue, ...Issue[]]` | Typed but has value or formatting issues | | `FailureDataset` | `false` | `[Issue, ...Issue[]]` | Not typed, has fatal issues | #### Issues When a schema or validation action finds a problem with the input, it adds an issue to the dataset. Every issue is a plain object that satisfies [`BaseIssue`](/api/BaseIssue.md): | Property | Type | Description | | ------------- | ---------------------------------------------- | -------------------------------------------------------- | | `kind` | `'schema' \| 'validation' \| 'transformation'` | Mirrors the kind of the object that raised it | | `type` | `string` | Mirrors the type of the object that raised it | | `input` | `unknown` | The raw input value that caused the issue | | `expected` | `string \| null` | Human-readable description of what was expected | | `received` | `string` | Human-readable description of what was actually received | | `message` | `string` | The final, resolved error message string | | `requirement` | `unknown \| undefined` | The specific constraint that failed, e.g. a `RegExp` | | `path` | `IssuePathItem[] \| undefined` | Location of the issue in a nested structure | | `issues` | `BaseIssue[] \| undefined` | Sub-issues, used by union and intersect schemas | `BaseIssue` also extends [`Config`](/api/Config.md), so the `lang`, `message`, `abortEarly`, and `abortPipeEarly` fields from the parse config are carried into the issue object as well. #### Config Every `'~run'` call receives a config object alongside the dataset. It controls language selection, custom error messages, and early-abort behavior. The [`Config`](/api/Config.md) interface has four fields: | Property | Type | Description | | ---------------- | --------------------------- | --------------------------------------------------- | | `lang` | `string \| undefined` | BCP 47 language tag for i18n error messages | | `message` | `ErrorMessage \| undefined` | A global error message override for the parse call | | `abortEarly` | `boolean \| undefined` | Stop on the first issue anywhere in the schema tree | | `abortPipeEarly` | `boolean \| undefined` | Stop on the first issue within a single pipe | #### Pipe execution The [`pipe`](/api/pipe.md) method is the universal connector between all building blocks. It returns a new schema object that spreads all properties of the root schema and adds a `pipe` property — a tuple with the root schema at index 0 and additional pipe items at index 1+. Pipe items can be validation actions, transformation actions, metadata actions, or even other schemas. The `'~run'` method is replaced with a new implementation that iterates all items in the tuple. `pipe` itself has no knowledge of any specific schema or action. It only depends on the shared interface contracts (`kind` and `'~run'`), which is what makes the entire system composable: ```ts function pipe(...pipe) { return { // Spread all properties of the root schema ...pipe[0], // Add the pipe tuple (root schema at index 0, other pipe items at index 1+) pipe, // Replace '~standard' with a lazy getter so that `this` refers to the new schema object get '~standard'() { return _getStandardProps(this); }, // Replace '~run' with a new implementation that executes the pipeline '~run'(dataset, config) { for (const item of pipe) { // Metadata actions are never executed if (item.kind !== 'metadata') { // Schemas and transformations abort if the dataset already has issues if ( dataset.issues && (item.kind === 'schema' || item.kind === 'transformation') ) { dataset.typed = false; break; } // Run pipe item unless an early abort is configured if ( !dataset.issues || (!config.abortEarly && !config.abortPipeEarly) ) { dataset = item['~run'](dataset, config); } } } return dataset; }, }; } ``` The following rules apply during pipe execution: - Metadata items are always skipped. - Schemas and transformations abort if the dataset already has issues. - Validations continue across existing issues unless `abortEarly` or `abortPipeEarly` is configured. Because the result of `pipe` is itself a `BaseSchema`, it can be nested inside other schemas or passed to `pipe` again just like any other schema. #### Immutability We treat all schema and action objects as immutable. Mutating them directly after creation leads to unpredictable behavior, especially when schemas are shared across multiple pipelines or modules. When we need a modified copy of a schema, we spread it into a new object and replace only the properties we want to change. Here is a simplified version of our [`fallback`](/api/fallback.md) method to demonstrate this pattern: ```ts function fallback(schema, fallbackValue) { return { // Copy all properties from the original schema ...schema, // Add the new fallback property as metadata fallback: fallbackValue, // Re-bind '~standard' so `this` refers to the new object get '~standard'() { return _getStandardProps(this); }, // Override '~run' to return the fallback value on failure '~run'(dataset, config) { const outputDataset = schema['~run'](dataset, config); return outputDataset.issues ? { typed: true, value: fallbackValue } : outputDataset; }, }; } ``` Two things are important when creating a modified copy. First, always re-bind the `'~standard'` getter so that `this` inside it refers to the new object instead of the original. Second, capture the original schema in a closure rather than reading `this` in `'~run'`, so the original `'~run'` logic is called correctly. If you want to create an entirely new schema or action from scratch rather than wrapping an existing one, see the [Extend Valibot](/guides/extend-valibot.md) guide. ### Integrate Valibot This guide is aimed at library authors who want to build on top of Valibot — whether that is a form library, an ORM, an API framework, a code generator, or other tooling. It covers Standard Schema for schema-agnostic integrations, schema introspection for extracting types and runtime properties, and schema tree traversal for analysis and code generation. #### Standard Schema Valibot implements [Standard Schema v1](https://standardschema.dev/schema). Every schema object exposes a `'~standard'` property that provides a vendor-neutral `validate` function and inferred TypeScript types. We recommend reading the Standard Schema documentation for the full interface specification. When building a library that accepts user-defined schemas, we recommend accepting a `StandardSchemaV1` instead of a Valibot-specific type — unless your integration requires Valibot-specific APIs. This ensures your library works with any Standard Schema-compatible library, not just Valibot. ```ts import type { StandardSchemaV1 } from '@standard-schema/spec'; async function validateData(schema: StandardSchemaV1, data: unknown) { const result = await schema['~standard'].validate(data); if (result.issues) { // Validation failed — result.issues is a readonly array of StandardIssue console.log(result.issues); } else { // Validation succeeded — result.value is the typed output console.log(result.value); } } ``` One important limitation: `'~standard'.validate` always uses Valibot's global config. There is no way to pass a custom config (such as `abortEarly` or a custom `lang`) through the Standard Schema interface. If you need that level of control, use Valibot's own parsing APIs directly. > Valibot also supports the [Standard JSON Schema](https://standardschema.dev/json-schema) specification via the `@valibot/to-json-schema` package, which exposes a `toStandardJsonSchema` function. #### Schema introspection Valibot schemas are plain objects, so all their properties are readable at runtime. This section covers how to extract static TypeScript types, read runtime properties, and use built-in type guards to narrow schema values safely. ##### Static types Valibot exposes three generic utility types for extracting type information from any schema, validation, transformation, or metadata object. ```ts import * as v from 'valibot'; const Schema = v.pipe(v.string(), v.decimal(), v.toNumber()); type Input = v.InferInput; // string type Output = v.InferOutput; // number type Issue = v.InferIssue; // StringIssue | DecimalIssue | ToNumberIssue ``` [`InferInput`](/api/InferInput.md), [`InferOutput`](/api/InferOutput.md), and [`InferIssue`](/api/InferIssue.md) read the phantom `'~types'` field. They work on schemas, validations, transformations, and metadata alike. `'~types'` is always `undefined` at runtime — this field exists solely for TypeScript's type inference, so we recommend never reading it in runtime code. ##### Runtime properties Every schema and action is a plain object, so you can read its properties directly at runtime. The base properties (`kind`, `type`, `async`, etc.) are always present. Use `kind` to distinguish schemas from actions, and `type` to identify specific schemas and actions. Some schemas expose additional properties listed in the table below. | Schema | Extra property | Description | | ------------------------------------------ | ----------------- | ------------------------------------------------- | | `object`, `looseObject`, `strictObject` | `entries` | `Record` of named fields | | `objectWithRest` | `entries`, `rest` | named fields + rest element schema | | `array` | `item` | element schema | | `tuple`, `looseTuple`, `strictTuple` | `items` | ordered tuple of element schemas | | `tupleWithRest` | `items`, `rest` | ordered elements + rest element schema | | `record`, `map` | `key`, `value` | key and value schemas | | `set` | `value` | value schema | | `union`, `intersect` | `options` | array of member schemas | | `variant` | `key`, `options` | discriminant key string + array of object schemas | | `optional`, `nullable`, and other wrappers | `wrapped` | inner schema | | `lazy` | `getter` | `(input: unknown) => BaseSchema` deferred getter | | any schema passed through `pipe` | `pipe` | tuple of the root schema followed by pipe items | ##### Type guards Use these helpers to narrow the TypeScript type of an unknown Valibot object before accessing its properties. Valibot exports three type guard helpers — [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md), and [`isValiError`](/api/isValiError.md) — that narrow `kind` and `type` with TypeScript inference: ```ts import * as v from 'valibot'; // Narrows to BaseSchema by kind if (v.isOfKind('schema', item)) { item; // BaseSchema<...> } // Narrows to StringSchema by type if (v.isOfType('string', schema)) { schema; // StringSchema<...> } ``` Direct `===` comparisons on `kind` and `type` are fine too, but `isOfKind` and `isOfType` can better narrow the TypeScript type of the object in some edge cases. [`isValiError`](/api/isValiError.md) is a separate helper for error handling. [`ValiError`](/api/ValiError.md) is the error class thrown by [`parse`](/api/parse.md) and [`parser`](/api/parser.md). It extends `Error` with `name = 'ValiError'` and a typed `issues` array: ```ts import * as v from 'valibot'; try { v.parse(Schema, input); } catch (error) { if (v.isValiError(error)) { // error is ValiError console.log(error.issues); } } ``` #### Schema tree traversal Because schemas are plain objects, we can walk a schema tree by reading its properties (see [Runtime properties](#runtime-properties)). When traversing a piped schema, read the `pipe` tuple — its first item is the root schema and subsequent items are pipe actions or nested schemas. Here is a simplified example inspired by [`getDefaults`](/api/getDefaults.md) that extracts deeply nested default values from object and tuple schemas: ```ts import * as v from 'valibot'; function getDefaults< const TSchema extends | v.BaseSchema> | v.ObjectSchema | undefined> | v.TupleSchema | undefined>, >(schema: TSchema): v.InferDefaults { // If it is an object schema, return defaults of entries if ('entries' in schema) { const object: Record = {}; for (const key in schema.entries) { object[key] = getDefaults(schema.entries[key]); } return object; } // If it is a tuple schema, return defaults of items if ('items' in schema) { return schema.items.map(getDefaults); } // Otherwise, return default or `undefined` return v.getDefault(schema); } ``` ### Extend Valibot This guide is for developers who need to go beyond Valibot's built-in primitives — for example when validating a domain-specific format, wrapping a schema in a reusable envelope, or building a library on top of Valibot. Because every schema and action is just a plain object satisfying a shared interface, custom schemas and actions are first-class citizens — not second-class extensions. We cover three levels of extension: Composing existing schemas into reusable factories, building fully custom schemas from scratch, and building fully custom actions from scratch. #### Dynamic schemas The lightest form of extension is composing existing schemas into a reusable generic factory — no custom interfaces or internal utilities required. We can wrap any user-provided schema by using [`GenericSchema`](/api/GenericSchema.md) as the type constraint. It is an alias for [`BaseSchema`](/api/BaseSchema.md) with all type parameters defaulting to `unknown`, designed specifically for this purpose. TypeScript propagates the concrete type so the return type is fully inferred. A common use case is wrapping a user-provided item schema in a reusable envelope, like a pagination wrapper: ```ts import * as v from 'valibot'; function paginatedList(item: TItem) { return v.object({ items: v.array(item), total: v.number(), page: v.number(), }); } const UserList = paginatedList(v.object({ id: v.number(), name: v.string() })); type UserList = v.InferOutput; // { // items: { id: number; name: string }[]; // total: number; // page: number; // } ``` #### Custom schemas A custom schema is a plain object with three parts: A typed issue interface extending [`BaseIssue`](/api/BaseIssue.md), a typed schema interface extending [`BaseSchema`](/api/BaseSchema.md), and a factory function that returns the object. Two internal utilities do the heavy lifting: `_getStandardProps` wires up the Standard Schema `'~standard'` getter, and `_addIssue` constructs and attaches a well-formed issue to the dataset. The `label` argument passed to `_addIssue` (e.g. `'type'`) describes what kind of issue it is and is used to build the human-readable `message`. Here is a simplified version of Valibot's own `string` schema: ```ts import * as v from 'valibot'; // 1. Define the issue interface interface StringIssue extends v.BaseIssue { kind: 'schema'; type: 'string'; expected: 'string'; } // 2. Define the schema interface interface StringSchema | undefined> extends v.BaseSchema { type: 'string'; reference: typeof string; expects: 'string'; message: TMessage; } // 3. Implement the factory function function string | undefined>( message?: TMessage ): StringSchema { return { kind: 'schema', type: 'string', reference: string, expects: 'string', async: false, message, get '~standard'() { return v._getStandardProps(this); }, '~run'(dataset, config) { if (typeof dataset.value === 'string') { // @ts-expect-error dataset.typed = true; } else { v._addIssue(this, 'type', dataset, config); } // @ts-expect-error return dataset as v.OutputDataset; }, }; } ``` The `// @ts-expect-error` comments are a deliberate trade-off in Valibot's codebase to avoid complex conditional generics and improve runtime performance by mutating the `dataset` object. They are safe here because the `typed` flag and return type are always consistent with the logic above. > `_addIssue` and `_getStandardProps` are prefixed with an underscore to signal that they are internal. They are exported for advanced use cases like this, but their signatures may change between minor versions. `v.ErrorMessage` accepts either a plain string or a callback `(issue: T) => string`, so custom error messages can be static or dynamically derived from the issue. #### Custom actions Actions follow the same plain-object pattern. Valibot has three action kinds — [`BaseValidation`](/api/BaseValidation.md), [`BaseTransformation`](/api/BaseTransformation.md), and [`BaseMetadata`](/api/BaseMetadata.md) — each with its own `kind` string. Validation actions check a typed value and may add issues. Transformation actions convert the value to a new type or value. Metadata actions carry static annotations and are never executed during pipeline runs. Here is a simplified version of Valibot's own `email` validation action: ```ts import * as v from 'valibot'; const EMAIL_REGEX = /^[\w+-]+(?:\.[\w+-]+)*@[\w+-]+(?:\.[\w+-]+)*\.[a-zA-Z]{2,}$/iu; // 1. Define the issue interface interface EmailIssue extends v.BaseIssue { kind: 'validation'; type: 'email'; expected: null; received: `"${string}"`; requirement: RegExp; } // 2. Define the action interface interface EmailAction< TInput extends string, TMessage extends v.ErrorMessage> | undefined, > extends v.BaseValidation> { type: 'email'; reference: typeof email; expects: null; requirement: RegExp; message: TMessage; } // 3. Implement the factory function function email< TInput extends string, TMessage extends v.ErrorMessage> | undefined, >(message?: TMessage): EmailAction { return { kind: 'validation', type: 'email', reference: email, expects: null, async: false, requirement: EMAIL_REGEX, message, '~run'(dataset, config) { if (dataset.typed && !this.requirement.test(dataset.value)) { v._addIssue(this, 'email', dataset, config); } return dataset; }, }; } ``` Notice that `'~run'` first checks `dataset.typed` before testing the value. This is the correct pattern for all validation actions — if the dataset is not yet typed (e.g. a schema earlier in the pipe failed), we skip the check entirely. ## Migration (guides) ### Migrate to v0.31.0 Migrating Valibot from an older version to v0.31.0 isn't complicated. Except for the new [`pipe`](/api/pipe.md) method, most things remain the same. The following guide will help you to migrate automatically or manually step by step and also point out important differences. #### Automatic upgrade We worked together with [Codemod](https://codemod.com/registry/valibot-migrate-to-v0-31-0) and Grit to automatically upgrade your schemas to the new version with a single CLI command. Both codemods are similar. You can use one or the other. Simply run the command in the directory of your project. > We recommend using a version control system like [Git](https://git-scm.com/) so that you can revert changes if the codemod screws something up. ```bash # Codemod npx codemod valibot/migrate-to-v0.31.0 # Grit npx @getgrit/cli apply github.com/open-circle/valibot#migrate_to_v0_31_0 ``` Please create an [issue](https://github.com/open-circle/valibot/issues/new) if you encounter any problems or unexpected behavior with the provided codemods. #### Restructure code As mentioned above, one of the biggest differences is the new [`pipe`](/api/pipe.md) method. Previously, you passed the pipeline as an array to a schema function. Now you pass the schema with various actions to the new [`pipe`](/api/pipe.md) method to extend a schema. ```ts // Change this const Schema = v.string([v.email()]); // To this const Schema = v.pipe(v.string(), v.email()); ``` We will be publishing a [blog post](/blog/valibot-v0.31.0-is-finally-available.md) soon explaining all the benefits of this change. In the meantime, you can read the description of discussion [#463](https://github.com/open-circle/valibot/discussions/463) and PR [#502](https://github.com/open-circle/valibot/pull/502), which introduced this change. #### Change names Most of the names are the same as before. However, there are some exceptions. The following table shows all names that have changed. | v0.30.0 | v0.31.0 | | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------- | | `anyAsync` | [`any`](/api/any.md) | | `BaseSchema` | [`GenericSchema`](/api/GenericSchema.md) | | `bigintAsync` | [`bigint`](/api/bigint.md) | | `blobAsync` | [`blob`](/api/blob.md) | | `booleanAsync` | [`boolean`](/api/boolean.md) | | `custom` | [`check`](/api/check.md) | | `customAsync` | [`checkAsync`](/api/checkAsync.md) | | `coerce` | [`pipe`](/api/pipe.md), [`unknown`](/api/unknown.md) and [`transform`](/api/transform.md) | | `dateAsync` | [`date`](/api/date.md) | | `enumAsync` | [`enum_`](/api/enum.md) | | `Input` | [`InferInput`](/api/InferInput.md) | | `instanceAsync` | [`instance`](/api/instance.md) | | `literalAsync` | [`literal`](/api/literal.md) | | `nanAsync` | [`nan`](/api/nan.md) | | `neverAsync` | [`never`](/api/never.md) | | `nullAsync` | [`null_`](/api/null.md) | | `numberAsync` | [`number`](/api/number.md) | | `Output` | [`InferOutput`](/api/InferOutput.md) | | `picklistAsync` | [`picklist`](/api/picklist.md) | | `SchemaConfig` | [`Config`](/api/Config.md) | | `special` | [`custom`](/api/custom.md) | | `specialAsync` | [`customAsync`](/api/customAsync.md) | | `SchemaConfig` | [`Config`](/api/string.md) | | `stringAsync` | [`string`](/api/string.md) | | `symbolAsync` | [`symbol`](/api/symbol.md) | | `undefinedAsync` | [`undefined_`](/api/undefined.md) | | `unknownAsync` | [`unknown`](/api/unknown.md) | | `toCustom` | [`transform`](/api/transform.md) | | `toTrimmed` | [`trim`](/api/trim.md) | | `toTrimmedEnd` | [`trimEnd`](/api/trimEnd.md) | | `toTrimmedStart` | [`trimStart`](/api/trimStart.md) | | `voidAsync` | [`void_`](/api/void.md) | #### Special cases More complex schemas may require a bit more restructuring. This section provides more details on how to migrate specific functions. ##### Objects and tuples Previously, you could pass a `rest` argument to the [`object`](/api/object.md) and [`tuple`](/api/tuple.md) schemas to define the behavior for unknown entries and items. We have removed the `rest` argument to simplify the implementation and reduce the bundle size if this functionality is not needed. If you do need this functionality, there is now a new [`objectWithRest`](/api/objectWithRest.md) and [`tupleWithRest`](/api/tupleWithRest.md) schema. ```ts // Change this const ObjectSchema = v.object({ key: v.string() }, v.null_()); const TupleSchema = v.tuple([v.string()], v.null_()); // To this const ObjectSchema = v.objectWithRest({ key: v.string() }, v.null_()); const TupleSchema = v.tupleWithRest([v.string()], v.null_()); ``` To further improve the developer experience, we have also added a [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`strictObject`](/api/strictObject.md) and [`strictTuple`](/api/strictTuple.md) schema. These schemas allow or disallow unknown entries or items. ```ts // Change this const LooseObjectSchema = v.object({ key: v.string() }, v.unknown()); const LooseTupleSchema = v.tuple([v.string()], v.unknown()); const StrictObjectSchema = v.object({ key: v.string() }, v.never()); const StrictTupleSchema = v.tuple([v.string()], v.never()); // To this const LooseObjectSchema = v.looseObject({ key: v.string() }); const LooseTupleSchema = v.looseTuple([v.string()]); const StrictObjectSchema = v.strictObject({ key: v.string() }); const StrictTupleSchema = v.strictTuple([v.string()]); ``` ##### Object merging Since there are now 4 different object schemas, we could no longer provide a simple `merge` function that works in all cases, as we never know which schema you want to merge the other objects into. But there is a simple workaround with a similar developer experience. ```ts const ObjectSchema1 = v.object({ foo: v.string() }); const ObjectSchema2 = v.object({ bar: v.number() }); // Change this const MergedObject = v.merge([ObjectSchema1, ObjectSchema2]); // To this const MergedObject = v.object({ ...ObjectSchema1.entries, ...ObjectSchema2.entries, }); ``` ##### Brand and transform Previously, [`brand`](/api/brand.md) and [`transform`](/api/transform.md) were methods that could be wrapped around a schema to modify it. With our new [`pipe`](/api/pipe.md) method, this is no longer necessary. Instead, [`brand`](/api/brand.md) and [`transform`](/api/transform.md) are now transformation actions that can be placed directly in a pipeline, resulting in better readability, especially for complex schemas. ```ts // Change this const BrandedSchema = v.brand(v.string(), 'foo'); const TransformedSchema = v.transform(v.string(), (input) => input.length); // To this const BrandedSchema = v.pipe(v.string(), v.brand('foo')); const TransformedSchema = v.pipe( v.string(), v.transform((input) => input.length) ); ``` ##### Coerce method The `coerce` method has been removed because we felt it was an insecure API. In most cases, you don't want to coerce an unknown input into a specific data type. Instead, you want to transform a specific data type into another specific data type. For example, a string or a number into a date. To explicitly define the input type, we recommend using the new [`pipe`](/api/pipe.md) method together with the [`transform`](/api/transform.md) action to achieve the same functionality. ```ts // Change this const DateSchema = v.coerce(v.date(), (input) => new Date(input)); // To this const DateSchema = v.pipe( v.union([v.string(), v.number()]), v.transform((input) => new Date(input)) ); ``` ##### Flatten issues Previously, the [`flatten`](/api/flatten.md) function accepted a [`ValiError`](/api/ValiError.md) or an array of issues. We have simplified the implementation by only allowing an array of issues to be passed. ```ts // Change this const flatErrors = v.flatten(error); // To this const flatErrors = v.flatten(error.issues); ``` ### Migrate from Zod Migrating from [Zod](https://zod.dev/) to Valibot is very easy in most cases since both APIs have a lot of similarities. The following guide will help you migrate step by step and also point out important differences. #### Official codemod To make the migration as smoth as possible, we have created an official codemod that automatically migrates your Zod schemas to Valibot. Just copy your schemas into this editor and click play. > The codemod is still in beta and may not cover all edge cases. If you encounter any problems or unexpected behaviour, please create an [issue](https://github.com/open-circle/valibot/issues/new). Alternatively, you can try to fix any issues yourself and create a [pull request](https://github.com/open-circle/valibot/pulls). You can find the source code [here](https://github.com/open-circle/valibot/tree/main/codemod/zod-to-valibot). You can also run the codemod locally to migrate your entire codebase at once: ```bash // Preview changes (no writes) npx @valibot/zod-to-valibot src/**/* --dry // Apply changes npx @valibot/zod-to-valibot src/**/* ``` #### Replace imports The first thing to do after [installing](/guides/installation.md) Valibot is to update your imports. Just change your Zod imports to Valibot's and replace all occurrences of `z.` with `v.`. ```ts // Change this import { z } from 'zod'; const Schema = z.object({ key: z.string() }); // To this import * as v from 'valibot'; const Schema = v.object({ key: v.string() }); ``` #### Restructure code One of the biggest differences between Zod and Valibot is the way you further validate a given type. In Zod, you chain methods like `.email` and `.endsWith`. In Valibot you use [pipelines](/guides/pipelines.md) to do the same thing. This is a function that starts with a schema and is followed by up to 19 validation or transformation actions. ```ts // Change this const Schema = z.string().email().endsWith('@example.com'); // To this const Schema = v.pipe(v.string(), v.email(), v.endsWith('@example.com')); ``` Due to the modular design of Valibot, also all other methods like `.parse` or `.safeParse` have to be used a little bit differently. Instead of chaining them, you usually pass the schema as the first argument and move any existing arguments one position to the right. ```ts // Change this const value = z.string().parse('foo'); // To this const value = v.parse(v.string(), 'foo'); ``` We recommend that you read our [mental model](/guides/mental-model.md) guide to understand how the individual functions of Valibot's modular API work together. #### Change names Most of the names are the same as in Zod. However, there are some exceptions. The following table shows all names that have changed. | Zod | Valibot | | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | `and` | [`intersect`](/api/intersect.md) | | `catch` | [`fallback`](/api/fallback.md) | | `catchall` | [`objectWithRest`](/api/objectWithRest.md) | | `coerce` | [`pipe`](/api/pipe.md), [`unknown`](/api/unknown.md) and [`transform`](/api/transform.md) | | `datetime` | [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md) | | `default` | [`optional`](/api/optional.md) | | `discriminatedUnion` | [`variant`](/api/variant.md) | | `element` | `item` | | `enum` | [`picklist`](/api/picklist.md) | | `extend` | [Object merging](/guides/intersections.md#merge-objects) | | `gt` | [`gtValue`](/api/gtValue.md) | | `gte` | [`minValue`](/api/minValue.md) | | `infer` | [`InferOutput`](/api/InferOutput.md) | | `int` | [`integer`](/api/integer.md) | | `input` | [`InferInput`](/api/InferInput.md) | | `instanceof` | [`instance`](/api/instance.md) | | `intersection` | [`intersect`](/api/intersect.md) | | `lt` | [`ltValue`](/api/ltValue.md) | | `lte` | [`maxValue`](/api/maxValue.md) | | `max` | [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md) | | `min` | [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md) | | `nativeEnum` | [`enum`](/api/enum.md) | | `negative` | [`maxValue`](/api/maxValue.md) | | `nonnegative` | [`minValue`](/api/minValue.md) | | `nonpositive` | [`maxValue`](/api/maxValue.md) | | `or` | [`union`](/api/union.md) | | `output` | [`InferOutput`](/api/InferOutput.md) | | `passthrough` | [`looseObject`](/api/looseObject.md) | | `positive` | [`minValue`](/api/minValue.md) | | `refine` | [`check`](/api/check.md), [`forward`](/api/forward.md) | | `rest` | [`tuple`](/api/tuple.md) | | `safe` | [`safeInteger`](/api/safeInteger.md) | | `shape` | `entries` | | `strict` | [`strictObject`](/api/strictObject.md) | | `strip` | [`object`](/api/object.md) | | `superRefine` | [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md) | #### Other details Below are some more details that may be helpful when migrating from Zod to Valibot. ##### Object and tuple To specify whether objects or tuples should allow or prevent unknown values, Valibot uses different schema functions. Zod uses the methods `.passthrough`, `.strict`, `.strip`, `.catchall` and `.rest` instead. See the [objects](/guides/objects.md) and [arrays](/guides/arrays.md) guide for more details. ```ts // Change this const ObjectSchema = z.object({ key: z.string() }).strict(); // To this const ObjectSchema = v.strictObject({ key: v.string() }); ``` ##### Error messages For individual error messages, you can pass a string or an object to Zod. It also allows you to differentiate between an error message for "required" and "invalid_type". With Valibot you just pass a single string instead. ```ts // Change this const StringSchema = z .string({ invalid_type_error: 'Not a string' }) .min(5, { message: 'Too short' }); // To this const StringSchema = v.pipe( v.string('Not a string'), v.minLength(5, 'Too short') ); ``` ##### Coerce type To enforce primitive values, you can use a method of the `coerce` object in Zod. There is no such object or function in Valibot. Instead, you use a pipeline with a [`transform`](/api/transform.md) action as the second argument. This forces you to explicitly define the input, resulting in safer code. ```ts // Change this const NumberSchema = z.coerce.number(); // To this const NumberSchema = v.pipe(v.unknown(), v.transform(Number)); ``` Instead of [`unknown`](/api/unknown.md) as in the previous example, we usually recommend using a specific schema such as [`string`](/api/string.md) to improve type safety. This allows you, for example, to validate the formatting of the string with [`decimal`](/api/decimal.md) before transforming it to a number. ```ts const NumberSchema = v.pipe(v.string(), v.decimal(), v.transform(Number)); ``` ##### Async validation Similar to Zod, Valibot supports synchronous and asynchronous validation. However, the API is a little bit different. See the [async guide](/guides/async-validation.md) for more details. ### Migrate from TypeBox Migrating from [TypeBox](https://github.com/sinclairzx81/typebox) to Valibot is straightforward in most cases since both libraries are type-safe and share the same basic concepts. Like Valibot, TypeBox schemas are required by default, which makes the structure of your schemas easy to map. The following guide will help you migrate step by step and also point out important differences. #### Replace imports The first thing to do after [installing](/guides/installation.md) Valibot is to update your imports. Since Valibot validates your data itself, the separate imports for the `Value` module or the `TypeCompiler` are no longer needed. To infer the type of a schema, replace `Static` with [`InferOutput`](/api/InferOutput.md). ```ts // Change this import { Type, type Static } from '@sinclair/typebox'; import { Value } from '@sinclair/typebox/value'; const Schema = Type.Object({ key: Type.String() }); type Data = Static; // To this import * as v from 'valibot'; const Schema = v.object({ key: v.string() }); type Data = v.InferOutput; ``` #### Restructure code TypeBox describes constraints with a JSON Schema options object as the last argument. In Valibot you use [pipelines](/guides/pipelines.md) to do the same thing. This is a function that starts with a schema and is followed by up to 19 validation or transformation actions. ```ts // Change this const Schema = Type.String({ minLength: 3, maxLength: 30 }); // To this const Schema = v.pipe(v.string(), v.minLength(3), v.maxLength(30)); ``` To validate or parse data, you pass the schema as the first argument to methods like [`is`](/api/is.md), [`parse`](/api/parse.md) or [`safeParse`](/api/safeParse.md). ```ts // Change this const valid = Value.Check(Schema, input); // To this const valid = v.is(Schema, input); ``` We recommend that you read our [mental model](/guides/mental-model.md) guide to understand how the individual functions of Valibot's modular API work together. #### String formats In TypeBox, string formats like `email` must be registered with the `FormatRegistry` before they can be used, or they will fail validation. Valibot ships these validations as actions that work out of the box. ```ts // Change this FormatRegistry.Set('email', (value) => isEmail(value)); const Schema = Type.String({ format: 'email' }); // To this const Schema = v.pipe(v.string(), v.email()); ``` #### No implicit type conversion TypeBox's `Value.Parse` runs the `Clean`, `Default` and `Convert` operations before asserting the type. This means that it removes unknown object keys and converts values to the expected type. For example, the string `'24'` is converted to the number `24`. In Valibot, this behavior is not controlled by the parsing method, but by the schema itself. The [`object`](/api/object.md) schema removes unknown keys and [`optional`](/api/optional.md) applies default values, but no schema ever converts types implicitly. If you rely on type conversion, use a pipeline with an explicit [`transform`](/api/transform.md) action or one of the dedicated transformation actions like [`toNumber`](/api/toNumber.md) or [`toDate`](/api/toDate.md). This forces you to explicitly define the input, resulting in safer code. ```ts // Change this const value = Value.Parse(Type.Number(), input); // To this const value = v.parse(v.pipe(v.string(), v.toNumber()), input); ``` Similarly, `Type.Transform` with its `Decode` and `Encode` functions is replaced by a pipeline with a [`transform`](/api/transform.md) action. Note that Valibot only transforms in one direction and does not provide an equivalent to `Value.Encode`. ```ts // Change this const Schema = Type.Transform(Type.String()) .Decode((value) => new Date(value)) .Encode((value) => value.toISOString()); const date = Value.Decode(Schema, input); // To this const Schema = v.pipe(v.string(), v.toDate()); const date = v.parse(Schema, input); ``` Keep in mind that [`toNumber`](/api/toNumber.md) behaves like JavaScript's `Number` function and therefore converts empty strings to `0`, and that [`toDate`](/api/toDate.md) accepts any string that the `Date` constructor can parse. For stricter validation, we recommend adding actions like [`decimal`](/api/decimal.md) or [`isoTimestamp`](/api/isoTimestamp.md) to validate the formatting of the string before converting it. ```ts const NumberSchema = v.pipe(v.string(), v.decimal(), v.toNumber()); const DateSchema = v.pipe(v.string(), v.isoTimestamp(), v.toDate()); ``` #### Change names Many type builder functions just change to lowercase, such as `Type.String` to [`string`](/api/string.md) or `Type.Object` to [`object`](/api/object.md). However, there are some exceptions. The following table shows all names that have changed beyond that. | TypeBox | Valibot | | ---------------- | -------------------------------------------------------------------------------------------- | | `Static` | [`InferOutput`](/api/InferOutput.md) | | `StaticDecode` | [`InferOutput`](/api/InferOutput.md) | | `StaticEncode` | [`InferInput`](/api/InferInput.md) | | `Type.Composite` | [Object merging](/guides/intersections.md#merge-objects) | | `Type.Integer` | [`number`](/api/number.md) with [`integer`](/api/integer.md) | | `Type.KeyOf` | [`keyof`](/api/keyof.md) | | `Type.Recursive` | [`lazy`](/api/lazy.md) | | `Type.Transform` | [`pipe`](/api/pipe.md) with [`transform`](/api/transform.md) | | `Type.Unsafe` | [`custom`](/api/custom.md) | | `TypeCompiler` | [`parser`](/api/parser.md), [`safeParser`](/api/safeParser.md) | | `Value.Check` | [`is`](/api/is.md) | | `Value.Decode` | [`parse`](/api/parse.md) | | `Value.Default` | [`optional`](/api/optional.md) | | `Value.Errors` | [`safeParse`](/api/safeParse.md) | | `Value.Parse` | [`parse`](/api/parse.md) | The same applies to the constraint options. The following table shows how they map to Valibot's actions. | TypeBox | Valibot | | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | | `additionalProperties: false` | [`strictObject`](/api/strictObject.md) | | `additionalProperties: T` | [`objectWithRest`](/api/objectWithRest.md) | | `default` | [`optional`](/api/optional.md) | | `exclusiveMaximum` | [`ltValue`](/api/ltValue.md) | | `exclusiveMinimum` | [`gtValue`](/api/gtValue.md) | | `format` | [`email`](/api/email.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md) and others | | `maximum` | [`maxValue`](/api/maxValue.md) | | `maxItems` | [`maxLength`](/api/maxLength.md) | | `maxProperties` | [`maxEntries`](/api/maxEntries.md) | | `minimum` | [`minValue`](/api/minValue.md) | | `minItems` | [`minLength`](/api/minLength.md) | | `minProperties` | [`minEntries`](/api/minEntries.md) | | `multipleOf` | [`multipleOf`](/api/multipleOf.md) | | `pattern` | [`regex`](/api/regex.md) | | `uniqueItems` | [`checkItems`](/api/checkItems.md) | #### Other details Below are some more details that may be helpful when migrating from TypeBox to Valibot. ##### Unknown object keys Following JSON Schema semantics, TypeBox allows and keeps unknown keys when validating objects by default. Valibot's [`object`](/api/object.md) schema removes them instead, similar to `Value.Clean`. If you rely on TypeBox's behavior, use [`looseObject`](/api/looseObject.md). To reject unknown keys, as with `additionalProperties: false`, use [`strictObject`](/api/strictObject.md). See the [objects](/guides/objects.md) guide for more details. ```ts // Change this const ObjectSchema = Type.Object( { key: Type.String() }, { additionalProperties: false } ); // To this const ObjectSchema = v.strictObject({ key: v.string() }); ``` ##### Unique items Valibot does not provide a dedicated action for JSON Schema's `uniqueItems` keyword. Instead, you can use the [`checkItems`](/api/checkItems.md) action. Its requirement function receives the entire array as its third argument, which allows you to compare each item against the others. ```ts // Change this const Schema = Type.Array(Type.Number(), { uniqueItems: true }); // To this const Schema = v.pipe( v.array(v.number()), v.checkItems( (item, index, array) => array.indexOf(item) === index, 'Duplicate items are not allowed' ) ); ``` ##### Reusable parsers TypeBox's `TypeCompiler` generates optimized JavaScript code for a schema at runtime. Valibot's schemas are executed directly and do not require a compile step. This also means that Valibot does not evaluate generated code, which allows it to run in environments with a strict Content Security Policy. If you like the ergonomics of a compiled validator, [`parser`](/api/parser.md) and [`safeParser`](/api/safeParser.md) create a reusable function bound to your schema. ```ts // Change this const Compiled = TypeCompiler.Compile(Schema); const valid = Compiled.Check(input); // To this const parseSchema = v.safeParser(Schema); const result = parseSchema(input); ``` ##### JSON Schema TypeBox schemas are JSON Schema objects. Valibot schemas are plain JavaScript objects with their own structure. If you need JSON Schema output, for example for OpenAPI definitions or LLM structured outputs, you can use the official `@valibot/to-json-schema` package to convert your Valibot schemas to JSON Schema. See the [JSON Schema](/guides/json-schema.md) guide for more details. ```ts import { toJsonSchema } from '@valibot/to-json-schema'; import * as v from 'valibot'; const ValibotSchema = v.object({ name: v.string(), email: v.pipe(v.string(), v.email()), }); const jsonSchema = toJsonSchema(ValibotSchema); ``` ##### Async validation Unlike TypeBox, Valibot also supports asynchronous validation, for example for database checks. See the [async guide](/guides/async-validation.md) for more details. ### Migrate from Joi Migrating from [Joi](https://joi.dev/) to Valibot is straightforward in most cases since both APIs share the same basic concepts. Beyond a much smaller bundle size, one of the biggest benefits of migrating is that Valibot infers the TypeScript type of your data from your schema, which eliminates the need to maintain separate type definitions. The following guide will help you migrate step by step and also point out important differences. #### Replace imports The first thing to do after [installing](/guides/installation.md) Valibot is to update your imports. Just change your Joi imports to Valibot's and replace all occurrences of `Joi.` with `v.`. ```ts // Change this import Joi from 'joi'; const Schema = Joi.object({ key: Joi.string().required() }); // To this import * as v from 'valibot'; const Schema = v.object({ key: v.string() }); ``` #### Restructure code One of the biggest differences between Joi and Valibot is the way you further validate a given type. In Joi, you chain methods like `.email` and `.max`. In Valibot you use [pipelines](/guides/pipelines.md) to do the same thing. This is a function that starts with a schema and is followed by up to 19 validation or transformation actions. ```ts // Change this const Schema = Joi.string().email().max(30); // To this const Schema = v.pipe(v.string(), v.email(), v.maxLength(30)); ``` Due to the modular design of Valibot, also all other methods like `.validate` have to be used a little bit differently. Instead of chaining them, you usually pass the schema as the first argument and move any existing arguments one position to the right. Where Joi returns an object with `value` and `error`, [`safeParse`](/api/safeParse.md) returns a result object with `output` and `issues`. ```ts // Change this const { value, error } = Joi.string().validate('foo'); // To this const result = v.safeParse(v.string(), 'foo'); if (result.success) { console.log(result.output); } else { console.log(result.issues); } ``` If you prefer an exception to be thrown on invalid input, as with `Joi.attempt` or `Joi.assert`, use [`parse`](/api/parse.md) instead. ```ts // Change this const value = Joi.attempt('foo', Joi.string()); // To this const value = v.parse(v.string(), 'foo'); ``` We recommend that you read our [mental model](/guides/mental-model.md) guide to understand how the individual functions of Valibot's modular API work together. #### Infer types Joi does not infer TypeScript types from your schemas, which usually forces you to maintain separate type definitions. With Valibot, you can remove these duplicate definitions and infer the types directly from your schemas. See the [infer types](/guides/infer-types.md) guide for more details. ```ts const UserSchema = v.object({ name: v.string(), email: v.pipe(v.string(), v.email()), }); type User = v.InferOutput; // { name: string; email: string } ``` #### Required by default Joi schemas are optional by default. To reject `undefined`, you have to append `.required()` to each schema. Valibot works the other way around. Every schema is required by default, and you explicitly mark schemas as optional by wrapping them with [`optional`](/api/optional.md), [`nullable`](/api/nullable.md) or [`nullish`](/api/nullish.md). ```ts // Change this const Schema = Joi.object({ name: Joi.string().required(), email: Joi.string(), }); // To this const Schema = v.object({ name: v.string(), email: v.optional(v.string()), }); ``` There is one detail to watch out for. Joi's string schema rejects empty strings by default. If you rely on this behavior, add the [`nonEmpty`](/api/nonEmpty.md) action to your pipeline. ```ts // Change this const Schema = Joi.string().required(); // To this const Schema = v.pipe(v.string(), v.nonEmpty()); ``` #### No implicit type conversion By default, Joi converts values to the expected type before validating them. For example, `Joi.number()` accepts the string `'24'` and converts it to the number `24`, and `Joi.date()` converts ISO strings to `Date` objects. Valibot never changes your data implicitly. If you rely on type conversion, use a pipeline with an explicit [`transform`](/api/transform.md) action or one of the dedicated transformation actions like [`toNumber`](/api/toNumber.md) or [`toDate`](/api/toDate.md). This forces you to explicitly define the input, resulting in safer code. ```ts // Change this const NumberSchema = Joi.number(); // To this const NumberSchema = v.pipe(v.string(), v.toNumber()); ``` ```ts // Change this const DateSchema = Joi.date(); // To this const DateSchema = v.pipe(v.string(), v.toDate()); ``` Keep in mind that [`toNumber`](/api/toNumber.md) behaves like JavaScript's `Number` function and therefore converts empty strings to `0`, and that [`toDate`](/api/toDate.md) accepts any string that the `Date` constructor can parse. For stricter validation, we recommend adding actions like [`decimal`](/api/decimal.md) or [`isoTimestamp`](/api/isoTimestamp.md) to validate the formatting of the string before converting it. ```ts const NumberSchema = v.pipe(v.string(), v.decimal(), v.toNumber()); const DateSchema = v.pipe(v.string(), v.isoTimestamp(), v.toDate()); ``` #### Collect all issues Another difference is that Joi stops validation after the first error by default. Valibot collects all issues instead. If you prefer Joi's behavior for performance reasons, you can pass a configuration object with `abortEarly: true` as the third argument to [`parse`](/api/parse.md) or [`safeParse`](/api/safeParse.md). ```ts // Change this const { error } = Schema.validate(input); // To this const result = v.safeParse(Schema, input, { abortEarly: true }); ``` #### Change names Most of the names are similar to Joi. However, there are some exceptions. The following table shows all names that have changed. | Joi | Valibot | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | `allow(null)` | [`nullable`](/api/nullable.md) | | `alphanum` | [`regex`](/api/regex.md) | | `alternatives` | [`union`](/api/union.md), [`variant`](/api/variant.md) | | `append` | [Object merging](/guides/intersections.md#merge-objects) | | `assert` | [`parse`](/api/parse.md) | | `attempt` | [`parse`](/api/parse.md) | | `concat` | [Object merging](/guides/intersections.md#merge-objects) | | `custom` | [`check`](/api/check.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md) | | `default` | [`optional`](/api/optional.md) | | `equal` | [`literal`](/api/literal.md), [`picklist`](/api/picklist.md) | | `external` | [`checkAsync`](/api/checkAsync.md) | | `forbidden` | [`optional`](/api/optional.md) with [`never`](/api/never.md) | | `greater` | [`gtValue`](/api/gtValue.md) | | `guid` | [`uuid`](/api/uuid.md) | | `hex` | [`hexadecimal`](/api/hexadecimal.md) | | `invalid` | [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md) | | `isoDate` | [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoTimestamp`](/api/isoTimestamp.md) | | `items` | Item argument of [`array`](/api/array.md) | | `keys` | [Object merging](/guides/intersections.md#merge-objects) | | `length` | [`length`](/api/length.md), [`size`](/api/size.md), [`entries`](/api/entries.md) | | `less` | [`ltValue`](/api/ltValue.md) | | `link` | [`lazy`](/api/lazy.md) | | `lowercase` | [`toLowerCase`](/api/toLowerCase.md) | | `max` | [`maxLength`](/api/maxLength.md), [`maxValue`](/api/maxValue.md), [`maxEntries`](/api/maxEntries.md) | | `min` | [`minLength`](/api/minLength.md), [`minValue`](/api/minValue.md), [`minEntries`](/api/minEntries.md) | | `multiple` | [`multipleOf`](/api/multipleOf.md) | | `negative` | [`ltValue`](/api/ltValue.md) | | `ordered` | [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md) | | `pattern` | [`regex`](/api/regex.md), [`record`](/api/record.md), [`objectWithRest`](/api/objectWithRest.md) | | `positive` | [`gtValue`](/api/gtValue.md) | | `try` | [`union`](/api/union.md), [`variant`](/api/variant.md) | | `unique` | [`checkItems`](/api/checkItems.md) | | `unknown` | [`looseObject`](/api/looseObject.md) | | `uppercase` | [`toUpperCase`](/api/toUpperCase.md) | | `uri` | [`url`](/api/url.md) | | `valid` | [`literal`](/api/literal.md), [`picklist`](/api/picklist.md) | | `validate` | [`parse`](/api/parse.md), [`safeParse`](/api/safeParse.md) | | `validateAsync` | [`parseAsync`](/api/parseAsync.md), [`safeParseAsync`](/api/safeParseAsync.md) | #### Other details Below are some more details that may be helpful when migrating from Joi to Valibot. ##### Unknown object keys By default, Joi rejects unknown keys when validating objects. This matches Valibot's [`strictObject`](/api/strictObject.md) schema. If you use `.unknown()` to keep unknown keys, use [`looseObject`](/api/looseObject.md) instead. If you use the `stripUnknown` option to remove them, [`object`](/api/object.md) is the right choice. See the [objects](/guides/objects.md) guide for more details. ```ts // Change this const ObjectSchema = Joi.object({ key: Joi.string().required() }); // To this const ObjectSchema = v.strictObject({ key: v.string() }); ``` ##### Cross-field validation Joi uses `Joi.ref` to reference the value of another field, for example to check that two passwords match. In Valibot, you use a pipeline on the object schema with [`forward`](/api/forward.md) and [`partialCheck`](/api/partialCheck.md) instead. ```ts // Change this const RegisterSchema = Joi.object({ password: Joi.string().required(), confirmPassword: Joi.string() .required() .valid(Joi.ref('password')) .messages({ 'any.only': 'The two passwords do not match.' }), }); // To this const RegisterSchema = v.pipe( v.object({ password: v.pipe(v.string(), v.nonEmpty()), confirmPassword: v.pipe(v.string(), v.nonEmpty()), }), v.forward( v.partialCheck( [['password'], ['confirmPassword']], (input) => input.password === input.confirmPassword, 'The two passwords do not match.' ), ['confirmPassword'] ) ); ``` ##### Conditional schemas There is no direct equivalent to Joi's `.when()` method. For discriminated unions, we recommend [`variant`](/api/variant.md). For other conditional validations, you can use [`check`](/api/check.md) or [`rawCheck`](/api/rawCheck.md) on the parent object, or select the schema dynamically with [`lazy`](/api/lazy.md), which receives the current input as an argument. ##### Error messages Instead of `.messages()`, `.message()` and `.label()`, you pass a single string as the first argument to schemas and as the last argument to actions. See the [quick start](/guides/quick-start.md#error-messages) and [internationalization](/guides/internationalization.md) guide for more details. ```ts // Change this const Schema = Joi.string().min(10).messages({ 'string.base': 'Must be a string', 'string.min': 'String is too short', }); // To this const Schema = v.pipe( v.string('Must be a string'), v.minLength(10, 'String is too short') ); ``` ##### Async validation Joi's `.external()` method allows asynchronous validation rules. Valibot provides dedicated async functions like [`parseAsync`](/api/parseAsync.md), [`pipeAsync`](/api/pipeAsync.md) and [`checkAsync`](/api/checkAsync.md) for this purpose. See the [async guide](/guides/async-validation.md) for more details. ```ts // Change this const Schema = Joi.string().external(async (value) => { if (await isUsernameTaken(value)) { throw new Error('Username is already taken'); } return value; }); // To this const Schema = v.pipeAsync( v.string(), v.checkAsync( async (input) => !(await isUsernameTaken(input)), 'Username is already taken' ) ); ``` ### Migrate from Yup Migrating from [Yup](https://github.com/jquense/yup) to Valibot is straightforward in most cases since both APIs share the same basic concepts. The following guide will help you migrate step by step and also point out important differences. #### Replace imports The first thing to do after [installing](/guides/installation.md) Valibot is to update your imports. Just change your Yup imports to Valibot's and replace all occurrences of `yup.` with `v.`. ```ts // Change this import * as yup from 'yup'; const Schema = yup.object({ key: yup.string().required() }); // To this import * as v from 'valibot'; const Schema = v.object({ key: v.string() }); ``` #### Restructure code One of the biggest differences between Yup and Valibot is the way you further validate a given type. In Yup, you chain methods like `.email` and `.max`. In Valibot you use [pipelines](/guides/pipelines.md) to do the same thing. This is a function that starts with a schema and is followed by up to 19 validation or transformation actions. ```ts // Change this const Schema = yup.string().email().max(30); // To this const Schema = v.pipe(v.string(), v.email(), v.maxLength(30)); ``` Due to the modular design of Valibot, also all other methods like `.validate` or `.isValid` have to be used a little bit differently. Instead of chaining them, you usually pass the schema as the first argument and move any existing arguments one position to the right. Note that Yup's `.validate` method is asynchronous by default, whereas [`parse`](/api/parse.md) is synchronous. ```ts // Change this const value = yup.string().validateSync('foo'); // To this const value = v.parse(v.string(), 'foo'); ``` We recommend that you read our [mental model](/guides/mental-model.md) guide to understand how the individual functions of Valibot's modular API work together. #### Required by default Yup schemas are optional by default. To reject `undefined`, you have to append `.required()` to each schema. Valibot works the other way around. Every schema is required by default, and you explicitly mark schemas as optional by wrapping them with [`optional`](/api/optional.md), [`nullable`](/api/nullable.md) or [`nullish`](/api/nullish.md). ```ts // Change this const Schema = yup.object({ name: yup.string().required(), email: yup.string(), }); // To this const Schema = v.object({ name: v.string(), email: v.optional(v.string()), }); ``` There is one detail to watch out for. For string schemas, Yup's `.required()` also rejects empty strings. If you rely on this behavior, add the [`nonEmpty`](/api/nonEmpty.md) action to your pipeline. ```ts // Change this const Schema = yup.string().required(); // To this const Schema = v.pipe(v.string(), v.nonEmpty()); ``` #### No implicit type coercion Before validating a value, Yup casts it to the expected type. For example, `yup.number()` accepts the string `'24'` and converts it to the number `24`. This even applies to `.isValid` checks. Valibot never changes your data implicitly. If you rely on type coercion, use a pipeline with an explicit [`transform`](/api/transform.md) action or one of the dedicated transformation actions like [`toNumber`](/api/toNumber.md) or [`toDate`](/api/toDate.md). This forces you to explicitly define the input, resulting in safer code. ```ts // Change this const NumberSchema = yup.number(); // To this const NumberSchema = v.pipe(v.string(), v.toNumber()); ``` The same applies to dates. Yup's `.cast` method converts ISO strings to `Date` objects. In Valibot, you define this conversion explicitly. ```ts // Change this const DateSchema = yup.date(); // To this const DateSchema = v.pipe(v.string(), v.toDate()); ``` Keep in mind that [`toNumber`](/api/toNumber.md) behaves like JavaScript's `Number` function and therefore converts empty strings to `0`, and that [`toDate`](/api/toDate.md) accepts any string that the `Date` constructor can parse. For stricter validation, we recommend adding actions like [`decimal`](/api/decimal.md) or [`isoTimestamp`](/api/isoTimestamp.md) to validate the formatting of the string before converting it. ```ts const NumberSchema = v.pipe(v.string(), v.decimal(), v.toNumber()); const DateSchema = v.pipe(v.string(), v.isoTimestamp(), v.toDate()); ``` #### Change names Most of the names are the same as in Yup. However, there are some exceptions. The following table shows all names that have changed. | Yup | Valibot | | -------------- | ------------------------------------------------------------------------------------------------------------ | | `bool` | [`boolean`](/api/boolean.md) | | `concat` | [Object merging](/guides/intersections.md#merge-objects) | | `default` | [`optional`](/api/optional.md) | | `InferType` | [`InferOutput`](/api/InferOutput.md) | | `isValid` | [`is`](/api/is.md) | | `json` | [`parseJson`](/api/parseJson.md) | | `lessThan` | [`ltValue`](/api/ltValue.md) | | `matches` | [`regex`](/api/regex.md) | | `max` | [`maxLength`](/api/maxLength.md), [`maxValue`](/api/maxValue.md) | | `min` | [`minLength`](/api/minLength.md), [`minValue`](/api/minValue.md) | | `mixed` | [`any`](/api/any.md), [`unknown`](/api/unknown.md) | | `moreThan` | [`gtValue`](/api/gtValue.md) | | `negative` | [`ltValue`](/api/ltValue.md) | | `noUnknown` | [`strictObject`](/api/strictObject.md) | | `notOneOf` | [`notValues`](/api/notValues.md) | | `notRequired` | [`nullish`](/api/nullish.md) | | `of` | Item argument of [`array`](/api/array.md) | | `oneOf` | [`picklist`](/api/picklist.md) | | `positive` | [`gtValue`](/api/gtValue.md) | | `shape` | `entries` | | `strip` | [`omit`](/api/omit.md) | | `test` | [`check`](/api/check.md), [`rawCheck`](/api/rawCheck.md) | | `typeError` | Error message argument of schema | | `validate` | [`parseAsync`](/api/parseAsync.md), [`safeParseAsync`](/api/safeParseAsync.md) | | `validateSync` | [`parse`](/api/parse.md), [`safeParse`](/api/safeParse.md) | #### Other details Below are some more details that may be helpful when migrating from Yup to Valibot. ##### Unknown object keys By default, Yup keeps unknown keys when validating objects. Valibot's [`object`](/api/object.md) schema removes them instead. If you rely on Yup's behavior, use [`looseObject`](/api/looseObject.md). If you use the `stripUnknown` option, [`object`](/api/object.md) is the right choice. To reject unknown keys, as with `.noUnknown()` in combination with `.strict()`, use [`strictObject`](/api/strictObject.md). See the [objects](/guides/objects.md) guide for more details. ```ts // Change this const ObjectSchema = yup.object({ key: yup.string().required() }); // To this const ObjectSchema = v.looseObject({ key: v.string() }); ``` ##### Cross-field validation Yup uses `ref` to reference the value of another field, for example to check that two passwords match. In Valibot, you use a pipeline on the object schema with [`forward`](/api/forward.md) and [`partialCheck`](/api/partialCheck.md) instead. ```ts // Change this const RegisterSchema = yup.object({ password: yup.string().required(), confirmPassword: yup .string() .required() .oneOf([yup.ref('password')], 'The two passwords do not match.'), }); // To this const RegisterSchema = v.pipe( v.object({ password: v.pipe(v.string(), v.nonEmpty()), confirmPassword: v.pipe(v.string(), v.nonEmpty()), }), v.forward( v.partialCheck( [['password'], ['confirmPassword']], (input) => input.password === input.confirmPassword, 'The two passwords do not match.' ), ['confirmPassword'] ) ); ``` ##### Conditional schemas There is no direct equivalent to Yup's `.when()` method. For discriminated unions, we recommend [`variant`](/api/variant.md). For other conditional validations, you can use [`check`](/api/check.md) or [`rawCheck`](/api/rawCheck.md) on the parent object, or select the schema dynamically with [`lazy`](/api/lazy.md), which receives the current input as an argument. ##### Error messages Instead of `.typeError()` and per-validation message arguments, you pass a single string as the first argument to schemas and as the last argument to actions. See the [quick start](/guides/quick-start.md#error-messages) guide for more details. ```ts // Change this const Schema = yup .number() .typeError('Must be a number') .min(10, 'Number is too small'); // To this const Schema = v.pipe( v.number('Must be a number'), v.minValue(10, 'Number is too small') ); ``` ##### Async validation In Yup, `.validate` is always asynchronous. Valibot is synchronous by default and provides dedicated async functions like [`parseAsync`](/api/parseAsync.md), [`pipeAsync`](/api/pipeAsync.md) and [`checkAsync`](/api/checkAsync.md) for schemas that require asynchronous logic, such as database checks. See the [async guide](/guides/async-validation.md) for more details. ### Migrate from class-validator Migrating from [class-validator](https://github.com/typestack/class-validator) to Valibot is a bigger paradigm shift than for other libraries, since you are switching from decorated classes to schemas. In return, it removes a lot of boilerplate. You no longer need experimental decorators, `reflect-metadata` or class-transformer, and your schemas validate plain data directly, with the TypeScript type inferred automatically. The following guide will help you migrate step by step. #### Replace classes with schemas Each decorated class becomes a schema, and each decorator becomes a schema function or an action within a [pipeline](/guides/pipelines.md). Since the class no longer exists, you infer the TypeScript type from the schema with [`InferOutput`](/api/InferOutput.md). ```ts // Change this import { IsEmail, IsInt, IsString, Min } from 'class-validator'; class User { @IsString() name: string; @IsEmail() email: string; @IsInt() @Min(0) age: number; } // To this import * as v from 'valibot'; const UserSchema = v.object({ name: v.string(), email: v.pipe(v.string(), v.email()), age: v.pipe(v.number(), v.integer(), v.minValue(0)), }); type User = v.InferOutput; ``` #### Restructure code With class-validator, you first convert plain data to a class instance, for example with class-transformer's `plainToInstance`, and then validate it. With Valibot, you validate plain data directly. The `validate` method, which resolves to an array of validation errors, is replaced by [`safeParse`](/api/safeParse.md), which returns a result object. Since Valibot is synchronous by default, there is no need for a separate `validateSync` method. ```ts // Change this const user = plainToInstance(User, input); const errors = await validate(user); if (errors.length === 0) { console.log(user); } else { console.log(errors); } // To this const result = v.safeParse(UserSchema, input); if (result.success) { console.log(result.output); } else { console.log(result.issues); } ``` If you prefer an exception to be thrown on invalid input, as with `validateOrReject`, use [`parse`](/api/parse.md) instead. ```ts // Change this await validateOrReject(user); // To this const output = v.parse(UserSchema, input); ``` We recommend that you read our [mental model](/guides/mental-model.md) guide to understand how the individual functions of Valibot's modular API work together. #### Optional properties The `@IsOptional` decorator skips validation when the value is `null` or `undefined`. This matches Valibot's [`nullish`](/api/nullish.md) schema. If a property can only be `undefined` but not `null`, use [`optional`](/api/optional.md) instead. ```ts // Change this class Profile { @IsOptional() @IsString() bio?: string; } // To this const ProfileSchema = v.object({ bio: v.nullish(v.string()), }); ``` #### Nested objects and arrays Instead of `@ValidateNested` in combination with class-transformer's `@Type` decorator, you nest schemas directly. For arrays, the `{ each: true }` option is replaced by wrapping the item schema with [`array`](/api/array.md). ```ts // Change this class Order { @IsArray() @ValidateNested({ each: true }) @Type(() => Item) items: Item[]; } // To this const OrderSchema = v.object({ items: v.array(ItemSchema), }); ``` #### Change names The following table shows how the most common decorators and methods map to Valibot's API. | class-validator | Valibot | | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | `@Contains` | [`includes`](/api/includes.md) | | `@IsArray` | [`array`](/api/array.md) | | `@IsBase64` | [`base64`](/api/base64.md) | | `@IsBoolean` | [`boolean`](/api/boolean.md) | | `@IsCreditCard` | [`creditCard`](/api/creditCard.md) | | `@IsDateString` | [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoTimestamp`](/api/isoTimestamp.md) | | `@IsDefined` | Default behavior of every schema | | `@IsEmail` | [`email`](/api/email.md) | | `@IsEnum` | [`enum`](/api/enum.md) | | `@IsHexadecimal` | [`hexadecimal`](/api/hexadecimal.md) | | `@IsIn` | [`picklist`](/api/picklist.md) | | `@IsInt` | [`number`](/api/number.md) with [`integer`](/api/integer.md) | | `@IsIP` | [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md) | | `@IsNegative` | [`ltValue`](/api/ltValue.md) | | `@IsNotEmpty` | [`nonEmpty`](/api/nonEmpty.md) | | `@IsNotIn` | [`notValues`](/api/notValues.md) | | `@IsNumber` | [`number`](/api/number.md) | | `@IsOptional` | [`nullish`](/api/nullish.md) | | `@IsPositive` | [`gtValue`](/api/gtValue.md) | | `@IsString` | [`string`](/api/string.md) | | `@IsUrl` | [`url`](/api/url.md) | | `@IsUUID` | [`uuid`](/api/uuid.md) | | `@Length` | [`minLength`](/api/minLength.md) with [`maxLength`](/api/maxLength.md) | | `@Matches` | [`regex`](/api/regex.md) | | `@Max` | [`maxValue`](/api/maxValue.md) | | `@MaxLength` | [`maxLength`](/api/maxLength.md) | | `@Min` | [`minValue`](/api/minValue.md) | | `@MinLength` | [`minLength`](/api/minLength.md) | | `@Validate` | [`check`](/api/check.md), [`checkAsync`](/api/checkAsync.md) | | `@ValidateNested` | Nested schema | | `validate` | [`safeParse`](/api/safeParse.md) | | `validateOrReject` | [`parse`](/api/parse.md) | | `validateSync` | [`safeParse`](/api/safeParse.md) | Many more specific decorators like `@IsMobilePhone` are backed by [validator.js](https://github.com/validatorjs/validator.js). For those without a direct Valibot equivalent, you can use [`check`](/api/check.md) or [`regex`](/api/regex.md) to implement the same validation. #### Other details Below are some more details that may be helpful when migrating from class-validator to Valibot. ##### Unknown properties By default, class-validator keeps properties without decorators on the instance. This matches [`looseObject`](/api/looseObject.md). The `whitelist: true` option, which strips unknown properties, matches the default behavior of [`object`](/api/object.md). The `forbidNonWhitelisted: true` option, which rejects them, matches [`strictObject`](/api/strictObject.md). See the [objects](/guides/objects.md) guide for more details. ```ts // Change this const errors = await validate(post, { whitelist: true, forbidNonWhitelisted: true, }); // To this const result = v.safeParse(v.strictObject({ title: v.string() }), input); ``` ##### Custom error messages Instead of the `message` property in the decorator options, you pass a single string as the first argument to schemas and as the last argument to actions. See the [quick start](/guides/quick-start.md#error-messages) guide for more details. ```ts // Change this class Login { @MinLength(8, { message: 'Password is too short' }) password: string; } // To this const LoginSchema = v.object({ password: v.pipe(v.string(), v.minLength(8, 'Password is too short')), }); ``` ##### Validation options Some validation options map only approximately to Valibot and require attention to details. The `skipMissingProperties` option skips properties that are `null` or `undefined`, except for those marked with `@IsDefined`. Wrapping your schema with [`partial`](/api/partial.md) comes close, but only allows `undefined` and affects every entry. For full parity, wrap the individual entries with [`nullish`](/api/nullish.md) instead. The `stopAtFirstError` option stops after the first error of each property, but still reports every invalid property. Valibot's `abortEarly` configuration is stricter and stops after the first issue overall. Validation groups have no direct equivalent. Instead, we recommend deriving multiple schemas from a shared object with methods like [`pick`](/api/pick.md), [`omit`](/api/omit.md) and [`partial`](/api/partial.md). ##### Framework integration If you use class-validator through a framework like NestJS, you can replace its validation pipe with a custom pipe that calls [`parse`](/api/parse.md) with your schema. See the [integration](/guides/integrate-valibot.md) guide for an overview of ecosystem integrations. ### Migrate from Superstruct Migrating from [Superstruct](https://github.com/ianstormtaylor/superstruct) to Valibot is particularly easy since both libraries share the same functional and composable design. Most structs map directly to a Valibot schema. The following guide will help you migrate step by step and also point out important differences. #### Replace imports The first thing to do after [installing](/guides/installation.md) Valibot is to update your imports. We recommend importing Valibot with a wildcard, which gives you access to the entire API through a single variable while remaining fully tree-shakable. ```ts // Change this import { object, string, assert } from 'superstruct'; const Schema = object({ key: string() }); // To this import * as v from 'valibot'; const Schema = v.strictObject({ key: v.string() }); ``` There is one detail to watch out for. Superstruct's methods expect the value as the first argument and the struct as the second. In Valibot, the schema always comes first. ```ts // Change this assert(input, Schema); // To this v.assert(Schema, input); ``` #### Restructure code Superstruct wraps structs with refinement functions like `size` and `pattern`. In Valibot you use [pipelines](/guides/pipelines.md) to do the same thing. This is a function that starts with a schema and is followed by up to 19 validation or transformation actions. ```ts // Change this const Schema = size(pattern(string(), /^[a-z]+$/), 3, 30); // To this const Schema = v.pipe( v.string(), v.regex(/^[a-z]+$/), v.minLength(3), v.maxLength(30) ); ``` The validation methods map almost one-to-one. `assert` keeps its name, `is` keeps its name with flipped arguments, `validate` returns a result object with [`safeParse`](/api/safeParse.md), and `create` becomes [`parse`](/api/parse.md). ```ts // Change this const [error, value] = validate(input, Schema); // To this const result = v.safeParse(Schema, input); if (result.success) { console.log(result.output); } else { console.log(result.issues); } ``` We recommend that you read our [mental model](/guides/mental-model.md) guide to understand how the individual functions of Valibot's modular API work together. #### Coercion and defaults Superstruct separates validation from coercion. Coercions and defaults defined with `coerce`, `defaulted` and `trimmed` are only applied when calling `create`, but not when calling `assert` or `is`. Valibot does not make this distinction. Transformations and default values are part of the schema and are always applied when parsing. ```ts // Change this const Schema = defaulted(trimmed(string()), 'foo'); const value = create(input, Schema); // To this const Schema = v.optional(v.pipe(v.string(), v.trim()), 'foo'); const value = v.parse(Schema, input); ``` For type coercions defined with `coerce`, use a pipeline with an explicit [`transform`](/api/transform.md) action or one of the dedicated transformation actions like [`toNumber`](/api/toNumber.md) or [`toDate`](/api/toDate.md). ```ts // Change this const Schema = coerce(number(), string(), (value) => parseFloat(value)); // To this const Schema = v.pipe(v.string(), v.decimal(), v.toNumber()); ``` #### Change names Most of the names are the same as in Superstruct. However, there are some exceptions. The following table shows all names that have changed. | Superstruct | Valibot | | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `assign` | [Object merging](/guides/intersections.md#merge-objects) | | `coerce` | [`pipe`](/api/pipe.md) and [`transform`](/api/transform.md) | | `create` | [`parse`](/api/parse.md) | | `defaulted` | [`optional`](/api/optional.md) | | `define` | [`custom`](/api/custom.md) | | `dynamic` | [`lazy`](/api/lazy.md) | | `enums` | [`picklist`](/api/picklist.md) | | `func` | [`function`](/api/function.md) | | `Infer` | [`InferOutput`](/api/InferOutput.md) | | `integer` | [`number`](/api/number.md) with [`integer`](/api/integer.md) | | `intersection` | [`intersect`](/api/intersect.md) | | `mask` | [`parse`](/api/parse.md) with [`object`](/api/object.md) | | `max` | [`maxValue`](/api/maxValue.md), [`ltValue`](/api/ltValue.md) | | `min` | [`minValue`](/api/minValue.md), [`gtValue`](/api/gtValue.md) | | `nonempty` | [`nonEmpty`](/api/nonEmpty.md) | | `object` | [`strictObject`](/api/strictObject.md) | | `pattern` | [`regex`](/api/regex.md) | | `refine` | [`check`](/api/check.md) | | `size` | [`minLength`](/api/minLength.md), [`maxLength`](/api/maxLength.md), [`minValue`](/api/minValue.md), [`maxValue`](/api/maxValue.md) and others | | `StructError` | [`ValiError`](/api/ValiError.md) | | `trimmed` | [`trim`](/api/trim.md) | | `type` | [`looseObject`](/api/looseObject.md) | | `validate` | [`safeParse`](/api/safeParse.md) | #### Other details Below are some more details that may be helpful when migrating from Superstruct to Valibot. ##### Unknown object keys Superstruct provides three behaviors for unknown object keys, and each of them has a direct equivalent in Valibot. `object` rejects unknown keys, which matches [`strictObject`](/api/strictObject.md). `type` allows and keeps unknown keys, which matches [`looseObject`](/api/looseObject.md). The `mask` method removes unknown keys, which matches the default behavior of [`object`](/api/object.md) when parsing. See the [objects](/guides/objects.md) guide for more details. ```ts // Change this const value = mask(input, object({ key: string() })); // To this const value = v.parse(v.object({ key: v.string() }), input); ``` ##### Error details Superstruct's `StructError` provides a `failures` method that returns all validation failures. In Valibot, the issues are directly available on the result of [`safeParse`](/api/safeParse.md) or via the `issues` property of a [`ValiError`](/api/ValiError.md). The [`flatten`](/api/flatten.md), [`summarize`](/api/summarize.md) and [`getDotPath`](/api/getDotPath.md) methods help you work with them. See the [issues](/guides/issues.md) guide for more details. ##### Async validation Superstruct does not support asynchronous validation. With Valibot, you get it for free. Functions like [`pipeAsync`](/api/pipeAsync.md) and [`checkAsync`](/api/checkAsync.md) allow you to run asynchronous logic, such as database checks, as part of your schema. See the [async guide](/guides/async-validation.md) for more details. ### Migrate from io-ts Migrating from [io-ts](https://github.com/gcanti/io-ts) to Valibot is straightforward in most cases since both libraries build schemas by composing small functions. A big difference is that Valibot does not depend on fp-ts. Instead of working with `Either` and functional combinators, you work with plain result objects. The following guide will help you migrate step by step and also point out important differences. #### Replace imports The first thing to do after [installing](/guides/installation.md) Valibot is to update your imports. Just change your io-ts imports to Valibot's and replace all occurrences of `t.` with `v.`. The imports from fp-ts are no longer needed. ```ts // Change this import * as t from 'io-ts'; import { isRight } from 'fp-ts/Either'; const Schema = t.type({ key: t.string }); // To this import * as v from 'valibot'; const Schema = v.looseObject({ key: v.string() }); ``` #### Restructure code Instead of calling `.decode` on the codec, you pass the schema as the first argument to [`safeParse`](/api/safeParse.md). Where io-ts returns an `Either` that you inspect with `isRight` or `fold`, Valibot returns a result object with a `success` property that narrows the type when checked. ```ts // Change this const result = Schema.decode(input); if (isRight(result)) { console.log(result.right); } else { console.log(PathReporter.report(result)); } // To this const result = v.safeParse(Schema, input); if (result.success) { console.log(result.output); } else { console.log(v.summarize(result.issues)); } ``` If you prefer an exception to be thrown on invalid input, use [`parse`](/api/parse.md) instead. The `.is` method of a codec maps directly to the [`is`](/api/is.md) method. ```ts // Change this if (Schema.is(input)) { // input is typed } // To this if (v.is(Schema, input)) { // input is typed } ``` To further validate a value, io-ts uses `t.brand` or `t.refinement`. In Valibot you use [pipelines](/guides/pipelines.md) instead. This is a function that starts with a schema and is followed by up to 19 validation or transformation actions. ```ts // Change this const Positive = t.brand( t.number, (input): input is t.Branded => input > 0, 'Positive' ); // To this const Positive = v.pipe( v.number(), v.check((input) => input > 0), v.brand('Positive') ); ``` We recommend that you read our [mental model](/guides/mental-model.md) guide to understand how the individual functions of Valibot's modular API work together. #### Optional properties io-ts has no dedicated way to mark a single property as optional. The common workaround is an intersection of `t.type` and `t.partial`. In Valibot, you simply wrap optional entries with [`optional`](/api/optional.md), which usually reduces the schema to a single object. ```ts // Change this const Schema = t.intersection([ t.type({ name: t.string }), t.partial({ age: t.number }), ]); // To this const Schema = v.looseObject({ name: v.string(), age: v.optional(v.number()), }); ``` #### Change names Many of the names are the same as in io-ts. However, there are some exceptions. The following table shows all names that have changed. | io-ts | Valibot | | --------------- | -------------------------------------------------------------------------------------------- | | `brand` | [`check`](/api/check.md) with [`brand`](/api/brand.md) | | `decode` | [`safeParse`](/api/safeParse.md), [`parse`](/api/parse.md) | | `exact` | [`object`](/api/object.md) | | `Int` | [`number`](/api/number.md) with [`integer`](/api/integer.md) | | `interface` | [`looseObject`](/api/looseObject.md) | | `intersection` | [`intersect`](/api/intersect.md) | | `keyof` | [`picklist`](/api/picklist.md) | | `OutputOf` | [`InferInput`](/api/InferInput.md) | | `PathReporter` | [`summarize`](/api/summarize.md), [`flatten`](/api/flatten.md) | | `readonlyArray` | [`array`](/api/array.md) with [`readonly`](/api/readonly.md) | | `recursion` | [`lazy`](/api/lazy.md) | | `refinement` | [`check`](/api/check.md) | | `strict` | [`object`](/api/object.md) | | `type` | [`looseObject`](/api/looseObject.md) | | `TypeOf` | [`InferOutput`](/api/InferOutput.md) | | `UnknownArray` | [`array`](/api/array.md) with [`unknown`](/api/unknown.md) | | `UnknownRecord` | [`record`](/api/record.md) with [`unknown`](/api/unknown.md) | #### Other details Below are some more details that may be helpful when migrating from io-ts to Valibot. ##### Unknown object keys io-ts keeps unknown keys when validating objects with `t.type` and removes them when the codec is wrapped with `t.exact` or created with `t.strict`. Valibot's [`looseObject`](/api/looseObject.md) and [`object`](/api/object.md) schemas match these two behaviors. In addition, [`strictObject`](/api/strictObject.md) allows you to reject unknown keys entirely, which io-ts does not support out of the box. See the [objects](/guides/objects.md) guide for more details. ```ts // Change this const Schema = t.strict({ key: t.string }); // To this const Schema = v.object({ key: v.string() }); ``` ##### Custom codecs Custom codecs created with `new t.Type` are usually replaced by a pipeline that validates the input and then transforms it. Note that Valibot only covers the decode direction. There is no equivalent to `.encode`, as Valibot does not support transforming in the reverse direction. ```ts // Change this const DateFromString = new t.Type( 'DateFromString', (input): input is Date => input instanceof Date, (input, context) => { if (typeof input !== 'string') return t.failure(input, context); const date = new Date(input); return isNaN(date.getTime()) ? t.failure(input, context) : t.success(date); }, (date) => date.toISOString() ); // To this const DateFromString = v.pipe(v.string(), v.isoTimestamp(), v.toDate()); ``` ##### Async validation The core of io-ts is synchronous. Valibot additionally provides dedicated async functions like [`pipeAsync`](/api/pipeAsync.md) and [`checkAsync`](/api/checkAsync.md) that allow you to run asynchronous logic, such as database checks, as part of your schema. See the [async guide](/guides/async-validation.md) for more details. ## Schemas (API) ### any Creates an any schema. > This schema function exists only for completeness and is not recommended in practice. Instead, [`unknown`](/api/unknown.md) should be used to accept unknown data. ```ts const Schema = v.any(); ``` #### Returns - `Schema` `AnySchema` #### Related The following APIs can be combined with `any`. ##### Schemas [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toBigint`](/api/toBigint.md), [`toBoolean`](/api/toBoolean.md), [`toCamelCase`](/api/toCamelCase.md), [`toDate`](/api/toDate.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toNumber`](/api/toNumber.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toString`](/api/toString.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### array Creates an array schema. ```ts const Schema = v.array(item, message); ``` #### Generics - `TItem` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `item` `TItem` - `message` `TMessage` ##### 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`](/api/tuple.md) for a more precise typing. #### Returns - `Schema` `ArraySchema` #### 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 [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`empty`](/api/empty.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`includes`](/api/includes.md), [`length`](/api/length.md), [`mapItems`](/api/mapItems.md), [`maxLength`](/api/maxLength.md), [`metadata`](/api/metadata.md), [`minLength`](/api/minLength.md), [`nonEmpty`](/api/nonEmpty.md), [`notLength`](/api/notLength.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### bigint Creates a bigint schema. ```ts const Schema = v.bigint(message); ``` #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### 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` `BigintSchema` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`ltValue`](/api/ltValue.md), [`maxValue`](/api/maxValue.md), [`metadata`](/api/metadata.md), [`minValue`](/api/minValue.md), [`multipleOf`](/api/multipleOf.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`toBoolean`](/api/toBoolean.md), [`toDate`](/api/toDate.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toNumber`](/api/toNumber.md), [`toString`](/api/toString.md), [`transform`](/api/transform.md), [`value`](/api/value.md), [`values`](/api/values.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### 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` `BlobSchema` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxSize`](/api/maxSize.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minSize`](/api/minSize.md), [`notSize`](/api/notSize.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`size`](/api/size.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### boolean Creates a boolean schema. ```ts const Schema = v.boolean(message); ``` #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### 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`](/api/pipe.md) to force `true` or `false` as a value, in most cases it makes more sense to use [`literal`](/api/literal.md) for better typing. #### Returns - `Schema` `BooleanSchema` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`ltValue`](/api/ltValue.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`minValue`](/api/minValue.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`transform`](/api/transform.md), [`value`](/api/value.md), [`values`](/api/values.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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` `extends any` - `TMessage` `extends ErrorMessage | undefined = ErrorMessage | undefined` #### Parameters - `check` `(input: unknown) => boolean` - `message` `TMessage` ##### 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` `CustomSchema` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toBigint`](/api/toBigint.md), [`toBoolean`](/api/toBoolean.md), [`toCamelCase`](/api/toCamelCase.md), [`toDate`](/api/toDate.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toNumber`](/api/toNumber.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toString`](/api/toString.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### date Creates a date schema. ```ts const Schema = v.date(message); ``` #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### 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` `DateSchema` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`ltValue`](/api/ltValue.md), [`maxValue`](/api/maxValue.md), [`metadata`](/api/metadata.md), [`minValue`](/api/minValue.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`transform`](/api/transform.md), [`value`](/api/value.md), [`values`](/api/values.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### enum Creates an enum schema. ```ts const Schema = v.enum(enum, message); ``` #### Generics - `TEnum` `extends Enum` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `enum` `TEnum` - `message` `TMessage` ##### 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` `EnumSchema` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### exactOptional Creates an exact optional schema. ```ts const Schema = v.exactOptional(wrapped, default_); ``` #### Generics - `TWrapped` `extends BaseSchema>` - `TDefault` `extends Default` #### Parameters - `wrapped` `TWrapped` - `default_` `TDefault` ##### 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. > **Important**: When used in object schemas, if a key is missing and no `default_` value is provided, the schema's pipe (including transformations) will not be executed. To ensure pipes run for missing keys, provide a `default_` value. > The difference to [`optional`](/api/optional.md) 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` `ExactOptionalSchema` #### 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`](/api/unwrap.md) to undo the effect of `exactOptional`. ```ts const OptionalNumberSchema = v.exactOptional(v.number()); const NumberSchema = v.unwrap(OptionalNumberSchema); ``` ##### Exact optional with pipes When using `exactOptional` in a [`pipe`](/api/pipe.md), the pipe actions only execute if a `default_` value is provided or the key is present. This applies to all pipe actions including [`transform`](/api/transform.md), [`check`](/api/check.md), and others. ```ts const SchemaWithoutDefault = v.object({ isEnabled: v.pipe( v.exactOptional(v.string()), v.transform((value) => value === '1') // Does not run for missing keys ), }); // Output type: { isEnabled?: boolean } const SchemaWithDefault = v.object({ isEnabled: v.pipe( v.exactOptional(v.string(), '0'), // Default value provided v.transform((value) => value === '1') // Runs for missing keys too ), }); // Output type: { isEnabled: boolean } ``` #### Related The following APIs can be combined with `exactOptional`. ##### Schemas [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### 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` `FileSchema` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxSize`](/api/maxSize.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minSize`](/api/minSize.md), [`notSize`](/api/notSize.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`size`](/api/size.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### function Creates a function schema. ```ts const Schema = v.function(message); ``` #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### 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` `FunctionSchema` #### Related The following APIs can be combined with `function`. ##### Schemas [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### instance Creates an instance schema. ```ts const Schema = v.instance(class_, message); ``` #### Generics - `TClass` `extends Class` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `class_` `TClass` - `message` `TMessage` ##### 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` `InstanceSchema` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`gtValue`](/api/gtValue.md), [`ltValue`](/api/ltValue.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`size`](/api/size.md), [`title`](/api/title.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`transform`](/api/transform.md), [`value`](/api/value.md), [`values`](/api/values.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### intersect Creates an intersect schema. > I recommend to read the [intersections guide](/guides/intersections.md) before using this schema function. ```ts const Schema = v.intersect(options, message); ``` #### Generics - `TOptions` `extends IntersectOptions` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `options` `TOptions` - `message` `TMessage` ##### 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` `IntersectSchema` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toCamelCase`](/api/toCamelCase.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### lazy Creates a lazy schema. ```ts const Schema = v.lazy(getter); ``` #### Generics - `TWrapped` `extends BaseSchema>` #### Parameters - `getter` `(input: unknown) => TWrapped` ##### 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`](/api/GenericSchema.md). Please see the examples below. #### Returns - `Schema` `LazySchema` #### 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`](/api/union.md) and [`variant`](/api/variant.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`undefined`](/api/undefined.md), [`union`](/api/union.md), [`undefinedable`](/api/undefinedable.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toCamelCase`](/api/toCamelCase.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### literal Creates a literal schema. ```ts const Schema = v.literal(literal, message); ``` #### Generics - `TLiteral` `extends Literal` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `literal` `TLiteral` - `message` `TMessage` ##### 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` `LiteralSchema` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### looseObject Creates a loose object schema. ```ts const Schema = v.looseObject(entries, message); ``` #### Generics - `TEntries` `extends ObjectEntries` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `entries` `TEntries` - `message` `TMessage` ##### 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`](/api/object.md) 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` `LooseObjectSchema` #### Examples The following examples show how `looseObject` can be used. Please see the [object guide](/guides/objects.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`forward`](/api/forward.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### looseTuple Creates a loose tuple schema. ```ts const Schema = v.looseTuple(items, message); ``` #### Generics - `TItems` `extends TupleItems` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `items` `TItems` - `message` `TMessage` ##### 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`](/api/tuple.md) is that this schema does include unknown items into the output. #### Returns - `Schema` `LooseTupleSchema` #### Examples The following examples show how `looseTuple` can be used. Please see the [arrays guide](/guides/arrays.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`empty`](/api/empty.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`includes`](/api/includes.md), [`length`](/api/length.md), [`mapItems`](/api/mapItems.md), [`maxLength`](/api/maxLength.md), [`metadata`](/api/metadata.md), [`minLength`](/api/minLength.md), [`nonEmpty`](/api/nonEmpty.md), [`notLength`](/api/notLength.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### map Creates a map schema. ```ts const Schema = v.map(key, value, message); ``` #### Generics - `TKey` `extends BaseSchema>` - `TValue` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `key` `TKey` - `value` `TValue` - `message` `TMessage` ##### Explanation With `map` you can validate the data type of the input and whether the entries matches `key` and `value`. If the input is not a map, you can use `message` to customize the error message. #### Returns - `Schema` `MapSchema` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxSize`](/api/maxSize.md), [`metadata`](/api/metadata.md), [`minSize`](/api/minSize.md), [`notSize`](/api/notSize.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`size`](/api/size.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### nan Creates a NaN schema. ```ts const Schema = v.nan(message); ``` #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### 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` `NanSchema` #### Related The following APIs can be combined with `nan`. ##### Schemas [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### never Creates a never schema. ```ts const Schema = v.never(message); ``` #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### Explanation When validated, `never` always returns an issue. You can use `message` to customize the error message. #### Returns - `Schema` `NeverSchema` #### Related The following APIs can be combined with `never`. ##### Schemas [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### nonNullable Creates a non nullable schema. > This schema function can be used to override the behavior of [`nullable`](/api/nullable.md). ```ts const Schema = v.nonNullable(wrapped, message); ``` #### Generics - `TWrapped` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `wrapped` `TWrapped` - `message` `TMessage` ##### 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` `NonNullableSchema` #### 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`](/api/unwrap.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### nonNullish Creates a non nullish schema. > This schema function can be used to override the behavior of [`nullish`](/api/nullish.md). ```ts const Schema = v.nonNullish(wrapped, message); ``` #### Generics - `TWrapped` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `wrapped` `TWrapped` - `message` `TMessage` ##### 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` `NonNullishSchema` #### 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`](/api/unwrap.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### nonOptional Creates a non optional schema. > This schema function can be used to override the behavior of [`optional`](/api/optional.md). ```ts const Schema = v.nonOptional(wrapped, message); ``` #### Generics - `TWrapped` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `wrapped` `TWrapped` - `message` `TMessage` ##### 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` `NonOptionalSchema` #### 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`](/api/unwrap.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### null Creates a null schema. ```ts const Schema = v.null(message); ``` #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### 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` `NullSchema` #### Related The following APIs can be combined with `null`. ##### Schemas [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### nullable Creates a nullable schema. ```ts const Schema = v.nullable(wrapped, default_); ``` #### Generics - `TWrapped` `extends BaseSchema>` - `TDefault` `extends Default` #### Parameters - `wrapped` `TWrapped` - `default_` `TDefault` ##### 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`](/api/optional.md), and if you want to accept `null` and `undefined` inputs, use [`nullish`](/api/nullish.md) instead. Also, if you want to set a default output value for any invalid input, you should use [`fallback`](/api/fallback.md) instead. #### Returns - `Schema` `NullableSchema` #### 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`](/api/unwrap.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### nullish Creates a nullish schema. ```ts const Schema = v.nullish(wrapped, default_); ``` #### Generics - `TWrapped` `extends BaseSchema>` - `TDefault` `extends Default` #### Parameters - `wrapped` `TWrapped` - `default_` `TDefault` ##### 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. > **Important**: When used in object schemas, if a key is missing and no `default_` value is provided, the schema's pipe (including transformations) will not be executed. To ensure pipes run for missing keys, provide a `default_` value. > Note that `nullish` accepts `undefined` and `null` as an input. If you want to accept only `null` inputs, use [`nullable`](/api/nullable.md), and if you want to accept only `undefined` inputs, use [`optional`](/api/optional.md) instead. Also, if you want to set a default output value for any invalid input, you should use [`fallback`](/api/fallback.md) instead. #### Returns - `Schema` `NullishSchema` #### 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()), }); ``` ##### Default to `undefined` By default, when an object input is missing a nullish entry, the corresponding key is omitted from the output. To always include the key in the output with an `undefined` value, pass a function that returns `undefined` as the `default_` parameter. ```ts const NullishEntrySchema = v.object({ key: v.nullish(v.string(), () => undefined), }); ``` ##### Unwrap nullish schema Use [`unwrap`](/api/unwrap.md) to undo the effect of `nullish`. ```ts const NullishNumberSchema = v.nullish(v.number()); const NumberSchema = v.unwrap(NullishNumberSchema); ``` ##### Nullish with pipes When using `nullish` in a [`pipe`](/api/pipe.md), missing object keys only execute the pipe if a `default_` value is provided. If the key is present with `null` or `undefined`, later pipe actions still run. ```ts const SchemaWithoutDefault = v.object({ value: v.pipe( v.nullish(v.string()), v.transform((input) => (input ?? 'hello').toUpperCase()) // Does not run for missing keys ), }); // Output type: { value?: string } const SchemaWithDefault = v.object({ value: v.pipe( v.nullish(v.string(), 'hello'), // Default value provided v.transform((input) => input.toUpperCase()) // Runs for missing keys, null, and undefined too ), }); // Output type: { value: string } ``` #### Related The following APIs can be combined with `nullish`. ##### Schemas [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### number Creates a number schema. ```ts const Schema = v.number(message); ``` #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### 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` `NumberSchema` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`integer`](/api/integer.md), [`ltValue`](/api/ltValue.md), [`maxValue`](/api/maxValue.md), [`metadata`](/api/metadata.md), [`minValue`](/api/minValue.md), [`multipleOf`](/api/multipleOf.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`safeInteger`](/api/safeInteger.md), [`title`](/api/title.md), [`toBoolean`](/api/toBoolean.md), [`toDate`](/api/toDate.md), [`toBigint`](/api/toBigint.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toString`](/api/toString.md), [`transform`](/api/transform.md), [`value`](/api/value.md), [`values`](/api/values.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### object Creates an object schema. ```ts const Schema = v.object(entries, message); ``` #### Generics - `TEntries` `extends ObjectEntries` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `entries` `TEntries` - `message` `TMessage` ##### 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`](/api/looseObject.md). To return an issue for unknown entries, use [`strictObject`](/api/strictObject.md). To include and validate unknown entries, use [`objectWithRest`](/api/objectWithRest.md). #### Returns - `Schema` `ObjectSchema` #### Examples The following examples show how `object` can be used. Please see the [object guide](/guides/objects.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`forward`](/api/forward.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### objectWithRest Creates an object with rest schema. ```ts const Schema = v.objectWithRest( entries, rest, message ); ``` #### Generics - `TEntries` `extends ObjectEntries` - `TRest` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `entries` `TEntries` - `rest` `TRest` - `message` `TMessage` ##### 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`](/api/object.md) 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` `ObjectWithRestSchema` #### Examples The following examples show how `objectWithRest` can be used. Please see the [object guide](/guides/objects.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`forward`](/api/forward.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### optional Creates an optional schema. ```ts const Schema = v.optional(wrapped, default_); ``` #### Generics - `TWrapped` `extends BaseSchema>` - `TDefault` `extends Default` #### Parameters - `wrapped` `TWrapped` - `default_` `TDefault` ##### 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. > **Important**: When used in object schemas, if a key is missing and no `default_` value is provided, the schema's pipe (including transformations) will not be executed. To ensure pipes run for missing keys, provide a `default_` value. > Note that `optional` does not accept `null` as an input. If you want to accept `null` inputs, use [`nullable`](/api/nullable.md), and if you want to accept `null` and `undefined` inputs, use [`nullish`](/api/nullish.md) instead. Also, if you want to set a default output value for any invalid input, you should use [`fallback`](/api/fallback.md) instead. #### Returns - `Schema` `OptionalSchema` #### 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()), }); ``` ##### Default to `undefined` By default, when an object input is missing an optional entry, the corresponding key is omitted from the output. To always include the key in the output with an `undefined` value, pass a function that returns `undefined` as the `default_` parameter. ```ts const OptionalEntrySchema = v.object({ key: v.optional(v.string(), () => undefined), }); ``` ##### Unwrap optional schema Use [`unwrap`](/api/unwrap.md) to undo the effect of `optional`. ```ts const OptionalNumberSchema = v.optional(v.number()); const NumberSchema = v.unwrap(OptionalNumberSchema); ``` ##### Optional with pipes When using `optional` in a [`pipe`](/api/pipe.md), the pipe actions only execute if a `default_` value is provided or the key is present. This applies to all pipe actions including [`transform`](/api/transform.md), [`check`](/api/check.md), and others. ```ts const SchemaWithoutDefault = v.object({ isActive: v.pipe( v.optional(v.string()), v.transform((value) => value === 'true') // Does not run for missing keys ), }); // Output type: { isActive?: boolean } const SchemaWithDefault = v.object({ isActive: v.pipe( v.optional(v.string(), 'false'), // Default value provided v.transform((value) => value === 'true') // Runs for missing keys too ), }); // Output type: { isActive: boolean } ``` #### Related The following APIs can be combined with `optional`. ##### Schemas [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### picklist Creates a picklist schema. ```ts const Schema = v.picklist(options, message); ``` #### Generics - `TOptions` `extends PicklistOptions` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `options` `TOptions` - `message` `TMessage` ##### 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`](/api/enum.md). However, in many cases it is easier to use because you can pass an array of values instead of an enum. #### Returns - `Schema` `PicklistSchema` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### promise Creates a promise schema. ```ts const Schema = v.promise(message); ``` #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### 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` `PromiseSchema` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`awaitAsync`](/api/awaitAsync.md), [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### record Creates a record schema. ```ts const Schema = v.record(key, value, message); ``` #### Generics - `TKey` `extends BaseSchema>` - `TValue` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `key` `TKey` - `value` `TValue` - `message` `TMessage` ##### 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`](/api/string.md), [`enum`](/api/enum.md) and [`picklist`](/api/picklist.md). However, if [`enum`](/api/enum.md) and [`picklist`](/api/picklist.md) are used, it is better to use [`object`](/api/object.md) with [`entriesFromList`](/api/entriesFromList.md) 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` `RecordSchema` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`minEntries`](/api/minEntries.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### set Creates a set schema. ```ts const Schema = v.set(value, message); ``` #### Generics - `TValue` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `value` `TValue` - `message` `TMessage` ##### 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` `SetSchema` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxSize`](/api/maxSize.md), [`metadata`](/api/metadata.md), [`minSize`](/api/minSize.md), [`notSize`](/api/notSize.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`size`](/api/size.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### strictObject Creates a strict object schema. ```ts const Schema = v.strictObject(entries, message); ``` #### Generics - `TEntries` `extends ObjectEntries` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `entries` `TEntries` - `message` `TMessage` ##### 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`](/api/object.md) 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`](/api/objectWithRest.md) schema with [`never`](/api/never.md) for the `rest` argument. #### Returns - `Schema` `StrictObjectSchema` #### Examples The following examples show how `strictObject` can be used. Please see the [object guide](/guides/objects.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`forward`](/api/forward.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### strictTuple Creates a strict tuple schema. ```ts const Schema = v.strictTuple(items, message); ``` #### Generics - `TItems` `extends TupleItems` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `items` `TItems` - `message` `TMessage` ##### 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`](/api/tuple.md) 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`](/api/tupleWithRest.md) schema with [`never`](/api/never.md) for the `rest` argument. #### Returns - `Schema` `StrictTupleSchema` #### Examples The following examples show how `strictTuple` can be used. Please see the [arrays guide](/guides/arrays.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`empty`](/api/empty.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`includes`](/api/includes.md), [`length`](/api/length.md), [`mapItems`](/api/mapItems.md), [`maxLength`](/api/maxLength.md), [`metadata`](/api/metadata.md), [`minLength`](/api/minLength.md), [`nonEmpty`](/api/nonEmpty.md), [`notLength`](/api/notLength.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### string Creates a string schema. ```ts const Schema = v.string(message); ``` #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### 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` `StringSchema` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`check`](/api/check.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`excludes`](/api/excludes.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`regex`](/api/regex.md), [`rfcEmail`](/api/rfcEmail.md), [`slug`](/api/slug.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toBigint`](/api/toBigint.md), [`toBoolean`](/api/toBoolean.md), [`toCamelCase`](/api/toCamelCase.md), [`toDate`](/api/toDate.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toNumber`](/api/toNumber.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### symbol Creates a symbol schema. ```ts const Schema = v.symbol(message); ``` #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### 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` `SymbolSchema` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### tuple Creates a tuple schema. ```ts const Schema = v.tuple(items, message); ``` #### Generics - `TItems` `extends TupleItems` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `items` `TItems` - `message` `TMessage` ##### 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`](/api/looseTuple.md). To return an issue for unknown items, use [`strictTuple`](/api/strictTuple.md). To include and validate unknown items, use [`tupleWithRest`](/api/tupleWithRest.md). #### Returns - `Schema` `TupleSchema` #### Examples The following examples show how `tuple` can be used. Please see the [arrays guide](/guides/arrays.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`empty`](/api/empty.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`includes`](/api/includes.md), [`length`](/api/length.md), [`mapItems`](/api/mapItems.md), [`maxLength`](/api/maxLength.md), [`metadata`](/api/metadata.md), [`minLength`](/api/minLength.md), [`nonEmpty`](/api/nonEmpty.md), [`notLength`](/api/notLength.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### tupleWithRest Creates a tuple with rest schema. ```ts const Schema = v.tupleWithRest(items, rest, message); ``` #### Generics - `TItems` `extends TupleItems` - `TRest` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `items` `TItems` - `rest` `TRest` - `message` `TMessage` ##### 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` `TupleWithRestSchema` #### Examples The following examples show how `tupleWithRest` can be used. Please see the [arrays guide](/guides/arrays.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`empty`](/api/empty.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`includes`](/api/includes.md), [`length`](/api/length.md), [`mapItems`](/api/mapItems.md), [`maxLength`](/api/maxLength.md), [`metadata`](/api/metadata.md), [`minLength`](/api/minLength.md), [`nonEmpty`](/api/nonEmpty.md), [`notLength`](/api/notLength.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### undefined Creates an undefined schema. ```ts const Schema = v.undefined(message); ``` #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### 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` `UndefinedSchema` #### Related The following APIs can be combined with `undefined`. ##### Schemas [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### undefinedable Creates an undefinedable schema. ```ts const Schema = v.undefinedable(wrapped, default_); ``` #### Generics - `TWrapped` `extends BaseSchema>` - `TDefault` `extends Default` #### Parameters - `wrapped` `TWrapped` - `default_` `TDefault` ##### 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`](/api/optional.md) at runtime. The only difference is the input and output type when used for object entries. While [`optional`](/api/optional.md) 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`](/api/nullable.md), and if you want to accept `null` and `undefined` inputs, use [`nullish`](/api/nullish.md) instead. Also, if you want to set a default output value for any invalid input, you should use [`fallback`](/api/fallback.md) instead. #### Returns - `Schema` `UndefinedableSchema` #### 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`](/api/unwrap.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### union Creates an union schema. > I recommend that you read the [unions guide](/guides/unions.md) before using this schema function. ```ts const Schema = v.union(options, message); ``` #### Generics - `TOptions` `extends UnionOptions` - `TMessage` `extends ErrorMessage>> | undefined` #### Parameters - `options` `TOptions` - `message` `TMessage` ##### 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` `UnionSchema` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toCamelCase`](/api/toCamelCase.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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` `UnknownSchema` #### Related The following APIs can be combined with `unknown`. ##### Schemas [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toBigint`](/api/toBigint.md), [`toBoolean`](/api/toBoolean.md), [`toCamelCase`](/api/toCamelCase.md), [`toDate`](/api/toDate.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toNumber`](/api/toNumber.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toString`](/api/toString.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### variant Creates a variant schema. ```ts const Schema = v.variant(key, options, message); ``` #### Generics - `TKey` `extends string` - `TOptions` `extends VariantOptions` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `key` `TKey` - `options` `TOptions` - `message` `TMessage` ##### 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` `VariantSchema` #### 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 [`object`](/api/object.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### void Creates a void schema. ```ts const Schema = v.void(message); ``` #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `message` `TMessage` ##### 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` `VoidSchema` #### Related The following APIs can be combined with `void`. ##### Schemas [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ## Methods (API) ### 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` `extends BaseSchema>` #### Parameters - `schema` `TSchema` - `input` `unknown` ##### 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`](/api/parse.md) and [`safeParse`](/api/safeParse.md). #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`unwrap`](/api/unwrap.md) ### cache Creates a version of a schema that caches its output. ```ts const Schema = v.cache(schema, config); ``` #### Generics - `TSchema` `extends BaseSchema>` - `TCacheConfig` `extends CacheConfig | undefined` #### Parameters - `schema` `TSchema` - `config` `TCacheConfig` ##### Explanation The `cache` method creates a version of the given `schema` that caches its output. This can be useful for performance optimization, for example when validation performs an expensive computation or complex parsing that you want to avoid repeating for the same input. > Hint: Primitive inputs are cached by value. Object and function inputs are cached by reference identity, so mutating input objects and reusing the same reference can return a stale cached dataset. Returned objects are also reused by reference, so mutating cached output can affect later cache hits. For best results, use `cache` with immutable inputs and avoid mutating returned cached objects. #### Returns - `Schema` `SchemaWithCache` #### Examples The following examples show how `cache` can be used. ##### Cache schema Schema that caches its output. ```ts const CacheSchema = v.cache(v.string()); ``` ##### Max size schema Schema that caches its output for a maximum of 100 items. ```ts const MaxSizeSchema = v.cache(v.string(), { maxSize: 100 }); ``` ##### Max age schema Schema that caches its output for a maximum of 10 seconds. ```ts const MaxAgeSchema = v.cache(v.string(), { maxAge: 10_000 }); ``` #### Related The following APIs can be combined with `cache`. ##### Schemas [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`message`](/api/message.md), [`unwrap`](/api/unwrap.md) ### config Changes the local configuration of a schema. ```ts const Schema = v.config(schema, config); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `schema` `TSchema` - `config` `Config>` ##### Explanation This method overwrites the selected configuration properties by merging the previous configuration of the `schema` with the provided `config`. #### Returns - `Schema` `TSchema` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toCamelCase`](/api/toCamelCase.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`partialAsync`](/api/partialAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### fallback Returns a fallback value as output if the input does not match the schema. ```ts const Schema = v.fallback(schema, fallback); ``` #### Generics - `TSchema` `extends BaseSchema>` - `TFallback` `extends Fallback` #### Parameters - `schema` `TSchema` - `fallback` `TFallback` ##### 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`](/api/optional.md), [`nullable`](/api/nullable.md) or [`nullish`](/api/nullish.md) instead. > The fallback value is not validated. Make sure that the fallback value matches your schema. #### Returns - `Schema` `SchemaWithFallback` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toCamelCase`](/api/toCamelCase.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### flatten Flatten the error messages of issues. ```ts const errors = v.flatten(issues); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `issues` `[InferIssue, ...InferIssue[]]` ##### 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` `FlatErrors` #### 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 [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`safeParse`](/api/safeParse.md) ### forward Forwards the issues of the passed validation action. ```ts const Action = v.forward(action, path); ``` #### Generics - `TInput` `extends Record | ArrayLike` - `TIssue` `extends BaseIssue` - `TPath` `extends RequiredPath` #### Parameters - `action` `BaseValidation` - `path` `ValidPath` ##### Explanation `forward` allows you to forward the issues of the passed validation `action` via `path` to a nested field of a schema. #### Returns - `Action` `BaseValidation` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`record`](/api/record.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md) ##### Methods [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md) ##### Actions [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`empty`](/api/empty.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`guard`](/api/guard.md), [`includes`](/api/includes.md), [`length`](/api/length.md), [`mapItems`](/api/mapItems.md), [`maxLength`](/api/maxLength.md), [`metadata`](/api/metadata.md), [`minLength`](/api/minLength.md), [`nonEmpty`](/api/nonEmpty.md), [`notLength`](/api/notLength.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`reduceItems`](/api/reduceItems.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### getDefault Returns the default value of the schema. ```ts const value = v.getDefault(schema, dataset, config); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `schema` `TSchema` - `dataset` `UnknownDataset | undefined` - `config` `Config> | undefined` #### Returns - `value` `InferDefault` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`unwrap`](/api/unwrap.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`partialAsync`](/api/partialAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### getDefaults Returns the default values of the schema. > The difference to [`getDefault`](/api/getDefault.md) 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` `extends BaseSchema>` #### Parameters - `schema` `TSchema` #### Returns - `values` `InferDefaults` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`unwrap`](/api/unwrap.md) ### 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` `extends BaseSchema> | BaseSchemaAsync> | SchemaWithPipe>, ...(PipeItem> | DescriptionAction)[]]> | SchemaWithPipeAsync> | BaseSchemaAsync>, ...(PipeItem> | PipeItemAsync> | DescriptionAction)[]]>` #### Parameters - `schema` `TSchema` #### Returns - `description` `string | undefined` #### 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 [`description`](/api/description.md) ### getExamples Returns the examples of the schema. > If multiple examples are defined, it concatenates them using depth-first search. If no examples are defined, an empty array is returned. ```ts const examples = v.getExamples(schema); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `schema` `TSchema` #### Returns - `examples` `InferExamples` #### Examples The following examples show how `getExamples` can be used. ##### String schema ```ts const StringSchema = v.pipe(v.string(), v.examples(['foo', 'bar', 'baz'])); const examples = v.getExamples(StringSchema); // ['foo', 'bar', 'baz'] ``` ##### Nested schema ```ts const NestedSchema = v.pipe( v.string(), v.examples(['foo', 'bar', 'baz']), v.pipe(v.string(), v.examples(['qux', 'quux'])) ); const examples = v.getExamples(NestedSchema); // ['foo', 'bar', 'baz', 'qux', 'quux'] ``` #### Related The following APIs can be combined with `getExamples`. ##### Schemas [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`pipe`](/api/pipe.md) ##### Actions [`examples`](/api/examples.md) ### getFallback Returns the fallback value of the schema. ```ts const value = v.getFallback(schema, dataset, config); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `schema` `TSchema` - `dataset` `OutputDataset, InferIssue> | undefined` - `config` `Config> | undefined` #### Returns - `value` `InferFallback` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`unwrap`](/api/unwrap.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`partialAsync`](/api/partialAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### getFallbacks Returns the fallback values of the schema. > The difference to [`getFallback`](/api/getFallback.md) 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` `extends BaseSchema>` #### Parameters - `schema` `TSchema` #### Returns - `values` `InferFallbacks` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`unwrap`](/api/unwrap.md) ### 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` `extends BaseSchema> | BaseSchemaAsync> | SchemaWithPipe>, ...(PipeItem> | MetadataAction)[]]> | SchemaWithPipeAsync> | BaseSchemaAsync>, ...(PipeItem> | PipeItemAsync> | MetadataAction)[]]>` #### Parameters - `schema` `TSchema` #### Returns - `metadata` `InferMetadata` #### 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 [`metadata`](/api/metadata.md) ### 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` `extends BaseSchema> | BaseSchemaAsync> | SchemaWithPipe>, ...(PipeItem> | TitleAction)[]]> | SchemaWithPipeAsync> | BaseSchemaAsync>, ...(PipeItem> | PipeItemAsync> | TitleAction)[]]>` #### Parameters - `schema` `TSchema` #### Returns - `title` `string | undefined` #### 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 [`title`](/api/title.md) ### 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` `extends BaseSchema>` #### Parameters - `schema` `TSchema` - `input` `unknown` ##### 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`](/api/parse.md) and [`safeParse`](/api/safeParse.md). #### Returns - `result` `boolean` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`unwrap`](/api/unwrap.md) ### keyof Creates a picklist schema of object keys. ```ts const Schema = v.keyof(schema, message); ``` #### Generics - `TSchema` `extends LooseObjectSchema | undefined> | LooseObjectSchemaAsync | undefined> | ObjectSchema | undefined> | ObjectSchemaAsync | undefined> | ObjectWithRestSchema>, ErrorMessage | undefined> | ObjectWithRestSchemaAsync> | BaseSchemaAsync>, ErrorMessage | undefined> | StrictObjectSchema | undefined> | StrictObjectSchemaAsync | undefined>` - `TMessage` `ErrorMessage | undefined` #### Parameters - `schema` `TSchema` - `message` `TMessage` #### Returns - `Schema` `PicklistSchema>` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`partialAsync`](/api/partialAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### message Changes the local message configuration of a schema. ```ts const Schema = v.message(schema, message_); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `schema` `TSchema` - `message_` `ErrorMessage>` ##### 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` `TSchema` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toCamelCase`](/api/toCamelCase.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`partialAsync`](/api/partialAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### 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` `extends SchemaWithoutPipe | undefined> | LooseObjectSchemaAsync | undefined> | ObjectSchema | undefined> | ObjectSchemaAsync | undefined> | ObjectWithRestSchema>, ErrorMessage | undefined> | ObjectWithRestSchemaAsync> | BaseSchemaAsync>, ErrorMessage | undefined> | StrictObjectSchema | undefined> | StrictObjectSchemaAsync | undefined>>` - `TKeys` `extends ObjectKeys` #### Parameters - `schema` `TSchema` - `keys` `TKey` ##### 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`](/api/pipe.md) method, as this may cause runtime errors. Please use the [`pipe`](/api/pipe.md) method after you have modified the schema with `omit`. #### Returns - `Schema` `SchemaWithOmit` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`forward`](/api/forward.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`required`](/api/required.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialAsync`](/api/partialAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md) ### parse Parses an unknown input based on a schema. ```ts const output = v.parse(schema, input, config); ``` #### Generics - `TSchema` `extends BaseSchema>` #### Parameters - `schema` `TSchema` - `input` `unknown` - `config` `Config> | undefined` ##### Explanation `parse` will throw a [`ValiError`](/api/ValiError.md) 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` `InferOutput` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`flatten`](/api/flatten.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`summarize`](/api/summarize.md), [`unwrap`](/api/unwrap.md) ##### Utils [`getDotPath`](/api/getDotPath.md), [`isValiError`](/api/isValiError.md), [`ValiError`](/api/ValiError.md) ### parser Returns a function that parses an unknown input based on a schema. ```ts const parser = v.parser(schema, config); ``` #### Generics - `TSchema` `extends BaseSchema>` - `TConfig` `extends Config> | undefined` #### Parameters - `schema` `TSchema` - `config` `TConfig` #### Returns - `parser` `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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`flatten`](/api/flatten.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`summarize`](/api/summarize.md), [`unwrap`](/api/unwrap.md) ##### Utils [`getDotPath`](/api/getDotPath.md), [`isValiError`](/api/isValiError.md), [`ValiError`](/api/ValiError.md) ### 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` `extends SchemaWithoutPipe | undefined> | ObjectSchema | undefined> | ObjectWithRestSchema>, ErrorMessage | undefined> | StrictObjectSchema | undefined>>` - `TKeys` `extends ObjectKeys | undefined` #### Parameters - `schema` `TSchema` - `keys` `TKey` ##### 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`](/api/pipe.md) method, as this may cause runtime errors. Please use the [`pipe`](/api/pipe.md) method after you have modified the schema with `partial`. #### Returns - `Schema` `SchemaWithPartial` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`forward`](/api/forward.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pick`](/api/pick.md), [`required`](/api/required.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### pick Creates a modified copy of an object schema that contains only the selected entries. ```ts const Schema = v.pick(schema, keys); ``` #### Generics - `TSchema` `extends SchemaWithoutPipe | undefined> | LooseObjectSchemaAsync | undefined> | ObjectSchema | undefined> | ObjectSchemaAsync | undefined> | ObjectWithRestSchema>, ErrorMessage | undefined> | ObjectWithRestSchemaAsync> | BaseSchemaAsync>, ErrorMessage | undefined> | StrictObjectSchema | undefined> | StrictObjectSchemaAsync | undefined>>` - `TKeys` `extends ObjectKeys` #### Parameters - `schema` `TSchema` - `keys` `TKey` ##### 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`](/api/pipe.md) method, as this may cause runtime errors. Please use the [`pipe`](/api/pipe.md) method after you have modified the schema with `pick`. #### Returns - `Schema` `SchemaWithPick` #### 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( v.object({ key1: string(), key2: number(), key3: boolean(), }), ['key1', 'key3'] ); // { key1: string; key3: boolean } ``` #### Related The following APIs can be combined with `pick`. ##### Schemas [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`forward`](/api/forward.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`partial`](/api/partial.md), [`required`](/api/required.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialAsync`](/api/partialAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md) ### pipe Adds a pipeline to a schema, that can validate and transform its input. ```ts const Schema = v.pipe(schema, ...items); ``` #### Generics - `TSchema` `extends BaseSchema>` - `TItems` `extends readonly PipeItem>[]` #### Parameters - `schema` `TSchema` - `items` `TItems` ##### 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` `SchemaWithPipe` #### Examples The following examples show how `pipe` can be used. Please see the [pipeline guide](/guides/pipelines.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`forward`](/api/forward.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`required`](/api/required.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toBigint`](/api/toBigint.md), [`toBoolean`](/api/toBoolean.md), [`toCamelCase`](/api/toCamelCase.md), [`toDate`](/api/toDate.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toNumber`](/api/toNumber.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toString`](/api/toString.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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` `extends SchemaWithoutPipe | undefined> | ObjectSchema | undefined> | ObjectWithRestSchema>, ErrorMessage | undefined> | StrictObjectSchema | undefined>>` - `TKeys` `extends ObjectKeys` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `schema` `TSchema` - `keys` `TKey` - `message` `TMessage` ##### 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`](/api/pipe.md) method, as this may cause runtime errors. Please use the [`pipe`](/api/pipe.md) method after you have modified the schema with `required`. #### Returns - `AllKeysSchema` `SchemaWithRequired` - `SelectedKeysSchema` `SchemaWithRequired` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`forward`](/api/forward.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### safeParse Parses an unknown input based on a schema. ```ts const result = v.safeParse(schema, input, config); ``` #### Generics - `TSchema` `extends BaseSchema>` #### Parameters - `schema` `TSchema` - `input` `unknown` - `config` `Config> | undefined` #### Returns - `result` `SafeParseResult` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`flatten`](/api/flatten.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`summarize`](/api/summarize.md), [`unwrap`](/api/unwrap.md) ##### Utils [`getDotPath`](/api/getDotPath.md) ### safeParser Returns a function that parses an unknown input based on a schema. ```ts const safeParser = v.safeParser(schema, config); ``` #### Generics - `TSchema` `extends BaseSchema>` - `TConfig` `extends Config> | undefined` #### Parameters - `schema` `TSchema` - `config` `TConfig` #### Returns - `safeParser` `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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`flatten`](/api/flatten.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`summarize`](/api/summarize.md), [`unwrap`](/api/unwrap.md) ##### Utils [`getDotPath`](/api/getDotPath.md) ### summarize Summarize the error messages of issues in a pretty-printable multi-line string. ```ts const errors = v.summarize(issues); ``` #### Parameters - `issues` `[BaseIssue, ...BaseIssue[]]` ##### 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` `string` #### 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 [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`safeParse`](/api/safeParse.md) ### unwrap Unwraps the wrapped schema. ```ts const Schema = v.unwrap(schema); ``` #### Generics - `TSchema` `extends ExactOptionalSchema>, unknown> | ExactOptionalSchemaAsync> | BaseSchemaAsync>, unknown> | NonNullableSchema>, ErrorMessage | undefined> | NonNullableSchemaAsync> | BaseSchemaAsync>, ErrorMessage | undefined> | NonNullishSchema>, ErrorMessage | undefined> | NonNullishSchemaAsync> | BaseSchemaAsync>, ErrorMessage | undefined> | NonOptionalSchema>, ErrorMessage | undefined> | NonOptionalSchemaAsync> | BaseSchemaAsync>, ErrorMessage | undefined> | NullableSchema>, unknown> | NullableSchemaAsync> | BaseSchemaAsync>, unknown> | NullishSchema>, unknown> | NullishSchemaAsync> | BaseSchemaAsync>, unknown> | OptionalSchema>, unknown> | OptionalSchemaAsync> | BaseSchemaAsync>, unknown>` #### Parameters - `schema` `TSchema` #### Returns - `Schema` `TSchema['wrapped']` #### 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 [`exactOptional`](/api/exactOptional.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`optional`](/api/optional.md), [`undefinedable`](/api/undefinedable.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md) ## Actions (API) ### args Creates a function arguments transformation action. ```ts const Action = v.args(schema); ``` #### Generics - `TInput` `extends (...args: any[]) => unknown` - `TSchema` `extends LooseTupleSchema | undefined> | StrictTupleSchema | undefined> | TupleSchema | undefined> | TupleWithRestSchema>, ErrorMessage | undefined>` #### Parameters - `schema` `TSchema` ##### Explanation With `args` you can force the arguments of a function to match the given `schema`. #### Returns - `Action` `ArgsAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`looseTuple`](/api/looseTuple.md), [`function`](/api/function.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### base64 Creates a [Base64](https://en.wikipedia.org/wiki/Base64) validation action. ```ts const Action = v.base64(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `Base64Action` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### bic Creates a [BIC](https://en.wikipedia.org/wiki/ISO_9362) validation action. ```ts const Action = v.bic(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `BicAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### brand Creates a brand transformation action. ```ts const Action = v.brand(name); ``` #### Generics - `TInput` `extends any` - `TName` `extends BrandName` #### Parameters - `name` `TName` ##### 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` `BrandAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### bytes Creates a [bytes](https://en.wikipedia.org/wiki/Byte) validation action. ```ts const Action = v.bytes(requirement, message); ``` #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `BytesAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### check Creates a check validation action. ```ts const Action = v.check(requirement, message); ``` #### Generics - `TInput` `extends any` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `(input: TInput) => boolean` - `message` `TMessage` ##### 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` `CheckAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`forward`](/api/forward.md), [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### checkItems Creates a check items validation action. ```ts const Action = v.checkItems(requirement, message); ``` #### Generics - `TInput` `extends ArrayInput` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `ArrayRequirement` - `message` `TMessage` ##### 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` `CheckItemsAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### codePoints Creates a [code points](https://developer.mozilla.org/en-US/docs/Glossary/Code_point) validation action. ```ts const Action = v.codePoints( requirement, message ); ``` #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### Explanation With `codePoints` you can validate the number of Unicode code points in a string. Code points are not the same as UTF-16 code units or user-perceived characters (graphemes): `😀` consists of 2 UTF-16 code units, 1 code point, and 1 grapheme, while `👨🏽‍👩🏽` consists of 5 code points but 1 grapheme. If the number of code points does not match the `requirement`, you can use `message` to customize the error message. #### Returns - `Action` `CodePointsAction` #### Examples The following examples show how `codePoints` can be used. ##### Code points schema Schema to validate a string with 8 code points. ```ts const CodePointsSchema = v.pipe( v.string(), v.codePoints(8, 'Exactly 8 code points are required.') ); ``` #### Related The following APIs can be combined with `codePoints`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Actions [`graphemes`](/api/graphemes.md), [`length`](/api/length.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### creditCard Creates a [credit card](https://en.wikipedia.org/wiki/Payment_card_number) validation action. ```ts const Action = v.creditCard(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `CreditCardAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### cuid2 Creates a [Cuid2](https://github.com/paralleldrive/cuid2) validation action. ```ts const Action = v.cuid2(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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`](/api/length.md) to ensure the correct length. #### Returns - `Action` `Cuid2Action` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### decimal Creates a [decimal](https://en.wikipedia.org/wiki/Decimal) validation action. > The difference between `decimal` and [`digits`](/api/digits.md) is that `decimal` accepts floating point numbers and negative numbers, while [`digits`](/api/digits.md) accepts only the digits 0-9. ```ts const Action = v.decimal(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `DecimalAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### description Creates a description metadata action. ```ts const Action = v.description(description_); ``` #### Generics - `TInput` `extends any` - `TDescription` `extends string` #### Parameters - `description_` `TDescription` ##### 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` `DescriptionAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`getDescription`](/api/getDescription.md), [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### digits Creates a [digits](https://en.wikipedia.org/wiki/Numerical_digit) validation action. > The difference between `digits` and [`decimal`](/api/decimal.md) is that `digits` accepts only the digits 0-9, while [`decimal`](/api/decimal.md) accepts floating point numbers and negative numbers. ```ts const Action = v.digits(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `DigitsAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### domain Creates a [domain name](https://en.wikipedia.org/wiki/Domain_name) validation action. ```ts const Action = v.domain(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### Explanation With `domain` you can validate the formatting of a domain string. If the input is not a valid domain, you can use `message` to customize the error message. > Validates ASCII domains. Limits: 63 chars per label, 253 chars total. [Internationalized domain names](https://en.wikipedia.org/wiki/Internationalized_domain_name) (IDNs) are not supported, including Punycode-encoded labels. > If you need to validate a full URL (including protocol, path, query, etc.), use the [`url`](/api/url.md) action. #### Returns - `Action` `DomainAction` #### Examples The following examples show how `domain` can be used. ##### Domain schema Schema to validate a domain. ```ts const DomainSchema = v.pipe( v.string(), v.nonEmpty('Please enter your domain.'), v.domain('The domain is badly formatted.') ); ``` #### Related The following APIs can be combined with `domain`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### email Creates an [email](https://en.wikipedia.org/wiki/Email_address) validation action. ```ts const Action = v.email(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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 a broader subset of RFC 5322 addresses, please use the [`rfcEmail`](/api/rfcEmail.md) action instead. #### Returns - `Action` `EmailAction` #### 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.') ); ``` ##### Optional email schema Schema to validate an email that is allowed to be an empty string, for example for an optional form field. ```ts const OptionalEmailSchema = v.optional( v.union([ v.literal(''), v.pipe(v.string(), v.email('The email is badly formatted.')), ]), '' ); ``` #### Related The following APIs can be combined with `email`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### emoji Creates an [emoji](https://en.wikipedia.org/wiki/Emoji) validation action. ```ts const Action = v.emoji(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `EmojiAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### empty Creates an empty validation action. ```ts const Action = v.empty(requirement, message); ``` #### Generics - `TInput` `extends LengthInput` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `EmptyAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`string`](/api/string.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### endsWith Creates an ends with validation action. ```ts const Action = v.endsWith(requirement, message); ``` #### Generics - `TInput` `extends string` - `TRequirement` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `EndsWithAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### entries Creates an entries validation action. ```ts const Action = v.entries(requirement, message); ``` #### Generics - `TInput` `extends EntriesInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `EntriesAction` #### 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 [`looseObject`](/api/looseObject.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`record`](/api/record.md), [`strictObject`](/api/strictObject.md), [`variant`](/api/variant.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### everyItem Creates an every item validation action. ```ts const Action = v.everyItem(requirement, message); ``` #### Generics - `TInput` `extends ArrayInput` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `ArrayRequirement` - `message` `TMessage` ##### 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` `EveryItemAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### examples Creates an examples metadata action. ```ts const Action = v.examples(examples_); ``` #### Generics - `TInput` `extends any` - `TExamples` `extends readonly TInput[]` #### Parameters - `examples_` `TExamples` ##### Explanation With `examples` you can provide examples for a schema. This can be useful when working with AI tools or for documentation purposes. #### Returns - `Action` `ExamplesAction` #### Examples The following examples show how `examples` can be used. ##### String schema Schema to validate a string with examples. ```ts const StringSchema = v.pipe(v.string(), v.examples(['foo', 'bar', 'baz'])); ``` ##### Number schema Schema to validate a number with examples. ```ts const NumberSchema = v.pipe(v.number(), v.examples([1, 2, 3])); ``` #### Related The following APIs can be combined with `examples`. ##### Schemas [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`getExamples`](/api/getExamples.md), [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### excludes Creates an excludes validation action. ```ts const Action = v.excludes(requirement, message); ``` #### Generics - `TInput` `extends ContentInput` - `TRequirement` `extends ContentRequirement` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `ExcludesAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`string`](/api/string.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### filterItems Creates a filter items transformation action. ```ts const Action = v.filterItems(operation); ``` #### Generics - `TInput` `extends ArrayInput` #### Parameters - `operation` `ArrayRequirement` ##### 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` `FilterItemsAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### findItem Creates a find item transformation action. ```ts const Action = v.findItem(operation); ``` #### Generics - `TInput` `extends ArrayInput` #### Parameters - `operation` `ArrayRequirement` ##### Explanation With `findItem` you can extract the first item of an array that matches the given `operation`. #### Returns - `Action` `FindItemAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### finite Creates a [finite](https://en.wikipedia.org/wiki/Finite) validation action. ```ts const Action = v.finite(message); ``` #### Generics - `TInput` `extends number` - `TMessage` `extends ErrorMessage> | unknown` #### Parameters - `message` `TMessage` ##### 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` `FiniteAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`number`](/api/number.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### flavor Creates a flavor transformation action. ```ts const Action = v.flavor(name); ``` #### Generics - `TInput` `extends any` - `TName` `extends FlavorName` #### Parameters - `name` `TName` ##### Explanation `flavor` is a less strict version of [`brand`](/api/brand.md) 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. > `flavor` 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` `FlavorAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### graphemes Creates a [graphemes](https://en.wikipedia.org/wiki/Grapheme) validation action. ```ts const Action = v.graphemes( requirement, message ); ``` #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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. > If you are looking for an equivalent of JavaScript's `.length`, use [`length`](/api/length.md) instead. If you need to count each Unicode code point as a single character (a supplementary code point occupies two UTF-16 code units in JavaScript), use [`codePoints`](/api/codePoints.md) instead. #### Returns - `Action` `GraphemesAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Actions [`codePoints`](/api/codePoints.md), [`length`](/api/length.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### gtValue Creates a greater than value validation action. ```ts const Action = v.gtValue(requirement, message); ``` #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `GtValueAction` #### 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 [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`number`](/api/number.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### guard Creates a guard transformation action. ```ts const Action = v.guard(requirement, message); ``` #### Generics - `TInput` `extends any` - `TGuard` `extends GuardFunction` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TGuard` - `message` `TMessage` ##### Explanation With `guard` 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. This is especially useful if you have an existing type predicate (for example, from an external library). > `guard` is useful for narrowing known types. For validating completely unknown values, consider [`custom`](/api/custom.md) instead. #### Returns - `Action` `GuardAction` #### Examples The following examples show how `guard` can be used. ##### Pixel string schema Schema to validate a pixel string. ```ts const PixelStringSchema = v.pipe( v.string(), v.guard((input): input is `${number}px` => /^\d+px$/.test(input)) ); ``` ##### Axios Error schema Schema to validate an object containing an Axios error. ```ts import { isAxiosError } from 'axios'; const AxiosErrorSchema = v.object({ error: v.pipe( v.instance(Error), v.guard(isAxiosError, 'The error is not an Axios error.') ), }); ``` #### Related The following APIs can be combined with `guard`. ##### Schemas [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`forward`](/api/forward.md), [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### hash Creates a [hash](https://en.wikipedia.org/wiki/Hash_function) validation action. ```ts const Action = v.hash(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `types` `[HashType, ...HashType[]]` - `message` `TMessage` ##### 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` `HashAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### hexadecimal Creates a [hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal) validation action. ```ts const Action = v.hexadecimal(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `HexadecimalAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### hexColor Creates a [hex color](https://en.wikipedia.org/wiki/Web_colors#Hex_triplet) validation action. ```ts const Action = v.hexColor(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `HexColorAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### imei Creates an [IMEI](https://en.wikipedia.org/wiki/International_Mobile_Equipment_Identity) validation action. ```ts const Action = v.imei(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `ImeiAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### includes Creates an includes validation action. ```ts const Action = v.includes(requirement, message); ``` #### Generics - `TInput` `extends ContentInput` - `TRequirement` `extends ContentRequirement` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `IncludesAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`string`](/api/string.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### integer Creates an [integer](https://en.wikipedia.org/wiki/Integer) validation action. ```ts const Action = v.integer(message); ``` #### Generics - `TInput` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `IntegerAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`number`](/api/number.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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`](/api/ipv4.md) or [`ipv6`](/api/ipv6.md). ```ts const Action = v.ip(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `IpAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### ipv4 Creates an [IPv4](https://en.wikipedia.org/wiki/IPv4) address validation action. ```ts const Action = v.ipv4(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `Ipv4Action` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### ipv6 Creates an [IPv6](https://en.wikipedia.org/wiki/IPv6) address validation action. ```ts const Action = v.ipv6(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `Ipv6Action` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### isbn Creates an [ISBN](https://en.wikipedia.org/wiki/ISBN) validation action. ```ts const Action = v.isbn(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### Explanation With `isbn` you can validate the formatting of a string. If the input is not an ISBN, you can use `message` to customize the error message. This action supports both ISBN-10 and ISBN-13 formats and accepts hyphens and spaces as separators. #### Returns - `Action` `IsbnAction` #### Examples The following examples show how `isbn` can be used. ##### ISBN schema Schema to validate an ISBN. ```ts const IsbnSchema = v.pipe(v.string(), v.isbn('The ISBN is badly formatted')); // Valid ISBN-10 formats: // '0-306-40615-2' // '0306406152' // '0 306 40615 2' // Valid ISBN-13 formats: // '978-0-306-40615-7' // '9780306406157' // '978 0 306 40615 7' ``` #### Related The following APIs can be combined with `isbn`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### isrc Creates an [ISRC](https://en.wikipedia.org/wiki/International_Standard_Recording_Code) validation action. ```ts const Action = v.isrc(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### Explanation With `isrc` you can validate the formatting of a string. If the input is not an ISRC, you can use `message` to customize the error message. This action supports both compact (`CCXXXYYNNNNN`) and hyphenated (`CC-XXX-YY-NNNNN`) formats. #### Returns - `Action` `IsrcAction` #### Examples The following examples show how `isrc` can be used. ##### ISRC schema Schema to validate an ISRC. ```ts const IsrcSchema = v.pipe(v.string(), v.isrc('The ISRC is badly formatted.')); // Valid ISRC formats: // 'USRC17607839' // 'US-RC1-76-07839' ``` #### Related The following APIs can be combined with `isrc`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `IsoDateAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `IsoDateTimeAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### isoDateTimeSecond Creates an [ISO date time second](https://en.wikipedia.org/wiki/ISO_8601) validation action. Format: `yyyy-mm-ddThh:mm:ss` > The regex used cannot validate the maximum number of days based on year and month. For example, "2023-06-31T00:00: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.isoDateTimeSecond(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### Explanation With `isoDateTimeSecond` you can validate the formatting of a string. If the input is not an ISO date time with seconds, you can use `message` to customize the error message. #### Returns - `Action` `IsoDateTimeSecondAction` #### Examples The following examples show how `isoDateTimeSecond` can be used. ##### ISO date time second schema Schema to validate an ISO date time with seconds. ```ts const IsoDateTimeSecondSchema = v.pipe( v.string(), v.isoDateTimeSecond('The date is badly formatted.') ); ``` #### Related The following APIs can be combined with `isoDateTimeSecond`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `IsoTimeAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `IsoTimeSecondAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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. > The regex also allows a space before the UTC offset (e.g., " +00:00") to support PostgreSQL's `timestamptz` output format. ```ts const Action = v.isoTimestamp(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `IsoTimestampAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `IsoWeekAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### jwsCompact Creates a [JWS compact serialization](https://datatracker.ietf.org/doc/html/rfc7515#section-3.1) validation action. ```ts const Action = v.jwsCompact(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### Explanation With `jwsCompact` you can validate that a string matches the three-part compact string shape used by JWS compact serialization with unpadded Base64URL-like segments. If the input does not match this JWS compact string shape, you can use `message` to customize the error message. > Hint: This validation action only checks the three-part compact string shape. It does not decode the segments, verify the signature, or validate claims. Empty payload and signature segments are accepted when they appear as valid compact-serialization segments. If you need full JWT validation, signature verification, or claim checks, use a dedicated library such as one from [jwt.io/libraries](https://www.jwt.io/libraries). #### Returns - `Action` `JwsCompactAction` #### Examples The following examples show how `jwsCompact` can be used. ##### Access token schema Schema to validate that an access token string matches the JWS compact string shape. ```ts const AccessTokenSchema = v.pipe( v.string(), v.nonEmpty('Provide an access token.'), v.jwsCompact('The token must be a valid JWS compact string.') ); ``` #### Related The following APIs can be combined with `jwsCompact`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### ksuid Creates a [KSUID](https://github.com/segmentio/ksuid) validation action. ```ts const Action = v.ksuid(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### Explanation With `ksuid` you can validate the formatting of a string. If the input is not a KSUID, you can use `message` to customize the error message. #### Returns - `Action` `KsuidAction` #### Examples The following examples show how `ksuid` can be used. ##### KSUID schema Schema to validate a KSUID. ```ts const KsuidSchema = v.pipe( v.string(), v.ksuid('The KSUID is badly formatted.') ); ``` #### Related The following APIs can be combined with `ksuid`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### length Creates a length validation action. ```ts const Action = v.length(requirement, message); ``` #### Generics - `TInput` `extends LengthInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### Explanation With `length` you can validate the length of a string or array. For strings, length is measured like JavaScript's `value.length`, i.e. by UTF-16 code units. For arrays, length is measured by the number of items. If the input does not match the `requirement`, you can use `message` to customize the error message. > If you need to validate the number of user-perceived characters, use [`graphemes`](/api/graphemes.md) instead. If you need to count each Unicode code point as a single character (a supplementary code point occupies two UTF-16 code units in JavaScript), use [`codePoints`](/api/codePoints.md) instead. #### Returns - `Action` `LengthAction` #### Examples The following examples show how `length` can be used. ##### String schema Schema to validate a string with a length of 8 UTF-16 code units. ```ts const StringSchema = v.pipe( v.string(), v.length(8, 'The string must be 8 UTF-16 code units 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`string`](/api/string.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Actions [`codePoints`](/api/codePoints.md), [`graphemes`](/api/graphemes.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### ltValue Creates a less than value validation action. ```ts const Action = v.ltValue(requirement, message); ``` #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### Explanation With `ltValue` 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` `LtValueAction` #### Examples The following examples show how `ltValue` can be used. ##### Number schema Schema to validate a number with a less than value. ```ts const NumberSchema = v.pipe( v.number(), v.ltValue(100, 'The number must be less than 100.') ); ``` ##### Date schema Schema to validate a date with a less than value. ```ts const DateSchema = v.pipe( v.date(), v.ltValue( new Date('2000-01-01'), 'The date must be less than 1st January 2000.' ) ); ``` #### Related The following APIs can be combined with `ltValue`. ##### Schemas [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`number`](/api/number.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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`](/api/mac48.md) or [`mac64`](/api/mac64.md). ```ts const Action = v.mac(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `MacAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### mac48 Creates a 48-bit [MAC address](https://en.wikipedia.org/wiki/MAC_address) validation action. ```ts const Action = v.mac48(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `Mac48Action` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### mac64 Creates a 64-bit [MAC address](https://en.wikipedia.org/wiki/MAC_address) validation action. ```ts const Action = v.mac64(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `Mac64Action` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### mapItems Creates a map items transformation action. ```ts const Action = v.mapItems(operation); ``` #### Generics - `TInput` `extends ArrayInput` - `TOutput` `extends any` #### Parameters - `operation` `(item: TInput[number], index: number, array: TInput) => TOutput` ##### Explanation With `mapItems` you can apply an `operation` to each item in an array to transform it. #### Returns - `Action` `MapItemsAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### maxBytes Creates a max [bytes](https://en.wikipedia.org/wiki/Byte) validation action. ```ts const Action = v.maxBytes(requirement, message); ``` #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `MaxBytesAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### maxCodePoints Creates a max [code points](https://developer.mozilla.org/en-US/docs/Glossary/Code_point) validation action. ```ts const Action = v.maxCodePoints( requirement, message ); ``` #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### Explanation With `maxCodePoints` you can validate the maximum number of Unicode code points in a string. Code points are not the same as UTF-16 code units or user-perceived characters (graphemes): `😀` consists of 2 UTF-16 code units, 1 code point, and 1 grapheme, while `👨🏽‍👩🏽` consists of 5 code points but 1 grapheme. If the number of code points exceeds the `requirement`, you can use `message` to customize the error message. > Hint: This action is suitable for enforcing `VARCHAR` limits in PostgreSQL and in MySQL with the `utf8mb4` character set. [NIST SP 800-63B](https://pages.nist.gov/800-63-4/sp800-63b.html#passwordver) also requires password length to be measured in Unicode code points. #### Returns - `Action` `MaxCodePointsAction` #### Examples The following examples show how `maxCodePoints` can be used. ##### Max code points schema Schema to validate a string with a maximum of 8 code points. ```ts const MaxCodePointsSchema = v.pipe( v.string(), v.maxCodePoints(8, 'The string must not exceed 8 code points.') ); ``` #### Related The following APIs can be combined with `maxCodePoints`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Actions [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### maxEntries Creates a max entries validation action. ```ts const Action = v.maxEntries( requirement, message ); ``` #### Generics - `TInput` `extends EntriesInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `MaxEntriesAction` #### 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 [`looseObject`](/api/looseObject.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`record`](/api/record.md), [`strictObject`](/api/strictObject.md), [`variant`](/api/variant.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### maxGraphemes Creates a max [graphemes](https://en.wikipedia.org/wiki/Grapheme) validation action. ```ts const Action = v.maxGraphemes( requirement, message ); ``` #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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. > If you are looking for an equivalent of JavaScript's `.length` for maximum length checks, use [`maxLength`](/api/maxLength.md) instead. If you want to count every Unicode code point as one character—for example, to enforce the password length rules in [NIST SP 800-63B](https://pages.nist.gov/800-63-4/sp800-63b.html#passwordver) or to match `LENGTH()` in PostgreSQL and SQLite or `CHAR_LENGTH()` in MySQL—use [`maxCodePoints`](/api/maxCodePoints.md) instead. > Hint: The number of characters per grapheme is not limited. You may want to consider combining `maxGraphemes` with [`maxLength`](/api/maxLength.md), [`maxCodePoints`](/api/maxCodePoints.md), or [`maxBytes`](/api/maxBytes.md) to set a stricter limit. #### Returns - `Action` `MaxGraphemesAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Actions [`maxCodePoints`](/api/maxCodePoints.md), [`maxLength`](/api/maxLength.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### maxLength Creates a max length validation action. ```ts const Action = v.maxLength( requirement, message ); ``` #### Generics - `TInput` `extends LengthInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### Explanation With `maxLength` you can validate the length of a string or array. For strings, length is measured like JavaScript's `value.length`, i.e. by UTF-16 code units. For arrays, length is measured by the number of items. If the input does not match the `requirement`, you can use `message` to customize the error message. > If you need to validate the maximum number of user-perceived characters, use [`maxGraphemes`](/api/maxGraphemes.md) instead. If you need to count each Unicode code point as a single character (a supplementary code point occupies two UTF-16 code units in JavaScript), use [`maxCodePoints`](/api/maxCodePoints.md) instead. #### Returns - `Action` `MaxLengthAction` #### Examples The following examples show how `maxLength` can be used. ##### Maximum string length Schema to validate a string with a maximum length of 32 UTF-16 code units. ```ts const MaxStringSchema = v.pipe( v.string(), v.maxLength(32, 'The string must not exceed 32 UTF-16 code units.') ); ``` ##### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`string`](/api/string.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Actions [`maxCodePoints`](/api/maxCodePoints.md), [`maxGraphemes`](/api/maxGraphemes.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### maxSize Creates a max size validation action. ```ts const Action = v.maxSize(requirement, message); ``` #### Generics - `TInput` `extends SizeInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `MaxSizeAction` #### 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 [`any`](/api/any.md), [`blob`](/api/blob.md), [`custom`](/api/custom.md), [`file`](/api/file.md), [`instance`](/api/instance.md), [`map`](/api/map.md), [`set`](/api/set.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### maxValue Creates a max value validation action. ```ts const Action = v.maxValue(requirement, message); ``` #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `MaxValueAction` #### 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 [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`number`](/api/number.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### maxWords Creates a max [words](https://en.wikipedia.org/wiki/Word) validation action. ```ts const Action = v.maxWords( locales, requirement, message ); ``` #### Generics - `TInput` `extends string` - `TLocales` `extends Intl.LocalesArgument` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `locales` `TLocales` - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `MaxWordsAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### metadata Creates a custom metadata action. ```ts const Action = v.metadata(metadata_); ``` #### Generics - `TInput` `extends any` - `TMetadata` `extends Record` #### Parameters - `metadata_` `TMetadata` ##### 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` `MetadataAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`getMetadata`](/api/getMetadata.md), [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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` `extends Blob` - `TRequirement` `extends string[]` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `MimeTypeAction` #### 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 [`any`](/api/any.md), [`blob`](/api/blob.md), [`custom`](/api/custom.md), [`file`](/api/file.md), [`instance`](/api/instance.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### minBytes Creates a min [bytes](https://en.wikipedia.org/wiki/Byte) validation action. ```ts const Action = v.minBytes(requirement, message); ``` #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `MinBytesAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### minCodePoints Creates a min [code points](https://developer.mozilla.org/en-US/docs/Glossary/Code_point) validation action. ```ts const Action = v.minCodePoints( requirement, message ); ``` #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### Explanation With `minCodePoints` you can validate the minimum number of Unicode code points in a string. Code points are not the same as UTF-16 code units or user-perceived characters (graphemes): `😀` consists of 2 UTF-16 code units, 1 code point, and 1 grapheme, while `👨🏽‍👩🏽` consists of 5 code points but 1 grapheme. If the number of code points is below the `requirement`, you can use `message` to customize the error message. > Hint: This action can help enforce minimum password length requirements measured in Unicode code points. [NIST SP 800-63B requires us to count the length of a password in code points.](https://pages.nist.gov/800-63-4/sp800-63b.html#passwordver) #### Returns - `Action` `MinCodePointsAction` #### Examples The following examples show how `minCodePoints` can be used. ##### Min code points schema Schema to validate a string with a minimum of 8 code points. ```ts const MinCodePointsSchema = v.pipe( v.string(), v.minCodePoints(8, 'The string must contain at least 8 code points.') ); ``` #### Related The following APIs can be combined with `minCodePoints`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Actions [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### minEntries Creates a min entries validation action. ```ts const Action = v.minEntries( requirement, message ); ``` #### Generics - `TInput` `extends EntriesInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `MinEntriesAction` #### 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 [`looseObject`](/api/looseObject.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`record`](/api/record.md), [`strictObject`](/api/strictObject.md), [`variant`](/api/variant.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### minGraphemes Creates a min [graphemes](https://en.wikipedia.org/wiki/Grapheme) validation action. ```ts const Action = v.minGraphemes( requirement, message ); ``` #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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. > If you are looking for an equivalent of JavaScript's `.length` for minimum length checks, use [`minLength`](/api/minLength.md) instead. If you need to count each Unicode code point as a single character (a supplementary code point occupies two UTF-16 code units in JavaScript), use [`minCodePoints`](/api/minCodePoints.md) instead. #### Returns - `Action` `MinGraphemesAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Actions [`minCodePoints`](/api/minCodePoints.md), [`minLength`](/api/minLength.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### minLength Creates a min length validation action. ```ts const Action = v.minLength( requirement, message ); ``` #### Generics - `TInput` `extends LengthInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### Explanation With `minLength` you can validate the length of a string or array. For strings, length is measured like JavaScript's `value.length`, i.e. by UTF-16 code units. For arrays, length is measured by the number of items. If the input does not match the `requirement`, you can use `message` to customize the error message. > If you need to validate the minimum number of user-perceived characters, use [`minGraphemes`](/api/minGraphemes.md) instead. If you need to count each Unicode code point as a single character (a supplementary code point occupies two UTF-16 code units in JavaScript), use [`minCodePoints`](/api/minCodePoints.md) instead. #### Returns - `Action` `MinLengthAction` #### Examples The following examples show how `minLength` can be used. ##### Minimum string length Schema to validate a string with a minimum length of 3 UTF-16 code units. ```ts const MinStringSchema = v.pipe( v.string(), v.minLength(3, 'The string must be 3 or more UTF-16 code units 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`string`](/api/string.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Actions [`minCodePoints`](/api/minCodePoints.md), [`minGraphemes`](/api/minGraphemes.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### minSize Creates a min size validation action. ```ts const Action = v.minSize(requirement, message); ``` #### Generics - `TInput` `extends SizeInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `MinSizeAction` #### 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 [`any`](/api/any.md), [`blob`](/api/blob.md), [`custom`](/api/custom.md), [`file`](/api/file.md), [`instance`](/api/instance.md), [`map`](/api/map.md), [`set`](/api/set.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### minValue Creates a min value validation action. ```ts const Action = v.minValue(requirement, message); ``` #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `MinValueAction` #### 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 [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`number`](/api/number.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### minWords Creates a min [words](https://en.wikipedia.org/wiki/Word) validation action. ```ts const Action = v.minWords( locales, requirement, message ); ``` #### Generics - `TInput` `extends string` - `TLocales` `extends Intl.LocalesArgument` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `locales` `TLocales` - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `MinWordsAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### multipleOf Creates a [multiple]() of validation action. ```ts const Action = v.multipleOf( requirement, message ); ``` #### Generics - `TInput` `extends number | bigint` - `TRequirement` `extends number | bigint` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `MultipleOfAction` #### 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 [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`custom`](/api/custom.md), [`number`](/api/number.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### nanoid Creates a [Nano ID](https://github.com/ai/nanoid) validation action. ```ts const Action = v.nanoid(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `NanoIdAction` #### 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`](/api/length.md) 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 [`any`](/api/any.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### nonEmpty Creates a non-empty validation action. ```ts const Action = v.nonEmpty(requirement, message); ``` #### Generics - `TInput` `extends LengthInput` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `NonEmptyAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`string`](/api/string.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### normalize Creates a normalize transformation action. ```ts const Action = v.normalize(form); ``` #### Generics - `TForm` `extends NormalizeForm | undefined` #### Parameters - `form` `TForm` #### Returns - `Action` `NormalizeAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### notBytes Creates a not [bytes](https://en.wikipedia.org/wiki/Byte) validation action. ```ts const Action = v.notBytes(requirement, message); ``` #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `NotBytesAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### notCodePoints Creates a not [code points](https://developer.mozilla.org/en-US/docs/Glossary/Code_point) validation action. ```ts const Action = v.notCodePoints( requirement, message ); ``` #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### Explanation With `notCodePoints` you can validate that a string does not have a specific number of Unicode code points. Code points are not the same as UTF-16 code units or user-perceived characters (graphemes): `😀` consists of 2 UTF-16 code units, 1 code point, and 1 grapheme, while `👨🏽‍👩🏽` consists of 5 code points but 1 grapheme. If the number of code points equals the `requirement`, you can use `message` to customize the error message. #### Returns - `Action` `NotCodePointsAction` #### Examples The following examples show how `notCodePoints` can be used. ##### Not code points schema Schema to validate a string with more or less than 8 code points. ```ts const NotCodePointsSchema = v.pipe( v.string(), v.notCodePoints(8, 'The string must not have 8 code points.') ); ``` #### Related The following APIs can be combined with `notCodePoints`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Actions [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### notEntries Creates a not entries validation action. ```ts const Action = v.notEntries( requirement, message ); ``` #### Generics - `TInput` `extends EntriesInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `NotEntriesAction` #### 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 [`looseObject`](/api/looseObject.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`record`](/api/record.md), [`strictObject`](/api/strictObject.md), [`variant`](/api/variant.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### notGraphemes Creates a not [graphemes](https://en.wikipedia.org/wiki/Grapheme) validation action. ```ts const Action = v.notGraphemes( requirement, message ); ``` #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `NotGraphemesAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Actions [`notCodePoints`](/api/notCodePoints.md), [`notLength`](/api/notLength.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### notLength Creates a not length validation action. ```ts const Action = v.notLength( requirement, message ); ``` #### Generics - `TInput` `extends LengthInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `NotLengthAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`string`](/api/string.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Actions [`notCodePoints`](/api/notCodePoints.md), [`notGraphemes`](/api/notGraphemes.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### notSize Creates a not size validation action. ```ts const Action = v.notSize(requirement, message); ``` #### Generics - `TInput` `extends SizeInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `NotSizeAction` #### 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 [`any`](/api/any.md), [`blob`](/api/blob.md), [`custom`](/api/custom.md), [`file`](/api/file.md), [`instance`](/api/instance.md), [`map`](/api/map.md), [`set`](/api/set.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### notValue Creates a not value validation action. ```ts const Action = v.notValue(requirement, message); ``` #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `NotValueAction` #### 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 [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`number`](/api/number.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### notValues Creates a not values validation action. ```ts const Action = v.notValues( requirement, message ); ``` #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends readonly TInput[]` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `NotValuesAction` #### 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 [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`number`](/api/number.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### notWords Creates a not [words](https://en.wikipedia.org/wiki/Word) validation action. ```ts const Action = v.notWords( locales, requirement, message ); ``` #### Generics - `TInput` `extends string` - `TLocales` `extends Intl.LocalesArgument` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `locales` `TLocales` - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `NotWordsAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### octal Creates an [octal](https://en.wikipedia.org/wiki/Octal) validation action. ```ts const Action = v.octal(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `OctalAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### parseBoolean Creates a parse boolean transformation action. ```ts const Action = v.parseBoolean(config, message); ``` #### Generics - `TInput` `extends any` - `TConfig` `extends ParseBooleanConfig | undefined` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `config` `TConfig` - `message` `TMessage` ##### Explanation With `parseBoolean` you can parse certain "boolish" values into a plain boolean value (e.g. parsing environment variables). It supports both string and non-string values and the comparison is case-insensitive for strings. By default, the truthy values are `true`, `1`, `"true"`, `"1"`, `"yes"`, `"y"`, `"on"`, and `"enabled"`. The falsy values are `false`, `0`, `"false"`, `"0"`, `"no"`, `"n"`, `"off"`, and `"disabled"`. You can override these defaults via the `config` argument. #### Returns - `Action` `ParseBooleanAction` #### Examples The following examples show how `parseBoolean` can be used. ```ts const EnvSchema = v.object({ // Default behavior PROD_MODE: v.pipe(v.string(), v.parseBoolean()), // With custom config LOG_MODE: v.pipe( v.string(), v.parseBoolean({ truthy: ['verbose', 'chatty', 'record'], falsy: ['silent', 'quiet', 'mute'], }) ), }); ``` #### Related The following APIs can be combined with `parseBoolean`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### parseJson Creates a JSON parse transformation action. ```ts const Action = v.parseJson(config, message); ``` #### Generics - `TInput` `extends string` - `TConfig` `extends ParseJsonConfig | undefined` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `config` `TConfig` - `message` `TMessage` ##### 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` `ParseJsonAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### partialCheck Creates a partial check validation action. ```ts const Action = v.partialCheck( paths, requirement, message ); ``` #### Generics - `TInput` `extends Record | ArrayLike` - `TPaths` `extends RequiredPaths` - `TSelection` `extends DeepPickN` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `paths` `ValidPaths` - `requirement` `(input: TSelection) => boolean` - `message` `TMessage` ##### 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`](/api/check.md) is that `partialCheck` can be executed whenever the selected part of the data is valid, while [`check`](/api/check.md) is executed only when the entire dataset is typed. This can be an important advantage when working with forms. #### Returns - `Action` `PartialCheckAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`record`](/api/record.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`union`](/api/union.md), [`variant`](/api/variant.md) ##### Methods [`forward`](/api/forward.md), [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### rawCheck Creates a raw check validation action. ```ts const Action = v.rawCheck(action); ``` #### Generics - `TInput` `extends any` #### Parameters - `action` `(context: RawCheckContext) => void` ##### Explanation With `rawCheck` you can freely validate the input with a custom `action` and add issues if necessary. #### Returns - `Action` `RawCheckAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`forward`](/api/forward.md), [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### rawTransform Creates a raw transformation action. ```ts const Action = v.rawTransform(action); ``` #### Generics - `TInput` `extends any` - `TOutput` `extends any` #### Parameters - `action` `(context: RawTransformContext) => TOutput` ##### Explanation With `rawTransform` you can freely transform and validate the input with a custom `action` and add issues if necessary. #### Returns - `Action` `RawTransformAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`forward`](/api/forward.md), [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### readonly Creates a readonly transformation action. ```ts const Action = v.readonly(); ``` #### Generics - `TInput` `extends any` #### Returns - `Action` `ReadonlyAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### reduceItems Creates a reduce items transformation action. ```ts const Action = v.reduceItems(operation, initial); ``` #### Generics - `TInput` `extends ArrayInput` - `TOutput` `extends any` #### Parameters - `operation` `(output: TOutput, item: TInput[number], index: number, array: TInput) => TOutput` - `initial` `TOutput` ##### Explanation With `reduceItems` you can apply an `operation` to each item in an array to reduce it to a single value. #### Returns - `Action` `ReduceItemsAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### regex Creates a [regex](https://en.wikipedia.org/wiki/Regular_expression) validation action. ```ts const Action = v.regex(requirement, message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `RegExp` - `message` `TMessage` ##### 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` `RegexAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### returns Creates a function return transformation action. ```ts const Action = v.returns(schema); ``` #### Generics - `TInput` `extends (...args: any[]) => unknown` - `TSchema` `extends BaseSchema>` #### Parameters - `schema` `TSchema` ##### Explanation With `returns` you can force the returned value of a function to match the given `schema`. #### Returns - `Action` `ReturnsAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### 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` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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 uses the regex defined by the HTML Living Standard for ``, which covers most of RFC 5322 but not all of it. For example, quoted local parts and comments are not supported. If you are interested in an action that only validates common email addresses, please use the [`email`](/api/email.md) action instead. #### Returns - `Action` `RfcEmailAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### safeInteger Creates a safe integer validation action. ```ts const Action = v.safeInteger(message); ``` #### Generics - `TInput` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `SafeIntegerAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`number`](/api/number.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### size Creates a size validation action. ```ts const Action = v.size(requirement, message); ``` #### Generics - `TInput` `extends SizeInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `SizeAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`string`](/api/string.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### slug Creates an [slug](https://en.wikipedia.org/wiki/Clean_URL#Slug) validation action. ```ts const Action = v.slug(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `SlugAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### someItem Creates a some item validation action. ```ts const Action = v.someItem(requirement, message); ``` #### Generics - `TInput` `extends ArrayInput` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `ArrayRequirement` - `message` `TMessage` ##### 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` `SomeItemAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### sortItems Creates a sort items transformation action. ```ts const Action = v.sortItems(operation); ``` #### Generics - `TInput` `extends ArrayInput` #### Parameters - `operation` `((itemA: TInput[number], itemB: TInput[number]) => number) | undefined` ##### 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` `SortItemsAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### startsWith Creates a starts with validation action. ```ts const Action = v.startsWith( requirement, message ); ``` #### Generics - `TInput` `extends string` - `TRequirement` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `StartsWithAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### stringifyJson Creates a JSON stringify transformation action. ```ts const Action = v.stringifyJson(config, message); ``` #### Generics - `TInput` `extends any` - `TConfig` `extends StringifyJsonConfig | undefined` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `config` `TConfig` - `message` `TMessage` ##### 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` `StringifyJsonAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`picklist`](/api/picklist.md), [`record`](/api/record.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### title Creates a title metadata action. ```ts const Action = v.title(title_); ``` #### Generics - `TInput` `extends any` - `TTitle` `extends string` #### Parameters - `title_` `TTitle` ##### 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` `TitleAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`getTitle`](/api/getTitle.md), [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### toBigint Creates a to bigint transformation action. ```ts const Action = v.toBigint(message); ``` #### Generics - `TInput` `extends any` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### Explanation With `toBigint` you can transform the input to a bigint. If the input cannot be transformed, you can use `message` to customize the error message. #### Returns - `Action` `ToBigintAction` #### Examples The following examples show how `toBigint` can be used. ##### Number schema Schema to validate a number and transform it to a bigint. ```ts const NumberSchema = v.pipe(v.number(), v.toBigint()); ``` #### Related The following APIs can be combined with `toBigint`. ##### Schemas [`any`](/api/any.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`number`](/api/number.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### toBoolean Creates a to boolean transformation action. ```ts const Action = v.toBoolean(); ``` #### Generics - `TInput` `extends any` #### Returns - `Action` `ToBooleanAction` #### Examples The following examples show how `toBoolean` can be used. ##### Boolean schema Schema to validate a string and transform it to a boolean. ```ts const BooleanSchema = v.pipe(v.string(), v.toBoolean()); ``` #### Related The following APIs can be combined with `toBoolean`. ##### Schemas [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`null`](/api/null.md), [`number`](/api/number.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`undefined`](/api/undefined.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### toCamelCase Creates a to camel case transformation action. Words are separated by `_`, `-` and ASCII whitespace, as well as by case and acronym boundaries. > Acronym runs are normalized to lowercase (e.g. `parseURLValue` → `parseUrlValue`) and digits stay attached to the preceding token (e.g. `item2Name` → `item2Name`). ```ts const Action = v.toCamelCase(); ``` #### Returns - `Action` `ToCamelCaseAction` #### Examples The following examples show how `toCamelCase` can be used. ##### Camel case string Schema that transforms a string to camel case. ```ts const StringSchema = v.pipe(v.string(), v.toCamelCase()); ``` #### Related The following APIs can be combined with `toCamelCase`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### toDate Creates a to date transformation action. ```ts const Action = v.toDate(message); ``` #### Generics - `TInput` `extends any` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### Explanation With `toDate` you can transform the input to a date. If the input cannot be transformed, you can use `message` to customize the error message. #### Returns - `Action` `ToDateAction` #### Examples The following examples show how `toDate` can be used. ##### Date schema Schema to validate a string and transform it to a date. ```ts const DateSchema = v.pipe(v.string(), v.toDate()); ``` #### Related The following APIs can be combined with `toDate`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`number`](/api/number.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### toKebabCase Creates a to kebab case transformation action. Words are separated by `_`, `-` and ASCII whitespace, as well as by case and acronym boundaries. > Acronym runs are normalized to lowercase (e.g. `parseURLValue` → `parse-url-value`) and digits stay attached to the preceding token (e.g. `item2Name` → `item2-name`). ```ts const Action = v.toKebabCase(); ``` #### Returns - `Action` `ToKebabCaseAction` #### Examples The following examples show how `toKebabCase` can be used. ##### Kebab case string Schema that transforms a string to kebab case. ```ts const StringSchema = v.pipe(v.string(), v.toKebabCase()); ``` #### Related The following APIs can be combined with `toKebabCase`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### toLowerCase Creates a to lower case transformation action. ```ts const Action = v.toLowerCase(); ``` #### Returns - `Action` `ToLowerCaseAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### toMaxValue Creates a to max value transformation action. ```ts const Action = v.toMaxValue(requirement); ``` #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` #### Parameters - `requirement` `TRequirement` ##### 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` `ToMaxValueAction` #### 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 [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`number`](/api/number.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### toMinValue Creates a to min value transformation action. ```ts const Action = v.toMinValue(requirement); ``` #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` #### Parameters - `requirement` `TRequirement` ##### 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` `ToMinValueAction` #### 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 [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`number`](/api/number.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### toNumber Creates a to number transformation action. ```ts const Action = v.toNumber(message); ``` #### Generics - `TInput` `extends any` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### Explanation With `toNumber` you can transform the input to a number. If the input cannot be transformed, you can use `message` to customize the error message. #### Returns - `Action` `ToNumberAction` #### Examples The following examples show how `toNumber` can be used. ##### Number schema Schema to validate a string and transform it to a number. ```ts const NumberSchema = v.pipe(v.string(), v.toNumber()); ``` #### Related The following APIs can be combined with `toNumber`. ##### Schemas [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`null`](/api/null.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### toPascalCase Creates a to pascal case transformation action. Words are separated by `_`, `-` and ASCII whitespace, as well as by case and acronym boundaries. > Acronym runs are normalized to lowercase (e.g. `parseURLValue` → `ParseUrlValue`) and digits stay attached to the preceding token (e.g. `item2Name` → `Item2Name`). ```ts const Action = v.toPascalCase(); ``` #### Returns - `Action` `ToPascalCaseAction` #### Examples The following examples show how `toPascalCase` can be used. ##### Pascal case string Schema that transforms a string to pascal case. ```ts const StringSchema = v.pipe(v.string(), v.toPascalCase()); ``` #### Related The following APIs can be combined with `toPascalCase`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### toSnakeCase Creates a to snake case transformation action. Words are separated by `_`, `-` and ASCII whitespace, as well as by case and acronym boundaries. > Acronym runs are normalized to lowercase (e.g. `parseURLValue` → `parse_url_value`) and digits stay attached to the preceding token (e.g. `item2Name` → `item2_name`). ```ts const Action = v.toSnakeCase(); ``` #### Returns - `Action` `ToSnakeCaseAction` #### Examples The following examples show how `toSnakeCase` can be used. ##### Snake case string Schema that transforms a string to snake case. ```ts const StringSchema = v.pipe(v.string(), v.toSnakeCase()); ``` #### Related The following APIs can be combined with `toSnakeCase`. ##### Schemas [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### toString Creates a to string transformation action. ```ts const Action = v.toString(message); ``` #### Generics - `TInput` `extends any` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### Explanation With `toString` you can transform the input to a string. If the input cannot be transformed, you can use `message` to customize the error message. #### Returns - `Action` `ToStringAction` #### Examples The following examples show how `toString` can be used. ##### String schema Schema to validate a number and transform it to a string. ```ts const StringSchema = v.pipe(v.number(), v.toString()); ``` #### Related The following APIs can be combined with `toString`. ##### Schemas [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`null`](/api/null.md), [`number`](/api/number.md), [`symbol`](/api/symbol.md), [`undefined`](/api/undefined.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### toUpperCase Creates a to upper case transformation action. ```ts const Action = v.toUpperCase(); ``` #### Returns - `Action` `ToUpperCaseAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### transform Creates a custom transformation action. ```ts const Action = v.transform(action); ``` #### Generics - `TInput` `extends any` - `TOutput` `extends any` #### Parameters - `action` `(input: TInput) => TOutput` ##### 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` `TransformAction` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### trim Creates a trim transformation action. ```ts const Action = v.trim(); ``` #### Returns - `Action` `TrimAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### trimEnd Creates a trim end transformation action. ```ts const Action = v.trimEnd(); ``` #### Returns - `Action` `TrimEndAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### trimStart Creates a trim start transformation action. ```ts const Action = v.trimStart(); ``` #### Returns - `Action` `TrimStartAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### ulid Creates an [ULID](https://github.com/ulid/spec) validation action. ```ts const Action = v.ulid(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `UlidAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### url Creates an [URL](https://en.wikipedia.org/wiki/URL) validation action. ```ts const Action = v.url(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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. > If you only need to validate an ASCII domain name, consider the [`domain`](/api/domain.md) action. #### Returns - `Action` `UrlAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### uuid Creates an [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier) validation action. ```ts const Action = v.uuid(message); ``` #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `message` `TMessage` ##### 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` `UuidAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### value Creates a value validation action. ```ts const Action = v.value(requirement, message); ``` #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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`](/api/literal.md) schema instead if you want the type to match a specific value. #### Returns - `Action` `ValueAction` #### 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 [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`number`](/api/number.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### values Creates a values validation action. ```ts const Action = v.values(requirement, message); ``` #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends readonly TInput[]` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `TRequirement` - `message` `TMessage` ##### 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`](/api/picklist.md) schema instead if you want the type to match the union of specific values. #### Returns - `Action` `ValuesAction` #### 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 [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`number`](/api/number.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ### words Creates a [words](https://en.wikipedia.org/wiki/Word) validation action. ```ts const Action = v.words( locales, requirement, message ); ``` #### Generics - `TInput` `extends string` - `TLocales` `extends Intl.LocalesArgument` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `locales` `TLocales` - `requirement` `TRequirement` - `message` `TMessage` ##### 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` `WordsAction` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ## Storages (API) ### deleteGlobalConfig Deletes the global configuration. ```ts v.deleteGlobalConfig(); ``` ### deleteGlobalMessage Deletes a global error message. ```ts v.deleteGlobalMessage(lang); ``` #### Parameters - `lang` `string | undefined` ### deleteSchemaMessage Deletes a schema error message. ```ts v.deleteSchemaMessage(lang); ``` #### Parameters - `lang` `string | undefined` ### deleteSpecificMessage Deletes a specific error message. ```ts v.deleteSpecificMessage(reference, lang); ``` #### Parameters - `reference` `Reference` - `lang` `string | undefined` ### getGlobalConfig Returns the global configuration. ```ts const config = v.getGlobalConfig(merge); ``` #### Generics - `TIssue` `extends BaseIssue` #### Parameters - `merge` `Config | undefined` ##### Explanation Properties that you want to explicitly override can be optionally specified with `merge`. #### Returns - `config` `Config` ### getGlobalMessage Returns a global error message. ```ts const message = v.getGlobalMessage(lang); ``` #### Parameters - `lang` `string | undefined` #### Returns - `message` `ErrorMessage> | undefined` ### getSchemaMessage Returns a schema error message. ```ts const message = v.getSchemaMessage(lang); ``` #### Parameters - `lang` `string | undefined` #### Returns - `message` `ErrorMessage> | undefined` ### getSpecificMessage Returns a specific error message. ```ts const message = v.getSpecificMessage(reference, lang); ``` #### Parameters - `reference` `Reference` - `lang` `string | undefined` #### Returns - `message` `ErrorMessage> | undefined` ### setGlobalConfig Sets the global configuration. ```ts v.setGlobalConfig(merge); ``` #### Parameters - `config` `GlobalConfig` ##### 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` `ErrorMessage>` - `lang` `string | undefined` ### setSchemaMessage Sets a schema error message. ```ts v.setSchemaMessage(message, lang); ``` #### Parameters - `message` `ErrorMessage>` - `lang` `string | undefined` ### setSpecificMessage Sets a specific error message. ```ts v.setSpecificMessage(reference, message, lang); ``` #### Generics - `TReference` `extends Reference` #### Parameters - `reference` `TReference` - `message` `ErrorMessage>>` - `lang` `string | undefined` ## Utils (API) ### entriesFromList Creates an object entries definition from a list of keys and a schema. ```ts const entries = v.entriesFromList(list, schema); ``` #### Generics - `TList` `extends (string | number | symbol)[]` - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `list` `TList` - `schema` `TSchema` #### Returns - `entries` `Record` #### Examples The following example show how `entriesFromList` can be used. ```ts const ObjectSchema = v.object( v.entriesFromList(['foo', 'bar', 'baz'], v.string()) ); const ObjectSchemaWithSpread = v.object({ name: v.string(), ...v.entriesFromList( ['foo', 'bar', 'baz'], v.pipe(v.string(), v.digits(), v.transform(Number)) ), }); ``` #### Related The following APIs can be combined with `entriesFromList`. ##### Schemas [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ### entriesFromObjects Creates a new object entries definition from existing object schemas. ```ts const entries = v.entriesFromObjects(schemas); ``` #### Generics - `TSchemas` `extends [Schema, ...Schema[]]` #### Parameters - `schemas` `TSchemas` #### Returns - `entries` `MergedEntries` #### 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 [`looseObject`](/api/looseObject.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`strictObject`](/api/strictObject.md) ### getDotPath Creates and returns the dot path of an issue if possible. ```ts const dotPath = v.getDotPath(issue); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `issue` `InferIssue` #### Returns - `dotPath` `IssueDotPath | null` ### isOfKind A generic type guard to check the kind of an object. ```ts const result = v.isOfKind(kind, object); ``` #### Generics - `TKind` `extends TObject['kind']` - `TObject` `extends { kind: string }` #### Parameters - `kind` `TKind` - `object` `TObject` #### Returns - `result` `boolean` ### isOfType A generic type guard to check the type of an object. ```ts const result = v.isOfType(type, object); ``` #### Generics - `TType` `extends TObject['type']` - `TObject` `extends { type: string }` #### Parameters - `type` `TType` - `object` `TObject` #### Returns - `result` `boolean` ### isValiError A type guard to check if an error is a ValiError. ```ts const result = v.isValiError(error); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `error` `unknown` #### Returns - `result` `boolean` ### ValiError Creates a Valibot error with useful information. ```ts const error = new v.ValiError(issues); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `issues` `[InferIssue, ...InferIssue[]]` #### Returns - `error` `ValiError` ## Async (API) ### argsAsync Creates a function arguments transformation action. ```ts const Action = v.argsAsync(schema); ``` #### Generics - `TInput` `extends (...args: any[]) => unknown` - `TSchema` `extends LooseTupleSchema | undefined> | LooseTupleSchemaAsync | undefined> | StrictTupleSchema | undefined> | StrictTupleSchemaAsync | undefined> | TupleSchema | undefined> | TupleSchemaAsync | undefined> | TupleWithRestSchema>, ErrorMessage | undefined> | TupleWithRestSchemaAsync> | BaseSchemaAsync>, ErrorMessage | undefined>` #### Parameters - `schema` `TSchema` ##### Explanation With `argsAsync` you can force the arguments of a function to match the given `schema`. #### Returns - `Action` `ArgsActionAsync` #### 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 [`any`](/api/any.md), [`custom`](/api/custom.md), [`looseTuple`](/api/looseTuple.md), [`function`](/api/function.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`customAsync`](/api/customAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`returnsAsync`](/api/returnsAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md) ### arrayAsync Creates an array schema. ```ts const Schema = v.arrayAsync(item, message); ``` #### Generics - `TItem` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `item` `TItem` - `message` `TMessage` ##### 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`](/api/tupleAsync.md) for a more precise typing. #### Returns - `Schema` `ArraySchemaAsync` #### 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 [`any`](/api/any.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`empty`](/api/empty.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`includes`](/api/includes.md), [`length`](/api/length.md), [`mapItems`](/api/mapItems.md), [`maxLength`](/api/maxLength.md), [`metadata`](/api/metadata.md), [`minLength`](/api/minLength.md), [`nonEmpty`](/api/nonEmpty.md), [`notLength`](/api/notLength.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### awaitAsync Creates an await transformation action. ```ts const Action = v.awaitAsync(); ``` #### Generics - `TInput` `extends Promise` ##### Explanation With `awaitAsync` you can transform a promise into its resolved value. #### Returns - `Action` `AwaitActionAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### cacheAsync Creates a version of a schema that caches its output. ```ts const Schema = v.cacheAsync(schema, config); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` - `TCacheConfig` `extends CacheConfig | undefined` #### Parameters - `schema` `TSchema` - `config` `TCacheConfig` ##### Explanation The `cacheAsync` method creates a version of the given `schema` that caches its output. This can be useful for performance optimization, for example when validation involves a network request. > Hint: Primitive inputs are cached by value. Object and function inputs are cached by reference identity, so mutating input objects and reusing the same reference can return a stale cached dataset. Returned objects are also reused by reference, so mutating cached output can affect later cache hits. For best results, use `cacheAsync` with immutable inputs and avoid mutating returned cached objects. #### Returns - `Schema` `SchemaWithCacheAsync` #### Examples The following examples show how `cacheAsync` can be used. ##### Cache schema Schema that caches its output. ```ts const CacheSchema = v.cacheAsync(v.string()); ``` ##### Max size schema Schema that caches its output for a maximum of 100 items. ```ts const MaxSizeSchema = v.cacheAsync(v.string(), { maxSize: 100 }); ``` ##### Max age schema Schema that caches its output for a maximum of 10 seconds. ```ts const MaxAgeSchema = v.cacheAsync(v.string(), { maxAge: 10_000 }); ``` #### Related The following APIs can be combined with `cacheAsync`. ##### Schemas [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`message`](/api/message.md), [`unwrap`](/api/unwrap.md) ##### Async [`parseAsync`](/api/parseAsync.md), [`safeParseAsync`](/api/safeParseAsync.md) ### checkAsync Creates a check validation action. ```ts const Action = v.checkAsync(requirement, message); ``` #### Generics - `TInput` `extends any` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `(input: TInput) => MaybePromise` - `message` `TMessage` ##### 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` `CheckActionAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### checkItemsAsync Creates a check items validation action. ```ts const Action = v.checkItemsAsync(requirement, message); ``` #### Generics - `TInput` `extends ArrayInput` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `requirement` `ArrayRequirementAsync` - `message` `TMessage` ##### 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` `CheckItemsActionAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`tupleAsync`](/api/tupleAsync.md) ### 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` `extends any` - `TMessage` `extends ErrorMessage | undefined = ErrorMessage | undefined` #### Parameters - `check` `(input: unknown) => MaybePromise` - `message` `TMessage` ##### 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` `CustomSchemaAsync` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toCamelCase`](/api/toCamelCase.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md) ### exactOptionalAsync Creates an exact optional schema. ```ts const Schema = v.exactOptionalAsync(wrapped, default_); ``` #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TDefault` `extends DefaultAsync` #### Parameters - `wrapped` `TWrapped` - `default_` `TDefault` ##### 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. > **Important**: When used in object schemas, if a key is missing and no `default_` value is provided, the schema's pipe (including transformations) will not be executed. To ensure pipes run for missing keys, provide a `default_` value. > The difference to [`optionalAsync`](/api/optionalAsync.md) 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` `ExactOptionalSchemaAsync` #### 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`](/api/unwrap.md) 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.') ) ) ); ``` ##### Exact optional async with pipes When using `exactOptionalAsync` in a [`pipeAsync`](/api/pipeAsync.md), the pipe actions only execute if a `default_` value is provided or the key is present. This applies to all pipe actions including [`transformAsync`](/api/transformAsync.md), [`checkAsync`](/api/checkAsync.md), and others. ```ts const SchemaWithoutDefault = v.objectAsync({ isEnabled: v.pipeAsync( v.exactOptionalAsync(v.string()), v.transformAsync(async (value) => value === '1') // Does not run for missing keys ), }); // Output type: { isEnabled?: boolean } const SchemaWithDefault = v.objectAsync({ isEnabled: v.pipeAsync( v.exactOptionalAsync(v.string(), '0'), // Default value provided v.transformAsync(async (value) => value === '1') // Runs for missing keys too ), }); // Output type: { isEnabled: boolean } ``` #### Related The following APIs can be combined with `exactOptionalAsync`. ##### Schemas [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md), [`unwrap`](/api/unwrap.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### fallbackAsync Returns a fallback value as output if the input does not match the schema. ```ts const Schema = v.fallbackAsync(schema, fallback); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` - `TFallback` `extends FallbackAsync` #### Parameters - `schema` `TSchema` - `fallback` `TFallback` ##### 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`](/api/optionalAsync.md), [`nullableAsync`](/api/nullableAsync.md) or [`nullishAsync`](/api/nullishAsync.md) instead. > The fallback value is not validated. Make sure that the fallback value matches your schema. #### Returns - `Schema` `SchemaWithFallbackAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`pick`](/api/pick.md), [`unwrap`](/api/unwrap.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toCamelCase`](/api/toCamelCase.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialAsync`](/api/partialAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### forwardAsync Forwards the issues of the passed validation action. ```ts const Action = v.forwardAsync(action, path); ``` #### Generics - `TInput` `extends Record | ArrayLike` - `TIssue` `extends BaseIssue` - `TPath` `extends RequiredPath` #### Parameters - `action` `BaseValidation | BaseValidationAsync` - `path` `ValidPath` ##### Explanation `forwardAsync` allows you to forward the issues of the passed validation `action` via `path` to a nested field of a schema. #### Returns - `Action` `BaseValidationAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`record`](/api/record.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md) ##### Methods [`omit`](/api/omit.md), [`pick`](/api/pick.md) ##### Actions [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`empty`](/api/empty.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`guard`](/api/guard.md), [`includes`](/api/includes.md), [`length`](/api/length.md), [`mapItems`](/api/mapItems.md), [`maxLength`](/api/maxLength.md), [`metadata`](/api/metadata.md), [`minLength`](/api/minLength.md), [`nonEmpty`](/api/nonEmpty.md), [`notLength`](/api/notLength.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`reduceItems`](/api/reduceItems.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`partialAsync`](/api/partialAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### getDefaultsAsync Returns the default values of the schema. > The difference to [`getDefault`](/api/getDefault.md) 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` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `schema` `TSchema` #### Returns - `values` `Promise>` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`unwrap`](/api/unwrap.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`partialAsync`](/api/partialAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### getFallbacksAsync Returns the fallback values of the schema. > The difference to [`getFallback`](/api/getFallback.md) 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` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `schema` `TSchema` #### Returns - `values` `Promise>` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`unwrap`](/api/unwrap.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`partialAsync`](/api/partialAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### intersectAsync Creates an intersect schema. > I recommend to read the [intersections guide](/guides/intersections.md) before using this schema function. ```ts const Schema = v.intersectAsync(options, message); ``` #### Generics - `TOptions` `extends IntersectOptionsAsync` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `options` `TOptions` - `message` `TMessage` ##### 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` `IntersectSchemaAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`hash`](/api/hash.md), [`hexColor`](/api/hexColor.md), [`hexadecimal`](/api/hexadecimal.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toCamelCase`](/api/toCamelCase.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### lazyAsync Creates a lazy schema. ```ts const Schema = v.lazyAsync(getter); ``` #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `getter` `(input: unknown) => MaybePromise` ##### 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` `LazySchemaAsync` #### 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`](/api/GenericSchemaAsync.md). ```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`](/api/unionAsync.md) and [`variantAsync`](/api/variantAsync.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`hash`](/api/hash.md), [`hexColor`](/api/hexColor.md), [`hexadecimal`](/api/hexadecimal.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toCamelCase`](/api/toCamelCase.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### looseObjectAsync Creates a loose object schema. ```ts const Schema = v.looseObjectAsync(entries, message); ``` #### Generics - `TEntries` `extends ObjectEntriesAsync` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `entries` `TEntries` - `message` `TMessage` ##### 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`](/api/objectAsync.md) 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` `LooseObjectSchemaAsync` #### Examples The following examples show how `looseObjectAsync` can be used. Please see the [object guide](/guides/objects.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md), [`keyof`](/api/keyof.md), [`omit`](/api/omit.md), [`pick`](/api/pick.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`forwardAsync`](/api/forwardAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialAsync`](/api/partialAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### looseTupleAsync Creates a loose tuple schema. ```ts const Schema = v.looseTupleAsync(items, message); ``` #### Generics - `TItems` `extends TupleItemsAsync` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `items` `TItems` - `message` `TMessage` ##### 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`](/api/tupleAsync.md) is that this schema does include unknown items into the output. #### Returns - `Schema` `LooseTupleSchemaAsync` #### Examples The following examples show how `looseTupleAsync` can be used. Please see the [arrays guide](/guides/arrays.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`empty`](/api/empty.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`includes`](/api/includes.md), [`length`](/api/length.md), [`mapItems`](/api/mapItems.md), [`maxLength`](/api/maxLength.md), [`metadata`](/api/metadata.md), [`minLength`](/api/minLength.md), [`nonEmpty`](/api/nonEmpty.md), [`notLength`](/api/notLength.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### mapAsync Creates a map schema. ```ts const Schema = v.mapAsync(key, value, message); ``` #### Generics - `TKey` `extends BaseSchema> | BaseSchemaAsync>` - `TValue` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `key` `TKey` - `value` `TValue` - `message` `TMessage` ##### 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` `MapSchemaAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`check`](/api/check.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxSize`](/api/maxSize.md), [`metadata`](/api/metadata.md), [`minSize`](/api/minSize.md), [`notSize`](/api/notSize.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`size`](/api/size.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### nonNullableAsync Creates a non nullable schema. > This schema function can be used to override the behavior of [`nullableAsync`](/api/nullableAsync.md). ```ts const Schema = v.nonNullableAsync(wrapped, message); ``` #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `wrapped` `TWrapped` - `message` `TMessage` ##### 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` `NonNullableSchemaAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md), [`unwrap`](/api/unwrap.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### nonNullishAsync Creates a non nullish schema. > This schema function can be used to override the behavior of [`nullishAsync`](/api/nullishAsync.md). ```ts const Schema = v.nonNullishAsync(wrapped, message); ``` #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `wrapped` `TWrapped` - `message` `TMessage` ##### 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` `NonNullishSchemaAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md), [`unwrap`](/api/unwrap.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### nonOptionalAsync Creates a non optional schema. > This schema function can be used to override the behavior of [`optionalAsync`](/api/optionalAsync.md). ```ts const Schema = v.nonOptionalAsync(wrapped, message); ``` #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `wrapped` `TWrapped` - `message` `TMessage` ##### 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` `NonOptionalSchemaAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md), [`unwrap`](/api/unwrap.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### nullableAsync Creates a nullable schema. ```ts const Schema = v.nullableAsync(wrapped, default_); ``` #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TDefault` `extends DefaultAsync` #### Parameters - `wrapped` `TWrapped` - `default_` `TDefault` ##### 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`](/api/optionalAsync.md), and if you want to accept `null` and `undefined` inputs, use [`nullishAsync`](/api/nullishAsync.md) instead. Also, if you want to set a default output value for any invalid input, you should use [`fallbackAsync`](/api/fallbackAsync.md) instead. #### Returns - `Schema` `NullableSchemaAsync` #### 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`](/api/unwrap.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md), [`unwrap`](/api/unwrap.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### nullishAsync Creates a nullish schema. ```ts const Schema = v.nullishAsync(wrapped, default_); ``` #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TDefault` `extends DefaultAsync` #### Parameters - `wrapped` `TWrapped` - `default_` `TDefault` ##### 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. > **Important**: When used in object schemas, if a key is missing and no `default_` value is provided, the schema's pipe (including transformations) will not be executed. To ensure pipes run for missing keys, provide a `default_` value. > Note that `nullishAsync` accepts `undefined` or `null` as an input. If you want to accept only `null` inputs, use [`nullableAsync`](/api/nullableAsync.md), and if you want to accept only `undefined` inputs, use [`optionalAsync`](/api/optionalAsync.md) instead. Also, if you want to set a default output value for any invalid input, you should use [`fallbackAsync`](/api/fallbackAsync.md) instead. #### Returns - `Schema` `NullishSchemaAsync` #### 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`](/api/unwrap.md) 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.') ) ) ); ``` ##### Nullish async with pipes When using `nullishAsync` in a [`pipeAsync`](/api/pipeAsync.md), missing object keys only execute the pipe if a `default_` value is provided. If the key is present with `null` or `undefined`, later pipe actions still run. ```ts const SchemaWithoutDefault = v.objectAsync({ value: v.pipeAsync( v.nullishAsync(v.string()), v.transformAsync(async (input) => (input ?? 'hello').toUpperCase()) // Does not run for missing keys ), }); // Output type: { value?: string } const SchemaWithDefault = v.objectAsync({ value: v.pipeAsync( v.nullishAsync(v.string(), 'hello'), // Default value provided v.transformAsync(async (input) => input.toUpperCase()) // Runs for missing keys, null, and undefined too ), }); // Output type: { value: string } ``` #### Related The following APIs can be combined with `nullishAsync`. ##### Schemas [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md), [`unwrap`](/api/unwrap.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### objectAsync Creates an object schema. ```ts const Schema = v.objectAsync(entries, message); ``` #### Generics - `TEntries` `extends ObjectEntriesAsync` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `entries` `TEntries` - `message` `TMessage` ##### 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`](/api/looseObjectAsync.md). To return an issue for unknown entries, use [`strictObjectAsync`](/api/strictObjectAsync.md). To include and validate unknown entries, use [`objectWithRestAsync`](/api/objectWithRestAsync.md). #### Returns - `Schema` `ObjectSchemaAsync` #### Examples The following examples show how `objectAsync` can be used. Please see the [object guide](/guides/objects.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md), [`keyof`](/api/keyof.md), [`omit`](/api/omit.md), [`pick`](/api/pick.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`forwardAsync`](/api/forwardAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialAsync`](/api/partialAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### objectWithRestAsync Creates an object with rest schema. ```ts const Schema = v.objectWithRestAsync( entries, rest, message ); ``` #### Generics - `TEntries` `extends ObjectEntriesAsync` - `TRest` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `entries` `TEntries` - `rest` `TRest` - `message` `TMessage` ##### 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`](/api/objectAsync.md) 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` `ObjectWithRestSchemaAsync` #### Examples The following examples show how `objectWithRestAsync` can be used. Please see the [object guide](/guides/objects.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md), [`keyof`](/api/keyof.md), [`omit`](/api/omit.md), [`pick`](/api/pick.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`forwardAsync`](/api/forwardAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialAsync`](/api/partialAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### optionalAsync Creates an optional schema. ```ts const Schema = v.optionalAsync(wrapped, default_); ``` #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TDefault` `extends DefaultAsync` #### Parameters - `wrapped` `TWrapped` - `default_` `TDefault` ##### 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. > **Important**: When used in object schemas, if a key is missing and no `default_` value is provided, the schema's pipe (including transformations) will not be executed. To ensure pipes run for missing keys, provide a `default_` value. > Note that `optionalAsync` does not accept `null` as an input. If you want to accept `null` inputs, use [`nullableAsync`](/api/nullableAsync.md), and if you want to accept `null` and `undefined` inputs, use [`nullishAsync`](/api/nullishAsync.md) instead. Also, if you want to set a default output value for any invalid input, you should use [`fallbackAsync`](/api/fallbackAsync.md) instead. #### Returns - `Schema` `OptionalSchemaAsync` #### 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`](/api/unwrap.md) 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.') ) ) ); ``` ##### Optional async with pipes When using `optionalAsync` in a [`pipeAsync`](/api/pipeAsync.md), the pipe actions only execute if a `default_` value is provided or the key is present. This applies to all pipe actions including [`transformAsync`](/api/transformAsync.md), [`checkAsync`](/api/checkAsync.md), and others. ```ts const SchemaWithoutDefault = v.objectAsync({ isActive: v.pipeAsync( v.optionalAsync(v.string()), v.transformAsync(async (value) => value === 'true') // Does not run for missing keys ), }); // Output type: { isActive?: boolean } const SchemaWithDefault = v.objectAsync({ isActive: v.pipeAsync( v.optionalAsync(v.string(), 'false'), // Default value provided v.transformAsync(async (value) => value === 'true') // Runs for missing keys too ), }); // Output type: { isActive: boolean } ``` #### Related The following APIs can be combined with `optionalAsync`. ##### Schemas [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md), [`unwrap`](/api/unwrap.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### parseAsync Parses an unknown input based on a schema. ```ts const output = v.parseAsync(schema, input, config); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `schema` `TSchema` - `input` `unknown` - `config` `Config> | undefined` ##### Explanation `parseAsync` will throw a [`ValiError`](/api/ValiError.md) 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`](/api/ValiError.md). #### Returns - `output` `Promise>` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`flatten`](/api/flatten.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`summarize`](/api/summarize.md), [`unwrap`](/api/unwrap.md) ##### Utils [`getDotPath`](/api/getDotPath.md), [`isValiError`](/api/isValiError.md), [`ValiError`](/api/ValiError.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`partialAsync`](/api/partialAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### parserAsync Returns a function that parses an unknown input based on a schema. ```ts const parser = v.parserAsync(schema, config); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` - `TConfig` `extends Config> | undefined` #### Parameters - `schema` `TSchema` - `config` `TConfig` #### Returns - `parser` `ParserAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`flatten`](/api/flatten.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`summarize`](/api/summarize.md), [`unwrap`](/api/unwrap.md) ##### Utils [`getDotPath`](/api/getDotPath.md), [`isValiError`](/api/isValiError.md), [`ValiError`](/api/ValiError.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`partialAsync`](/api/partialAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### 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` `extends SchemaWithoutPipe | undefined> | ObjectSchemaAsync | undefined> | ObjectWithRestSchemaAsync> | BaseSchemaAsync>, ErrorMessage | undefined> | StrictObjectSchemaAsync | undefined>>` - `TKeys` `extends ObjectKeys | undefined` #### Parameters - `schema` `TSchema` - `keys` `TKey` ##### 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`](/api/pipeAsync.md) method, as this may cause runtime errors. Please use the [`pipeAsync`](/api/pipeAsync.md) method after you have modified the schema with `partialAsync`. #### Returns - `Schema` `SchemaWithPartialAsync` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`forward`](/api/forward.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`pick`](/api/pick.md), [`required`](/api/required.md), [`unwrap`](/api/unwrap.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`forwardAsync`](/api/forwardAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md) ### partialCheckAsync Creates a partial check validation action. ```ts const Action = v.partialCheckAsync( paths, requirement, message ); ``` #### Generics - `TInput` `extends PartialInput` - `TPaths` `extends RequiredPaths` - `TSelection` `extends DeepPickN` - `TMessage` `extends ErrorMessage> | undefined` #### Parameters - `paths` `ValidPaths` - `requirement` `(input: TSelection) => MaybePromise` - `message` `TMessage` ##### 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`](/api/checkAsync.md) is that `partialCheckAsync` can be executed whenever the selected part of the data is valid, while [`checkAsync`](/api/checkAsync.md) is executed only when the entire dataset is typed. This can be an important advantage when working with forms. #### Returns - `Action` `PartialCheckActionAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`record`](/api/record.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`union`](/api/union.md), [`variant`](/api/variant.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`customAsync`](/api/customAsync.md), [`forwardAsync`](/api/forwardAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### pipeAsync Adds a pipeline to a schema, that can validate and transform its input. ```ts const Schema = v.pipeAsync(schema, ...items); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` - `TItems` `extends readonly (PipeItem> | PipeItemAsync>)[]` #### Parameters - `schema` `TSchema` - `items` `TItems` ##### 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` `SchemaWithPipeAsync` #### Examples The following examples show how `pipeAsync` can be used. Please see the [pipeline guide](/guides/pipelines.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`forward`](/api/forward.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`required`](/api/required.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toCamelCase`](/api/toCamelCase.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`forwardAsync`](/api/forwardAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialAsync`](/api/partialAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### rawCheckAsync Creates a raw check validation action. ```ts const Action = v.rawCheckAsync(action); ``` #### Generics - `TInput` `extends any` #### Parameters - `action` `(context: Context) => MaybePromise` ##### Explanation With `rawCheckAsync` you can freely validate the input with a custom `action` and add issues if necessary. #### Returns - `Action` `RawCheckActionAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`forwardAsync`](/api/forwardAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### rawTransformAsync Creates a raw transformation action. ```ts const Action = v.rawTransformAsync(action); ``` #### Generics - `TInput` `extends any` - `TOutput` `extends any` #### Parameters - `action` `(context: Context) => MaybePromise` ##### Explanation With `rawTransformAsync` you can freely transform and validate the input with a custom `action` and add issues if necessary. #### Returns - `Action` `RawTransformActionAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`forwardAsync`](/api/forwardAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### recordAsync Creates a record schema. ```ts const Schema = v.recordAsync(key, value, message); ``` #### Generics - `TKey` `extends BaseSchema> | BaseSchemaAsync>` - `TValue` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `key` `TKey` - `value` `TValue` - `message` `TMessage` ##### 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`](/api/string.md), [`enum`](/api/enum.md) and [`picklist`](/api/picklist.md). However, if [`enum`](/api/enum.md) and [`picklist`](/api/picklist.md) are used, it is better to use [`objectAsync`](/api/objectAsync.md) with [`entriesFromList`](/api/entriesFromList.md) 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` `RecordSchemaAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### 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` `extends SchemaWithoutPipe | undefined> | ObjectSchemaAsync | undefined> | ObjectWithRestSchemaAsync> | BaseSchemaAsync>, ErrorMessage | undefined> | StrictObjectSchemaAsync | undefined>>` - `TKeys` `ObjectKeys` - `TMessage` `ErrorMessage | undefined` #### Parameters - `schema` `TSchema` - `keys` `TKey` - `message` `TMessage` ##### 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`](/api/pipeAsync.md) method, as this may cause runtime errors. Please use the [`pipeAsync`](/api/pipeAsync.md) method after you have modified the schema with `requiredAsync`. #### Returns - `AllKeysSchema` `SchemaWithRequiredAsync` - `SelectedKeysSchema` `SchemaWithRequiredAsync` #### 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 [`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`forward`](/api/forward.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`unwrap`](/api/unwrap.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`forwardAsync`](/api/forwardAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialAsync`](/api/partialAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md) ### returnsAsync Creates a function return transformation action. ```ts const Action = v.returnsAsync(schema); ``` #### Generics - `TInput` `extends (...args: any[]) => unknown` - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `schema` `TSchema` ##### Explanation With `returnsAsync` you can force the returned value of a function to match the given `schema`. #### Returns - `Action` `ReturnsActionAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`pipe`](/api/pipe.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### safeParseAsync Parses an unknown input based on a schema. ```ts const result = v.safeParseAsync(schema, input, config); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Parameters - `schema` `TSchema` - `input` `unknown` - `config` `Config> | undefined` #### Returns - `result` `Promise>` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`flatten`](/api/flatten.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`summarize`](/api/summarize.md), [`unwrap`](/api/unwrap.md) ##### Utils [`getDotPath`](/api/getDotPath.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`partialAsync`](/api/partialAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### safeParserAsync Returns a function that parses an unknown input based on a schema. ```ts const safeParser = v.safeParserAsync(schema, config); ``` #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` - `TConfig` `extends Config> | undefined` #### Parameters - `schema` `TSchema` - `config` `TConfig` #### Returns - `safeParser` `SafeParserAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`flatten`](/api/flatten.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`summarize`](/api/summarize.md), [`unwrap`](/api/unwrap.md) ##### Utils [`getDotPath`](/api/getDotPath.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`partialAsync`](/api/partialAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### setAsync Creates a set schema. ```ts const Schema = v.setAsync(value, message); ``` #### Generics - `TValue` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `value` `TValue` - `message` `TMessage` ##### 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` `SetSchemaAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxSize`](/api/maxSize.md), [`metadata`](/api/metadata.md), [`minSize`](/api/minSize.md), [`notSize`](/api/notSize.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`size`](/api/size.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### strictObjectAsync Creates a strict object schema. ```ts const Schema = v.strictObjectAsync(entries, message); ``` #### Generics - `TEntries` `extends ObjectEntriesAsync` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `entries` `TEntries` - `message` `TMessage` ##### 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`](/api/objectAsync.md) 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`](/api/objectWithRestAsync.md) schema with [`never`](/api/never.md) for the `rest` argument. #### Returns - `Schema` `StrictObjectSchemaAsync` #### Examples The following examples show how `strictObjectAsync` can be used. Please see the [object guide](/guides/objects.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md), [`keyof`](/api/keyof.md), [`omit`](/api/omit.md), [`pick`](/api/pick.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`forwardAsync`](/api/forwardAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialAsync`](/api/partialAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### strictTupleAsync Creates a strict tuple schema. ```ts const Schema = v.strictTupleAsync(items, message); ``` #### Generics - `TItems` `extends TupleItemsAsync` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `items` `TItems` - `message` `TMessage` ##### 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`](/api/tupleAsync.md) 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`](/api/tupleWithRestAsync.md) schema with [`never`](/api/never.md) for the `rest` argument. #### Returns - `Schema` `StrictTupleSchemaAsync` #### Examples The following examples show how `strictTupleAsync` can be used. Please see the [arrays guide](/guides/arrays.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`empty`](/api/empty.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`includes`](/api/includes.md), [`length`](/api/length.md), [`mapItems`](/api/mapItems.md), [`maxLength`](/api/maxLength.md), [`metadata`](/api/metadata.md), [`minLength`](/api/minLength.md), [`nonEmpty`](/api/nonEmpty.md), [`notLength`](/api/notLength.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### transformAsync Creates a custom transformation action. ```ts const Action = v.transformAsync(operation); ``` #### Generics - `TInput` `extends any` - `TOutput` `extends any` #### Parameters - `operation` `(input: TInput) => Promise` ##### 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` `TransformActionAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Utils [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`recordAsync`](/api/recordAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### tupleAsync Creates a tuple schema. ```ts const Schema = v.tupleAsync(items, message); ``` #### Generics - `TItems` `extends TupleItemsAsync` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `items` `TItems` - `message` `TMessage` ##### 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`](/api/looseTupleAsync.md). To return an issue for unknown items, use [`strictTupleAsync`](/api/strictTupleAsync.md). To include and validate unknown items, use [`tupleWithRestAsync`](/api/tupleWithRestAsync.md). #### Returns - `Schema` `TupleSchemaAsync` #### Examples The following examples show how `tupleAsync` can be used. Please see the [arrays guide](/guides/arrays.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`empty`](/api/empty.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`includes`](/api/includes.md), [`length`](/api/length.md), [`mapItems`](/api/mapItems.md), [`maxLength`](/api/maxLength.md), [`metadata`](/api/metadata.md), [`minLength`](/api/minLength.md), [`nonEmpty`](/api/nonEmpty.md), [`notLength`](/api/notLength.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### tupleWithRestAsync Creates a tuple with rest schema. ```ts const Schema = v.tupleWithRestAsync( items, rest, message ); ``` #### Generics - `TItems` `extends TupleItemsAsync` - `TRest` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `items` `TItems` - `rest` `TRest` - `message` `TMessage` ##### 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` `TupleWithRestSchemaAsync` #### Examples The following examples show how `tupleWithRestAsync` can be used. Please see the [arrays guide](/guides/arrays.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`brand`](/api/brand.md), [`description`](/api/description.md), [`empty`](/api/empty.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`includes`](/api/includes.md), [`length`](/api/length.md), [`mapItems`](/api/mapItems.md), [`maxLength`](/api/maxLength.md), [`metadata`](/api/metadata.md), [`minLength`](/api/minLength.md), [`nonEmpty`](/api/nonEmpty.md), [`notLength`](/api/notLength.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### undefinedableAsync Creates an undefinedable schema. ```ts const Schema = v.undefinedableAsync(wrapped, default_); ``` #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TDefault` `extends DefaultAsync` #### Parameters - `wrapped` `TWrapped` - `default_` `TDefault` ##### 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`](/api/optionalAsync.md) at runtime. The only difference is the input and output type when used for object entries. While [`optionalAsync`](/api/optionalAsync.md) 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`](/api/nullableAsync.md), and if you want to accept `null` and `undefined` inputs, use [`nullishAsync`](/api/nullishAsync.md) instead. Also, if you want to set a default output value for any invalid input, you should use [`fallbackAsync`](/api/fallbackAsync.md) instead. #### Returns - `Schema` `UndefinedableSchemaAsync` #### 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`](/api/unwrap.md) 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md), [`unwrap`](/api/unwrap.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`metadata`](/api/metadata.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`unionAsync`](/api/unionAsync.md), [`variantAsync`](/api/variantAsync.md) ### unionAsync Creates an union schema. > I recommend that you read the [unions guide](/guides/unions.md) before using this schema function. ```ts const Schema = v.unionAsync(options, message); ``` #### Generics - `TOptions` `extends UnionOptionsAsync` - `TMessage` `extends ErrorMessage>> | undefined` #### Parameters - `options` `TOptions` - `message` `TMessage` ##### 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` `UnionSchemaAsync` #### 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 [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toCamelCase`](/api/toCamelCase.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`arrayAsync`](/api/arrayAsync.md), [`awaitAsync`](/api/awaitAsync.md), [`checkAsync`](/api/checkAsync.md), [`customAsync`](/api/customAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`variantAsync`](/api/variantAsync.md) ### variantAsync Creates a variant schema. ```ts const Schema = v.variantAsync(key, options, message); ``` #### Generics - `TKey` `extends string` - `TOptions` `extends VariantOptionsAsync` - `TMessage` `extends ErrorMessage | undefined` #### Parameters - `key` `TKey` - `options` `TOptions` - `message` `TMessage` ##### 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` `VariantSchemaAsync` #### 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 [`looseObject`](/api/looseObject.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`strictObject`](/api/strictObject.md) ##### Methods [`config`](/api/config.md), [`getDefault`](/api/getDefault.md), [`getFallback`](/api/getFallback.md) ##### Actions [`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md) ##### Utils [`entriesFromList`](/api/entriesFromList.md), [`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md) ##### Async [`checkAsync`](/api/checkAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`pipeAsync`](/api/pipeAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`transformAsync`](/api/transformAsync.md) ## Types (API) ### AnySchema Any schema interface. #### Definition - `AnySchema` `extends BaseSchema` - `type` `'any'` - `reference` `typeof any` - `expects` `'any'` ### ArgsAction Args action interface. #### Generics - `TInput` `extends (...args: any[]) => unknown` - `TSchema` `extends LooseTupleSchema | undefined> | StrictTupleSchema | undefined> | TupleSchema | undefined> | TupleWithRestSchema>, ErrorMessage | undefined>` #### Definition - `ArgsAction` `extends BaseTransformation) => ReturnType, never>` - `type` `'args'` - `reference` `typeof args` - `schema` `TSchema` ### ArgsActionAsync Args action interface. #### Generics - `TInput` `extends (...args: any[]) => unknown` - `TSchema` `extends LooseTupleSchema | undefined> | LooseTupleSchemaAsync | undefined> | StrictTupleSchema | undefined> | StrictTupleSchemaAsync | undefined> | TupleSchema | undefined> | TupleSchemaAsync | undefined> | TupleWithRestSchema>, ErrorMessage | undefined> | TupleWithRestSchemaAsync> | BaseSchemaAsync>, ErrorMessage | undefined>` #### Definition - `ArgsActionAsync` `extends BaseTransformation) => Promise>>, never>` - `type` `'args'` - `reference` `typeof argsAsync` - `schema` `TSchema` ### ArrayInput Array input type. #### Definition - `ArrayInput` `MaybeReadonly` ### ArrayIssue Array issue interface. #### Definition - `ArrayIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'array'` - `expected` `'Array'` ### ArrayPathItem Array path item interface. #### Definition - `ArrayPathItem` - `type` `'array'` - `origin` `'value'` - `input` `MaybeReadonly` - `key` `number` - `value` `unknown` 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` `extends ArrayInput` #### Definition - `ArrayRequirement` `(item: TInput[number], index: number, array: TInput) => boolean` ### ArrayRequirementAsync Array requirement async type. #### Generics - `TInput` `extends ArrayInput` #### Definition - `ArrayRequirementAsync` `(item: TInput[number], index: number, array: TInput) => MaybePromise` ### ArraySchema Array schema interface. #### Generics - `TItem` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `ArraySchema` `extends BaseSchema[], InferOutput[], ArrayIssue | InferIssue>` - `type` `'array'` - `reference` `typeof array` - `expects` `'Array'` - `item` `TItem` - `message` `TMessage` ### ArraySchemaAsync Array schema async interface. #### Generics - `TItem` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `ArraySchemaAsync` `extends BaseSchemaAsync[], InferOutput[], ArrayIssue | InferIssue>` - `type` `'array'` - `reference` `typeof array | typeof arrayAsync` - `expects` `'Array'` - `item` `TItem` - `message` `TMessage` ### AwaitActionAsync Await action async interface. #### Generics - `TInput` `extends Promise` #### Definition - `AwaitActionAsync` `extends BaseTransformationAsync, never>` - `type` `'await'` - `reference` `typeof awaitAsync` ### Base64Action Base64 action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `Base64Action` `extends BaseValidation>` - `type` `'base64'` - `reference` `typeof base64` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### Base64Issue Base64 issue interface. #### Generics - `TInput` `extends string` #### Definition - `Base64Issue` `extends BaseIssue` - `kind` `'validation'` - `type` `'base64'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### BaseIssue Schema issue interface. #### Generics - `TInput` `extends any` #### Definition - `BaseIssue` `extends Config>` - `kind` `'schema' | 'validation' | 'transformation'` - `type` `string` - `input` `TInput` - `expected` `string | null` - `received` `string` - `message` `string` - `requirement` `unknown | undefined` - `path` `[IssuePathItem, ...IssuePathItem[]] | undefined` - `issues` `[BaseIssue, ...BaseIssue[]] | undefined` ### BaseMetadata Base metadata interface. #### Generics - `TInput` `extends any` #### Definition - `BaseMetadata` - `kind` `'metadata'` - `type` `string` - `reference` `(...args: any[]) => BaseMetadata` - `~types` `{ input: TInput, output: TInput, issue: never } | undefined` ### BaseSchema Base schema interface. #### Generics - `TInput` `extends any` - `TOutput` `extends any` - `TIssue` `extends BaseIssue` #### Definition - `BaseSchema` - `kind` `'schema'` - `type` `string` - `reference` `(...args: any[]) => BaseSchema>` - `expects` `string` - `async` `false` - `~standard` `StandardProps` - `~run` `(dataset: UnknownDataset, config: Config>) => OutputDataset` - `~types` `{ input: TInput, output: TOutput, issue: TIssue } | undefined` ### BaseSchemaAsync Base schema async interface. #### Generics - `TInput` `extends any` - `TOutput` `extends any` - `TIssue` `extends BaseIssue` #### Definition - `BaseSchemaAsync` `extends Omit, 'reference' | 'async' | '~run'>` - `reference` `((...args: any[]) => BaseSchema> | BaseSchemaAsync>)` - `async` `true` - `~run` `(dataset: UnknownDataset, config: Config>) => Promise>` ### BaseTransformation Base transformation interface. #### Generics - `TInput` `extends any` - `TOutput` `extends any` - `TIssue` `extends BaseIssue` #### Definition - `BaseTransformation` - `kind` `'transformation'` - `type` `string` - `reference` `(...args: any[]) => BaseTransformation>` - `async` `false` - `~run` `(dataset: SuccessDataset, config: Config>) => OutputDataset | TIssue>` - `~types` `{ input: TInput, output: TOutput, issue: TIssue } | undefined` ### BaseTransformationAsync Base transformation async interface. #### Generics - `TInput` `extends any` - `TOutput` `extends any` - `TIssue` `extends BaseIssue` #### Definition - `BaseTransformationAsync` `extends Omit, 'reference' | 'async' | '~run'>` - `reference` `((...args: any[]) => BaseTransformation> | BaseTransformationAsync>)` - `async` `true` - `~run` `(dataset: SuccessDataset, config: Config>) => Promise | TIssue>>` ### BaseValidation Base action interface. #### Generics - `TInput` `extends any` - `TOutput` `extends any` - `TIssue` `extends BaseIssue` #### Definition - `BaseValidation` - `kind` `'validation'` - `type` `string` - `reference` `(...args: any[]) => BaseValidation>` - `expects` `string | null` - `async` `false` - `~run` `(dataset: OutputDataset>, config: Config) => OutputDataset | TIssue>` - `~types` `{ input: TInput, output: TOutput, issue: TIssue } | undefined` ### BaseValidationAsync Base validation async interface. #### Generics - `TInput` `extends any` - `TOutput` `extends any` - `TIssue` `extends BaseIssue` #### Definition - `BaseValidationAsync` `extends Omit, 'reference' | 'async' | '~run'>` - `reference` `((...args: any[]) => BaseValidation> | BaseValidationAsync>)` - `async` `true` - `~run` `(dataset: OutputDataset>, config: Config) => Promise | TIssue>>` ### BicAction BIC action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `BicAction` `extends BaseValidation>` - `type` `'bic'` - `reference` `typeof bic` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### BicIssue Bic issue interface. #### Generics - `TInput` `extends string` #### Definition - `BicIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'bic'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### BigintIssue Bigint issue interface. #### Definition - `BigintIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'bigint'` - `expected` `'bigint'` ### BigintSchema Bigint schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `BigintSchema` `extends BaseSchema` - `type` `'bigint'` - `reference` `typeof bigint` - `expects` `'bigint'` - `message` `TMessage` ### BlobIssue Blob issue interface. #### Definition - `BlobIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'blob'` - `expected` `'Blob'` ### BlobSchema Blob schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `BlobSchema` `extends BaseSchema` - `type` `'blob'` - `reference` `typeof blob` - `expects` `'Blob'` - `message` `BlobIssue` ### BooleanIssue Boolean issue interface. #### Definition - `BooleanIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'boolean'` - `expected` `'boolean'` ### BooleanSchema Boolean schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `BooleanSchema` `extends BaseSchema` - `type` `'boolean'` - `reference` `typeof boolean` - `expects` `'boolean'` - `message` `TMessage` ### Brand Brand interface. #### Generics - `TName` `extends BrandName` #### Definition - `Brand` `{ [BrandSymbol]: { [TValue in TName]: TValue } }` ### BrandAction Brand action interface. #### Generics - `TInput` `extends any` - `TName` `extends BrandName` #### Definition - `BrandAction` `extends BaseTransformation, never>` - `type` `'brand'` - `reference` `typeof brand` - `name` `TName` ### BrandName Brand name type. #### Definition - `BrandName` `string | number | symbol` ### BytesAction Bytes action interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `BytesAction` `extends BaseValidation>` - `type` `'bytes'` - `reference` `typeof bytes` - `expects` `` `${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### BytesIssue Bytes issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `BytesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'bytes'` - `expected` `` `${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### Cache Cache interface type. > Hint: The `key` method uses value-based keys for primitive inputs and reference-identity keys for object and function inputs. #### Generics - `TValue` `extends any` #### Definition - `Cache` - `key` `(input: unknown, config?: Config>) => string` - `get` `((key: string) => TValue | undefined)` - `set` `(key: string, value: TValue) => void` - `clear` `() => void` ### CacheConfig Cache config interface. #### Definition - `CacheConfig` - `maxSize?` `number` - `maxAge?` `number` ### CheckAction Check action interface. #### Generics - `TInput` `extends any` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `CheckAction` `extends BaseValidation>` - `type` `'check'` - `reference` `typeof check` - `expects` `null` - `requirement` `(input: TInput) => boolean` - `message` `TMessage` ### CheckActionAsync Check action async interface. #### Generics - `TInput` `extends any` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `CheckActionAsync` `extends BaseValidationAsync>` - `type` `'check'` - `reference` `typeof checkAsync` - `expects` `null` - `requirement` `(input: TInput) => MaybePromise` - `message` `TMessage` ### CheckIssue Check issue interface. #### Generics - `TInput` `extends any` #### Definition - `CheckIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'check'` - `expected` `null` - `requirement` `(input: TInput) => MaybePromise` ### CheckItemsAction Check items action interface. #### Generics - `TInput` `extends ArrayInput` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `CheckItemsAction` `extends BaseValidation>` - `type` `'check_items'` - `reference` `typeof checkItems` - `expects` `null` - `requirement` `ArrayRequirement` - `message` `TMessage` ### CheckItemsActionAsync Check items action async interface. #### Generics - `TInput` `extends ArrayInput` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `CheckItemsActionAsync` `extends BaseValidationAsync>` - `type` `'check_items'` - `reference` `typeof checkItemsAsync` - `expects` `null` - `requirement` `ArrayRequirementAsync` - `message` `TMessage` ### CheckItemsIssue Check items issue interface. #### Generics - `TInput` `extends ArrayInput` #### Definition - `CheckItemsIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'check_items'` - `expected` `null` - `requirement` `ArrayRequirementAsync` ### Class Class type. #### Definition - `Class` `new (...args: any[]) => any` ### CodePointsAction Code points action interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `CodePointsAction` `extends BaseValidation>` - `type` `'code_points'` - `reference` `typeof codePoints` - `expects` `` `${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### CodePointsIssue Code points issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `CodePointsIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'code_points'` - `expected` `` `${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### Config Config interface. #### Generics - `TIssue` `extends BaseIssue` #### Definition - `Config` - `lang` `string | undefined` - `message` `ErrorMessage | undefined` - `abortEarly` `boolean | undefined` - `abortPipeEarly` `boolean | undefined` ### ContentInput Content input type. #### Definition - `ContentInput` `string | MaybeReadonly` ### ContentRequirement Content requirement type. #### Generics - `TInput` `extends ContentInput` #### Definition - `ContentRequirement` `TInput extends readonly unknown[] ? TInput[number] : TInput` ### CreditCardAction Credit card action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `CreditCardAction` `extends BaseValidation>` - `type` `'credit_card'` - `reference` `typeof creditCard` - `expects` `null` - `requirement` `(input: string) => boolean` - `message` `TMessage` ### CreditCardIssue Credit card issue interface. #### Generics - `TInput` `extends string` #### Definition - `CreditCardIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'credit_card'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `(input: string) => boolean` ### Cuid2Action Cuid2 action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `Cuid2Action` `extends BaseValidation>` - `type` `'cuid2'` - `reference` `typeof cuid2` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### Cuid2Issue Cuid2 issue interface. #### Generics - `TInput` `extends string` #### Definition - `Cuid2Issue` `extends BaseIssue` - `kind` `'validation'` - `type` `'cuid2'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### CustomIssue Custom issue interface. #### Definition - `CustomIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'custom'` - `expected` `'unknown'` ### CustomSchema Custom schema interface. #### Generics - `TInput` `extends any` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `CustomSchema` `extends BaseSchema` - `type` `'custom'` - `reference` `typeof custom` - `expects` `'unknown'` - `check` `(input: unknown) => boolean` - `message` `TMessage` ### CustomSchemaAsync Custom schema async interface. #### Generics - `TInput` `extends any` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `CustomSchemaAsync` `extends BaseSchemaAsync` - `type` `'custom'` - `reference` `typeof custom | typeof customAsync` - `expects` `'unknown'` - `check` `(input: unknown) => MaybePromise` - `message` `TMessage` ### DateIssue Date issue interface. #### Definition - `DateIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'date'` - `expected` `'Date'` ### DateSchema Date schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `DateSchema` `extends BaseSchema` - `type` `'date'` - `reference` `typeof date` - `expects` `'Date'` - `message` `TMessage` ### DecimalAction Decimal action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `DecimalAction` `extends BaseValidation>` - `type` `'decimal'` - `reference` `typeof decimal` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### DecimalIssue Decimal issue interface. #### Generics - `TInput` `extends string` #### Definition - `DecimalIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'decimal'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### DeepPickN Deeply picks N specific keys. > This type is too complex to display. Please refer to the [source code](https://github.com/open-circle/valibot/blob/main/library/src/actions/partialCheck/types.ts). ### Default Default type. #### Generics - `TWrapped` `extends BaseSchema>` - `TInput` `extends null | undefined` #### Definition - `Default` `MaybeReadonly, TInput> | ((dataset?: UnknownDataset, config?: Config>) => MaybeReadonly, TInput>)` ### DefaultAsync Default async type. #### Generics - `TWrapped` `extends BaseSchema>` - `TInput` `extends null | undefined` #### Definition - `DefaultAsync` `MaybeReadonly, TInput> | ((dataset?: UnknownDataset, config?: Config>) => MaybePromise, TInput>>)` ### DefaultValue Default value type. #### Generics - `TDefault` `extends Default>, null | undefined> | DefaultAsync> | BaseSchemaAsync>, null | undefined>` #### Definition - `DefaultValue` `TDefault extends DefaultAsync ? TDefault extends (dataset?: UnknownDataset, config?: Config>) => MaybePromise, TInput>> ? Awaited> : TDefault : never` ### DescriptionAction Description action interface. #### Generics - `TInput` `extends any` - `TDescription` `extends string` #### Definition - `DescriptionAction` `extends BaseMetadata` - `type` `'description'` - `reference` `typeof description` - `description` `TDescription` ### DigitsAction Digits action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `DigitsAction` `extends BaseValidation>` - `type` `'digits'` - `reference` `typeof digits` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### DigitsIssue Digits issue interface. #### Generics - `TInput` `extends string` #### Definition - `DigitsIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'digits'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### DomainAction Domain action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `DomainAction` `extends BaseValidation>` - `type` `'domain'` - `reference` `typeof domain` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### DomainIssue Domain issue interface. #### Generics - `TInput` `extends string` #### Definition - `DomainIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'domain'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### EmailAction Email action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `EmailAction` `extends BaseValidation>` - `type` `'email'` - `reference` `typeof email` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### EmailIssue Email issue interface. #### Generics - `TInput` `extends string` #### Definition - `EmailIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'email'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### EmojiAction Emoji action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `EmojiAction` `extends BaseValidation>` - `type` `'emoji'` - `reference` `typeof emoji` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### EmojiIssue Emoji issue interface. #### Generics - `TInput` `extends string` #### Definition - `EmojiIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'emoji'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### EmptyAction Empty action interface. #### Generics - `TInput` `extends LengthInput` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `EmptyAction` `extends BaseValidation>` - `type` `'empty'` - `reference` `typeof empty` - `expects` `'0'` - `message` `TMessage` ### EmptyIssue Empty issue interface. #### Generics - `TInput` `extends LengthInput` #### Definition - `EmptyIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'empty'` - `expected` `'0'` - `received` `` `${number}` `` ### EndsWithAction Ends with action interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `EndsWithAction` `extends BaseValidation>` - `type` `'ends_with'` - `reference` `typeof endsWith` - `expects` `` `"${TRequirement}"` `` - `requirement` `TRequirement` - `message` `TMessage` ### EndsWithIssue Ends with issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends string` #### Definition - `EndsWithIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'ends_with'` - `expected` `` `"${TRequirement}"` `` - `received` `` `"${string}"` `` - `requirement` `TRequirement` ### EntriesAction Entries action interface. #### Generics - `TInput` `extends EntriesInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `EntriesAction` `extends BaseValidation>` - `type` `'entries'` - `reference` `typeof entries` - `expects` `` `${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### EntriesInput Entries input type. #### Definition - `EntriesInput` `Record` ### EntriesIssue Entries issue interface. #### Generics - `TInput` `extends EntriesInput` - `TRequirement` `extends number` #### Definition - `EntriesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'entries'` - `expected` `` `${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### Enum Enum interface. #### Definition - `Enum` `{ [key: string]: string | number }` ### EnumIssue Enum issue interface. #### Definition - `EnumIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'enum'` - `expected` `string` ### EnumSchema Enum schema interface. #### Generics - `TEnum` `extends Enum` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `EnumSchema` `extends BaseSchema` - `type` `'enum'` - `reference` `typeof enum` - `enum` `TEnum` - `options` `TEnum[keyof TEnum][]` - `message` `TMessage` ### ErrorMessage Error message type. #### Generics - `TIssue` `extends BaseIssue` #### Definition - `ErrorMessage` `((issue: TIssue) => string) | string` ### EveryItemAction Every action interface. #### Generics - `TInput` `extends readonly unknown[]` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `EveryItemAction` `extends BaseValidation>` - `type` `'every_item'` - `reference` `typeof everyItem` - `expects` `null` - `requirement` `(item: TInput[number], index: number, array: TInput) => boolean` - `message` `TMessage` ### EveryItemIssue Every item issue interface. #### Generics - `TInput` `extends ArrayInput` #### Definition - `EveryItemIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'every_item'` - `expected` `null` - `requirement` `ArrayRequirement` ### ExactOptionalSchema Exact optional schema interface. #### Generics - `TWrapped` `extends BaseSchema>` - `TDefault` `extends Default` #### Definition - `ExactOptionalSchema` `extends BaseSchema, InferOutput, InferIssue>` - `type` `'exact_optional'` - `reference` `typeof exactOptional` - `expects` `TWrapped['expects']` - `wrapped` `TWrapped` - `default` `TDefault` ### ExactOptionalSchemaAsync Exact optional schema async interface. #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TDefault` `extends DefaultAsync` #### Definition - `ExactOptionalSchemaAsync` `BaseSchemaAsync, InferOutput, InferIssue>` - `type` `'exact_optional'` - `reference` `typeof exactOptional | typeof exactOptionalAsync` - `expects` `` `(${TWrapped['expects']} | undefined)` `` - `wrapped` `TWrapped` - `default` `TDefault` ### ExamplesAction Examples metadata action. #### Generics - `TInput` `extends any` - `TExamples` `extends readonly TInput[]` #### Definition - `ExamplesAction` `extends BaseMetadata` - `type` `'examples'` - `reference` `typeof examples` - `examples` `TExamples` #### Related The following APIs can be combined with `ExamplesAction`. ##### Schemas [`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md) ##### Methods [`getExamples`](/api/getExamples.md), [`pipe`](/api/pipe.md) ##### Actions [`examples`](/api/examples.md) ### ExcludesAction Excludes action interface. #### Generics - `TInput` `extends ContentInput` - `TRequirement` `extends ContentRequirement` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `ExcludesAction` `extends BaseValidation>` - `type` `'excludes'` - `referece` `typeof excludes` - `expects` `string` - `requirement` `TRequirement` - `message` `TMessage` ### ExcludesIssue Excludes issue interface. #### Generics - `TInput` `extends ContentInput` - `TRequirement` `extends ContentRequirement` #### Definition - `ExcludesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'excludes'` - `expected` `string` - `requirement` `TRequirement` ### FailureDataset Failure dataset interface. #### Generics - `TIssue` `extends BaseIssue` #### Definition - `UntypedDataset` - `typed` `false` - `value` `unknown` - `issues` `[TIssue, ...TIssue[]]` ### Fallback Fallback type. #### Generics - `TSchema` `extends BaseSchema>` #### Definition - `Fallback` `extends MaybeReadonly> | ((dataset?: OutputDataset, InferIssue>, config?: Config>) => MaybeReadonly>)` ### FallbackAsync Fallback async type. #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Definition - `FallbackAsync` `extends MaybeReadonly> | ((dataset?: OutputDataset, InferIssue>, config?: Config>) => MaybePromise>>)` ### FileIssue File issue interface. #### Definition - `FileIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'file'` - `expected` `'File'` ### FileSchema File schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `FileSchema` `extends BaseSchema` - `type` `'file'` - `reference` `typeof file` - `expects` `'File'` - `message` `TMessage` ### FilterItemsAction Filter items action interface. #### Generics - `TInput` `extends ArrayInput` #### Definition - `FilterItemsAction` `extends BaseTransformation` - `type` `'filter_items'` - `reference` `typeof filterItems` - `operation` `ArrayRequirement` ### FindItemAction Find item action interface. #### Generics - `TInput` `extends ArrayInput` #### Definition - `FindItemAction` `extends BaseTransformation` - `type` `'find_item'` - `reference` `typeof findItem` - `operation` `ArrayRequirement` ### FiniteAction Finite action interface. #### Generics - `TInput` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `FiniteAction` `extends BaseValidation>` - `type` `'finite'` - `reference` `typeof finite` - `expects` `null` - `requirement` `(input: number) => boolean` - `message` `TMessage` ### FiniteIssue Finite issue interface. #### Generics - `TInput` `extends number` #### Definition - `FiniteIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'finite'` - `expected` `null` - `received` `` `${number}` `` - `requirement` `(input: number) => boolean` ### FirstTupleItem Extracts first tuple item. #### Generics - `TTuple` `extends [unknown, ...unknown[]]` #### Definition - `FirstTupleItem` `TTuple[0]` ### FlatErrors Flat errors type. > This type is too complex to display. Please refer to the [source code](https://github.com/open-circle/valibot/blob/main/library/src/methods/flatten/flatten.ts). ### Flavor Flavor interface. #### Generics - `TName` `extends FlavorName` #### Definition - `Flavor` `{ [FlavorSymbol]: { [TValue in TName]: TValue } }` ### FlavorAction Flavor action interface. #### Generics - `TInput` `extends any` - `TName` `extends FlavorName` #### Definition - `FlavorAction` `extends BaseTransformation, never>` - `type` `'flavor'` - `reference` `typeof flavor` - `name` `TName` ### FlavorName Flavor name type. #### Definition - `FlavorName` `string | number | symbol` ### FunctionIssue Function issue interface. #### Definition - `FunctionIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'function'` - `expected` `'Function'` ### FunctionSchema Function schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `FunctionSchema` `extends BaseSchema<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown, FunctionIssue>` - `type` `'function'` - `reference` `typeof function` - `expects` `'Function'` - `message` `TMessage` ### GenericIssue Generic issue type. #### Generics - `TInput` `extends any = unknown` #### Definition - `GenericIssue` `extends BaseIssue` ### GenericMetadata Generic metadata type. #### Generics - `TInput` `extends any = any` #### Definition - `GenericMetadata` `extends BaseMetadata` ### GenericPipeAction Generic pipe action type. #### Generics - `TInput` `extends any = any` - `TOutput` `extends any = TInput` - `TIssue` `extends BaseIssue = BaseIssue` #### Definition - `GenericPipeAction` `extends PipeAction` ### GenericPipeActionAsync Generic pipe action async type. #### Generics - `TInput` `extends any = any` - `TOutput` `extends any = TInput` - `TIssue` `extends BaseIssue = BaseIssue` #### Definition - `GenericPipeActionAsync` `extends PipeActionAsync` ### GenericPipeItem Generic pipe item type. #### Generics - `TInput` `extends any = any` - `TOutput` `extends any = TInput` - `TIssue` `extends BaseIssue = BaseIssue` #### Definition - `GenericPipeItem` `extends PipeItem` ### GenericPipeItemAsync Generic pipe item async type. #### Generics - `TInput` `extends any = any` - `TOutput` `extends any = TInput` - `TIssue` `extends BaseIssue = BaseIssue` #### Definition - `GenericPipeItemAsync` `extends PipeItemAsync` ### GenericSchema Generic schema type. #### Generics - `TInput` `extends any = unknown` - `TOutput` `extends any = TInput` - `TIssue` `extends BaseIssue = BaseIssue` #### Definition - `GenericSchema` `extends BaseSchema` ### GenericSchemaAsync Generic schema async type. #### Generics - `TInput` `extends any = unknown` - `TOutput` `extends any = TInput` - `TIssue` `extends BaseIssue = BaseIssue` #### Definition - `GenericSchemaAsync` `BaseSchemaAsync` ### GenericTransformation Generic transformation type. #### Generics - `TInput` `extends any = any` - `TOutput` `extends any = TInput` - `TIssue` `extends BaseIssue = BaseIssue` #### Definition - `GenericTransformation` `extends BaseTransformation` ### GenericTransformationAsync Generic transformation async type. #### Generics - `TInput` `extends any = any` - `TOutput` `extends any = TInput` - `TIssue` `extends BaseIssue = BaseIssue` #### Definition - `GenericTransformationAsync` `BaseTransformationAsync` ### GenericValidation Generic validation type. #### Generics - `TInput` `extends any = any` - `TOutput` `extends any = TInput` - `TIssue` `extends BaseIssue = BaseIssue` #### Definition - `GenericValidation` `extends BaseValidation` ### GenericValidationAsync Generic validation async type. #### Generics - `TInput` `extends any = any` - `TOutput` `extends any = TInput` - `TIssue` `extends BaseIssue = BaseIssue` #### Definition - `GenericValidationAsync` `BaseValidationAsync` ### GlobalConfig The global config type. #### Definition - `GlobalConfig` `Omit, 'message'>` ### GraphemesAction Graphemes action interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `GraphemesAction` `extends BaseValidation>` - `type` `'graphemes'` - `reference` `typeof graphemes` - `expects` `` `${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### GraphemesIssue Graphemes issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `GraphemesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'graphemes'` - `expected` `` `${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### GtValueAction Greater than value action type. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `GtValueAction` `extends BaseValidation>` - `type` `'gt_value'` - `reference` `typeof gtValue` - `expects` `` `>${string}` `` - `requirement` `TRequirement` - `message` `TMessage` ### GtValueIssue Greater than value issue type. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` #### Definition - `GtValueIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'gt_value'` - `expected` `` `>${string}` `` - `requirement` `TRequirement` ### GuardAction Guard action interface. #### Generics - `TInput` `extends any` - `TGuard` `extends GuardFunction` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `GuardAction` `extends BaseTransformation, GuardIssue>` - `type` `'guard'` - `reference` `typeof guard` - `requirement` `TGuard` - `message` `TMessage` ### GuardFunction Guard function type. #### Generics - `TInput` `extends any` #### Definition - `GuardFunction` `(input: TInput) => input is any` ### GuardIssue Guard issue interface. #### Generics - `TInput` `extends any` - `TGuard` `extends GuardFunction` #### Definition - `GuardIssue` `extends BaseIssue` - `kind` `'transformation'` - `type` `'guard'` - `requirement` `TGuard` ### HashAction Hash action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `HashAction` `extends BaseValidation>` - `type` `'hash'` - `reference` `typeof hash` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### HashIssue Hash issue interface. #### Generics - `TInput` `extends string` #### Definition - `HashIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'hash'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### HashType Hash type type. #### Definition - `HashType` `'md4' | 'md5' | 'sha1' | 'sha256' | 'sha384' | 'sha512' | 'ripemd128' | 'ripemd160' | 'tiger128' | 'tiger160' | 'tiger192' | 'crc32' | 'crc32b' | 'adler32'` ### HexadecimalAction Hexadecimal action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `HexadecimalAction` `extends BaseValidation>` - `type` `'hexadecimal'` - `reference` `typeof hexadecimal` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### HexadecimalIssue Hexadecimal issue interface. #### Generics - `TInput` `extends string` #### Definition - `HexadecimalIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'hexadecimal'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### HexColorAction Hex color action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `HexColorAction` `extends BaseValidation>` - `type` `'hex_color'` - `reference` `typeof hexColor` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### HexColorIssue HexColor issue interface. #### Generics - `TInput` `extends string` #### Definition - `HexColorIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'hex_color'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### ImeiAction Imei action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `ImeiAction` `extends BaseValidation>` - `type` `'imei'` - `reference` `typeof imei` - `expects` `null` - `requirement` `(input: string) => boolean` - `message` `TMessage` ### ImeiIssue IMEI issue interface. #### Generics - `TInput` `extends string` #### Definition - `ImeiIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'imei'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `(input: string) => boolean` ### IncludesAction Includes action interface. #### Generics - `TInput` `extends ContentInput` - `TRequirement` `extends ContentRequirement` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `IncludesAction` `extends BaseValidation>` - `type` `'includes'` - `reference` `typeof includes` - `expects` `string` - `requirement` `TRequirement` - `message` `TMessage` ### IncludesIssue Includes issue interface. #### Generics - `TInput` `extends ContentInput` - `TRequirement` `extends ContentRequirement` #### Definition - `IncludesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'includes'` - `expected` `string` - `requirement` `TRequirement` ### InferDefault Infer default type. > This type is too complex to display. Please refer to the [source code](https://github.com/open-circle/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/open-circle/valibot/blob/main/library/src/methods/getDefaults/types.ts). ### InferExamples Infer examples type. > This type is too complex to display. Please refer to the [source code](https://github.com/open-circle/valibot/blob/main/library/src/methods/getExamples/getExamples.ts). ### InferFallback Infer fallback type. > This type is too complex to display. Please refer to the [source code](https://github.com/open-circle/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/open-circle/valibot/blob/main/library/src/methods/getFallbacks/types.ts). ### InferGuardOutput Infer guard output type. #### Generics - `TGuard` `extends GuardFunction` #### Definition - `InferGuardOutput` `TGuard extends (input: any) => input is infer TOutput ? TOutput : unknown` ### InferInput Infer input type. #### Generics - `TItem` `extends BaseSchema> | BaseSchemaAsync> | BaseValidation> | BaseValidationAsync> | BaseTransformation> | BaseTransformationAsync> | BaseMetadata` #### Definition - `InferInput` `NonNullable['input']` #### 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` `extends BaseSchema> | BaseSchemaAsync> | BaseValidation> | BaseValidationAsync> | BaseTransformation> | BaseTransformationAsync> | BaseMetadata` #### Definition - `InferIssue` `NonNullable['issue']` ### InferMapInput Infer map input type. #### Generics - `TKey` `extends BaseSchema> | BaseSchemaAsync>` - `TValue` `extends BaseSchema> | BaseSchemaAsync>` #### Definition - `InferMapInput` `Map, InferInput>` ### InferMapOutput Infer map output type. #### Generics - `TKey` `extends BaseSchema> | BaseSchemaAsync>` - `TValue` `extends BaseSchema> | BaseSchemaAsync>` #### Definition - `InferMapOutput` `Map, InferOutput>` ### InferMetadata Infer fallbacks type. > This type is too complex to display. Please refer to the [source code](https://github.com/open-circle/valibot/blob/main/library/src/methods/getMetadata/getMetadata.ts). ### InferNonNullableInput Infer non nullable input type. ```ts // Create nullable string 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/open-circle/valibot/blob/main/library/src/schemas/nonNullable/types.ts). ### InferNonNullableOutput Infer non nullable output type. ```ts // Create nullable string 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 string 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/open-circle/valibot/blob/main/library/src/schemas/nonNullish/types.ts). ### InferNonNullishOutput Infer non nullable output type. ```ts // Create nullish string 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 string 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/open-circle/valibot/blob/main/library/src/schemas/nonOptional/types.ts). ### InferNonOptionalOutput Infer non optional output type. ```ts // Create optional string 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` `extends BaseSchema> | BaseSchemaAsync>` - `TDefault` `extends DefaultAsync` #### Definition - `InferNullableOutput` `[TDefault] extends [never] ? InferOutput | null : NonNullable> | Extract, null>` ### InferNullishOutput Infer nullish output type. #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TDefault` `extends DefaultAsync` #### Definition - `InferNullishOutput` `[TDefault] extends [never] ? InferOutput | null | undefined : NonNullish> | Extract, null | undefined>` ### 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` `extends ObjectEntries | ObjectEntriesAsync` #### Definition - `InferObjectIssue` `InferIssue` ### 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` `extends BaseSchema> | BaseSchemaAsync>` - `TDefault` `extends DefaultAsync` #### Definition - `InferOptionalOutput` `[TDefault] extends [never] ? InferOutput | undefined : NonOptional> | Extract, undefined>` ### InferOutput Infer output type. #### Generics - `TItem` `extends BaseSchema> | BaseSchemaAsync> | BaseValidation> | BaseValidationAsync> | BaseTransformation> | BaseTransformationAsync> | BaseMetadata` #### Definition - `InferIssue` `NonNullable['output']` #### 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/open-circle/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/open-circle/valibot/blob/main/library/src/schemas/record/types.ts). ### InferSetInput Infer set input type. #### Generics - `TValue` `extends BaseSchema> | BaseSchemaAsync>` #### Definition - `InferSetInput` `Set>` ### InferSetOutput Infer set output type. #### Generics - `TValue` `extends BaseSchema> | BaseSchemaAsync>` #### Definition - `InferSetOutput` `Set>` ### 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` `extends TupleItems | TupleItemsAsync` #### Definition - `InferTupleIssue` `InferIssue` ### 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` `extends VariantOptions | VariantOptionsAsync` #### Definition - `InferVariantIssue` `Exclude, { type: 'loose_object' | 'object' | 'object_with_rest' }>` ### InstanceIssue Instance issue interface. #### Definition - `InstanceIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'instance'` - `expected` `string` ### InstanceSchema Instance schema interface. #### Generics - `TClass` `extends Class` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `InstanceSchema` `extends BaseSchema, InstanceType, InstanceIssue>` - `type` `'instance'` - `reference` `typeof instance` - `class` `TClass` - `message` `TMessage` ### IntegerAction Integer action interface. #### Generics - `TInput` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `IntegerAction` `extends BaseValidation>` - `type` `'integer'` - `reference` `typeof integer` - `expects` `null` - `requirement` `(input: number) => boolean` - `message` `TMessage` ### IntegerIssue Integer issue interface. #### Generics - `TInput` `extends number` #### Definition - `IntegerIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'integer'` - `expected` `null` - `received` `` `${number}` `` - `requirement` `(input: number) => boolean` ### IntersectIssue Intersect issue interface. #### Definition - `IntersectIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'intersect'` - `expected` `string` ### IntersectOptions Intersect options type. #### Definition - `IntersectOptions` `MaybeReadonly>[]>` ### IntersectOptionsAsync Intersect options async type. #### Definition - `IntersectOptionsAsync` `MaybeReadonly<(BaseSchema> | BaseSchemaAsync>)[]>` ### IntersectSchema Intersect schema interface. #### Generics - `TOptions` `extends IntersectOptions` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `IntersectSchema` `extends BaseSchema, InferIntersectOutput, IntersectIssue | InferIssue>` - `type` `'intersect'` - `reference` `typeof intersect` - `options` `TOptions` - `message` `TMessage` ### IntersectSchemaAsync Intersect schema async interface. #### Generics - `TOptions` `extends IntersectOptionsAsync` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `IntersectSchemaAsync` `extends BaseSchemaAsync, InferIntersectOutput, IntersectIssue | InferIssue>` - `type` `'intersect'` - `reference` `typeof intersect | typeof intersectAsync` - `options` `TOptions` - `message` `TMessage` ### IpAction IP action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `IpAction` `extends BaseValidation>` - `type` `'ip'` - `reference` `typeof ip` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### IpIssue IP issue interface. #### Generics - `TInput` `extends string` #### Definition - `IpIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'ip'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### Ipv4Action IPv4 action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `Ipv4Action` `extends BaseValidation>` - `type` `'ipv4'` - `reference` `typeof ipv4` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### Ipv4Issue IPv4 issue interface. #### Generics - `TInput` `extends string` #### Definition - `Ipv4Issue` `extends BaseIssue` - `kind` `'validation'` - `type` `'ipv4'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### Ipv6Action IPv6 action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `Ipv6Action` `extends BaseValidation>` - `type` `'ipv6'` - `reference` `typeof ipv6` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### Ipv6Issue IPv6 issue interface. #### Generics - `TInput` `extends string` #### Definition - `Ipv6Issue` `extends BaseIssue` - `kind` `'validation'` - `type` `'ipv6'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### IsbnAction ISBN action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `IsbnAction` `extends BaseValidation>` - `type` `'isbn'` - `reference` `typeof isbn` - `expects` `null` - `requirement` `(input: string) => boolean` - `message` `TMessage` ### IsbnIssue ISBN issue interface. #### Generics - `TInput` `extends string` #### Definition - `IsbnIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'isbn'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `(input: string) => boolean` ### IsrcAction ISRC action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `IsrcAction` `extends BaseValidation>` - `type` `'isrc'` - `reference` `typeof isrc` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### IsrcIssue ISRC issue interface. #### Generics - `TInput` `extends string` #### Definition - `IsrcIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'isrc'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### IsoDateAction ISO date action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `IsoDateAction` `extends BaseValidation>` - `type` `'iso_date'` - `reference` `typeof isoDate` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### IsoDateIssue ISO date issue interface. #### Generics - `TInput` `extends string` #### Definition - `IsoDateIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'iso_date'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### IsoDateTimeAction ISO date time action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `IsoDateTimeAction` `extends BaseValidation>` - `type` `'iso_date_time'` - `reference` `typeof isoDateTime` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### IsoDateTimeIssue ISO date time issue interface. #### Generics - `TInput` `extends string` #### Definition - `IsoDateTimeIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'iso_date_time'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### IsoDateTimeSecondAction ISO date time second action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `IsoDateTimeSecondAction` `extends BaseValidation>` - `type` `'iso_date_time_second'` - `reference` `typeof isoDateTimeSecond` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### IsoDateTimeSecondIssue ISO date time second issue interface. #### Generics - `TInput` `extends string` #### Definition - `IsoDateTimeSecondIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'iso_date_time_second'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### IsoTimeAction ISO time action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `IsoTimeAction` `extends BaseValidation>` - `type` `'iso_time'` - `reference` `typeof isoTime` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### IsoTimeIssue ISO time issue interface. #### Generics - `TInput` `extends string` #### Definition - `IsoTimeIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'iso_time'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### IsoTimeSecondAction ISO time second action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `IsoTimeSecondAction` `extends BaseValidation>` - `type` `'iso_time_second'` - `reference` `typeof isoTimeSecond` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### IsoTimeSecondIssue ISO time second issue interface. #### Generics - `TInput` `extends string` #### Definition - `IsoTimeSecondIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'iso_time_second'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### IsoTimestampAction ISO timestamp action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `IsoTimestampAction` `extends BaseValidation>` - `type` `'iso_timestamp'` - `reference` `typeof isoTimestamp` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### IsoTimestampIssue ISO timestamp issue interface. #### Generics - `TInput` `extends string` #### Definition - `IsoTimestampIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'iso_timestamp'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### IsoWeekAction ISO week action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `IsoWeekAction` `extends BaseValidation>` - `type` `'iso_week'` - `reference` `typeof isoWeek` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### IsoWeekIssue ISO week issue interface. #### Generics - `TInput` `extends string` #### Definition - `IsoWeekIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'iso_week'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### IssueDotPath Issue dot path type. > This type is too complex to display. Please refer to the [source code](https://github.com/open-circle/valibot/blob/main/library/src/types/issue.ts). ### IssuePathItem Path item type. #### Definition - `IssuePathItem` `ArrayPathItem | MapPathItem | ObjectPathItem | SetPathItem | UnknownPathItem` ### JwsCompactAction JWS compact action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `JwsCompactAction` `extends BaseValidation>` - `type` `'jws_compact'` - `reference` `typeof jwsCompact` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### JwsCompactIssue JWS compact issue interface. #### Generics - `TInput` `extends string` #### Definition - `JwsCompactIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'jws_compact'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### KsuidAction KSUID action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `KsuidAction` `extends BaseValidation>` - `type` `'ksuid'` - `reference` `typeof ksuid` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### KsuidIssue KSUID issue interface. #### Generics - `TInput` `extends string` #### Definition - `KsuidIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'ksuid'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### LastTupleItem Extracts last tuple item. #### Generics - `TTuple` `extends [unknown, ...unknown[]]` #### Definition - `LastTupleItem` `TTuple[TTuple extends [unknown, ...TRest] ? TRest['length'] : never]` ### LazySchema Lazy schema interface. #### Generics - `TWrapped` `extends BaseSchema>` #### Definition - `LazySchema` `extends BaseSchema, InferOutput, InferIssue>` - `type` `'lazy'` - `reference` `typeof lazy` - `expects` `'unknown'` - `getter` `(input: unknown) => TWrapped` ### LazySchemaAsync Lazy schema async interface. #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` #### Definition - `LazySchemaAsync` `extends BaseSchemaAsync, InferOutput, InferIssue>` - `type` `'lazy'` - `reference` `typeof lazy | typeof lazyAsync` - `expects` `'unknown'` - `getter` `(input: unknown) => MaybePromise` ### LengthAction Length action interface. #### Generics - `TInput` `extends LengthInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `LengthAction` `extends BaseValidation>` - `type` `'length'` - `reference` `typeof length` - `expects` `` `${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### LengthInput Length input type. #### Definition - `LengthInput` `string | ArrayLike` ### LengthIssue Length issue interface. #### Generics - `TInput` `extends LengthInput` - `TRequirement` `extends number` #### Definition - `LengthIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'length'` - `expected` `` `${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### Literal Literal type. #### Definition - `Literal` `bigint | boolean | number | string | symbol` ### LiteralIssue Literal issue interface. #### Definition - `LiteralIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'literal'` - `expected` `string` ### LooseObjectIssue Loose object issue interface. #### Definition - `LooseObjectIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'loose_object'` - `expected` `` 'Object' | `"${string}"` `` ### LooseObjectSchema Loose object schema interface. #### Generics - `TEntries` `extends ObjectEntries` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `LooseObjectSchema` `extends BaseSchema & { [key: string]: unknown }, InferObjectOutput & { [key: string]: unknown }, LooseObjectIssue | InferObjectIssue>` - `type` `'loose_object'` - `reference` `typeof looseObject` - `expects` `'Object'` - `entries` `TEntries` - `message` `TMessage` ### LooseObjectSchemaAsync Loose object schema async interface. #### Generics - `TEntries` `extends ObjectEntriesAsync` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `LooseObjectSchemaAsync` `extends BaseSchemaAsync & { [key: string]: unknown }, InferObjectOutput & { [key: string]: unknown }, LooseObjectIssue | InferObjectIssue>` - `type` `'loose_object'` - `reference` `typeof looseObject | typeof looseObjectAsync` - `expects` `'Object'` - `entries` `TEntries` - `message` `TMessage` ### LooseTupleIssue Loose tuple issue interface. #### Definition - `LooseTupleIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'loose_tuple'` - `expected` `'Array'` ### LooseTupleSchema Loose tuple schema interface. #### Generics - `TItems` `extends TupleItems` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `LooseTupleSchema` `extends BaseSchema<[...InferTupleInput, ...unknown[]], [...InferTupleOutput, ...unknown[]], LooseTupleIssue | InferTupleIssue>` - `type` `'loose_tuple'` - `reference` `typeof looseTuple` - `expects` `'Array'` - `items` `TItems` - `message` `TMessage` ### LooseTupleSchemaAsync Loose tuple schema async interface. #### Generics - `TItems` `extends TupleItemsAsync` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `LooseTupleSchemaAsync` `extends BaseSchemaAsync<[...InferTupleInput, ...unknown[]], [...InferTupleOutput, ...unknown[]], LooseTupleIssue | InferTupleIssue>` - `type` `'loose_tuple'` - `reference` `typeof looseTuple | typeof looseTupleAsync` - `expects` `'Array'` - `items` `TItems` - `message` `TMessage` ### LiteralSchema Literal schema interface. #### Generics - `TLiteral` `extends Literal` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `LiteralSchema` `extends BaseSchema` - `type` `'literal'` - `reference` `typeof literal` - `literal` `TLiteral` - `message` `TMessage` ### LtValueAction Less than value action type. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `LtValueAction` `extends BaseValidation>` - `type` `'lt_value'` - `reference` `typeof ltValue` - `expects` `` `<${string}` `` - `requirement` `TRequirement` - `message` `TMessage` ### LtValueIssue Less than value issue type. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` #### Definition - `LtValueIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'lt_value'` - `expected` `` `<${string}` `` - `requirement` `TRequirement` ### Mac48Action 48-bit MAC action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `Mac48Action` `extends BaseValidation>` - `type` `'mac48'` - `reference` `typeof mac48` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### Mac48Issue 48-bit MAC issue interface. #### Generics - `TInput` `extends string` #### Definition - `Mac48Issue` `extends BaseIssue` - `kind` `'validation'` - `type` `'mac48'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### Mac64Action 64-bit MAC action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `Mac64Action` `extends BaseValidation>` - `type` `'mac64'` - `reference` `typeof mac64` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### Mac64Issue 64-bit MAC issue interface. #### Generics - `TInput` `extends string` #### Definition - `Mac64Issue` `extends BaseIssue` - `kind` `'validation'` - `type` `'mac64'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### MacAction MAC action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MacAction` `extends BaseValidation>` - `type` `'mac'` - `reference` `typeof mac` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### MacIssue MAC issue interface. #### Generics - `TInput` `extends string` #### Definition - `MacIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'mac'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### MapIssue Map issue interface. #### Definition - `MapIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'map'` - `expected` `'Map'` ### MapItemsAction Map items action interface. #### Generics - `TInput` `extends ArrayInput` - `TOutput` `extends any` #### Definition - `MapItemsAction` `extends BaseTransformation` - `type` `'map_items'` - `reference` `typeof mapItems` - `operation` `(item: TInput[number], index: number, array: TInput) => TOutput` ### MapPathItem Map path item interface. #### Definition - `MapPathItem` - `type` `'map'` - `origin` `'key' | 'value'` - `input` `Map` - `key` `unknown` - `value` `unknown` 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` `extends BaseSchema>` - `TValue` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `MapSchema` `extends BaseSchema, InferMapOutput, MapIssue | InferIssue | InferIssue>` - `type` `'map'` - `reference` `typeof map` - `expects` `'Map'` - `key` `TKey` - `value` `TValue` - `message` `TMessage` ### MapSchemaAsync Map schema async interface. #### Generics - `TKey` `extends BaseSchema> | BaseSchemaAsync>` - `TValue` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `MapSchemaAsync` `extends BaseSchemaAsync, InferMapOutput, MapIssue | InferIssue | InferIssue>` - `type` `'map'` - `reference` `typeof map | typeof mapAsync` - `expects` `'Map'` - `key` `TKey` - `value` `TValue` - `message` `TMessage` ### MaxBytesAction Max bytes action interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MaxBytesAction` `extends BaseValidation>` - `type` `'max_bytes'` - `reference` `typeof maxBytes` - `expects` `` `<=${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MaxBytesIssue Max bytes issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `MaxBytesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'max_bytes'` - `expected` `` `<=${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### MaxCodePointsAction Max code points action interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MaxCodePointsAction` `extends BaseValidation>` - `type` `'max_code_points'` - `reference` `typeof maxCodePoints` - `expects` `` `<=${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MaxCodePointsIssue Max code points issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `MaxCodePointsIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'max_code_points'` - `expected` `` `<=${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### MaxEntriesAction Max entries action interface. #### Generics - `TInput` `extends EntriesInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MaxEntriesAction` `extends BaseValidation>` - `type` `'max_entries'` - `reference` `typeof maxEntries` - `expects` `` `<=${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MaxEntriesIssue Max entries issue interface. #### Generics - `TInput` `extends EntriesInput` - `TRequirement` `extends number` #### Definition - `MaxEntriesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'max_entries'` - `expected` `` `<=${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### MaxGraphemesAction Max graphemes action interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MaxGraphemesAction` `extends BaseValidation>` - `type` `'max_graphemes'` - `reference` `typeof maxGraphemes` - `expects` `` `<=${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MaxGraphemesIssue Max graphemes issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `MaxGraphemesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'max_graphemes'` - `expected` `` `<=${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### MaxLengthAction Max length action interface. #### Generics - `TInput` `extends LengthInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MaxLengthAction` `extends BaseValidation>` - `type` `'max_length'` - `reference` `typeof maxLength` - `expects` `` `<=${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MaxLengthIssue Max length issue interface. #### Generics - `TInput` `extends LengthInput` - `TRequirement` `extends number` #### Definition - `MaxLengthIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'max_length'` - `expected` `` `<=${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### MaxSizeAction Max size action interface. #### Generics - `TInput` `extends SizeInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MaxSizeAction` `extends BaseValidation>` - `type` `'max_size'` - `reference` `typeof maxSize` - `expects` `` `<=${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MaxSizeIssue Max size issue interface. #### Generics - `TInput` `extends SizeInput` - `TRequirement` `extends number` #### Definition - `MaxSizeIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'max_size'` - `expected` `` `<=${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### MaxValueAction Max value action interface. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MaxValueAction` `extends BaseValidation>` - `type` `'max_value'` - `reference` `typeof maxValue` - `expects` `` `<=${string}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MaxValueIssue Max value issue interface. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` #### Definition - `MaxValueIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'max_value'` - `expected` `` `<=${string}` `` - `requirement` `TRequirement` ### MaxWordsAction Max words action interface. #### Generics - `TInput` `extends string` - `TLocales` `extends Intl.LocalesArgument` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MaxWordsAction` `extends BaseValidation>` - `type` `'max_words'` - `reference` `typeof maxWords` - `expects` `` `<=${TRequirement}` `` - `locales` `TLocales` - `requirement` `TRequirement` - `message` `TMessage` ### MaxWordsIssue Max words issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `MaxWordsIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'max_words'` - `expected` `` `<=${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### MaybePromise Maybe promise type. #### Generics - `TValue` `extends any` #### Definition - `MaybePromise` `TValue | Promise` ### MaybeReadonly Maybe readonly type. #### Generics - `TValue` `extends any` #### Definition - `MaybeReadonly` `TValue | Readonly` ### MetadataAction Metadata action interface. #### Generics - `TInput` `extends any` - `TMetadata` `extends Record` #### Definition - `MetadataAction` `extends BaseMetadata` - `type` `'metadata'` - `reference` `typeof metadata` - `metadata_` `TMetadata` ### MimeTypeAction MIME type action interface. #### Generics - `TInput` `extends Blob` - `TRequirement` `extends string[]` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MimeTypeAction` `extends BaseValidation>` - `type` `'mime_type'` - `reference` `typeof mimeType` - `expects` `string` - `requirement` `TRequirement` - `message` `TMessage` ### MimeTypeIssue Mime type issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `` extends `${string}/${string}`[] `` #### Definition - `MimeTypeIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'mime_type'` - `expected` `string` - `received` `` `"${string}"` `` - `requirement` `TRequirement` ### MinBytesAction Min bytes action interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MinBytesAction` `extends BaseValidation>` - `type` `'min_bytes'` - `reference` `typeof minBytes` - `expects` `` `>=${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MinBytesIssue Min bytes issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `MinBytesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'min_bytes'` - `expected` `` `>=${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### MinCodePointsAction Min code points action interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MinCodePointsAction` `extends BaseValidation>` - `type` `'min_code_points'` - `reference` `typeof minCodePoints` - `expects` `` `>=${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MinCodePointsIssue Min code points issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `MinCodePointsIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'min_code_points'` - `expected` `` `>=${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### MinEntriesAction Min entries action interface. #### Generics - `TInput` `extends EntriesInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MinEntriesAction` `extends BaseValidation>` - `type` `'min_entries'` - `reference` `typeof minEntries` - `expects` `` `>=${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MinEntriesIssue Min entries issue interface. #### Generics - `TInput` `extends EntriesInput` - `TRequirement` `extends number` #### Definition - `MinEntriesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'min_entries'` - `expected` `` `>=${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### MinGraphemesAction Min graphemes action interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MinGraphemesAction` `extends BaseValidation>` - `type` `'min_graphemes'` - `reference` `typeof minGraphemes` - `expects` `` `>=${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MinGraphemesIssue Min graphemes issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `MinGraphemesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'min_graphemes'` - `expected` `` `>=${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### MinLengthAction Min length action interface. #### Generics - `TInput` `extends LengthInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MinLengthAction` `extends BaseValidation>` - `type` `'min_length'` - `reference` `typeof minLength` - `expects` `` `>=${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MinLengthIssue Min length issue interface. #### Generics - `TInput` `extends LengthInput` - `TRequirement` `extends number` #### Definition - `MinLengthIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'min_length'` - `expected` `` `>=${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### MinSizeAction Min size action interface. #### Generics - `TInput` `extends SizeInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MinSizeAction` `extends BaseValidation>` - `type` `'min_size'` - `referece` `typeof minSize` - `expects` `` `>=${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MinSizeIssue Min size issue interface. #### Generics - `TInput` `extends SizeInput` - `TRequirement` `extends number` #### Definition - `MinSizeIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'min_size'` - `expected` `` `>=${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### MinValueAction Min value action interface. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MinValueAction` `extends BaseValidation>` - `type` `'min_value'` - `reference` `typeof minValue` - `expects` `` `>=${string}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MinValueIssue Min value issue interface. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` #### Definition - `MinValueIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'min_value'` - `expected` `` `>=${string}` `` - `requirement` `TRequirement` ### MinWordsAction Min words action interface. #### Generics - `TInput` `extends string` - `TLocales` `extends Intl.LocalesArgument` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MinWordsAction` `extends BaseValidation>` - `type` `'min_words'` - `reference` `typeof minWords` - `expects` `` `>=${TRequirement}` `` - `locales` `TLocales` - `requirement` `TRequirement` - `message` `TMessage` ### MinWordsIssue Min words issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `MinWordsIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'min_words'` - `expected` `` `>=${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### MultipleOfAction Multiple of action interface. #### Generics - `TInput` `extends number | bigint` - `TRequirement` `extends number | bigint` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `MultipleOfAction` `extends BaseValidation>` - `type` `'multiple_of'` - `reference` `typeof multipleOf` - `expects` `` `%${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### MultipleOfIssue Multiple of issue interface. #### Generics - `TInput` `extends number | bigint` - `TRequirement` `extends number | bigint` #### Definition - `MultipleOfIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'multiple_of'` - `expected` `` `%${TRequirement}` `` - `received` `` `${TInput}` `` - `requirement` `TRequirement` ### NanIssue NaN issue interface. #### Definition - `NanIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'nan'` - `expected` `'NaN'` ### NanSchema NaN schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `NanSchema` `extends BaseSchema` - `type` `'nan'` - `reference` `readonly nan` - `expects` `'NaN'` - `message` `TMessage` ### NeverIssue Never issue interface. #### Definition - `NeverIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'never'` - `expected` `'never'` ### NeverSchema Never schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `NeverSchema` `extends BaseSchema` - `type` `'never'` - `reference` `readonly never` - `expects` `'never'` - `message` `TMessage` ### NonEmptyAction Non empty action interface. #### Generics - `TInput` `extends LengthInput` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `NonEmptyAction` `extends BaseValidation>` - `type` `'non_empty'` - `reference` `typeof nonEmpty` - `expects` `'!0'` - `message` `TMessage` ### NonEmptyIssue Non empty issue interface. #### Generics - `TInput` `extends LengthInput` #### Definition - `NonEmptyIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'non_empty'` - `expected` `'!0'` - `received` `'0'` ### NonNullable Extracts `null` from a type. #### Generics - `TValue` `extends any` #### Definition - `NonNullable` `TValue extends null ? never : TValue` ### NonNullableIssue Non nullable issue interface. #### Definition - `NonNullableIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'non_nullable'` - `expected` `'!null'` ### NonNullableSchema Non nullable schema interface. #### Generics - `TWrapped` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `NonNullableSchema` `extends BaseSchema, InferNonNullableOutput, NonNullableIssue | InferNonNullableIssue>` - `type` `'non_nullable'` - `reference` `typeof nonNullable` - `expects` `'!null'` - `wrapped` `TWrapped` - `message` `TMessage` ### NonNullableSchemaAsync Non nullable schema async interface. #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `NonNullableSchemaAsync` `BaseSchema, InferNonNullableOutput, NonNullableIssue | InferNonNullishIssue>` - `type` `'non_nullable'` - `reference` `typeof nonNullable | typeof nonNullableAsync` - `expects` `'!null'` - `wrapped` `TWrapped` - `message` `TMessage` ### NonNullish Extracts `null` and `undefined` from a type. #### Generics - `TValue` `extends any` #### Definition - `NonNullish` `TValue extends null | undefined ? never : TValue` ### NonNullishIssue Non nullish issue interface. #### Definition - `NonNullishIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'non_nullish'` - `expected` `'(!null & !undefined)'` ### NonNullishSchema Non nullish schema interface. #### Generics - `TWrapped` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `NonNullishSchema` `extends BaseSchema, InferNonNullishOutput, NonNullishIssue | InferNonNullishIssue>` - `type` `'non_nullish'` - `reference` `typeof nonNullish` - `expects` `'(!null & !undefined)'` - `wrapped` `TWrapped` - `message` `TMessage` ### NonNullishSchemaAsync Non nullish schema async interface. #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `NonNullishSchemaAsync` `BaseSchema, InferNonNullishOutput, NonNullishIssue | InferNonNullishIssue>` - `type` `'non_nullish'` - `reference` `typeof nonNullish | typeof nonNullishAsync` - `expects` `'(!null & !undefined)'` - `wrapped` `TWrapped` - `message` `TMessage` ### NonOptional Extracts `undefined` from a type. #### Generics - `TValue` `extends any` #### Definition - `NonOptional` `TValue extends undefined ? never : TValue` ### NonOptionalIssue Non optional issue interface. #### Definition - `NonOptionalIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'non_optional'` - `expected` `'!undefined'` ### NonOptionalSchema Non optional schema interface. #### Generics - `TWrapped` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `NonOptionalSchema` `extends BaseSchema, InferNonOptionalOutput, NonOptionalIssue | InferNonOptionalIssue>` - `type` `'non_optional'` - `reference` `typeof nonOptional` - `expects` `'!undefined'` - `wrapped` `TWrapped` - `message` `TMessage` ### NonOptionalSchemaAsync Non optional schema async interface. #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `NonOptionalSchemaAsync` `BaseSchema, InferNonOptionalOutput, NonOptionalIssue | InferNonOptionalIssue>` - `type` `'non_optional'` - `reference` `typeof nonOptional | typeof nonOptionalAsync` - `expects` `'!undefined'` - `wrapped` `TWrapped` - `message` `TMessage` ### NormalizeAction Normalize action interface. #### Generics - `TForm` `extends NormalizeForm` #### Definition - `NormalizeAction` `extends BaseTransformation` - `type` `'normalize'` - `reference` `typeof normalize` - `form` `TForm` ### NormalizeForm Normalize form type. #### Definition - `NormalizeForm` `'NFC' | 'NFD' | 'NFKC' | 'NFKD'` ### NotBytesAction Not bytes action interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `NotBytesAction` `extends BaseValidation>` - `type` `'not_bytes'` - `reference` `typeof notBytes` - `expects` `` `!${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### NotBytesIssue Not bytes issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `NotBytesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'not_bytes'` - `expected` `` `!${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### NotCodePointsAction Not code points action interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `NotCodePointsAction` `extends BaseValidation>` - `type` `'not_code_points'` - `reference` `typeof notCodePoints` - `expects` `` `!${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### NotCodePointsIssue Not code points issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `NotCodePointsIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'not_code_points'` - `expected` `` `!${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### NotEntriesAction Not entries action interface. #### Generics - `TInput` `extends EntriesInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `NotEntriesAction` `extends BaseValidation>` - `type` `'not_entries'` - `reference` `typeof notEntries` - `expects` `` `!${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### NotEntriesIssue Not entries issue interface. #### Generics - `TInput` `extends EntriesInput` - `TRequirement` `extends number` #### Definition - `NotEntriesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'not_entries'` - `expected` `` `!${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### NotGraphemesAction Not graphemes action interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `NotGraphemesAction` `extends BaseValidation>` - `type` `'not_graphemes'` - `reference` `typeof notGraphemes` - `expects` `` `!${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### NotGraphemesIssue Not graphemes issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `NotGraphemesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'not_graphemes'` - `expected` `` `!${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### NotLengthAction Not length action interface. #### Generics - `TInput` `extends LengthInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `NotLengthAction` `extends BaseValidation>` - `type` `'not_length'` - `reference` `typeof notLength` - `expects` `` `!${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### NotLengthIssue Not length issue interface. #### Generics - `TInput` `extends LengthInput` - `TRequirement` `extends number` #### Definition - `NotLengthIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'not_length'` - `expected` `` `!${TRequirement}` `` - `received` `` `${TRequirement}` `` - `requirement` `TRequirement` ### NotSizeAction Not size action interface. #### Generics - `TInput` `extends SizeInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `NotSizeAction` `extends BaseValidation>` - `type` `'not_size'` - `reference` `typeof notSize` - `expects` `` `!${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### NotSizeIssue Not size issue interface. #### Generics - `TInput` `extends SizeInput` - `TRequirement` `extends number` #### Definition - `NotSizeIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'not_size'` - `expected` `` `!${TRequirement}` `` - `received` `` `${TRequirement}` `` - `requirement` `TRequirement` ### NotValueAction Not value action interface. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `NotValueAction` `extends BaseValidation>` - `type` `'not_value'` - `reference` `typeof notValue` - `expects` `` `!${string}` `` - `requirement` `TRequirement` - `message` `TMessage` ### NotValuesAction Not values action type. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends readonly TInput[]` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `NotValuesAction` `extends BaseValidation>` - `type` `'not_values'` - `reference` `typeof notValues` - `expects` `` `!${string}` `` - `requirement` `TRequirement` - `message` `TMessage` ### NotValueIssue Not value issue interface. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` #### Definition - `NotValueIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'not_value'` - `expected` `` `!${string}` `` - `requirement` `TRequirement` ### NotValuesIssue Not values issue type. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends readonly TInput[]` #### Definition - `NotValuesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'not_values'` - `expected` `` `!${string}` `` - `requirement` `TRequirement` ### NotWordsAction Not words action interface. #### Generics - `TInput` `extends string` - `TLocales` `extends Intl.LocalesArgument` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `NotWordsAction` `extends BaseValidation>` - `type` `'not_words'` - `reference` `typeof notWords` - `expects` `` `!${TRequirement}` `` - `locales` `TLocales` - `requirement` `TRequirement` - `message` `TMessage` ### NotWordsIssue Not words issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `NotWordsIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'not_words'` - `expected` `` `!${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### NullableSchema Nullable schema interface. #### Generics - `TWrapped` `extends BaseSchema>` - `TDefault` `extends Default` #### Definition - `NullableSchema` `extends BaseSchema | null, InferNullableOutput, InferIssue>` - `type` `'nullable'` - `reference` `typeof nullable` - `expects` `` `(${TWrapped['expects']} | null)` `` - `wrapped` `TWrapped` - `default` `TDefault` ### NullableSchemaAsync Nullable schema async interface. #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TDefault` `extends DefaultAsync` #### Definition - `NullableSchemaAsync` `BaseSchemaAsync | null, InferNullableOutput, InferIssue>` - `type` `'nullable'` - `reference` `typeof nullable | typeof nullableAsync` - `expects` `` `(${TWrapped['expects']} | null)` `` - `wrapped` `TWrapped` - `default` `TDefault` ### NullishSchema Nullish schema interface. #### Generics - `TWrapped` `extends BaseSchema>` - `TDefault` `extends Default` #### Definition - `Nullish` `extends BaseSchema | null | undefined, InferNullishOutput, InferIssue>` - `type` `'nullish'` - `reference` `typeof nullish` - `expects` `` `(${TWrapped['expects']} | null | undefined)` `` - `wrapped` `TWrapped` - `default` `TDefault` ### NullishSchemaAsync Nullish schema async interface. #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TDefault` `extends DefaultAsync` #### Definition - `Nullish` `BaseSchemaAsync | null | undefined, InferNullishOutput, InferIssue>` - `type` `'nullish'` - `reference` `typeof nullishAsync` - `expects` `` `(${TWrapped['expects']} | null | undefined)` `` - `wrapped` `TWrapped` - `default` `TDefault` ### NullIssue Null issue interface. #### Definition - `NullIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'null'` - `expected` `'null'` ### NullSchema Null schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `NullSchema` `extends BaseSchema` - `type` `'null'` - `reference` `typeof null` - `expects` `'null'` - `message` `TMessage` ### NumberIssue Number issue interface. #### Definition - `NumberIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'number'` - `expected` `'number'` ### NumberSchema Number schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `NumberSchema` `extends BaseSchema` - `type` `'number'` - `reference` `typeof number` - `expects` `'number'` - `message` `TMessage` ### ObjectEntries Object entries interface. #### Definition - `ObjectEntries` `{ [key: string]: BaseSchema> }` ### ObjectEntriesAsync Object entries async interface. #### Definition - `ObjectEntriesAsync` `{ [key: string]: BaseSchema> | BaseSchemaAsync> }` ### ObjectIssue Object issue interface. #### Definition - `ObjectIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'object'` - `expected` `` 'Object' | `"${string}"` `` ### ObjectKeys Object keys type. #### Generics - `TSchema` `extends LooseObjectSchema | undefined> | LooseObjectSchemaAsync | undefined> | ObjectSchema | undefined> | ObjectSchemaAsync | undefined> | ObjectWithRestSchema>, ErrorMessage | undefined> | ObjectWithRestSchemaAsync> | BaseSchemaAsync>, ErrorMessage | undefined> | StrictObjectSchema | undefined> | StrictObjectSchemaAsync | undefined>` #### Definition - `ObjectKeys` `MaybeReadonly<[keyof TSchema['entries'], ...(keyof TSchema['entries'])[]]>` ### ObjectPathItem Object path item interface. #### Definition - `ObjectPathItem` - `type` `'object'` - `origin` `'key' | 'value'` - `input` `Record` - `key` `string` - `value` `unknown` 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` `extends ObjectEntries` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `ObjectSchema` `extends BaseSchema, InferObjectOutput, ObjectIssue | InferObjectIssue>` - `type` `'object'` - `reference` `typeof object` - `expects` `'Object'` - `entries` `TEntries` - `message` `TMessage` ### ObjectSchemaAsync Object schema async interface. #### Generics - `TEntries` `extends ObjectEntriesAsync` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `ObjectSchemaAsync` `extends BaseSchemaAsync, InferObjectOutput, ObjectIssue | InferObjectIssue>` - `type` `'object'` - `reference` `typeof object | typeof objectAsync` - `expects` `'Object'` - `entries` `TEntries` - `message` `TMessage` ### ObjectWithRestIssue Object with rest issue interface. #### Definition - `ObjectWithRestIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'object_with_rest'` - `expected` `` 'Object' | `"${string}"` `` ### ObjectWithRestSchema Object with rest schema interface. #### Generics - `TEntries` `extends ObjectEntries` - `TRest` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `ObjectWithRestSchema` `extends BaseSchema & { [key: string]: InferInput }, InferObjectOutput & { [key: string]: InferInput }, ObjectWithRestIssue | InferObjectIssue>` - `type` `'object_with_rest'` - `reference` `typeof objectWithRest` - `expects` `'Object'` - `entries` `TEntries` - `rest` `TRest` - `message` `TMessage` ### ObjectWithRestSchemaAsync Object schema async interface. #### Generics - `TEntries` `extends ObjectEntriesAsync` - `TRest` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `ObjectWithRestSchemaAsync` `extends BaseSchema & { [key: string]: InferInput }, InferObjectOutput & { [key: string]: InferInput }, ObjectWithRestIssue | InferObjectIssue>` - `type` `'object_with_rest'` - `reference` `typeof objectWithRest` - `expects` `'Object'` - `entries` `TEntries` - `rest` `TRest` - `message` `TMessage` ### OctalAction Octal action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `OctalAction` `extends BaseValidation>` - `type` `'octal'` - `reference` `typeof octal` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### OctalIssue Octal issue interface. #### Generics - `TInput` `extends string` #### Definition - `OctalIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'octal'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### OptionalSchema Optional schema interface. #### Generics - `TWrapped` `extends BaseSchema>` - `TDefault` `extends Default` #### Definition - `OptionalSchema` `extends BaseSchema | undefined, InferOptionalOutput, InferIssue>` - `type` `'optional'` - `reference` `typeof optional` - `expects` `` `(${TWrapped['expects']} | undefined)` `` - `wrapped` `TWrapped` - `default` `TDefault` ### OptionalSchemaAsync Optional schema async interface. #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TDefault` `extends DefaultAsync` #### Definition - `OptionalSchemaAsync` `BaseSchemaAsync | undefined, InferOptionalOutput, InferIssue>` - `type` `'optional'` - `reference` `typeof optional | typeof optionalAsync` - `expects` `` `(${TWrapped['expects']} | undefined)` `` - `wrapped` `TWrapped` - `default` `TDefault` ### OutputDataset Output dataset interface. #### Generics - `TValue` `extends any` - `TIssue` `extends BaseIssue` #### Definition - `OutputDataset` `SuccessDataset | PartialDataset | FailureDataset` ### ParseBooleanAction Parse boolean action interface. #### Generics - `TInput` `extends any` - `TConfig` `extends ParseBooleanConfig | undefined` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `ParseBooleanAction` `extends BaseTransformation>` - `type` `'parse_boolean'` - `reference` `typeof parseBoolean` - `expects` `string` - `config` `TConfig` - `message` `TMessage` ### ParseBooleanConfig Parse boolean config interface. #### Definition - `ParseBooleanConfig` - `truthy` `MaybeReadonly` - `falsy` `MaybeReadonly` ### ParseBooleanIssue Parse boolean issue interface. #### Generics - `TInput` `extends any` #### Definition - `ParseBooleanIssue` `extends BaseIssue` - `kind` `'transformation'` - `type` `'parse_boolean'` - `expected` `string` ### ParseJsonAction JSON parse action interface. #### Generics - `TInput` `extends string` - `TConfig` `extends ParseJsonConfig | undefined` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `ParseJsonAction` `extends BaseTransformation>` - `type` `'parse_json'` - `reference` `typeof parseJson` - `config` `TConfig` - `message` `TMessage` ### ParseJsonConfig JSON parse config interface. #### Definition - `ParseJsonConfig` - `reviver` `((this: any, key: string, value: any) => any) | undefined` ### ParseJsonIssue JSON parse issue interface. #### Generics - `TInput` `extends string` #### Definition - `ParseJsonIssue` `extends BaseIssue` - `kind` `'transformation'` - `type` `'parse_json'` - `expected` `null` - `received` `` `"${string}"` `` ### Parser The parser interface. #### Generics - `TSchema` `extends BaseSchema>` - `TConfig` `extends Config> | undefined` #### Definition - `Parser` - `(input: unknown) => InferOutput` - `schema` `TSchema` - `config` `TConfig` ### ParserAsync The parser async interface. #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` - `TConfig` `extends Config> | undefined` #### Definition - `ParserAsync` - `(input: unknown) => Promise>` - `schema` `TSchema` - `config` `TConfig` ### PartialCheckAction Partial check action interface. #### Generics - `TInput` `extends PartialInput` - `TPaths` `extends Paths` - `TSelection` `extends DeepPickN` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `PartialCheckAction` `extends BaseValidation>` - `type` `'partial_check'` - `reference` `typeof partialCheck` - `expects` `null` - `paths` `TPaths` - `requirement` `(input: TSelection) => boolean` - `message` `TMessage` ### PartialCheckActionAsync Partial check action async interface. #### Generics - `TInput` `extends PartialInput` - `TPaths` `extends Paths` - `TSelection` `extends DeepPickN` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `PartialCheckActionAsync` `extends BaseValidationAsync>` - `type` `'partial_check'` - `reference` `typeof partialCheckAsync` - `expects` `null` - `paths` `TPaths` - `requirement` `(input: TSelection) => MaybePromise` - `message` `TMessage` ### PartialCheckIssue Partial check issue interface. #### Generics - `TInput` `extends PartialInput` #### Definition - `PartialCheckIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'partial_check'` - `expected` `null` - `requirement` `(input: TInput) => MaybePromise` ### PartialDataset Partial dataset interface. #### Generics - `TValue` `extends any` - `TIssue` `extends BaseIssue` #### Definition - `UntypedDataset` - `typed` `true` - `value` `TValue` - `issues` `[TIssue, ...TIssue[]]` ### PartialInput Partial input type. #### Definition - `PartialInput` `Record | ArrayLike` ### Path Path type. #### Definition - `Path` `readonly (string | number)[]` ### PicklistOptions Picklist options type. #### Definition - `PicklistOptions` `MaybeReadonly<(string | number | bigint)[]>` ### PicklistIssue Picklist issue interface. #### Definition - `PicklistIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'picklist'` - `expected` `string` ### PicklistSchema Picklist schema interface. #### Generics - `TOptions` `extends PicklistOptions` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `PicklistSchema` `extends BaseSchema` - `type` `'picklist'` - `reference` `typeof picklist` - `options` `TOptions` - `message` `TMessage` ### PipeAction Pipe action interface. #### Generics - `TInput` `extends any` - `TOutput` `extends any` - `TIssue` `extends BaseIssue` #### Definition - `PipeAction` `BaseValidation | BaseTransformation | BaseMetadata` ### PipeActionAsync Pipe action async interface. #### Generics - `TInput` `extends any` - `TOutput` `extends any` - `TIssue` `extends BaseIssue` #### Definition - `PipeActionAsync` `BaseValidationAsync | BaseTransformationAsync` ### PipeItem Pipe item type. #### Generics - `TInput` `extends any` - `TOutput` `extends any` - `TIssue` `extends BaseIssue` #### Definition - `PipeItem` `BaseSchema | PipeAction` ### PipeItemAsync Pipe item async type. #### Generics - `TInput` `extends any` - `TOutput` `extends any` - `TIssue` `extends BaseIssue` #### Definition - `PipeItemAsync` `BaseSchemaAsync | PipeActionAsync` ### PromiseIssue Promise issue interface. #### Definition - `PromiseIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'promise'` - `expected` `'Promise'` ### PromiseSchema Promise schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `PromiseSchema` `extends BaseSchema, Promise, PromiseIssue>` - `type` `'promise'` - `reference` `typeof promise` - `expects` `'Promise'` - `message` `TMessage` ### RawCheckAction Raw check action interface. #### Generics - `TInput` `extends any` #### Definition - `RawCheckAction` `extends BaseValidation>` - `type` `'raw_check'` - `reference` `typeof rawCheck` ### RawCheckActionAsync Raw check action async interface. #### Generics - `TInput` `extends any` #### Definition - `RawCheckActionAsync` `extends BaseValidationAsync>` - `type` `'raw_check'` - `reference` `typeof rawCheckAsync` - `expects` `null` ### RawCheckAddIssue Raw check add issue type. #### Generics - `TInput` `extends any` #### Definition - `RawCheckAddIssue` `(info?: RawCheckIssueInfo) => void` ### RawCheckContext Raw check context interface. #### Generics - `TInput` `extends any` #### Definition - `RawCheckContext` - `dataset` `OutputDataset>` - `config` `Config>` - `addIssue` `RawCheckAddIssue` ### RawCheckIssue Raw check issue interface. #### Generics - `TInput` `extends any` #### Definition - `RawCheckIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'raw_check'` ### RawCheckIssueInfo Raw check issue info interface. #### Generics - `TInput` `extends any` #### Definition - `RawCheckIssueInfo` - `label` `string | undefined` - `input` `unknown | undefined` - `expected` `string | undefined` - `received` `string | undefined` - `message` `ErrorMessage> | undefined` - `path` `[IssuePathItem, ...IssuePathItem[]] | undefined` ### RawTransformAction Raw transform action interface. #### Generics - `TInput` `extends any` - `TOutput` `extends any` #### Definition - `RawTransformAction` `extends BaseTransformation>` - `type` `'raw_transform'` - `reference` `typeof rawTransform` ### RawTransformActionAsync Raw transform action async interface. #### Generics - `TInput` `extends any` - `TOutput` `extends any` #### Definition - `RawTransformActionAsync` `extends BaseTransformationAsync>` - `type` `'raw_transform'` - `reference` `typeof rawTransformAsync` ### RawTransformAddIssue Raw transform add issue type. #### Generics - `TInput` `extends any` #### Definition - `RawTransformAddIssue` `(info?: RawTransformIssueInfo) => void` ### RawTransformContext Raw transform context interface. #### Generics - `TInput` `extends any` #### Definition - `RawTransformContext` - `dataset` `SuccessDataset` - `config` `Config>` - `addIssue` `RawTransformAddIssue` - `NEVER` `never` ### RawTransformIssue Raw transform issue interface. #### Generics - `TInput` `extends any` #### Definition - `RawTransformIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'raw_transform'` ### RawTransformIssueInfo Raw transform issue info interface. #### Generics - `TInput` `extends any` #### Definition - `RawTransformIssueInfo` - `label` `string | undefined` - `input` `unknown | undefined` - `expected` `string | undefined` - `received` `string | undefined` - `message` `ErrorMessage> | undefined` - `path` `[IssuePathItem, ...IssuePathItem[]] | undefined` ### ReadonlyAction Readonly action interface. #### Generics - `TInput` `extends any` #### Definition - `ReadonlyAction` `extends BaseTransformation, never>` - `type` `'readonly'` - `reference` `typeof readonly` ### RecordIssue Record issue interface. #### Definition - `RecordIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'record'` - `expected` `'Object'` ### RecordSchema Record schema interface. #### Generics - `TKey` `extends BaseSchema>` - `TValue` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `RecordSchema` `extends BaseSchema, InferRecordOutput, RecordIssue | InferIssue | InferIssue>` - `type` `'record'` - `reference` `typeof record` - `expects` `'Object'` - `key` `TKey` - `value` `TValue` - `message` `TMessage` ### RecordSchemaAsync Record schema async interface. #### Generics - `TKey` `extends BaseSchema> | BaseSchemaAsync>` - `TValue` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `RecordSchemaAsync` `extends BaseSchemaAsync, InferRecordOutput, RecordIssue | InferIssue | InferIssue>` - `type` `'record'` - `reference` `typeof record | typeof recordAsync` - `expects` `'Object'` - `key` `TKey` - `value` `TValue` - `message` `TMessage` ### ReduceItemsAction Reduce items action interface. #### Generics - `TInput` `extends ArrayInput` - `TOutput` `extends any` #### Definition - `ReduceItemsAction` `extends BaseTransformation` - `type` `'reduce_items'` - `reference` `typeof reduceItems` - `operation` `(output: TOutput, item: TInput[number], index: number, array: TInput) => TOutput` - `initial` `TOutput` ### Reference Reference type. #### Definition - `Reference` `((...args: any[]) => BaseSchema> | BaseSchemaAsync> | BaseValidation> | BaseValidationAsync> | BaseTransformation> | BaseTransformationAsync>)` ### RegexAction Regex action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `RegexAction` `extends BaseValidation>` - `type` `'regex'` - `reference` `typeof regex` - `expects` `string` - `requirement` `RegExp` - `message` `TMessage` ### RegexIssue Regex issue interface. #### Generics - `TInput` `extends string` #### Definition - `RegexIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'regex'` - `expected` `string` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### RequiredPath Required path type. #### Definition - `RequiredPath` `readonly [string | number, ...Path]` ### RequiredPaths Required paths type. #### Definition - `RequiredPaths` `readonly [RequiredPath, ...RequiredPath[]]` ### ReturnsAction Returns action interface. #### Generics - `TInput` `extends (...args: any[]) => unknown` - `TSchema` `extends BaseSchema>` #### Definition - `ReturnsAction` `extends BaseTransformation) => InferOutput, never>` - `type` `'returns'` - `reference` `typeof returns` - `schema` `TSchema` ### ReturnsActionAsync Returns action interface. #### Generics - `TInput` `extends (...args: any[]) => unknown` - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Definition - `ReturnsActionAsync` `extends BaseTransformation) => Promise>>, never>` - `type` `'returns'` - `reference` `typeof returnsAsync` - `schema` `TSchema` ### RfcEmailAction RFC email action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `EmailAction` `extends BaseValidation>` - `type` `'rfc_email'` - `reference` `typeof rfcEmail` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### RfcEmailIssue RFC email issue interface. #### Generics - `TInput` `extends string` #### Definition - `EmailIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'rfc_email'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### SafeIntegerAction Safe integer action interface. #### Generics - `TInput` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `SafeIntegerAction` `extends BaseValidation>` - `type` `'safe_integer'` - `reference` `typeof safeInteger` - `expects` `null` - `requirement` `(input: number) => boolean` - `message` `TMessage` ### SafeIntegerIssue Safe integer issue interface. #### Generics - `TInput` `extends number` #### Definition - `SafeIntegerIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'safe_integer'` - `expected` `null` - `received` `` `${number}` `` - `requirement` `(input: number) => boolean` ### SafeParser The safe parser interface. #### Generics - `TSchema` `extends BaseSchema>` - `TConfig` `extends Config> | undefined` #### Definition - `SafeParser` - `(input: unknown) => SafeParseResult` - `schema` `TSchema` - `config` `TConfig` ### SafeParserAsync The safe parser async interface. #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` - `TConfig` `extends Config> | undefined` #### Definition - `SafeParserAsync` - `(input: unknown) => Promise>` - `schema` `TSchema` - `config` `TConfig` ### SafeParseResult Safe parse result type. #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Definition - `SafeParseResult` - `typed` `boolean` - `success` `boolean` - `output` `InferOutput | unknown` - `issues` `[InferIssue, ...InferIssue[]] | undefined` ### SchemaWithCache Schema with cache type. #### Generics - `TSchema` `extends BaseSchema>` - `TCacheConfig` `extends CacheConfig | undefined` #### Definition - `SchemaWithCache` `extends TSchema` - `cacheConfig` `TCacheConfig` - `cache` `Cache, InferIssue>>` ### SchemaWithCacheAsync Schema with cache async type. #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` - `TCacheConfig` `extends CacheConfig | undefined` #### Definition - `SchemaWithCacheAsync` `extends TSchema` - `async` `true` - `cacheConfig` `TCacheConfig` - `cache` `Cache, InferIssue>>` ### SchemaWithFallback Schema with fallback type. #### Generics - `TSchema` `extends BaseSchema>` - `TFallback` `extends Fallback` #### Definition - `SchemaWithFallback` `extends TSchema` - `fallback` `TFallback` ### SchemaWithFallbackAsync Schema with fallback async type. #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` - `TFallback` `extends FallbackAsync` #### Definition - `SchemaWithFallbackAsync` `extends Omit` - `fallback` `TFallback` - `async` `true` - `~run` `(dataset: UnknownDataset, config: Config>) => Promise, InferIssue>>` ### SchemaWithoutPipe Schema without pipe type. #### Generics - `TSchema` `extends BaseSchema> | BaseSchemaAsync>` #### Definition - `SchemaWithoutPipe` `TSchema & { pipe?: never }` ### SchemaWithPartial Schema with partial type. > This type is too complex to display. Please refer to the [source code](https://github.com/open-circle/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/open-circle/valibot/blob/main/library/src/methods/partial/partialAsync.ts). ### SchemaWithPipe Schema with pipe type. #### Generics - `TPipe` `extends readonly [BaseSchema>, ...PipeItem>[]]` #### Definition - `SchemaWithPipe` `extends Omit, '~types' | '~run'>` - `pipe` `TPipe` - `~types` `{ input: InferInput>, output: InferOutput>, issue: InferIssue } | undefined` - `~run` `(dataset: UnknownDataset, config: Config>) => OutputDataset>, InferIssue>` ### SchemaWithPipeAsync Schema with pipe async type. #### Generics - `TPipe` `extends readonly [BaseSchema> | BaseSchemaAsync>, ...(PipeItem> | PipeItemAsync>)[]]` #### Definition - `SchemaWithPipeAsync` `extends Omit, 'async' | '~types' | '~run'>` - `pipe` `TPipe` - `async` `true` - `~types` `{ input: InferInput>, output: InferOutput>, issue: InferIssue } | undefined` - `~run` `(dataset: UnknownDataset, config: Config>) => Promise>, InferIssue>>` ### SchemaWithRequired Schema with required type. > This type is too complex to display. Please refer to the [source code](https://github.com/open-circle/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/open-circle/valibot/blob/main/library/src/methods/required/requiredAsync.ts). ### SetPathItem Set path item interface. #### Definition - `SetPathItem` `object` - `type` `'set'` - `origin` `'value'` - `input` `Set` - `value` `unknown` 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` `extends BaseIssue` - `kind` `'schema'` - `type` `'set'` - `expected` `'Set'` ### SetSchema Set schema interface. #### Generics - `TValue` `extends BaseSchema>` - `TMessage` `ErrorMessage | undefined` #### Definition - `SetSchema` `extends BaseSchema, InferSetOutput, SetIssue | InferIssue>` - `type` `'set'` - `reference` `typeof set` - `expects` `'Set'` - `value` `TValue` - `message` `TMessage` ### SetSchemaAsync Set schema async interface. #### Generics - `TValue` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `ErrorMessage | undefined` #### Definition - `SetSchemaAsync` `extends BaseSchemaAsync, InferSetOutput, SetIssue | InferIssue>` - `type` `'set'` - `reference` `typeof set | typeof setAsync` - `expects` `'Set'` - `value` `TValue` - `message` `TMessage` ### SizeAction Size action interface. #### Generics - `TInput` `extends SizeInput` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `SizeAction` `extends BaseValidation>` - `type` `'size'` - `reference` `typeof size` - `expects` `` `${TRequirement}` `` - `requirement` `TRequirement` - `message` `TMessage` ### SizeInput Size input type. #### Definition - `SizeInput` `Blob | Map | Set` ### SizeIssue Size issue interface. #### Generics - `TInput` `extends SizeInput` - `TRequirement` `extends number` #### Definition - `SizeIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'size'` - `expected` `` `${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement` ### SlugAction Slug action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `SlugAction` `extends BaseValidation>` - `type` `'slug'` - `reference` `typeof slug` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### SlugIssue Slug issue interface. #### Generics - `TInput` `extends string` #### Definition - `SlugIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'slug'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### SomeItemAction Some action interface. #### Generics - `TInput` `extends readonly unknown[]` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `SomeItemAction` `extends BaseValidation>` - `type` `'some_item'` - `reference` `typeof someItem` - `expects` `null` - `requirement` `(item: TInput[number], index: number, array: TInput) => boolean` - `message` `TMessage` ### SomeItemIssue Some item issue interface. #### Generics - `TInput` `extends ArrayInput` #### Definition - `SomeItemIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'some_item'` - `expected` `null` - `requirement` `ArrayRequirement` ### SortItemsAction Sort items action interface. #### Generics - `TInput` `extends ArrayInput` #### Definition - `SortItemsAction` `extends BaseTransformation` - `type` `'sort_items'` - `reference` `typeof sortItems` - `operation` `((itemA: TInput[number], itemB: TInput[number]) => number) | undefined` ### StandardFailureResult The result interface if validation fails. #### Definition - `StandardFailureResult` - `issues` `readonly StandardIssue[]` ### StandardIssue The issue interface of the failure output. #### Definition - `StandardIssue` - `message` `string` - `path` `readonly (PropertyKey | StandardPathItem)[] | undefined` ### StandardPathItem The path item interface of the issue. #### Definition - `StandardPathItem` - `key` `PropertyKey` ### StandardProps The Standard Schema properties interface. #### Generics - `TInput` `extends any` - `TOutput` `extends any` #### Definition - `StandardProps` - `version` `1` - `vendor` `'valibot'` - `validate` `((value: unknown) => StandardResult | Promise>)` - `types` `StandardTypes` ### StandardResult The result interface of the validate function. #### Generics - `TOutput` `extends any` #### Definition - `StandardResult` `StandardSuccessResult | StandardFailureResult` ### StandardSuccessResult The result interface if validation succeeds. #### Generics - `TOutput` `extends any` #### Definition - `StandardSuccessResult` - `value` `TOutput` - `issues` `undefined` ### StandardTypes The Standard Schema types interface. #### Generics - `TInput` `extends any` - `TOutput` `extends any` #### Definition - `StandardTypes` - `input` `TInput` - `output` `TOutput` ### StartsWithAction Starts with action interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `StartsWithAction` `extends BaseValidation>` - `type` `'starts_with'` - `reference` `typeof startsWith` - `expects` `` `"${TRequirement}"` `` - `requirement` `TRequirement` - `message` `TMessage` ### StartsWithIssue Starts with issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends string` #### Definition - `StartsWithIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'starts_with'` - `expected` `` `"${TRequirement}"` `` - `received` `` `"${string}"` `` - `requirement` `TRequirement` ### StrictObjectIssue Strict object issue interface. #### Definition - `StrictObjectIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'strict_object'` - `expected` `` 'Object' | `"${string}"` | 'never' `` ### StrictObjectSchema Strict object schema interface. #### Generics - `TEntries` `extends ObjectEntries` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `StrictObjectSchema` `extends BaseSchema, InferObjectOutput, StrictObjectIssue | InferObjectIssue>` - `type` `'strict_object'` - `reference` `typeof strictObject` - `expects` `'Object'` - `entries` `TEntries` - `message` `TMessage` ### StrictObjectSchemaAsync Strict object schema async interface. #### Generics - `TEntries` `extends ObjectEntriesAsync` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `StrictObjectSchemaAsync` `extends BaseSchemaAsync, InferObjectOutput, StrictObjectIssue | InferObjectIssue>` - `type` `'strict_object'` - `reference` `typeof strictObject | typeof strictObjectAsync` - `expects` `'Object'` - `entries` `TEntries` - `message` `TMessage` ### StrictTupleIssue Strict tuple issue interface. #### Definition - `StrictTupleIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'strict_tuple'` - `expected` `'Array'` ### StrictTupleSchema Strict tuple schema interface. #### Generics - `TItems` `extends TupleItems` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `StrictTupleSchema` `extends BaseSchema, InferTupleOutput, StrictTupleIssue | InferTupleIssue>` - `type` `'strict_tuple'` - `reference` `typeof strictTuple` - `expects` `'Array'` - `items` `TItems` - `message` `TMessage` ### StrictTupleSchemaAsync Strict tuple schema async interface. #### Generics - `TItems` `extends TupleItemsAsync` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `StrictTupleSchemaAsync` `extends BaseSchemaAsync, InferTupleOutput, StrictTupleIssue | InferTupleIssue>` - `type` `'strict_tuple'` - `reference` `typeof strictTuple | typeof strictTupleAsync` - `expects` `'Array'` - `items` `TItems` - `message` `TMessage` ### RecordIssue Record issue interface. #### Definition - `RecordIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'string'` - `expected` `'string'` ### StringSchema String schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `StringSchema` `extends BaseSchema` - `type` `'string'` - `reference` `typeof string` - `expects` `'string'` - `message` `TMessage` ### StringifyJsonAction JSON stringify action interface. #### Generics - `TInput` `extends any` - `TConfig` `extends StringifyJsonConfig | undefined` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `StringifyJsonAction` `extends BaseTransformation>` - `type` `'stringify_json'` - `reference` `typeof stringifyJson` - `config` `TConfig` - `message` `TMessage` ### StringifyJsonConfig JSON stringify config interface. #### Definition - `StringifyJsonConfig` - `replacer` `((this: any, key: string, value: any) => any) | (string | number)[] | undefined` - `space` `string | number | undefined` ### StringifyJsonIssue JSON stringify issue interface. #### Generics - `TInput` `extends any` #### Definition - `StringifyJsonIssue` `extends BaseIssue` - `kind` `'transformation'` - `type` `'stringify_json'` - `expected` `null` - `received` `` `"${string}"` `` ### SuccessDataset Success dataset interface. #### Generics - `TValue` `extends any` #### Definition - `TypedDataset` - `typed` `true` - `value` `TValue` - `issues` `undefined` ### SymbolIssue Symbol issue interface. #### Definition - `SymbolIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'symbol'` - `expected` `'symbol'` ### SymbolSchema Symbol schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `SymbolSchema` `extends BaseSchema` - `type` `'symbol'` - `reference` `typeof symbol` - `expects` `'symbol'` - `message` `TMessage` ### TitleAction Title action interface. #### Generics - `TInput` `extends any` - `TTitle` `extends string` #### Definition - `TitleAction` `extends BaseMetadata` - `type` `'title'` - `reference` `typeof title` - `title` `TTitle` ### ToBigintAction To bigint action interface. #### Generics - `TInput` `extends any` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `ToBigintAction` `extends BaseTransformation>` - `type` `'to_bigint'` - `reference` `typeof toBigint` - `message` `TMessage` ### ToBigintIssue To bigint issue interface. #### Generics - `TInput` `extends any` #### Definition - `ToBigintIssue` `extends BaseIssue` - `kind` `'transformation'` - `type` `'to_bigint'` - `expected` `null` ### ToBooleanAction To boolean action interface. #### Generics - `TInput` `extends any` #### Definition - `ToBooleanAction` `extends BaseTransformation` - `type` `'to_boolean'` - `reference` `typeof toBoolean` ### ToCamelCaseAction To camel case action interface. #### Definition - `ToCamelCaseAction` `extends BaseTransformation` - `type` `'to_camel_case'` - `reference` `typeof toCamelCase` ### ToDateAction To date action interface. #### Generics - `TInput` `extends any` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `ToDateAction` `extends BaseTransformation>` - `type` `'to_date'` - `reference` `typeof toDate` - `message` `TMessage` ### ToDateIssue To date issue interface. #### Generics - `TInput` `extends any` #### Definition - `ToDateIssue` `extends BaseIssue` - `kind` `'transformation'` - `type` `'to_date'` - `expected` `null` ### ToKebabCaseAction To kebab case action interface. #### Definition - `ToKebabCaseAction` `extends BaseTransformation` - `type` `'to_kebab_case'` - `reference` `typeof toKebabCase` ### ToLowerCaseAction To lower case action interface. #### Definition - `ToLowerCaseAction` `extends BaseTransformation` - `type` `'to_lower_case'` - `reference` `typeof toLowerCase` ### ToMinValueAction To min value action interface. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` #### Definition - `ToMinValueAction` `extends BaseTransformation` - `type` `'to_min_value'` - `reference` `typeof toMinValue` - `requirement` `TRequirement` ### ToMaxValueAction To max value action interface. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` #### Definition - `ToMaxValueAction` `extends BaseTransformation` - `type` `'to_max_value'` - `reference` `typeof toMaxValue` - `requirement` `TRequirement` ### ToNumberAction To number action interface. #### Generics - `TInput` `extends any` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `ToNumberAction` `extends BaseTransformation>` - `type` `'to_number'` - `reference` `typeof toNumber` - `message` `TMessage` ### ToNumberIssue To number issue interface. #### Generics - `TInput` `extends any` #### Definition - `ToNumberIssue` `extends BaseIssue` - `kind` `'transformation'` - `type` `'to_number'` - `expected` `null` ### ToPascalCaseAction To pascal case action interface. #### Definition - `ToPascalCaseAction` `extends BaseTransformation` - `type` `'to_pascal_case'` - `reference` `typeof toPascalCase` ### ToSnakeCaseAction To snake case action interface. #### Definition - `ToSnakeCaseAction` `extends BaseTransformation` - `type` `'to_snake_case'` - `reference` `typeof toSnakeCase` ### ToStringAction To string action interface. #### Generics - `TInput` `extends any` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `ToStringAction` `extends BaseTransformation>` - `type` `'to_string'` - `reference` `typeof toString` - `message` `TMessage` ### ToStringIssue To string issue interface. #### Generics - `TInput` `extends any` #### Definition - `ToStringIssue` `extends BaseIssue` - `kind` `'transformation'` - `type` `'to_string'` - `expected` `null` ### ToUpperCaseAction To upper case action interface. #### Definition - `ToUpperCaseAction` `extends BaseTransformation` - `type` `'to_upper_case'` - `reference` `typeof toUpperCase` ### TransformAction Transform action interface. #### Generics - `TInput` `extends any` - `TOutput` `extends any` #### Definition - `TransformAction` `extends BaseTransformation` - `type` `'transform'` - `reference` `typeof transform` - `operation` `(input: TInput) => TOutput` ### TransformActionAsync Transform action async interface. #### Generics - `TInput` `extends any` - `TOutput` `extends any` #### Definition - `TransformActionAsync` `extends BaseTransformationAsync` - `type` `'transform'` - `reference` `typeof transform | typeof transformAsync` - `operation` `(input: TInput) => Promise` ### TrimAction Trim action interface. #### Definition - `TrimAction` `extends BaseTransformation` - `type` `'trim'` - `reference` `typeof trim` ### TrimEndAction Trim end action interface. #### Definition - `TrimEndAction` `extends BaseTransformation` - `type` `'trim_end'` - `reference` `typeof trimEnd` ### TrimStartAction Trim start action interface. #### Definition - `TrimStartAction` `extends BaseTransformation` - `type` `'trim_start'` - `reference` `typeof trimStart` ### TupleIssue Tuple issue interface. #### Definition - `TupleIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'tuple'` - `expected` `'Array'` ### TupleItems Tuple items type. #### Definition - `TupleItems` `MaybeReadonly>[]>` ### TupleItemsAsync Tuple items async type. #### Definition - `TupleItemsAsync` `MaybeReadonly<(BaseSchema> | BaseSchemaAsync>)[]>` ### TupleSchema Tuple schema interface. #### Generics - `TItems` `extends TupleItems` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `TupleSchema` `extends BaseSchema, InferTupleOutput, TupleIssue | InferTupleIssue>` - `type` `'tuple'` - `reference` `typeof tuple` - `expects` `'Array'` - `items` `TItems` - `message` `TMessage` ### TupleSchemaAsync Tuple schema async interface. #### Generics - `TItems` `extends TupleItemsAsync` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `TupleSchemaAsync` `extends BaseSchemaAsync, InferTupleOutput, TupleIssue | InferTupleIssue>` - `type` `'tuple'` - `reference` `typeof tuple | typeof tupleAsync` - `expects` `'Array'` - `items` `TItems` - `message` `TMessage` ### TupleWithRestIssue Tuple with rest issue interface. #### Definition - `TupleWithRestIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'tuple_with_rest'` - `expected` `'Array'` ### TupleWithRestSchema Tuple with rest schema interface. #### Generics - `TItems` `extends TupleItems` - `TRest` `extends BaseSchema>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `TupleWithRestSchema` `extends BaseSchema<[...InferTupleInput, ...InferInput[]], [...InferTupleOutput, ...InferOutput[]], TupleWithRestIssue | InferTupleIssue | InferIssue>` - `type` `'tuple_with_rest'` - `reference` `typeof tupleWithRest` - `expects` `'Array'` - `items` `TItems` - `rest` `TRest` - `message` `TMessage` ### TupleWithRestSchemaAsync Tuple with rest schema async interface. #### Generics - `TItems` `extends TupleItemsAsync` - `TRest` `extends BaseSchema> | BaseSchemaAsync>` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `TupleWithRestSchemaAsync` `extends BaseSchemaAsync<[...InferTupleInput, ...InferInput[]], [...InferTupleOutput, ...InferOutput[]], TupleWithRestIssue | InferTupleIssue | InferIssue>` - `type` `'tuple_with_rest'` - `reference` `typeof tupleWithRest | typeof tupleWithRestAsync` - `expects` `'Array'` - `items` `TItems` - `rest` `TRest` - `message` `TMessage` ### UlidAction ULID action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `UlidAction` `extends BaseValidation>` - `type` `'ulid'` - `reference` `typeof ulid` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### UlidIssue ULID issue interface. #### Generics - `TInput` `extends string` #### Definition - `UlidIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'ulid'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### UndefinedableSchema Undefinedable schema interface. #### Generics - `TWrapped` `extends BaseSchema>` - `TDefault` `extends Default` #### Definition - `UndefinedableSchema` `extends BaseSchema | undefined, InferUndefinedableOutput, InferIssue>` - `type` `'undefinedable'` - `reference` `typeof undefinedable` - `expects` `` `(${TWrapped['expects']} | undefined)` `` - `wrapped` `TWrapped` - `default` `TDefault` ### UndefinedableSchemaAsync Undefinedable schema async interface. #### Generics - `TWrapped` `extends BaseSchema> | BaseSchemaAsync>` - `TDefault` `extends DefaultAsync` #### Definition - `UndefinedableSchemaAsync` `BaseSchemaAsync | undefined, InferUndefinedableOutput, InferIssue>` - `type` `'undefinedable'` - `reference` `typeof undefinedable | typeof undefinedableAsync` - `expects` `` `(${TWrapped['expects']} | undefined)` `` - `wrapped` `TWrapped` - `default` `TDefault` ### UndefinedIssue Undefined issue interface. #### Definition - `UndefinedIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'undefined'` - `expected` `'undefined'` ### UndefinedSchema Undefined schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `UndefinedSchema` `extends BaseSchema` - `type` `'undefined'` - `reference` `typeof undefined` - `expects` `'undefined'` - `message` `TMessage` ### UnionOptions Union options type. #### Definition - `UnionOptions` `MaybeReadonly>[]>` ### UnionOptionsAsync Union options async type. #### Definition - `UnionOptionsAsync` `MaybeReadonly<(BaseSchema> | BaseSchemaAsync>)[]>` ### UnionIssue Union issue interface. #### Generics - `TSubIssue` `extends BaseIssue` #### Definition - `UnionIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'union'` - `expected` `string` - `issues` `[TSubIssue, ...TSubIssue[]]` ### UnionSchema Union schema interface. #### Generics - `TOptions` `extends UnionOptions` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `UnionSchema` `extends BaseSchema, InferOutput, UnionIssue> | InferIssue>` - `type` `'union'` - `reference` `typeof union` - `options` `TOptions` - `message` `TMessage` ### UnionSchemaAsync Union schema async interface. #### Generics - `TOptions` `extends UnionOptionsAsync` - `TMessage` `extends ErrorMessage>> | undefined` #### Definition - `UnionSchemaAsync` `BaseSchemaAsync, InferOutput, UnionIssue> | InferIssue>` - `type` `'union'` - `reference` `typeof union | typeof unionAsync` - `options` `TOptions` - `message` `TMessage` ### UnknownDataset Unknown dataset interface. #### Definition - `TypedDataset` - `typed` `false` - `value` `unknown` - `issues` `undefined` ### UnknownPathItem Unknown path item interface. #### Definition - `UnknownPathItem` - `type` `'unknown'` - `origin` `'key' | 'value'` - `input` `unknown` - `key` `unknown` - `value` `unknown` 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` `extends BaseSchema` - `type` `'unknown'` - `reference` `typeof unknown` - `expects` `'unknown'` ### UrlAction URL action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `UrlAction` `extends BaseValidation>` - `type` `'url'` - `reference` `typeof url` - `expects` `null` - `requirement` `(input: string) => boolean` - `message` `TMessage` ### UrlIssue URL issue interface. #### Generics - `TInput` `extends string` #### Definition - `UrlIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'url'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `(input: string) => boolean` ### UuidAction UUID action interface. #### Generics - `TInput` `extends string` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `UuidAction` `extends BaseValidation>` - `type` `'uuid'` - `reference` `typeof uuid` - `expects` `null` - `requirement` `RegExp` - `message` `TMessage` ### UuidIssue UUID issue interface. #### Generics - `TInput` `extends string` #### Definition - `UuidIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'uuid'` - `expected` `null` - `received` `` `"${string}"` `` - `requirement` `RegExp` ### ValueAction Value action interface. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `ValueAction` `extends BaseValidation>` - `type` `'value'` - `reference` `typeof value` - `expects` `string` - `requirement` `TRequirement` - `message` `TMessage` ### ValuesAction Values action type. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends readonly TInput[]` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `ValuesAction` `extends BaseValidation>` - `type` `'values'` - `reference` `typeof values` - `expects` `string` - `requirement` `TRequirement` - `message` `TMessage` ### ValueInput Value input type. #### Definition - `ValueInput` `string | number | bigint | boolean | Date` ### ValueIssue Value issue interface. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends TInput` #### Definition - `ValueIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'value'` - `expected` `string` - `requirement` `TRequirement` ### ValuesIssue Values issue type. #### Generics - `TInput` `extends ValueInput` - `TRequirement` `extends readonly TInput[]` #### Definition - `ValuesIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'values'` - `expected` `string` - `requirement` `TRequirement` ### VariantIssue Variant issue interface. #### Definition - `VariantIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'variant'` - `expected` `string` ### VariantOption Variant option type. > This type is too complex to display. Please refer to the [source code](https://github.com/open-circle/valibot/blob/main/library/src/schemas/variant/types.ts). ### VariantOptionAsync Variant option async type. > This type is too complex to display. Please refer to the [source code](https://github.com/open-circle/valibot/blob/main/library/src/schemas/variant/types.ts). ### VariantOptions Variant options type. #### Generics - `TKey` `extends string` #### Definition - `VariantOptions` `MaybeReadonly[]>` ### VariantOptionsAsync Variant options async type. #### Generics - `TKey` `extends string` #### Definition - `VariantOptionsAsync` `MaybeReadonly[] | VariantOptionAsync[]>` ### VariantSchema Variant schema interface. #### Generics - `TKey` `extends string` - `TOptions` `extends VariantOptions` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `VariantSchema` `extends BaseSchema, InferOutput, VariantIssue | InferVariantIssue>` - `type` `'variant'` - `reference` `typeof variant` - `expects` `'Object'` - `key` `TKey` - `options` `TOptions` - `message` `TMessage` ### VariantSchemaAsync Variant schema async interface. #### Generics - `TKey` `extends string` - `TOptions` `extends VariantOptionsAsync` - `TMessage` `extends ErrorMessage | undefined` #### Definition - `VariantSchemaAsync` `extends BaseSchemaAsync, InferOutput, VariantIssue | InferVariantIssue>` - `type` `'variant'` - `reference` `typeof variant | typeof variantAsync` - `expects` `'Object'` - `key` `TKey` - `options` `TOptions` - `message` `TMessage` ### VoidIssue Void issue interface. #### Definition - `VoidIssue` `extends BaseIssue` - `kind` `'schema'` - `type` `'void'` - `expected` `'void'` ### VoidSchema Void schema interface. #### Generics - `TMessage` `extends ErrorMessage | undefined` #### Definition - `VoidSchema` `extends BaseSchema` - `type` `'void'` - `reference` `typeof void` - `expects` `'void'` - `message` `TMessage` ### WordsAction Words action interface. #### Generics - `TInput` `extends string` - `TLocales` `extends Intl.LocalesArgument` - `TRequirement` `extends number` - `TMessage` `extends ErrorMessage> | undefined` #### Definition - `WordsAction` `extends BaseValidation>` - `type` `'words'` - `reference` `typeof words` - `expects` `` `${TRequirement}` `` - `locales` `TLocales` - `requirement` `TRequirement` - `message` `TMessage` ### WordsIssue Words issue interface. #### Generics - `TInput` `extends string` - `TRequirement` `extends number` #### Definition - `WordsIssue` `extends BaseIssue` - `kind` `'validation'` - `type` `'words'` - `expected` `` `${TRequirement}` `` - `received` `` `${number}` `` - `requirement` `TRequirement`