How to use the extend function from joi

Find comprehensive JavaScript joi.extend code examples handpicked from public code repositorys.

5
6
7
8
9
10
11
12
13
14

// Declare internals

const internals = {};

internals.Joi = Joi.extend({
    type: 'object',
    base: Joi.object(),
    messages: {
        'object.withPattern': 'fails to match the {{#name}} pattern',
fork icon44
star icon264
watch icon26

+ 5 other calls in file

3
4
5
6
7
8
9
10
11
12
const { BIP32Factory } = require('bip32')
const { getName } = require('country-list')
const Joi = require('joi')
const ethereumAddress = require('ethereum-address')

module.exports = Joi.extend((joi) => {
  return {
    base: joi.string(),
    type: 'string',
    messages: {
fork icon25
star icon0
watch icon0

+ 3 other calls in file

10
11
12
13
14
15
16
17
18
19
 * or submit itself to any jurisdiction.
 */

const Joi = require('joi');

const detectorsDto = Joi.extend((joi) => ({
    base: joi.string(),
    type: 'detectorList',
    validate: (value, helpers) => {
        const validList = ['CPV', 'EMC', 'FDD', 'FT0', 'FV0', 'HMP', 'ITS', 'MCH', 'MFT', 'MID', 'PHS', 'TOF', 'TPC', 'TRD', 'TST', 'ZDC'];
fork icon13
star icon14
watch icon7

79
80
81
82
83
84
85
86
87
88
getenv.setObjectFallback = function (fallbackName) {

  objectFallback = fallbackName;
};

getenv.joi = Joi.extend((joi) => {

  return {
    type: 'envarray',
    base: joi.array(),
fork icon1
star icon0
watch icon2

213
214
215
216
217
218
219
220
221
222

#### Examples

```js
const Joi = require('joi');
const customJoi = Joi.extend((joi) => ({
    base: joi.number(),
    name: 'number',
    language: {
        round: 'needs to be a rounded number', // Used below as 'number.round'
fork icon0
star icon0
watch icon3

18
19
20
21
22
23
24
25
26
27
28
29
            }
        }
    }
});


const Joi = BaseJoi.extend(extension)


module.exports.campgroundSchema = Joi.object({
    campground: Joi.object({ // We are taking inputs in campground object so I need to check the object first then its properties..
        title: Joi.string().required().escapeHTML(),
fork icon0
star icon0
watch icon0