Markets utils for Tipser
How to use ?
Install the package
First - install via npm
npm install @tipser/markets
or via yarn
yarn add @tipser/markets
Import it in your source code
import { getMarketName } from '@tipser/markets';
Example of usage
Formatting currency
import { getLocaleByMarket, getCurrencyByMarket } from '@tipser/markets';
const someMarket = 'se';
const currentLocale = getLocaleByMarket(someMarket);
const currentCurrency = getCurrencyByMarket(someMarket)
const myNicePrice = (123.4567).toLocaleString(currentLocale, { style: 'currency', currency: currentCurrency })
console.log(myNicePrice);
// prints: "123,46 kr"
Validating incoming market
import { isMarketName } from '@tipser/markets';
console.log(isMarketName('se'));
// prints: true
console.log(isMarketName('it'));
// prints: false
Flags images
Import flag file for any marketName
from @tipser/markets/dist/assets/flags/{marketName}.svg
.
e.g.
import deFlagPath from '@tipser/markets/dist/assets/flags/de.svg'
//(...) somewhere in e.g. React component
return <img src={deFlagPath} alt="german flag"/>
👆 deFlagPath
should be a path to a static assets in project's build folder.This is default behaviour in e.g. Creat React App 3.x. It happens because its webpack is configured to hit most of the files from node_modules via
file-loader
)