# @codenhub/validation

> Validation of untrusted input for TypeScript. Each validator is a standalone function that returns `{ ok: true, value }` or `{ ok: false, error: { issues } }`, and never throws for invalid input. `email()` and `url()` return what the URL parser read, what a failing input reports is bounded, and an issue never holds a value of the input. The package is experimental.

Create a validator by calling a factory, then call it with the value: `email()(input)`, `object({ name: string({ min: 2 }) })(input)`. A factory takes its own arguments, then options, then checks: `string({ max: 30 }, startsWith("a"))`. A validator with an asynchronous rule is an `AsyncValidator`, and its result must be awaited. Read the type a validator produces with `Infer`, and the type it accepts with `InferInput`.

## Documentation

- [Documentation overview](docs/index.md): Why validate, a first validator, and the reading path through the pages below.
- [Getting started](docs/getting-started.md): Results, primitives, built-in checks, objects, `Infer`, `is`, and sync against async.
- [Forms](docs/forms.md): Rules across fields with `check` and `checkFields`, `optional` and defaults, `flatten`, files with `formData`, `file` and `contentType`, and `InferInput`.
- [Request bodies](docs/request-bodies.md): `json`, collections, `union`, `tagged`, `intersection`, and recursive data with `lazy`.
- [Text input](docs/text-input.md): The `coerce*` validators, dates, `searchParams` for a query string, and the environment.
- [Issues and messages](docs/errors.md): The issue, built-in codes and params, `formatIssue`, English, Portuguese and Spanish messages, the `message` option, `assert`.
- [Custom validators](docs/custom-validators.md): `check`, `format`, `guard`, validators written by hand, asynchronous rules, and the exported types.
- [Formats](docs/formats.md): `email`, `url` and their parts, `domain`, `hostname`, `ip`, `datetime`, `time`, and every other format.
- [Shaping values](docs/shaping-values.md): `pipe`, `transform`, `codec`, `encode`, `brand`, `readonly`, `meta`, `fallback`, and `pick`, `omit`, `partial`, `required`, `extend`.
- [Standard Schema](docs/standard-schema.md): Every validator a factory makes is a Standard Schema, and one written by hand is not; `standard` and `standardJsonSchema` choose its wording and add its JSON Schema.
- [JSON Schema](docs/json-schema.md): `toJsonSchema`, what each validator is written as, and `describe` for reading a validator.
- [Integrations](docs/integrations.md): react-hook-form, TanStack Form, tRPC, Hono, the AI SDK, the Model Context Protocol, OpenAPI, zod and valibot.
- [Limits](docs/limits.md): The 1,000-issue limit of each collection, `maxDepth` and `maxCalls` of `lazy`, sizes to cap, and `audit`.

## Optional

- [API reference](docs/reference/index.md): Every export with its signature and documentation, generated from the source.
- [Changelog](docs/changelog/index.md): Release notes, and the migrations from earlier versions.
