Validations
import { Validation } from 'Blini'A Validation allows you to define a transformation or rejection that will be applied to data before flushing to the database.
Validations are simple function accepting a value in input and returning a new value or throwing an error. Validations can be async by returning a promise.
General validations
required
requiredValidation.required(message: String)
Enforce that the field is set, throw an error with message otherwise.
default
defaultValidation.default(value: Mixed)
Defaults the value of the field if non existant. It doesn't reject the valuation, only transform the data set.
String Validations
minLength
minLengthValidation.minLength(min: Number, message: String)
Enforce that the string value is at least min characters long.
maxLength
maxLengthValidation.maxLength(max: Number, message: String)
Enforce that the string value is less than max characters long.
regExp
regExpValidation.regExp(re: RegExp, message: String)
Enforce that the string value match a RegExp (re).
oneOf
oneOfValidation.oneOf(constants: Array, message: String)
Enforce that the value is one of the constants.
Iterable Validations
limitAt
limitAtValidation.limitAt(max: Number)
Enforce that iterable doesn't have more than max element, it does not throw error, but normalize the value.
Last updated
Was this helpful?