### datatypes-validation
![](https://img.shields.io/npm/v/datatypes-validation.svg)
![](https://img.shields.io/npm/dm/datatypes-validation.svg)
![](coverage/badge-lines.svg)
![](coverage/badge-functions.svg)
![](coverage/badge-statements.svg)
![](coverage/badge-branches.svg)

This package was created with the purpose to facilitate the validation 
the backend level with NODEJS.

See the complete
[documentation](https://igor-barbosa.github.io/datatypes-validation/index.html).

#### Install

install with yarn

```
yarn add datatypes-validation
```

install with npm

```
npm add datatypes-validation
```

#### Importing

```javascript
import {DataTypes} from 'datatypes-validation'; // ES6

const {DataTypes} = require('datatypes-validation'); // ES5
```

#### Simple example usage

```javascript
const schema = {
    name: DataTypes.string.isRequired({ 
        shortMessage: (field) => `The field "${field.label}" is required`, 
        longMessage: 'The field "Name" is required'
    }),
    age: DataTypes.required,
    locale: DataTypes.objectOf({ 
        country: DataTypes.required 
    }).required
}

try {
    const response = DataTypes.validate(schema, body);
}
catch (e) {  
    const {errors} = e;
}
```

