@sofaws/dapp-core
Version:
A library to hold the main logic for a dapp on the Elrond Network
3 lines (2 loc) • 1.45 kB
JavaScript
import{a as f}from"./chunk-JBJD3IUJ.js";import{a as B}from"./chunk-QFTWB3KE.js";import{e as O,f as P,r as A,s as R}from"./chunk-ZR7YL3KO.js";import{m as I}from"./chunk-HBP5N4FR.js";I();R();import{TokenPayment as S}from"@elrondnetwork/erdjs";import r from"bignumber.js";r.config({ROUNDING_MODE:r.ROUND_FLOOR});function _({input:i,decimals:w=O,digits:t=P,showLastNonZeroDecimal:o=!0,showIsLessThanDecimalsLabel:v=!1,addCommas:T=!1}){if(!B(i,!1))throw new Error("Invalid input");let h=new r(i).isNegative(),c=i;return h&&(c=i.substring(1)),f(c).then(()=>S.fungibleFromBigInteger("",c,w).toRationalNumber()).then(u=>{let g=new r(u);if(g.isZero())return A;let b=g.toString(10),[y,n]=b.split("."),d=new r(n||0),p=f(0).if(Boolean(n&&o)).then(()=>Math.max(n.length,t)).if(d.isZero()&&!o).then(0).if(Boolean(n&&!o)).then(()=>Math.min(n.length,t)).valueOf(),$=n&&t>=1&&t<=n.length&&d.isGreaterThan(0)&&new r(n.substring(0,t)).isZero(),E=g.toFormat(p);return f(b).if(T).then(E).if(Boolean($)).then(s=>{let a=new r(y).isZero(),[e,l]=s.split("."),m=new Array(t-1).fill(0),F=[...m,0].join(""),N=[...m,1].join("");return a?v?`<${e}.${N}`:o?`${e}.${l}`:e:`${e}.${F}`}).if(Boolean(!$&&n)).then(s=>{let[a]=s.split("."),e=n.substring(0,p);if(o){let l=t-e.length;if(l>0){let m=Array(l).fill(0).join("");return e=`${e}${m}`,`${a}.${e}`}return s}return e?`${a}.${e}`:a}).valueOf()}).if(h).then(u=>`-${u}`).valueOf()}export{_ as a};
//# sourceMappingURL=chunk-V4XSYEH7.js.map