A Joi plugin that validates if the string is an ISO 3166 currency code.
npm install joi-currency --save
const Joi = require('joi-currency'); // require this plugin as Joi
const product = {
id: 'k1773y',
name: 'Hello Kitty Backpack',
price: 125,
currency: 'XYZ'
};
const schema = Joi.object().keys({
id: Joi.string().noChange(origObj).required().label('id'),
name: Joi.string().required().label('name'),
price: Joi.number().positive().integer().label('price'),
currency: Joi.string().currency().required().label('currency')
}
});
var result = schema.validate(product);
// check and throw if there is an error (there is)
if (result.error) {
throw result.error; // Joi Error
}
// object is available at `result.value`