Releases: icebob/fastest-validator
Releases · icebob/fastest-validator
v1.4.1
v1.4.0
New custom
function signature
Thanks for @erfanium, in this version there is a new signature of custom check functions.
In this new function you should always return the value. It means you can change the value, thus you can also sanitize the input value.
Old custom function:
const v = new Validator({});
const schema = {
weight: {
type: "custom",
minWeight: 10,
check(value, schema) {
return (value < schema.minWeight)
? [{ type: "weightMin", expected: schema.minWeight, actual: value }]
: true;
}
}
};
New custom function:
const v = new Validator({
useNewCustomCheckerFunction: true, // using new version
});
const schema = {
name: { type: "string", min: 3, max: 255 },
weight: {
type: "custom",
minWeight: 10,
check(value, errors, schema) {
if (value < minWeight) errors.push({ type: "weightMin", expected: schema.minWeight, actual: value });
if (value > 100) value = 100
return value
}
}
};
Please note: the old version will be removed in the version 2.0.0!
The signature is used in custom
function of built-in rules.
const v = new Validator({
useNewCustomCheckerFunction: true // using new version
});
const schema = {
phone: { type: "string", length: 15, custom(v, errors) => {
if (!v.startWith("+")) errors.push({ type: "phoneNumber" })
return v.replace(/[^\d+]/g, ""); // Sanitize: remove all special chars except numbers
} }
};
v1.3.0
v1.2.0
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v1.0.0-beta4
Changes
- fix array rule return value issue (again).
v1.0.0-beta3
Changes
- fix optional multi rule.