joi-currency

1.0.2 • Public • Published

Joi Currency Plugin

A Joi plugin that validates if the string is an ISO 3166 currency code.

Build Status

Installing

npm install joi-currency --save

Usage

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`

Package Sidebar

Install

npm i joi-currency

Weekly Downloads

16

Version

1.0.2

License

MIT

Last publish

Collaborators

  • zagreus