support extending joi with new shorthand meta properties
- Dominant language
- JavaScript
- Stars
- 21.2k
- Forks
- 1.5k
- Avg merge
- 4h 57m
- Merged PRs (30d)
- 14
Description
#### Support plan
* *is this issue currently blocking your project?* (yes/no): no
* *is this issue affecting a production system?* (yes/no): no
#### Context
* *node version*: node v10.22.0
* *module version*: 17.2.1
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): none
* *any other relevant information*: https://runkit.com/embed/zp9j6gbst2xf
#### What problem are you trying to solve?
I like `any.meta` but I'd like to use custom meta fields that I use often conveniently like `any.description`, `any.notes`, etc.
```js
var Joi = require("joi");
console.log(
Joi
.any()
.description('this key will match anything you give it')
.describe()
);
console.log(
Joi
.object({
name: Joi.string().meta({ pii: true }),
age: Joi.number().meta({ pii: false }),
})
.describe()
);
const joi = Joi.extend(joi => [
{
type: 'pii',
base: joi.description()
},
{
type: 'nonPii',
base: joi.description()
},
]);
console.log(
joi
.object({
name: joi.string().pii(),
age: Joi.number().nonPii(),
})
.describe()
);
```
#### Do you have a new or modified API suggestion to solve the problem?
can `joi.description` be available in `Joi.extend`? or maybe instead of extend this should be more of a `defineMeta` function that lets you define one or multiple aliases for meta properties
Contributor guide
Assessment
This issue has not been assessed yet.