# adonis-validators

> AdonisJS Validators extensions provider

Latest version **0.0.3** (published 2020-04-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install adonis-validators
pnpm add adonis-validators
yarn add adonis-validators
bun add adonis-validators
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2020-04-10 |
| First published | 2020-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | josemiguelmelo |

## Links

- npm: https://www.npmjs.com/package/adonis-validators
- Repository: https://github.com/josemiguelmelo/adonis-validators
- Homepage: https://github.com/josemiguelmelo/adonis-validators#readme
- Issues: https://github.com/josemiguelmelo/adonis-validators/issues
- npm.io page: https://npm.io/package/adonis-validators

## Dependencies (1)

- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.149

## Recent versions

- 0.0.3 (latest) — 2020-04-10
- 0.0.2 — 2020-04-10
- 0.0.1 — 2020-04-10

## README

# Adonis validators

This is an extension for Adonis validator, adding new validators to it.

## Installation

In order to install, run the following command:

    yarn add adonis-validators

After that, add Adonis Validators to the list of providers on `start/app.js`:

    const providers = [
        ....,
        'adonis-validators/providers/AdonisValidatorsProvider'
    ]

## Validators

-   ShouldNotExistWhen - a field should not be present when another field is present on the request. 
    > Example: password should not be sent if token is sent; token should not be sent if password is sent.

Usage:

```js
    get rules() {
        return {
          password: 'shouldNotExistWhen:token',
          token: 'shouldNotExistWhen:password',
        }
    }
```

## Contributing

If you want to contribute and add more validators:

1) Add a new validator class which extends `CustomValidator`
2) Implement validate method
3) Set `validatorName`. This validator name is the name used on the validation rule.

```js
import CustomValidator from './CustomValidator';

class ExampleValidator extends CustomValidator {
    validatorName: string = 'exampleValidator';

    async validate(data: any, field: any, message: any, args: any, get: any) {
        const value = get(data, field);
        if (!value) {
            return;
        }

        throw message
    }
}

export default new ExampleValidator();
```

2) Add the new validator to `modules` on `providers/index.ts`

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