Other than just guessing (like I've done below), is there a more direct and efficient way of reflectively retrieving a list of all currencies supported by your JavaScript environment?
function getSupportedCurrencies() {
function $(amount, currency) {
let locale = 'en-US';
let options = {
style: 'currency',
currency: currency,
currencyDisplay: "name"
};
return Intl.NumberFormat(locale, options).format(amount);
}
const getAllPossibleThreeLetterWords = () => {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const arr = [];
let text = '';
for (let i = 0; i < chars.length; i++) {
for (let x = 0; x < chars.length; x++) {
for (let j = 0; j < chars.length; j++) {
text += chars[i];
text += chars[x];
text += chars[j];
arr.push(text);
text = '';
}
}
}
return arr;
};
let ary = getAllPossibleThreeLetterWords();
let currencies = [];
const rx = /(?<= ).+/; // This line doesn't work in Firefox versions older than version 78 due to bug 1225665: https://bugzilla.mozilla.org/show_bug.cgi?id=1225665
ary.forEach((cur) => {
let output = $(0, cur).trim();
if (output.replace(/^[^ ]+ /, '') !== cur) {
let obj = {};
obj.code = cur;
obj.name = output.match(rx)[0];
currencies.push(obj);
}
});
return currencies;
}
console.log(getSupportedCurrencies());