Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.
/ joi-currency Public archive

A Joi plugin which validates that a string is an ISO 3166 currency code.

License

Notifications You must be signed in to change notification settings

zagreusinoz/joi-currency

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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`

About

A Joi plugin which validates that a string is an ISO 3166 currency code.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published