veracious
v0.0.2
Published
Validator based on PHP's Illuminate/Validate aka Laravel. Built with async/await in mind and promises.
Downloads
1
Readme
Veracious
A Javascript validator that tries to be similar to Laravel's.
Installation
Save To Dependencies
npm i veracious --save
Usage
const request = {
username: 'Chs'
}
const rules = {
username: 'required|min:1|max:10|alphanum|exists:users,username'
}
try {
await Veracious.validate(request, rules, database)
} catch (e) {
console.log(e)
}
Database Paramater (optional)
The database paramater is optional and is just a plain knex connection. It's used for the unique and exists rules.
let database = Knex({
client: 'mysql2',
connection: {
host: 'localhost',
user: 'root',
password: 'password',
database: 'habbo'
}
})
Error Handling
Errors that are returned will be strings that have a serialized message, ie: [ ERROR ] username does not exist!
Rules
-required
-min:length
-max:length
-unique:table,column
-exists:table,column
-alpha
-alpha_num
-alpha_dash
-numeric