-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(isISO4217): add currency code validator (#1706)
* feat(isISO4217): add currency code validator (#1703) * perf(isISO4217): use a Set along with .has instead of .indexOf * refactor(isISO4217): Enhance tests with lowercase examples
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import assertString from './util/assertString'; | ||
|
||
// from https://en.wikipedia.org/wiki/ISO_4217 | ||
const validISO4217CurrencyCodes = new Set([ | ||
'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', | ||
'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BOV', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BZD', | ||
'CAD', 'CDF', 'CHE', 'CHF', 'CHW', 'CLF', 'CLP', 'CNY', 'COP', 'COU', 'CRC', 'CUC', 'CUP', 'CVE', 'CZK', | ||
'DJF', 'DKK', 'DOP', 'DZD', | ||
'EGP', 'ERN', 'ETB', 'EUR', | ||
'FJD', 'FKP', | ||
'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', | ||
'HKD', 'HNL', 'HRK', 'HTG', 'HUF', | ||
'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK', | ||
'JMD', 'JOD', 'JPY', | ||
'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', | ||
'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', | ||
'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRU', 'MUR', 'MVR', 'MWK', 'MXN', 'MXV', 'MYR', 'MZN', | ||
'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', | ||
'OMR', | ||
'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', | ||
'QAR', | ||
'RON', 'RSD', 'RUB', 'RWF', | ||
'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLL', 'SOS', 'SRD', 'SSP', 'STN', 'SVC', 'SYP', 'SZL', | ||
'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS', | ||
'UAH', 'UGX', 'USD', 'USN', 'UYI', 'UYU', 'UYW', 'UZS', | ||
'VES', 'VND', 'VUV', | ||
'WST', | ||
'XAF', 'XAG', 'XAU', 'XBA', 'XBB', 'XBC', 'XBD', 'XCD', 'XDR', 'XOF', 'XPD', 'XPF', 'XPT', 'XSU', 'XTS', 'XUA', 'XXX', | ||
'YER', | ||
'ZAR', 'ZMW', 'ZWL', | ||
]); | ||
|
||
export default function isISO4217(str) { | ||
assertString(str); | ||
return validISO4217CurrencyCodes.has(str.toUpperCase()); | ||
} | ||
|
||
export const CurrencyCodes = validISO4217CurrencyCodes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters