# altheia-async-data-validator

> A very simple, fast and customizable async data validator

Latest version **5.0.15** (published 2022-08-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install altheia-async-data-validator
pnpm add altheia-async-data-validator
yarn add altheia-async-data-validator
bun add altheia-async-data-validator
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.15 |
| Published | 2022-08-08 |
| First published | 2018-04-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 10.13.0 |
| Dependencies | 1 |
| Unpacked size | 78 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Samuel Bodin |
| Maintainers | h1fra |
| Keywords | validator, validate, validation, async, schema, valid, assert, data, json, joi |

## Links

- npm: https://www.npmjs.com/package/altheia-async-data-validator
- Repository: https://github.com/bodinsamuel/altheia
- Homepage: https://github.com/bodinsamuel/altheia#readme
- Issues: http://github.com/bodinsamuel/altheia/issues
- npm.io page: https://npm.io/package/altheia-async-data-validator

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 5.0.15 (latest) — 2022-08-08
- 5.0.0-beta.3 (beta) — 2019-07-28
- 5.0.14 — 2022-07-26
- 5.0.13 — 2022-01-17
- 5.0.12 — 2021-09-02
- 5.0.11 — 2021-04-30
- 5.0.10 — 2021-03-08
- 5.0.9 — 2021-03-08
- 5.0.8 — 2020-07-13
- 5.0.7 — 2020-03-14
- 5.0.6 — 2020-02-28
- 5.0.5 — 2020-02-28
- 5.0.4 — 2020-02-28
- 5.0.3 — 2020-02-05
- 5.0.2 — 2020-01-30
- … 28 more at https://npm.io/package/altheia-async-data-validator/versions

## README

# Altheia

[![CI](https://github.com/bodinsamuel/altheia/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/bodinsamuel/altheia/actions/workflows/ci.yml)

A very simple, fast and customizable async data validator, inspired by Joi .

```javascript
await alt
  .string()
  .email()
  .custom('not_in_db', async (val) => await searchDB(val));
```

Online documentation: [github.io/altheia/](https://bodinsamuel.github.io/altheia/)

## 🤓 Why?

After searching for a long time a simple data validator that allow async validation, I decided to implement one. Heavily inspired from Joi, it aim at being very lightweight, simple to use and allow to check anything from standard schema to very custom ones.

The goal of this library is to validate json -- for example in express middleware -- and complexe javascript object.

- 💅 **Easy to customize.** Use builtin or create your own validation.
- ⚡️**Async.** Call any resources asynchronously to do check your data (e.g: database, xhr...)
- 🤩 **Typescript.** No more checking long documentation and wondering what to write.
- 🧘 **Easy to use.** No configuration required

## ✨ Install

```bash
npm install altheia-async-data-validator
```

```sh
yarn add altheia-async-data-validator
```

## 🖼 Example

```javascript
import alt from 'altheia-async-data-validator'

alt.lang('string.min', (name, args) => `This ${name} is too short`);
alt.template('login', alt.string().min(3).not('admin'));

const errors = await alt({
    login: alt.is('login'),
    email: alt.string()
        .email()
        .custom('not_in_db', async (val) => await searchDB(val)),
    eyes: alt.number().integer().positive().max(2),
    date: alt.date().iso(),
    gender: alt.string().if({
        test: test => test.uppercase(),
        then: test => test.in('F', 'M'),
        otherwise: test => test.in('female', 'male')
    })
}).options({
    required: true
}).validate({
    login: 'leela',
    email: 'captain@planetexpress.com',
    eyes: 1,
    date: '2015-01-04T17:35:22Z',
    gender: 'female',
});

console.log(errors); // false
```

## 📚 Documentation

- Full [Documentation](/docs/)
- Validator [API](/docs/api.md)
- [Changelog](../master/CHANGELOG.md)

## 📋 Contributing

Every contribution or feature requests will be gladly accepted in the issue section.

---
_Source: https://npm.io/package/altheia-async-data-validator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
