v1.6.0
New objectID
rule
You can validate BSON/MongoDB ObjectID's
Example
const { ObjectID } = require("mongodb") // or anywhere else
const schema = {
id: {
type: "objectID",
ObjectID // passing the ObjectID class
}
}
const check = v.compile(schema);
check({ id: "5f082780b00cc7401fb8e8fc" }) // ok
check({ id: new ObjectID() }) // ok
check({ id: "5f082780b00cc7401fb8e8" }) // Error
Dynamic default value
You can use dynamic default value by defining a function that returns a value.
Example
In the following code, if createdAt
field not defined in object`, the validator sets the current time into the property:
const schema = {
createdAt: {
type: "date",
default: () => new Date()
}
};
const obj = {}
v.validate(obj, schema); // Valid
console.log(obj);
/*
{
createdAt: Date(2020-07-25T13:17:41.052Z)
}
*/
Changes
- Add support for uuid v6. #181
- Add
addMessage
method for using in plugins #166 - Fix uppercase uuid issue. #176
- Add
singleLine
property tostring
rule. #180