This is a package that uses the exchangerate.host API for easy currency conversion within node.js. It contains methods for finding the rate and a conversion of a specific value between two different currencies.
Installation
For installing this, please run:
npm install @cxllm/currency
Or, if you prefer the yarn package manager
yarn install @cxllm/currency
Methods + Examples
In the examples below I will be using British Pounds (GBP) and Canadian Dollars (CAD), however they are interchangeable with other 3-character currency codes, e.g. USD (United States Dollar), TRY (Turkish Lira), AUD (Australian Dollar) etc. You can also use this library with TypeScript's import instead of require, however I just used require for the purpose of this example
Convert Method
This is the method used for converting between 2 currencies with a specific value.
The arguments are as follows:
convert(
amount: number,
from: string,
to: string
)
This returns a promise with an object containing values with these types:
from: string;
to: string;
amount: number;
rate: number;
conversion: number;
updated: Date;
Example
const converter = require("@cxllm/currency");
convertor.convert(12.8, "GBP", "CAD").then(console.log);
Rate Method
This is the method for finding the exchange rate between two currencies
The syntax is as follows:
rate(
from: string,
to: string
);
This returns a promise with an object containing values with these types:
from: string;
to: string;
rate: number;
updated: Date;
Example
const converter = require("@cxllm/currency");
convertor.rate("GBP", "CAD").then(console.log);
Currencies Method
This is the method for listing all currencies supported, and their names.
The syntax is as follows:
currencies();
This returns a promise with an array:
Array<{
name: string,
code: string
}>
Example
const converter = require("@cxllm/currency");
convertor.currencies().then(console.log);
## Support
If you require any further support, please contact me through the twitter and discord links listed [here](https: