Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
currencyxchange
Advanced tools
Readme
A light weight library for currency locale and exchange rates. Currency x-change module use auto caching of exchange rates.
It is based on exchangeratesapi.io API.
Use the package manager npm or yarn to install foobar.
npm i currencyxchange
or
yarn add currencyxchange
import { formatCurrency, getCurrencyRate, getCurrencyRateList, getCurrencyCode, getCurrencySymbol } from 'currencyxchange';
or
import currencyxchange from 'currencyxchange';
This package exports following functions to use
getCurrencyRate(): Takes base currency as parameter and return exchange rates to all supported currencies, Returns a promise.
getCurrencyRateList(): Fetch latest exchange rates for all supported currencies, Returns a promise.
formatCurrency(): convert price to reuested currency based on latest exchange rates, Returns a formatted price in string format.
getCurrencyCode(): Fetch currency code by country code, Returns a string.
getCurrencySymbol(): Fetch currency symbol by currency code, Returns a string.
By default it will return exchange rates with base currency 'USD'. It will return cached exchange rates. If no cache found it will fetch exchange rates, cache it and return.
Example
await getCurrencyRate('USD')
output:
{
"rates": {
"CAD": 1.3079191238,
"HKD": 7.7531592249,
"ISK": 137.7422072452,
"PHP": 48.1819713564,
"DKK": 6.2757371525,
"HUF": 302.4599831508,
"CZK": 22.4658803707,
"GBP": 0.7618365628,
.
.
.
.
},
"base": "USD",
"date": "2020-11-06"
}
It will return an array of cached exchange rates for all supported currencies. If no cache found it will fetch exchange rates, cache it and return.
Example
await getCurrencyRateList()
output:
[
{
"rates": {
"CAD": 0.0043242716,
"HKD": 0.0256336694,
"ISK": 0.455406384,
"PHP": 0.1593003175,
"DKK": 0.0207489833,
"HUF": 1,
"CZK": 0.074277199,
"GBP": 0.0025188012,
"RON": 0.0135563478,
.
.
.
.
},
"base": "HUF",
"date": "2020-11-06"
},
{
"rates": {
"CAD": 0.2084088438,
"HKD": 1.235418093,
"ISK": 21.9483709879,
"PHP": 7.6774998993,
"DKK": 1,
"HUF": 48.1951324286,
.
.
.
.
},
"base": "DKK",
"date": "2020-11-06"
},
{
"rates": {
"CAD": 0.2053843101,
"HKD": 1.2174890859,
"ISK": 21.6298452176,
"PHP": 7.5660801693,
"DKK": 0.9854874983,
"HUF": 47.4957004895,
.
.
.
.
},
"base": "HRK",
"date": "2020-11-06"
}
.
.
.
.
.
]
Developer can use their own conversion rates, or use above two methods. In the example I am using my own. Example
const conversionRates = {
"rates": {
"CAD": 1.3079191238,
"INR": 74.25262772,
"HKD": 7.7531592249,
"ISK": 137.7422072452,
"PHP": 48.1819713564,
"DKK": 6.2757371525,
"HUF": 302.4599831508,
"CZK": 22.4658803707,
"GBP": 0.7618365628,
.
.
.
.
},
"base": "USD",
"date": "2020-11-06"
}
formatCurrency({
rates: conversionRates.rates,
amount: 100,
from: 'USD',
to: 'INR'
})
// output: '₹74'
or
formatCurrency({
rates: conversionRates.rates,
amount: 100,
from: 'USD',
country: 'IN'
})
// output: '₹74'
Example
getCurrencyCode('US')
// output: 'USD'
Example
getCurrencySymbol({ country: 'US' })
// output: '$'
or
getCurrencySymbol({ currency: 'USD' })
// output: '$'
For now thats it!.
Working on to support more currencies...
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
FAQs
A light weight library for currency locale and exchange rates. Currency x-change module use auto caching of exchange rates.
The npm package currencyxchange receives a total of 61 weekly downloads. As such, currencyxchange popularity was classified as not popular.
We found that currencyxchange demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.