Search code examples
node.jsjoi

Joi How boolean can accept empty string


I have a scenario I want subscribe to accept true, false and empty string '' how can I do this

const Register = Joi.object().keys({
   company_id: Joi.string().required(),
   subscribe: Joi.boolean()
});

Solution

  • subscribe: [Joi.boolean, Joi.string.max(0)]
    

    As described in the github documentation.