1.1.1 • Published 4 years ago
humo v1.1.1
Humo
Super simple (158B) validator 😅
Install
$ npm install --save humo
Example
import Humo from "humo";
const validator = new Humo();
const data = {
username: "lex",
password: "1234",
confirmPassword: "1234"
};
const rules = {
username(val) {
return !val
? "required"
: val.length <= 3 && "must be more than 3 characters";
},
password(val) {
return !val
? "required"
: val.length <= 6 && "must be more than 6 characters";
},
confirmPassword(val, { password }) {
return !val ? "required" : val !== password && "must match your password";
}
};
validator.validate(rules, data);
if (validator.check()) {
console.log(validator.errors);
}