This repository has been archived by the owner on Apr 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
joi-currency.js
53 lines (47 loc) · 1.86 KB
/
joi-currency.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const Joi = require('joi');
module.exports = Joi.extend({
base: Joi.string(),
name: 'string',
language: {
currency: 'needs to be a currency code'
},
rules: [
{
name: 'currency',
validate(params, value, state, options) {
const currencies = [
'ALL', 'AFN', 'ARS', 'AWG', 'AUD', 'AZN',
'BSD', 'BBD', 'BYN', 'BZD', 'BMD', 'BOB', 'BAM', 'BWP', 'BGN', 'BRL', 'BND',
'KHR', 'CAD', 'KYD', 'CLP', 'CNY', 'COP', 'CRC', 'HRK', 'CUP', 'CZK',
'DKK', 'DOP',
'XCD', 'EGP', 'SVC', 'EUR',
'FKP', 'FJD',
'GHS', 'GIP', 'GTQ', 'GGP', 'GYD',
'HNL', 'HKD', 'HUF',
'ISK', 'INR', 'IDR', 'IRR', 'IMP', 'ILS',
'JMD', 'JPY', 'JEP',
'KZT', 'KPW', 'KRW', 'KGS',
'LAK', 'LBP', 'LRD',
'MKD', 'MYR', 'MUR', 'MXN', 'MNT', 'MZN',
'NAD', 'NPR', 'ANG', 'NZD', 'NIO', 'NGN', 'KPW', 'NOK',
'OMR',
'PKR', 'PAB', 'PYG', 'PEN', 'PHP', 'PLN',
'QAR',
'RON', 'RUB',
'SHP', 'SAR', 'RSD', 'SCR', 'SGD', 'SBD', 'SOS', 'ZAR', 'KRW', 'LKR', 'SEK', 'CHF', 'SRD', 'SYP',
'TWD', 'THB', 'TTD', 'TRY', 'TVD',
'UAH', 'GBP', 'USD', 'UYU', 'UZS',
'VEF', 'VND',
'YER',
'ZWD'
];
value = value.toUpperCase();
if (currencies.indexOf(value) < 0) {
return this.createError('string.currency', { v: value }, state, options);
}
return value; // Everything is OK
}
}
]
});