I would like to have a schema that after being validated with the validate function it transforms the output data to a new format.
For instance:
const schema = Joi.object({
name: customJoi.string(),
email: customJoi.string().email().required(),
}).transform((value) => {
if (value.name === "John") value.name = "Jonathan";
return value;
});
const data = {
name: "John", email: 'jane@example.com'
};
const result = schema.validate(data);
// result.name should be "Jonathan"
If possible, I would also love that the transform function could be asynchronous and that it could even return a different type.
As, let's say I could maybe want to return the object stringified.
I would like to have a schema that after being validated with the
validate
function it transforms the output data to a new format.For instance:
If possible, I would also love that the transform function could be asynchronous and that it could even return a different type. As, let's say I could maybe want to return the object stringified.