@m00nbyte/currency-converter
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

currency-converter

npm version npm downloads


Description

Effortlessly converts currency values between different denominations, utilizing the latest pricing data available from the frankfurter.app API.

Installation

npm install -D @m00nbyte/currency-converter
yarn add -D @m00nbyte/currency-converter

Using parameters

Parameters

query

Type: string | number

Default: undefined

Specifies the amount to convert. If only this parameter is provided, it is considered as the base currency.

fromCurrency

Type: string | null

Default: null

Specifies the currency code for the base currency. Defaults to null for automatic detection.

toCurrency

Type: string | null

Default: null

Specifies the currency code for the target currency. Defaults to null for automatic detection.

Examples

Get currency list with default base currency (USD)

import fx from '@m00nbyte/currency-converter';

const usdRates = await fx();
console.log(usdRates);

Get currency list with custom base currency

import fx from '@m00nbyte/currency-converter';

const eurRates = await fx('eur');
console.log(eurRates);

Convert amount to all available currencies using custom base currency

import fx from '@m00nbyte/currency-converter';

const conversionResult = await fx(100, 'eur');
console.log('Converted 100 EUR to all available currencies:', conversionResult);

Convert amount from base currency to target currency

import fx from '@m00nbyte/currency-converter';

const conversionResult = await fx(100, 'eur', 'usd');
console.log(`Converted 100 EUR to USD: ${conversionResult}`);

Using Method Chaining

Methods

fx(amount: Number): fx

amount

Type: Number

Default: undefined

Specifies the amount for the conversion.

from(currency: String): fx

currency

Type: String

Default: undefined

Sets the base currency for the conversion.

to(currency: String): Promise<Number>

currency

Type: String

Default: undefined

Sets the target currency for the conversion and returns the converted amount.

Examples

Convert amount from base currency to target currency

import fx from '@m00nbyte/currency-converter';

const conversionResult = await fx(100).from('eur').to('usd');
console.log(`Converted 100 EUR to USD: ${conversionResult}`);

Contribution

Feel free to submit issues or pull requests.

Like my work?

This project needs a ⭐ from you. Don't forget to leave a star.

Buy Me A Coffee

Package Sidebar

Install

npm i @m00nbyte/currency-converter

Weekly Downloads

11

Version

1.0.1

License

MIT

Unpacked Size

11.2 kB

Total Files

12

Last publish

Collaborators

  • m00nbyte