Socket
Socket
Sign inDemoInstall

@cxllm/currency

Package Overview
Dependencies
2
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @cxllm/currency

A currency converter api that uses exchangerate.host


Version published
Weekly downloads
7
increased by250%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

@cxllm/currency

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, // the amount to convert
    from: string, // the currency to convert from
    to: string // the currency to convert to
)

This returns a promise with an object containing values with these types:

from: string; // the currency converted from
to: string; // the currency converted to
amount: number; // the amount converted
rate: number; // the exchange rate
conversion: number; // the conversion of the amount
updated: Date; // the time it was last updated (a JavaScript Date object)
Example
const converter = require("@cxllm/currency");
convertor.convert(12.8, "GBP", "CAD").then(console.log);
// { from: 'GBP', to: 'CAD', amount: 12.8, rate: 1.709844, conversion: 21.886, updated: 2022-01-30T00:00:00.000Z

Rate Method

This is the method for finding the exchange rate between two currencies The syntax is as follows:

rate(
    from: string, // the currency to convert from
    to: string // the currency to convert to
);

This returns a promise with an object containing values with these types:

from: string; //the currency converted from
to: string; // the currency converted to
rate: number; // the exchange rate
updated: Date; // the time it was last updated (a JavaScript Date object)
Example
const converter = require("@cxllm/currency");
convertor.rate("GBP", "CAD").then(console.log);
// { from: 'GBP', to: 'CAD', rate: 1.709844, updated: 2022-01-30T00:00:00.000Z }

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, // The currency name
    code: string // The 3 letter code
}>
Example
const converter = require("@cxllm/currency");
convertor.currencies().then(console.log);
// [ { name: 'United Arab Emirates Dirham', code: 'AED' }, { name: 'Afghan Afghani', code: 'AFN' }, ... etc ]

## Support

If you require any further support, please contact me through the twitter and discord links listed [here](https://github.com/cxllm/)

Keywords

FAQs

Last updated on 05 Feb 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc