joi-enums-extension
Joi extensions for enums and value mapping.
Lead Maintainer: Wes Tyler
Usage
This extension provides 2 flavors of .map
methods.
- The first can be chained onto the base Joi "any" schema and can map any key/value pairs:
const BaseJoi = ;const Maps = ;const Joi = BaseJoi; const schema = Joi; schema; // error: null, value: 'mapped value'schema; // error: null, value: 2schema; // error: null, value: { inner: 'items' }schema; // ValidationError: "value" must be one of [1, next, object]
- The second can be chained onto the base Joi number schema and maps keys to numbers:
const BaseJoi = ;const Maps = ;const Joi = BaseJoi; const schema = Joi; schema; // error: null, value: 1schema; // error: null, value: 1schema; // error: null, value: 17schema; // ValidationError: "value" must be a number or one of [admin, vendor, client]