# @oats-ts/validators

> Standalone lightweight runtime validator utility functions used extensively in oats libraries.

Latest version **0.0.51** (published 2023-12-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @oats-ts/validators
pnpm add @oats-ts/validators
yarn add @oats-ts/validators
bun add @oats-ts/validators
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.51 |
| Published | 2023-12-17 |
| First published | 2021-07-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 62.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | Balázs Édes |
| Maintainers | bali182 |

## Links

- npm: https://www.npmjs.com/package/@oats-ts/validators
- Repository: https://github.com/oats-ts/oats-ts
- Homepage: https://oats-ts.github.io/docs
- Issues: https://github.com/oats-ts/oats-ts/issues
- npm.io page: https://npm.io/package/@oats-ts/validators

## Recent versions

- 0.0.51 (latest) — 2023-12-17
- 0.0.50 — 2023-12-10
- 0.0.49 — 2022-12-08
- 0.0.48 — 2022-12-02
- 0.0.47 — 2022-11-16
- 0.0.46 — 2022-11-13
- 0.0.45 — 2022-11-11
- 0.0.44 — 2022-11-09
- 0.0.43 — 2022-10-30
- 0.0.42 — 2022-10-13
- 0.0.41 — 2022-10-12
- 0.0.40 — 2022-10-10
- 0.0.39 — 2022-10-09
- 0.0.38 — 2022-10-04
- 0.0.37 — 2022-10-02
- … 36 more at https://npm.io/package/@oats-ts/validators/versions

## README

# @oats-ts/validators

Standalone lightweight runtime validator utility functions used extensively in oats libraries.

- Created by function composition.
- Validators **NEVER** throw, if they do, please [report](https://github.com/oats-ts/oats-ts/issues) it.
- Validators returns a list of `Issue`s that can be formatted, and presented to the user.

And an example validator:

```ts
import { object, shape, string, number, array, items, boolean, union, lazy } from '@oats-ts/validators'

const personValidator = configure(
  object(
    shape({
      name: string(),
      email: optional(string()),
      occupation: union({
        programmer: literal('programmer'),
        musician: literal('musician'),
        other: literal('other'),
      }),
      married: boolean(),
      friends: array(items(lazy(() => personValidator))),
      address: object(
        shape({
          country: string(),
          zip: number(),
          city: string(),
          street: string(),
        }),
      ),
    }),
  ),
)
```

When validating simply call this function. It will return a list of `Issue`s, reporting everything that's wrong with the input:

```ts
const validPerson = {
  name: 'Test',
  email: 'test',
  occupation: 'other',
  married: false,
  friends: [],
  address: {
    country: 'Test',
    zip: 1243,
    city: 'Test',
    street: 'Test',
  },
}

const invalidPerson = {
  name: false,
  email: 1,
  fr_iends: [{ hi: true }],
}

// Returns an empty array
expect(personValidator(validPerson).length).toBe(0)
// Returns an array with all the issues
expect(personValidator(invalidPerson).length).toBeGreaterThan(0)
```

---
_Source: https://npm.io/package/@oats-ts/validators · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
