UNPKG

emmet.sdk

Version:
31 lines 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.bnToHumanReadable = void 0; const replaceAll_1 = require("./replaceAll"); const significantDigits_1 = require("./significantDigits"); const bnToHumanReadable = (bi, decimals = 18) => { if (!bi) return ''; const cleaned = (0, replaceAll_1.replaceAll)(bi.toString(), ",", ''); let value = BigInt(cleaned.replace('.', '')); const dividend = BigInt(10 ** decimals); let whole = value / dividend; let formattedWhole; if (!whole) { whole = 0n; } formattedWhole = whole.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); let fraction = value % dividend; if (!fraction) { fraction = 0n; } let digits = !fraction ? 0 : (0, significantDigits_1.significantDigits)(fraction.toString()); const factor = BigInt(10 ** digits); const roundedFraction = fraction * factor / dividend; let formattedFraction = roundedFraction.toString().padStart(digits, '0'); return `${formattedWhole}.${formattedFraction}`; }; exports.bnToHumanReadable = bnToHumanReadable; //# sourceMappingURL=bnToHumanReadable.js.map