Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
22 lines
510 B
Plaintext
22 lines
510 B
Plaintext
/**
|
|
* This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping
|
|
* @param str string to convert
|
|
*/
|
|
function toUpperCase(str) {
|
|
return str.replace(/([a-z])/g, (_, c) => c.toUpperCase());
|
|
}
|
|
const NOT_A_Z_REGEX = /[^A-Z]/;
|
|
/**
|
|
* https://tc39.es/ecma402/#sec-iswellformedcurrencycode
|
|
*/
|
|
export function IsWellFormedCurrencyCode(currency) {
|
|
currency = toUpperCase(currency);
|
|
if (currency.length !== 3) {
|
|
return false;
|
|
}
|
|
if (NOT_A_Z_REGEX.test(currency)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|