@rathmika/currencyconverter
Version:
A simple currency converter using exchange rate.
12 lines (9 loc) • 372 B
JavaScript
;
async function convertCurrency(amount, from, to) {
const response = await fetch(`https://v6.exchangerate-api.com/v6/4f13c7ffd80d489ecc1f2039/latest/${from}`);
const data = await response.json();
const rate = data.rates[to];
return rate ? (amount * rate).toFixed(2) : "Invalid Currency";
}
const index = { convertCurrency };
module.exports = index;