Joi: Feature Request - Boolean type cast

Created on 22 Sep 2016  路  4Comments  路  Source: sideway/joi

Context

  • _node version_: v4.5
  • _joi version_: 9.0.4
  • _environment_ (node, browser): node
  • _used with_ (hapi, standalone, ...): standalone
  • _any other relevant information_:

    Feature

Is it possible to add "Y" and "N" in boolean type cast? MLS & bunch of state tax record data often do "Y"

breaking changes feature

Most helpful comment

I'd go for an API like Joi.boolean().truthy(...).falsy(...), the standard being the current Joi.boolean().strict() (true/false).

All 4 comments

It doesn't look like it is supported currently based on the code for that to be converted (or for the Boolean to be configured to override the flags).

I'm sure your PR would be reviewed if you wanted to add a new set of values there, personally I'd love to see Boolean take some configuration like this:

var obj = Joi.object().keys({
  enabled: Joi.boolean({
    truthyStrings: ['yes', 'y', 'true'],
    falseyStrings: ['no', 'n', 'false']
  }).required();
});

My thoughts precisely. I think I'm going to make this a breaking change and accept configuration.

I'd go for an API like Joi.boolean().truthy(...).falsy(...), the standard being the current Joi.boolean().strict() (true/false).

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JbIPS picture JbIPS  路  4Comments

n-sviridenko picture n-sviridenko  路  3Comments

Dreamystify picture Dreamystify  路  4Comments

chrisegner picture chrisegner  路  4Comments

normancarcamo picture normancarcamo  路  3Comments