I'm using Yup package for data validation schemas but I would like to start to use Joi now. Or atleast, learn it.
This screenshot is what I have now for my app : My Yup version
And I would like to do exactly the same thing but with Joi and I can't find the equivalent of Yup's "transform()" method.
My need is simple: I have a property, I want to accept null values BUT if I get a null value, then I transform it to false (as you see in the screenshot above).
Thanks in advance !
UPDATE:
Yup.boolean().nullable().transform((value) => (value === null ? false : value));
UPDATE 2::
I tried this, it doesn't work :
Joi.boolean().allow(null).custom((value, helper) => {
if (value === null) {
return false;
}
return value;
});
The result of my unit test of the code above :
Expected: false
Received: null