A small library of functions routinely used in the transledger architecture. They are all bunched here for easy access, easy modification and to give a uniform convention for the different recurrent quantities.
npm install translibnpm install --save translib
javascript
const TransLib = require("translib")
const translib = new TransLib();
`
Then you can invoke the methods:
`javascript
let value = translib.convertAmountToInteger(amount, ticker);
`
Methods
`javascript
convertAmountToInteger(amount, ticker)
`
This method is used for converting amounts to a representation in terms of their smallest unit (BTC => Satoshi, ETH => Wei, etc).
Parameters:
amount: string or number
ticker: token symbol, one of (TBTC, TLTC, TBCH, TETH, TEOS, TXLM, TXRP, BTC, LTC, BCH, ETH, EOS, XLM, XRP)
`javascript
convertAmountToDecimal(amount, ticker)
`
This method is used for converting amounts from integer to decimal representations (ex: 200000 Satoshi => 0.002 BTC).
Parameters:
amount: string or number
ticker: token symbol, one of (TBTC, TLTC, TBCH, TETH, TEOS, TXLM, TXRP, BTC, LTC, BCH, ETH, EOS, XLM, XRP)
`javascript
uuidv4()
`
Generate a random uuid with pattern 8-4-4-4-12.
`javascript
getNetworkSymbol(Network)
`
Returns a symbol representing the network. For now, they all point towards the testnets.
Parameter:
Network: one of (TBTC, TLTC, TBCH, TETH, TEOS, TXLM, TXRP, BTC, LTC, BCH, ETH, EOS, XLM, XRP)
`javascript
getBlockchainType(Network)
`
Returns the type of blockchains (UTXO or Account)
Parameter:
Network: one of (TBTC, TLTC, TBCH, TETH, TEOS, TXLM, TXRP, BTC, LTC, BCH, ETH, EOS, XLM, XRP)
`javascript
logTime()
`
Returns the Date and Time in a chosen format
Prerequisite
* node: install node from here
Prior to run, install all dependencies with npm install`. To view dependencies, please refer to the package.json file.