Validate Data
NodeJs backend library for validate data against the rules provided.
Usage
Install the library with npm install validate-data
const validate = require('validate-data');
const rules = {
required: "email name age",
email: "email",
string: "email name",
number: "age",
array: "options",
boolean: "status"
};
const data = {
email: "example@sample.com",
name: "John",
age: 25,
options: [1,2,3],
status: true
};
let error = validate(data, rules);
console.log(error);
Error will be null if all the validation rules passs, otherwise will get the following error
[
{
rule: 'required',
errorOn: ['sample']
},
{
rule: 'email',
errorOn: ['email']
},
{
rule: 'number',
errorOn: ['age']
},
{
rule: 'array',
errorOn: ['options']
},
{
rule: 'boolean',
errorOn: ['status']
}
]
Validators
Module ensure that the given data will be validated against the following strategies.
- Required
- String
- Number
- Email
- Array
- Boolean
Feature requests
Feature requests are welcome. But take a moment to find out whether your idea fits with the scope and aims of the project. Please provide as much detail and context as possible. Click here to add feature requests and issues.
Change Log
CHANGELOG.md
Tests
yarn run test
License
MIT