-
Notifications
You must be signed in to change notification settings - Fork 1
Filters
Filters are methods that manipulate the incoming value structure from the body, params, or query before and/or after the validators are called.
Example:
const { v, f } = require('koa-fluent-validation');
app.use(async ctx => {
if (ctx.method !== 'POST') {
ctx.throw(404);
return;
}
ctx.validateBody({
firstName: v().required().string(),
lastName: v().required().string(),
email: v().required().email()
}, {
before: {
firstName: f().trim().toUpper(),
lastName: f().trim().toUpper(),
email: f().trim().normalizeEmail()
}
});
});The beginning of any filter chain. It's a function that returns an instance of the FilterBuilder class. Each function that is called on this instance returns the same type.
Example:
// v is a function ready to give you a builder to work off of.
const { f } = require('koa-fluent-validation');If the value is a string, it trims it.
If the value is a string, it converts it to uppercase.
If the value is a string, it converts it to lowercase.
If the value is a string, it fills it on the left with the fill parameter it until the length is reached. If fill is not specified, empty spaces will be applied.
See padStart for more information.
If the value is a string, it fills it on the right with the fill parameter it until the length is reached. If fill is not specified, empty spaces will be applied.
See padEnd for more information.
If the value is a string, it normalizes the email.
See validator for more information and the options parameter.
If the value is a string, it will try to convert to an integer. NaN is outputted when it can't.
convert the input string to a boolean. Everything except for '0', 'false' and '' returns true. In strict mode only '1' and 'true' return true.
See validator for more information.