How to use the _flags function from joi

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

joi._flags is a private property in the Joi library used to store metadata for a validation rule.

545
546
547
548
549
550
551
552
553
554
  }
  if (joi._valids._set && joi._valids._set.length) {
    item.enum = joi._valids._set;
  }
  if (joi._flags.hasOwnProperty('default')) {
    item.default = joi._flags.default;
  }
  return param;
}

fork icon3
star icon0
watch icon0

How does joi._flags work?

In Joi, _flags is a private property that holds the validation flags that are set on a schema. These flags are used to alter the behavior of the validation process for a particular schema.

Ai Example

1
2
3
4
5
const Joi = require("joi");

const schema = Joi.string().required().min(3);

console.log(schema._flags); // outputs { presence: 'required', min: 3 }

In this example, schema._flags will return an object that contains the flags associated with the Joi.string() schema. In this case, it will show that the presence flag is set to required and the min flag is set to 3.