Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Boolean type cast #991

Closed
kevbook opened this issue Sep 21, 2016 · 4 comments · Fixed by #998
Closed

Feature Request - Boolean type cast #991

kevbook opened this issue Sep 21, 2016 · 4 comments · Fixed by #998
Labels
breaking changes Change that can breaking existing code feature New functionality or improvement

Comments

@kevbook
Copy link

kevbook commented Sep 21, 2016

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"

@DavidTPate
Copy link
Contributor

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();
});

@Marsup
Copy link
Collaborator

Marsup commented Sep 22, 2016

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

@Marsup Marsup added request breaking changes Change that can breaking existing code labels Sep 22, 2016
@Marsup
Copy link
Collaborator

Marsup commented Sep 22, 2016

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

@hueniverse hueniverse added feature New functionality or improvement and removed request labels Sep 19, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking changes Change that can breaking existing code feature New functionality or improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants