0.0.3 • Published 4 years ago

adonis-validators v0.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

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:

    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.

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

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago