Skip to content

Support base parameters in extend() #1932

@rightaway

Description

@rightaway
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.

Metadata

Metadata

Assignees

Labels

featureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions