IE9 and up, Edge, iOS Safari 6+, Chrome 8+, Firefox 6+
You may store the instance by assigning the result of an invocation to a variable.
Here are a few ways to do it.
const cc = currencyConverter("#myID", {}); // currencyConverter
const myElement = document.querySelector(".myElement");
const cc = currencyConverter(myElement, {}); // currencyConverter
const instances = currencyConverter(".currencyElm", {});
instances[0] // currencyConverter
Prop name | Description | Default value | Example values |
---|---|---|---|
baseAmount | Default input amount. | 100 |
20 |
currencyApi | The api which will be used to fetch currency data if "currencyData" prop is not set |
“https://api.exchangeratesapi.io/latest” | “https://data.fixer.io/api/latest” |
currencyData | Currency values for dropdown. If not provided, it will be fetch through exchangeApi. | n/a | { AUD: 1.6376, BGN: 1.9558, BRL: 6.0777} |
fromCurrency | Initial from currency value for for dropdown. | "EUR" |
"INR" |
inputFromAmountClass | Class name(s) that will be added along with "input-from-amount" to the from amount <input> element. |
n/a | "class1 class2" |
inputFromCurrencyClass | Class name(s) that will be added along with "select-from-curreny" to the from currency <select> element. |
n/a | "class1 class2" |
inputToAmountClass | Class name(s) that will be added along with "input-to-amount" to the to amount <input> element. |
n/a | "class1 class2" |
inputToCurrencyClass | Class name(s) that will be added along with "select-to-curreny" to the to currency <select> element. |
n/a | "class1 class2" |
locale | Localization data | n/a | { From: 'Von', To: 'Zu'} |
onChange | Callback method when data is changed. | n/a | (data) => console.log(data) |
precision | Decimal precision for conversation. | 4 |
2 |
toCurrency | Initial to currency value for for dropdown. | "USD" |
"JPY" |
wrapperClass | Class name(s) that will be added along with "currency-converter" to the main <div> element. |
n/a | "class1 class2" |
withText | Whether to show currency text. "1 EUR = 1.1608 USD" |
true |
false |
Sets the input from amount
Sets the select from currency
Updates the currency data
onInit gets triggered when the component is initialized
onChange gets triggered when currency or amount is changed
onDestroy gets triggered when the component is destroyed
Author: shailesh-satariya
Demo: https://shailesh-satariya.github.io/currency-converter/
Source Code: https://github.com/shailesh-satariya/currency-converter
#javascript