Say hello to
CurrencyNet - a small library that allows you to convert currencies. It uses the exchangerate-api.com API to do so. You can use it in your own projects or just use it as a library.
import / Install CurrencyNet
$ npm install currencynet
CurrencyNet tutorial
USING CDN LINK
Initialize Currencynet
-
Set up your build currency by creating a new instance of
currrencyNet. - The first parameter is the currency you want to use as your build currency.
-
XPF- This can be replaced by any of ISO 4217 CODE based on the currency used in building your application - The second parameter is whether you want your value to return a float or not.
-
The
reWritemethod must be called after initailing your currencynet Object.
Use the currencynet className
-
The first
spanelement uses yourbuild currencyto convert to the client currency. - The second
spanelement help you use other currency ( for that case Indian Rupeeinr) to convert to your build currency. -
Note: for the secondspanelement you will need to attach ISO 4217 CODE in `lower case` to `currencynet-init` class - For the all class name avaliable see ISO 4217 CODE
Setting up your value
-
Output for the first
span: -
Output for the Second
span:
Adding Dropdown option to change client currency
-
Output for
Drop down: -
Output for the first
span: -
Output for the Second
span: -
NOTE: thecurrencynet-selectclass must be attached to theselectelement. -
NOTE: Only one select element can have thecurrencynet-selectclass.
USING React Package
Import Currencynet
import { CurrencyNet } from 'currencynet'
-
The
CurrrencyNetdata been extracted from'currencynet'return a jsx element.
Using Currencynet
-
The
CurrrencyNetjsx element need two propsbuildCurrency&&value -
The
buildCurrencyprops is the ISO 4217 CODE of your build currency in `upper case`. -
The
valueprops is the value in your build currency -
The
isfloatprop is an optional param that determine if the output will be a float ontrue, otherwise. It`s default istrue
Best pratice Using the React package
You will see that the build currency has to be declared on every declaration of the CurrencyNet jsx element, this is likely to cause a bug on your application or rather be so exhausting.
So to solve this it is best to create a component for a particular currency like the example below, either by using the children property of the deconstructed props param or having your own props property
-
Although it is not advicable to use the
childrenmethod as passing in string ( by accident ) can or might cause fatal and diffcult to trace bug
Using Github
You can always fall back to thecurrencynet github`s repos for more code sample or issues
For the CDN based libray
- Repo: Check here
- Issues: Check here
For the React libray
- Repo: Check here
- Code Playground: Check here
- Issues: Check here
All avaliable currency
| Country | ISO_3_CODE | ClassName |
|---|---|---|
| Your Build Country | currencynet-init |