@prygun/currency-converter
Description
This is a module for converting currency. It uses the OpenExchangeRates API to retrieve the current exchange rates for various currencies.
Installation
To install this module, run the following command:
npm install @prygun/currency-converter
Usage
To use this module, first import the convertCurrency
function:
import { convertCurrency } from '@prygun/currency-converter';
Then, call the function with the desired fromCurrency
, toCurrency
, and amount
parameters:
const convertedAmount = await convertCurrency('USD', 'EUR', 10);
console.log(convertedAmount);
Error Handling
If any required parameters are missing or an error occurs during conversion, an error will be thrown. You should wrap calls to convertCurrency
in a try-catch block to handle these errors:
try {
const convertedAmount = await convertCurrency('USD', 'XYZ', 10);
console.log(convertedAmount);
} catch (error) {
console.error(error.message);
}
Configuration
To use this module, you will need to set the OPENEXCHANGERATES_API_KEY
environment variable to your API key for the OpenExchangeRates API. You can obtain an API key by signing up for a free account on their website: https://openexchangerates.org/signup
License
This module is licensed under the ISC License. See the LICENSE file for details.