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

Support base parameters in extend() #1932

Closed
rightaway opened this issue Jun 25, 2019 · 1 comment
Closed

Support base parameters in extend() #1932

rightaway opened this issue Jun 25, 2019 · 1 comment
Assignees
Labels
feature New functionality or improvement
Milestone

Comments

@rightaway
Copy link

joi => ({
  name: 'customregex',
  base: joi.string().lowercase().min(20).regex(PARAM)
})

I'm trying to extend the joi object using base, which works fine when static properties are assigned like .min(20), but how can I pass a param to .regex(PARAM) when calling this with joi.customregex(regexParam)?

It doesn't look like base can be a function so I don't see how it could work using just base.

I could create a validate function then use the params argument to manually check the regex myself, but then I'm duplicating the functionality of Joi's .regex() validator.

What's the recommended way to do this? The regex example is just an example, I'd like to use this method of extending joi in many different ways.

@hueniverse hueniverse added the support Questions, discussions, and general support label Jun 25, 2019
@rightaway
Copy link
Author

As a feature request could base accept a function? So that we could do

joi => ({
  name: 'customregex',
  base: params => joi.string().lowercase().min(20).regex(params.regExp)
})

@hueniverse hueniverse changed the title Question: How to extend joi object with base that takes a parameter? Support base parameters in extend() Jun 28, 2019
@hueniverse hueniverse added request and removed support Questions, discussions, and general support labels Jun 28, 2019
@hueniverse hueniverse added this to the 16.0.0 milestone Jun 28, 2019
@hueniverse hueniverse self-assigned this Aug 11, 2019
@hueniverse hueniverse added the v16 label Aug 11, 2019
@hueniverse hueniverse added feature New functionality or improvement and removed request labels Sep 19, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

2 participants