UNPKG

@mavrykdynamics/taquito-utils

Version:

converts michelson data and types into convenient JS/TS objects

28 lines (27 loc) 737 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.format = void 0; const bignumber_js_1 = require("bignumber.js"); const TZ_DECIMALS = 6; const MTZ_DECIMALS = 3; function getDecimal(format) { switch (format) { case 'mv': return TZ_DECIMALS; case 'mmv': return MTZ_DECIMALS; case 'mumav': default: return 0; } } function format(from = 'mumav', to = 'mumav', amount) { const bigNum = new bignumber_js_1.default(amount); if (bigNum.isNaN()) { return amount; } return bigNum .multipliedBy(Math.pow(10, getDecimal(from))) .dividedBy(Math.pow(10, getDecimal(to))); } exports.format = format;