y-currency

1.0.3 • Public • Published

Instalation

npm install y-currency

y-currency

Easy currency conversion using the yahoo api.

Version: 1.0.2
Author: Matas Kairaitis
License: MIT

y-currency.convert(values, from, to, cb)

Converts the provided values to another currency in one request.

Kind: static method of y-currency
Summary: When converting multiple values you should always pass them as an array instead of calling this function multiple times. This way you minimize the amount of requests that are made.

Param Type Description
values number | Array.<number> A string or array of strings of the amounts to convert.
from string The currency symbol to convert from. Will return an error if the symbol is not supported.
to string The currency symbol to convert to. ill return an error if the symbol is not supported.
cb convertCallback The calback that will be executed when the request is processed.

Example

currency.convert(10, 'USD', 'EUR', function(err, converted) {
   if (err) // Handle error
 
   console.log(converted); // Outputs ~8.91 (the converted value)
});

Example

currency.convert([10, 20, 40], 'USD', 'EUR', function(err, converted) {
   if (err) // Handle error
 
   console.log(converted); // Outputs [9.11, 18.22, 27.33] (the converted values in an array)
});

y-currency.getCurrency(symbols, cb)

Gets currency information as an object or array of objects in one request.

Kind: static method of y-currency

Param Type Description
symbols string | Array.<string> A string or array of strings of the pairs to get information on.
cb getCurrencyCallback The calback that will be executed when the request is processed.

Example

currency.getCurrency('USDEUR', function(err, result) {
   if (err) // Handle error
 
   console.log(result); // Outputs an object with currency information
   
   // Output
   { id: 'USDEUR',
     Name: 'USD to EUR',
     Rate: '0.891',
     Date: '2/27/2015',
     Time: '10:56am',
     Ask: '0.891',
     Bid: '0.8909' }
});

Example

currency.getCurrency(['USDEUR', 'NZDCAD', 'THBSEK'], function(err, result) {
   if (err) // Handle error
 
   console.log(result); // Outputs an object array with currency information
   
   // Output
   [ { id: 'USDEUR',
      Name: 'USD to EUR',
      Rate: '0.8935',
      Date: '2/27/2015',
      Time: '12:07pm',
      Ask: '0.8935',
      Bid: '0.8935' },
    { id: 'NZDCAD',
      Name: 'NZD to CAD',
      Rate: '0.9452',
      Date: '2/27/2015',
      Time: '12:07pm',
      Ask: '0.9455',
      Bid: '0.9449' },
    { id: 'THBSEK',
      Name: 'THB to SEK',
      Rate: '0.2587',
      Date: '2/27/2015',
      Time: '12:07pm',
      Ask: '0.2592',
      Bid: '0.2581' } ]
});

y-currency~convertCallback : function

Callback that handles the response by convert().

Kind: inner typedef of y-currency

Param Type Description
err error | null If an error occurs during the execution of the function it is passed here, otherwise null.
values number | Array.<number> | null If no errors occured this contains the converted value/values, otherwise null.

y-currency~getCurrencyCallback : function

Callback that handles the response by getCurrency().

Kind: inner typedef of y-currency

Param Type Description
err error | null If an error occurs during the execution of the function it is passed here, otherwise null.
values Object | Array.<Object> | null If no errors occured this contains the object or object array containing the currency information, otherwise null.

Package Sidebar

Install

npm i y-currency

Weekly Downloads

1

Version

1.0.3

License

MIT

Last publish

Collaborators

  • mkairaitis