UNPKG

@taquito/utils

Version:

Encoding, crypto, and utility helpers for Taquito.

33 lines (32 loc) 783 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.format = format; const bignumber_js_1 = require("bignumber.js"); const TZ_DECIMALS = 6; const MTZ_DECIMALS = 3; function getDecimal(format) { switch (format) { case 'tz': return TZ_DECIMALS; case 'mtz': return MTZ_DECIMALS; case 'mutez': default: return 0; } } function format(from = 'mutez', to = 'mutez', amount) { let bigNum; try { bigNum = new bignumber_js_1.default(amount); } catch { return amount; } if (bigNum.isNaN()) { return amount; } return bigNum .multipliedBy(Math.pow(10, getDecimal(from))) .dividedBy(Math.pow(10, getDecimal(to))); }