UNPKG

@fruitsjs/util

Version:

Useful utilities and tools for building Fruits Eco-Blockchain applications

17 lines (14 loc) 31.5 kB
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e=e||self).fruitsjs$util={})}(this,(function(e){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */function r(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function n(e,r){for(var n=0;n<r.length;n++){var t=r[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}function t(e,r,t){return r&&n(e.prototype,r),t&&n(e,t),e}var i=Date.UTC(2021,8,15,0,0,0,0)/1e3,o=function(){function e(n){r(this,e),this._chainTimestamp=n}return t(e,[{key:"getChainTimestamp",value:function(){return this._chainTimestamp}},{key:"setChainTimestamp",value:function(e){this._chainTimestamp=e}},{key:"getEpoch",value:function(){return 1e3*(i+this._chainTimestamp)}},{key:"getDate",value:function(){return new Date(this.getEpoch())}},{key:"setDate",value:function(e){this._chainTimestamp=Math.round(e.getTime()/1e3)-i}},{key:"equals",value:function(e){return this._chainTimestamp===e._chainTimestamp}},{key:"before",value:function(e){return this._chainTimestamp<e._chainTimestamp}},{key:"after",value:function(e){return this._chainTimestamp>e._chainTimestamp}}],[{key:"fromChainTimestamp",value:function(r){return new e(r)}},{key:"fromDate",value:function(r){var n=new e(0);return n.setDate(r),n}}]),e}(),a=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,c=Math.ceil,u=Math.floor,l="[BigNumber Error] ",s=l+"Number primitive has more than 15 significant digits: ",f=1e14,h=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],p=1e9;function g(e){var r=0|e;return e>0||e===r?r:r-1}function d(e){for(var r,n,t=1,i=e.length,o=e[0]+"";t<i;){for(n=14-(r=e[t++]+"").length;n--;r="0"+r);o+=r}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function v(e,r){var n,t,i=e.c,o=r.c,a=e.s,c=r.s,u=e.e,l=r.e;if(!a||!c)return null;if(n=i&&!i[0],t=o&&!o[0],n||t)return n?t?0:-c:a;if(a!=c)return a;if(n=a<0,t=u==l,!i||!o)return t?0:!i^n?1:-1;if(!t)return u>l^n?1:-1;for(c=(u=i.length)<(l=o.length)?u:l,a=0;a<c;a++)if(i[a]!=o[a])return i[a]>o[a]^n?1:-1;return u==l?0:u>l^n?1:-1}function m(e,r,n,t){if(e<r||e>n||e!==u(e))throw Error(l+(t||"Argument")+("number"==typeof e?e<r||e>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function y(e){var r=e.c.length-1;return g(e.e/14)==r&&e.c[r]%2!=0}function w(e,r){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(r<0?"e":"e+")+r}function S(e,r,n){var t,i;if(r<0){for(i=n+".";++r;i+=n);e=i+e}else if(++r>(t=e.length)){for(i=n,r-=t;--r;i+=n);e+=i}else r<t&&(e=e.slice(0,r)+"."+e.slice(r));return e}var b,A=function e(r){var n,t,i,o,b,A,E,k,T,N=H.prototype={constructor:H,toString:null,valueOf:null},x=new H(1),_=20,O=4,F=-7,C=21,B=-1e7,D=1e7,I=!1,P=1,R=0,U={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},L="0123456789abcdefghijklmnopqrstuvwxyz";function H(e,r){var n,o,c,l,f,h,p,g,d=this;if(!(d instanceof H))return new H(e,r);if(null==r){if(e&&!0===e._isBigNumber)return d.s=e.s,void(!e.c||e.e>D?d.c=d.e=null:e.e<B?d.c=[d.e=0]:(d.e=e.e,d.c=e.c.slice()));if((h="number"==typeof e)&&0*e==0){if(d.s=1/e<0?(e=-e,-1):1,e===~~e){for(l=0,f=e;f>=10;f/=10,l++);return void(l>D?d.c=d.e=null:(d.e=l,d.c=[e]))}g=String(e)}else{if(!a.test(g=String(e)))return i(d,g,h);d.s=45==g.charCodeAt(0)?(g=g.slice(1),-1):1}(l=g.indexOf("."))>-1&&(g=g.replace(".","")),(f=g.search(/e/i))>0?(l<0&&(l=f),l+=+g.slice(f+1),g=g.substring(0,f)):l<0&&(l=g.length)}else{if(m(r,2,L.length,"Base"),10==r)return q(d=new H(e),_+d.e+1,O);if(g=String(e),h="number"==typeof e){if(0*e!=0)return i(d,g,h,r);if(d.s=1/e<0?(g=g.slice(1),-1):1,H.DEBUG&&g.replace(/^0\.0*|\./,"").length>15)throw Error(s+e)}else d.s=45===g.charCodeAt(0)?(g=g.slice(1),-1):1;for(n=L.slice(0,r),l=f=0,p=g.length;f<p;f++)if(n.indexOf(o=g.charAt(f))<0){if("."==o){if(f>l){l=p;continue}}else if(!c&&(g==g.toUpperCase()&&(g=g.toLowerCase())||g==g.toLowerCase()&&(g=g.toUpperCase()))){c=!0,f=-1,l=0;continue}return i(d,String(e),h,r)}h=!1,(l=(g=t(g,r,10,d.s)).indexOf("."))>-1?g=g.replace(".",""):l=g.length}for(f=0;48===g.charCodeAt(f);f++);for(p=g.length;48===g.charCodeAt(--p););if(g=g.slice(f,++p)){if(p-=f,h&&H.DEBUG&&p>15&&(e>9007199254740991||e!==u(e)))throw Error(s+d.s*e);if((l=l-f-1)>D)d.c=d.e=null;else if(l<B)d.c=[d.e=0];else{if(d.e=l,d.c=[],f=(l+1)%14,l<0&&(f+=14),f<p){for(f&&d.c.push(+g.slice(0,f)),p-=14;f<p;)d.c.push(+g.slice(f,f+=14));f=14-(g=g.slice(f)).length}else f-=p;for(;f--;g+="0");d.c.push(+g)}}else d.c=[d.e=0]}function M(e,r,n,t){var i,o,a,c,u;if(null==n?n=O:m(n,0,8),!e.c)return e.toString();if(i=e.c[0],a=e.e,null==r)u=d(e.c),u=1==t||2==t&&(a<=F||a>=C)?w(u,a):S(u,a,"0");else if(o=(e=q(new H(e),r,n)).e,c=(u=d(e.c)).length,1==t||2==t&&(r<=o||o<=F)){for(;c<r;u+="0",c++);u=w(u,o)}else if(r-=a,u=S(u,o,"0"),o+1>c){if(--r>0)for(u+=".";r--;u+="0");}else if((r+=o-c)>0)for(o+1==c&&(u+=".");r--;u+="0");return e.s<0&&i?"-"+u:u}function j(e,r){for(var n,t=1,i=new H(e[0]);t<e.length;t++){if(!(n=new H(e[t])).s){i=n;break}r.call(i,n)&&(i=n)}return i}function G(e,r,n){for(var t=1,i=r.length;!r[--i];r.pop());for(i=r[0];i>=10;i/=10,t++);return(n=t+14*n-1)>D?e.c=e.e=null:n<B?e.c=[e.e=0]:(e.e=n,e.c=r),e}function q(e,r,n,t){var i,o,a,l,s,p,g,d=e.c,v=h;if(d){e:{for(i=1,l=d[0];l>=10;l/=10,i++);if((o=r-i)<0)o+=14,a=r,g=(s=d[p=0])/v[i-a-1]%10|0;else if((p=c((o+1)/14))>=d.length){if(!t)break e;for(;d.length<=p;d.push(0));s=g=0,i=1,a=(o%=14)-14+1}else{for(s=l=d[p],i=1;l>=10;l/=10,i++);g=(a=(o%=14)-14+i)<0?0:s/v[i-a-1]%10|0}if(t=t||r<0||null!=d[p+1]||(a<0?s:s%v[i-a-1]),t=n<4?(g||t)&&(0==n||n==(e.s<0?3:2)):g>5||5==g&&(4==n||t||6==n&&(o>0?a>0?s/v[i-a]:0:d[p-1])%10&1||n==(e.s<0?8:7)),r<1||!d[0])return d.length=0,t?(r-=e.e+1,d[0]=v[(14-r%14)%14],e.e=-r||0):d[0]=e.e=0,e;if(0==o?(d.length=p,l=1,p--):(d.length=p+1,l=v[14-o],d[p]=a>0?u(s/v[i-a]%v[a])*l:0),t)for(;;){if(0==p){for(o=1,a=d[0];a>=10;a/=10,o++);for(a=d[0]+=l,l=1;a>=10;a/=10,l++);o!=l&&(e.e++,d[0]==f&&(d[0]=1));break}if(d[p]+=l,d[p]!=f)break;d[p--]=0,l=1}for(o=d.length;0===d[--o];d.pop());}e.e>D?e.c=e.e=null:e.e<B&&(e.c=[e.e=0])}return e}function $(e){var r,n=e.e;return null===n?e.toString():(r=d(e.c),r=n<=F||n>=C?w(r,n):S(r,n,"0"),e.s<0?"-"+r:r)}return H.clone=e,H.ROUND_UP=0,H.ROUND_DOWN=1,H.ROUND_CEIL=2,H.ROUND_FLOOR=3,H.ROUND_HALF_UP=4,H.ROUND_HALF_DOWN=5,H.ROUND_HALF_EVEN=6,H.ROUND_HALF_CEIL=7,H.ROUND_HALF_FLOOR=8,H.EUCLID=9,H.config=H.set=function(e){var r,n;if(null!=e){if("object"!=typeof e)throw Error(l+"Object expected: "+e);if(e.hasOwnProperty(r="DECIMAL_PLACES")&&(m(n=e[r],0,p,r),_=n),e.hasOwnProperty(r="ROUNDING_MODE")&&(m(n=e[r],0,8,r),O=n),e.hasOwnProperty(r="EXPONENTIAL_AT")&&((n=e[r])&&n.pop?(m(n[0],-p,0,r),m(n[1],0,p,r),F=n[0],C=n[1]):(m(n,-p,p,r),F=-(C=n<0?-n:n))),e.hasOwnProperty(r="RANGE"))if((n=e[r])&&n.pop)m(n[0],-p,-1,r),m(n[1],1,p,r),B=n[0],D=n[1];else{if(m(n,-p,p,r),!n)throw Error(l+r+" cannot be zero: "+n);B=-(D=n<0?-n:n)}if(e.hasOwnProperty(r="CRYPTO")){if((n=e[r])!==!!n)throw Error(l+r+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw I=!n,Error(l+"crypto unavailable");I=n}else I=n}if(e.hasOwnProperty(r="MODULO_MODE")&&(m(n=e[r],0,9,r),P=n),e.hasOwnProperty(r="POW_PRECISION")&&(m(n=e[r],0,p,r),R=n),e.hasOwnProperty(r="FORMAT")){if("object"!=typeof(n=e[r]))throw Error(l+r+" not an object: "+n);U=n}if(e.hasOwnProperty(r="ALPHABET")){if("string"!=typeof(n=e[r])||/^.$|[+-.\s]|(.).*\1/.test(n))throw Error(l+r+" invalid: "+n);L=n}}return{DECIMAL_PLACES:_,ROUNDING_MODE:O,EXPONENTIAL_AT:[F,C],RANGE:[B,D],CRYPTO:I,MODULO_MODE:P,POW_PRECISION:R,FORMAT:U,ALPHABET:L}},H.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!H.DEBUG)return!0;var r,n,t=e.c,i=e.e,o=e.s;e:if("[object Array]"=={}.toString.call(t)){if((1===o||-1===o)&&i>=-p&&i<=p&&i===u(i)){if(0===t[0]){if(0===i&&1===t.length)return!0;break e}if((r=(i+1)%14)<1&&(r+=14),String(t[0]).length==r){for(r=0;r<t.length;r++)if((n=t[r])<0||n>=f||n!==u(n))break e;if(0!==n)return!0}}}else if(null===t&&null===i&&(null===o||1===o||-1===o))return!0;throw Error(l+"Invalid BigNumber: "+e)},H.maximum=H.max=function(){return j(arguments,N.lt)},H.minimum=H.min=function(){return j(arguments,N.gt)},H.random=(o=9007199254740992*Math.random()&2097151?function(){return u(9007199254740992*Math.random())}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var r,n,t,i,a,s=0,f=[],g=new H(x);if(null==e?e=_:m(e,0,p),i=c(e/14),I)if(crypto.getRandomValues){for(r=crypto.getRandomValues(new Uint32Array(i*=2));s<i;)(a=131072*r[s]+(r[s+1]>>>11))>=9e15?(n=crypto.getRandomValues(new Uint32Array(2)),r[s]=n[0],r[s+1]=n[1]):(f.push(a%1e14),s+=2);s=i/2}else{if(!crypto.randomBytes)throw I=!1,Error(l+"crypto unavailable");for(r=crypto.randomBytes(i*=7);s<i;)(a=281474976710656*(31&r[s])+1099511627776*r[s+1]+4294967296*r[s+2]+16777216*r[s+3]+(r[s+4]<<16)+(r[s+5]<<8)+r[s+6])>=9e15?crypto.randomBytes(7).copy(r,s):(f.push(a%1e14),s+=7);s=i/7}if(!I)for(;s<i;)(a=o())<9e15&&(f[s++]=a%1e14);for(e%=14,(i=f[--s])&&e&&(a=h[14-e],f[s]=u(i/a)*a);0===f[s];f.pop(),s--);if(s<0)f=[t=0];else{for(t=-1;0===f[0];f.splice(0,1),t-=14);for(s=1,a=f[0];a>=10;a/=10,s++);s<14&&(t-=14-s)}return g.e=t,g.c=f,g}),H.sum=function(){for(var e=1,r=arguments,n=new H(r[0]);e<r.length;)n=n.plus(r[e++]);return n},t=function(){function e(e,r,n,t){for(var i,o,a=[0],c=0,u=e.length;c<u;){for(o=a.length;o--;a[o]*=r);for(a[0]+=t.indexOf(e.charAt(c++)),i=0;i<a.length;i++)a[i]>n-1&&(null==a[i+1]&&(a[i+1]=0),a[i+1]+=a[i]/n|0,a[i]%=n)}return a.reverse()}return function(r,t,i,o,a){var c,u,l,s,f,h,p,g,v=r.indexOf("."),m=_,y=O;for(v>=0&&(s=R,R=0,r=r.replace(".",""),h=(g=new H(t)).pow(r.length-v),R=s,g.c=e(S(d(h.c),h.e,"0"),10,i,"0123456789"),g.e=g.c.length),l=s=(p=e(r,t,i,a?(c=L,"0123456789"):(c="0123456789",L))).length;0==p[--s];p.pop());if(!p[0])return c.charAt(0);if(v<0?--l:(h.c=p,h.e=l,h.s=o,p=(h=n(h,g,m,y,i)).c,f=h.r,l=h.e),v=p[u=l+m+1],s=i/2,f=f||u<0||null!=p[u+1],f=y<4?(null!=v||f)&&(0==y||y==(h.s<0?3:2)):v>s||v==s&&(4==y||f||6==y&&1&p[u-1]||y==(h.s<0?8:7)),u<1||!p[0])r=f?S(c.charAt(1),-m,c.charAt(0)):c.charAt(0);else{if(p.length=u,f)for(--i;++p[--u]>i;)p[u]=0,u||(++l,p=[1].concat(p));for(s=p.length;!p[--s];);for(v=0,r="";v<=s;r+=c.charAt(p[v++]));r=S(r,l,c.charAt(0))}return r}}(),n=function(){function e(e,r,n){var t,i,o,a,c=0,u=e.length,l=r%1e7,s=r/1e7|0;for(e=e.slice();u--;)c=((i=l*(o=e[u]%1e7)+(t=s*o+(a=e[u]/1e7|0)*l)%1e7*1e7+c)/n|0)+(t/1e7|0)+s*a,e[u]=i%n;return c&&(e=[c].concat(e)),e}function r(e,r,n,t){var i,o;if(n!=t)o=n>t?1:-1;else for(i=o=0;i<n;i++)if(e[i]!=r[i]){o=e[i]>r[i]?1:-1;break}return o}function n(e,r,n,t){for(var i=0;n--;)e[n]-=i,i=e[n]<r[n]?1:0,e[n]=i*t+e[n]-r[n];for(;!e[0]&&e.length>1;e.splice(0,1));}return function(t,i,o,a,c){var l,s,h,p,d,v,m,y,w,S,b,A,E,k,T,N,x,_=t.s==i.s?1:-1,O=t.c,F=i.c;if(!(O&&O[0]&&F&&F[0]))return new H(t.s&&i.s&&(O?!F||O[0]!=F[0]:F)?O&&0==O[0]||!F?0*_:_/0:NaN);for(w=(y=new H(_)).c=[],_=o+(s=t.e-i.e)+1,c||(c=f,s=g(t.e/14)-g(i.e/14),_=_/14|0),h=0;F[h]==(O[h]||0);h++);if(F[h]>(O[h]||0)&&s--,_<0)w.push(1),p=!0;else{for(k=O.length,N=F.length,h=0,_+=2,(d=u(c/(F[0]+1)))>1&&(F=e(F,d,c),O=e(O,d,c),N=F.length,k=O.length),E=N,b=(S=O.slice(0,N)).length;b<N;S[b++]=0);x=F.slice(),x=[0].concat(x),T=F[0],F[1]>=c/2&&T++;do{if(d=0,(l=r(F,S,N,b))<0){if(A=S[0],N!=b&&(A=A*c+(S[1]||0)),(d=u(A/T))>1)for(d>=c&&(d=c-1),m=(v=e(F,d,c)).length,b=S.length;1==r(v,S,m,b);)d--,n(v,N<m?x:F,m,c),m=v.length,l=1;else 0==d&&(l=d=1),m=(v=F.slice()).length;if(m<b&&(v=[0].concat(v)),n(S,v,b,c),b=S.length,-1==l)for(;r(F,S,N,b)<1;)d++,n(S,N<b?x:F,b,c),b=S.length}else 0===l&&(d++,S=[0]);w[h++]=d,S[0]?S[b++]=O[E]||0:(S=[O[E]],b=1)}while((E++<k||null!=S[0])&&_--);p=null!=S[0],w[0]||w.splice(0,1)}if(c==f){for(h=1,_=w[0];_>=10;_/=10,h++);q(y,o+(y.e=h+14*s-1)+1,a,p)}else y.e=s,y.r=+p;return y}}(),b=/^(-?)0([xbo])(?=\w[\w.]*$)/i,A=/^([^.]+)\.$/,E=/^\.([^.]+)$/,k=/^-?(Infinity|NaN)$/,T=/^\s*\+(?=[\w.])|^\s+|\s+$/g,i=function(e,r,n,t){var i,o=n?r:r.replace(T,"");if(k.test(o))e.s=isNaN(o)?null:o<0?-1:1;else{if(!n&&(o=o.replace(b,(function(e,r,n){return i="x"==(n=n.toLowerCase())?16:"b"==n?2:8,t&&t!=i?e:r})),t&&(i=t,o=o.replace(A,"$1").replace(E,"0.$1")),r!=o))return new H(o,i);if(H.DEBUG)throw Error(l+"Not a"+(t?" base "+t:"")+" number: "+r);e.s=null}e.c=e.e=null},N.absoluteValue=N.abs=function(){var e=new H(this);return e.s<0&&(e.s=1),e},N.comparedTo=function(e,r){return v(this,new H(e,r))},N.decimalPlaces=N.dp=function(e,r){var n,t,i,o=this;if(null!=e)return m(e,0,p),null==r?r=O:m(r,0,8),q(new H(o),e+o.e+1,r);if(!(n=o.c))return null;if(t=14*((i=n.length-1)-g(this.e/14)),i=n[i])for(;i%10==0;i/=10,t--);return t<0&&(t=0),t},N.dividedBy=N.div=function(e,r){return n(this,new H(e,r),_,O)},N.dividedToIntegerBy=N.idiv=function(e,r){return n(this,new H(e,r),0,1)},N.exponentiatedBy=N.pow=function(e,r){var n,t,i,o,a,s,f,h,p=this;if((e=new H(e)).c&&!e.isInteger())throw Error(l+"Exponent not an integer: "+$(e));if(null!=r&&(r=new H(r)),a=e.e>14,!p.c||!p.c[0]||1==p.c[0]&&!p.e&&1==p.c.length||!e.c||!e.c[0])return h=new H(Math.pow(+$(p),a?2-y(e):+$(e))),r?h.mod(r):h;if(s=e.s<0,r){if(r.c?!r.c[0]:!r.s)return new H(NaN);(t=!s&&p.isInteger()&&r.isInteger())&&(p=p.mod(r))}else{if(e.e>9&&(p.e>0||p.e<-1||(0==p.e?p.c[0]>1||a&&p.c[1]>=24e7:p.c[0]<8e13||a&&p.c[0]<=9999975e7)))return o=p.s<0&&y(e)?-0:0,p.e>-1&&(o=1/o),new H(s?1/o:o);R&&(o=c(R/14+2))}for(a?(n=new H(.5),s&&(e.s=1),f=y(e)):f=(i=Math.abs(+$(e)))%2,h=new H(x);;){if(f){if(!(h=h.times(p)).c)break;o?h.c.length>o&&(h.c.length=o):t&&(h=h.mod(r))}if(i){if(0===(i=u(i/2)))break;f=i%2}else if(q(e=e.times(n),e.e+1,1),e.e>14)f=y(e);else{if(0===(i=+$(e)))break;f=i%2}p=p.times(p),o?p.c&&p.c.length>o&&(p.c.length=o):t&&(p=p.mod(r))}return t?h:(s&&(h=x.div(h)),r?h.mod(r):o?q(h,R,O,void 0):h)},N.integerValue=function(e){var r=new H(this);return null==e?e=O:m(e,0,8),q(r,r.e+1,e)},N.isEqualTo=N.eq=function(e,r){return 0===v(this,new H(e,r))},N.isFinite=function(){return!!this.c},N.isGreaterThan=N.gt=function(e,r){return v(this,new H(e,r))>0},N.isGreaterThanOrEqualTo=N.gte=function(e,r){return 1===(r=v(this,new H(e,r)))||0===r},N.isInteger=function(){return!!this.c&&g(this.e/14)>this.c.length-2},N.isLessThan=N.lt=function(e,r){return v(this,new H(e,r))<0},N.isLessThanOrEqualTo=N.lte=function(e,r){return-1===(r=v(this,new H(e,r)))||0===r},N.isNaN=function(){return!this.s},N.isNegative=function(){return this.s<0},N.isPositive=function(){return this.s>0},N.isZero=function(){return!!this.c&&0==this.c[0]},N.minus=function(e,r){var n,t,i,o,a=this,c=a.s;if(r=(e=new H(e,r)).s,!c||!r)return new H(NaN);if(c!=r)return e.s=-r,a.plus(e);var u=a.e/14,l=e.e/14,s=a.c,h=e.c;if(!u||!l){if(!s||!h)return s?(e.s=-r,e):new H(h?a:NaN);if(!s[0]||!h[0])return h[0]?(e.s=-r,e):new H(s[0]?a:3==O?-0:0)}if(u=g(u),l=g(l),s=s.slice(),c=u-l){for((o=c<0)?(c=-c,i=s):(l=u,i=h),i.reverse(),r=c;r--;i.push(0));i.reverse()}else for(t=(o=(c=s.length)<(r=h.length))?c:r,c=r=0;r<t;r++)if(s[r]!=h[r]){o=s[r]<h[r];break}if(o&&(i=s,s=h,h=i,e.s=-e.s),(r=(t=h.length)-(n=s.length))>0)for(;r--;s[n++]=0);for(r=f-1;t>c;){if(s[--t]<h[t]){for(n=t;n&&!s[--n];s[n]=r);--s[n],s[t]+=f}s[t]-=h[t]}for(;0==s[0];s.splice(0,1),--l);return s[0]?G(e,s,l):(e.s=3==O?-1:1,e.c=[e.e=0],e)},N.modulo=N.mod=function(e,r){var t,i,o=this;return e=new H(e,r),!o.c||!e.s||e.c&&!e.c[0]?new H(NaN):!e.c||o.c&&!o.c[0]?new H(o):(9==P?(i=e.s,e.s=1,t=n(o,e,0,3),e.s=i,t.s*=i):t=n(o,e,0,P),(e=o.minus(t.times(e))).c[0]||1!=P||(e.s=o.s),e)},N.multipliedBy=N.times=function(e,r){var n,t,i,o,a,c,u,l,s,h,p,d,v,m,y=this,w=y.c,S=(e=new H(e,r)).c;if(!(w&&S&&w[0]&&S[0]))return!y.s||!e.s||w&&!w[0]&&!S||S&&!S[0]&&!w?e.c=e.e=e.s=null:(e.s*=y.s,w&&S?(e.c=[0],e.e=0):e.c=e.e=null),e;for(t=g(y.e/14)+g(e.e/14),e.s*=y.s,(u=w.length)<(h=S.length)&&(v=w,w=S,S=v,i=u,u=h,h=i),i=u+h,v=[];i--;v.push(0));for(m=f,1e7,i=h;--i>=0;){for(n=0,p=S[i]%1e7,d=S[i]/1e7|0,o=i+(a=u);o>i;)n=((l=p*(l=w[--a]%1e7)+(c=d*l+(s=w[a]/1e7|0)*p)%1e7*1e7+v[o]+n)/m|0)+(c/1e7|0)+d*s,v[o--]=l%m;v[o]=n}return n?++t:v.splice(0,1),G(e,v,t)},N.negated=function(){var e=new H(this);return e.s=-e.s||null,e},N.plus=function(e,r){var n,t=this,i=t.s;if(r=(e=new H(e,r)).s,!i||!r)return new H(NaN);if(i!=r)return e.s=-r,t.minus(e);var o=t.e/14,a=e.e/14,c=t.c,u=e.c;if(!o||!a){if(!c||!u)return new H(i/0);if(!c[0]||!u[0])return u[0]?e:new H(c[0]?t:0*i)}if(o=g(o),a=g(a),c=c.slice(),i=o-a){for(i>0?(a=o,n=u):(i=-i,n=c),n.reverse();i--;n.push(0));n.reverse()}for((i=c.length)-(r=u.length)<0&&(n=u,u=c,c=n,r=i),i=0;r;)i=(c[--r]=c[r]+u[r]+i)/f|0,c[r]=f===c[r]?0:c[r]%f;return i&&(c=[i].concat(c),++a),G(e,c,a)},N.precision=N.sd=function(e,r){var n,t,i,o=this;if(null!=e&&e!==!!e)return m(e,1,p),null==r?r=O:m(r,0,8),q(new H(o),e,r);if(!(n=o.c))return null;if(t=14*(i=n.length-1)+1,i=n[i]){for(;i%10==0;i/=10,t--);for(i=n[0];i>=10;i/=10,t++);}return e&&o.e+1>t&&(t=o.e+1),t},N.shiftedBy=function(e){return m(e,-9007199254740991,9007199254740991),this.times("1e"+e)},N.squareRoot=N.sqrt=function(){var e,r,t,i,o,a=this,c=a.c,u=a.s,l=a.e,s=_+4,f=new H("0.5");if(1!==u||!c||!c[0])return new H(!u||u<0&&(!c||c[0])?NaN:c?a:1/0);if(0==(u=Math.sqrt(+$(a)))||u==1/0?(((r=d(c)).length+l)%2==0&&(r+="0"),u=Math.sqrt(+r),l=g((l+1)/2)-(l<0||l%2),t=new H(r=u==1/0?"5e"+l:(r=u.toExponential()).slice(0,r.indexOf("e")+1)+l)):t=new H(u+""),t.c[0])for((u=(l=t.e)+s)<3&&(u=0);;)if(o=t,t=f.times(o.plus(n(a,o,s,1))),d(o.c).slice(0,u)===(r=d(t.c)).slice(0,u)){if(t.e<l&&--u,"9999"!=(r=r.slice(u-3,u+1))&&(i||"4999"!=r)){+r&&(+r.slice(1)||"5"!=r.charAt(0))||(q(t,t.e+_+2,1),e=!t.times(t).eq(a));break}if(!i&&(q(o,o.e+_+2,0),o.times(o).eq(a))){t=o;break}s+=4,u+=4,i=1}return q(t,t.e+_+1,O,e)},N.toExponential=function(e,r){return null!=e&&(m(e,0,p),e++),M(this,e,r,1)},N.toFixed=function(e,r){return null!=e&&(m(e,0,p),e=e+this.e+1),M(this,e,r)},N.toFormat=function(e,r,n){var t,i=this;if(null==n)null!=e&&r&&"object"==typeof r?(n=r,r=null):e&&"object"==typeof e?(n=e,e=r=null):n=U;else if("object"!=typeof n)throw Error(l+"Argument not an object: "+n);if(t=i.toFixed(e,r),i.c){var o,a=t.split("."),c=+n.groupSize,u=+n.secondaryGroupSize,s=n.groupSeparator||"",f=a[0],h=a[1],p=i.s<0,g=p?f.slice(1):f,d=g.length;if(u&&(o=c,c=u,u=o,d-=o),c>0&&d>0){for(o=d%c||c,f=g.substr(0,o);o<d;o+=c)f+=s+g.substr(o,c);u>0&&(f+=s+g.slice(o)),p&&(f="-"+f)}t=h?f+(n.decimalSeparator||"")+((u=+n.fractionGroupSize)?h.replace(new RegExp("\\d{"+u+"}\\B","g"),"$&"+(n.fractionGroupSeparator||"")):h):f}return(n.prefix||"")+t+(n.suffix||"")},N.toFraction=function(e){var r,t,i,o,a,c,u,s,f,p,g,v,m=this,y=m.c;if(null!=e&&(!(u=new H(e)).isInteger()&&(u.c||1!==u.s)||u.lt(x)))throw Error(l+"Argument "+(u.isInteger()?"out of range: ":"not an integer: ")+$(u));if(!y)return new H(m);for(r=new H(x),f=t=new H(x),i=s=new H(x),v=d(y),a=r.e=v.length-m.e-1,r.c[0]=h[(c=a%14)<0?14+c:c],e=!e||u.comparedTo(r)>0?a>0?r:f:u,c=D,D=1/0,u=new H(v),s.c[0]=0;p=n(u,r,0,1),1!=(o=t.plus(p.times(i))).comparedTo(e);)t=i,i=o,f=s.plus(p.times(o=f)),s=o,r=u.minus(p.times(o=r)),u=o;return o=n(e.minus(t),i,0,1),s=s.plus(o.times(f)),t=t.plus(o.times(i)),s.s=f.s=m.s,g=n(f,i,a*=2,O).minus(m).abs().comparedTo(n(s,t,a,O).minus(m).abs())<1?[f,i]:[s,t],D=c,g},N.toNumber=function(){return+$(this)},N.toPrecision=function(e,r){return null!=e&&m(e,1,p),M(this,e,r,2)},N.toString=function(e){var r,n=this,i=n.s,o=n.e;return null===o?i?(r="Infinity",i<0&&(r="-"+r)):r="NaN":(null==e?r=o<=F||o>=C?w(d(n.c),o):S(d(n.c),o,"0"):10===e?r=S(d((n=q(new H(n),_+o+1,O)).c),n.e,"0"):(m(e,2,L.length,"Base"),r=t(S(d(n.c),o,"0"),10,e,i,!0)),i<0&&n.c[0]&&(r="-"+r)),r},N.valueOf=N.toJSON=function(){return $(this)},N._isBigNumber=!0,N[Symbol.toStringTag]="BigNumber",N[Symbol.for("nodejs.util.inspect.custom")]=N.valueOf,null!=r&&H.set(r),H}();function E(e){if(!e||!/^-?\d*(\.\d+)?$/.test(e))throw new Error("Invalid value: ".concat(e))}A.config({EXPONENTIAL_AT:[-9,20]}),(b=e.AmountFormat||(e.AmountFormat={}))[b.PLANCK=0]="PLANCK",b[b.FRUITS=1]="FRUITS";var k=function(){function n(e){r(this,n),"string"==typeof e&&E(e),this._planck=new A(e)}return t(n,[{key:"getRaw",value:function(){return this._planck}},{key:"getPlanck",value:function(){return this._planck.toString()}},{key:"setPlanck",value:function(e){E(e),this._planck=new A(e)}},{key:"getFrts",value:function(){return this._planck.dividedBy(1e8).toString()}},{key:"setFrts",value:function(e){E(e),this._planck=new A(e).multipliedBy(1e8)}},{key:"equals",value:function(e){return this._planck.eq(e._planck)}},{key:"lessOrEqual",value:function(e){return this._planck.lte(e._planck)}},{key:"less",value:function(e){return this._planck.lt(e._planck)}},{key:"greaterOrEqual",value:function(e){return this._planck.gte(e._planck)}},{key:"greater",value:function(e){return this._planck.gt(e._planck)}},{key:"add",value:function(e){return this._planck=this._planck.plus(e._planck),this}},{key:"subtract",value:function(e){return this._planck=this._planck.minus(e._planck),this}},{key:"multiply",value:function(e){return this._planck=this._planck.multipliedBy(e),this}},{key:"divide",value:function(e){if(0===e)throw new Error("Division by zero");return this._planck=this._planck.div(e),this}},{key:"toString",value:function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e.AmountFormat.FRUITS;return r===e.AmountFormat.FRUITS?"".concat("FRTS"," ").concat(this.getFrts()):"".concat("frts"," ").concat(this._planck)}},{key:"clone",value:function(){return n.fromPlanck(this.getPlanck())}}],[{key:"CurrencySymbol",value:function(){return"FRTS"}},{key:"Zero",value:function(){return new n("0")}},{key:"fromPlanck",value:function(e){return new n(e)}},{key:"fromFrts",value:function(e){var r=new n("0");return r.setFrts("number"==typeof e?e.toString(10):e),r}}]),n}();const T="function"==typeof atob,N="function"==typeof btoa,x="function"==typeof Buffer,_="function"==typeof TextDecoder?new TextDecoder:void 0,O="function"==typeof TextEncoder?new TextEncoder:void 0,F=Array.prototype.slice.call("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="),C=(e=>{let r={};return e.forEach((e,n)=>r[e]=n),r})(F),B=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,D=String.fromCharCode.bind(String),I="function"==typeof Uint8Array.from?Uint8Array.from.bind(Uint8Array):(e,r=(e=>e))=>new Uint8Array(Array.prototype.slice.call(e,0).map(r)),P=e=>e.replace(/[+\/]/g,e=>"+"==e?"-":"_").replace(/=+$/m,""),R=e=>e.replace(/[^A-Za-z0-9\+\/]/g,""),U=e=>{let r,n,t,i,o="";const a=e.length%3;for(let a=0;a<e.length;){if((n=e.charCodeAt(a++))>255||(t=e.charCodeAt(a++))>255||(i=e.charCodeAt(a++))>255)throw new TypeError("invalid character found");r=n<<16|t<<8|i,o+=F[r>>18&63]+F[r>>12&63]+F[r>>6&63]+F[63&r]}return a?o.slice(0,a-3)+"===".substring(a):o},L=N?e=>btoa(e):x?e=>Buffer.from(e,"binary").toString("base64"):U,H=x?e=>Buffer.from(e).toString("base64"):e=>{let r=[];for(let n=0,t=e.length;n<t;n+=4096)r.push(D.apply(null,e.subarray(n,n+4096)));return L(r.join(""))},M=e=>{if(e.length<2)return(r=e.charCodeAt(0))<128?e:r<2048?D(192|r>>>6)+D(128|63&r):D(224|r>>>12&15)+D(128|r>>>6&63)+D(128|63&r);var r=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320);return D(240|r>>>18&7)+D(128|r>>>12&63)+D(128|r>>>6&63)+D(128|63&r)},j=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,G=e=>e.replace(j,M),q=x?e=>Buffer.from(e,"utf8").toString("base64"):O?e=>H(O.encode(e)):e=>L(G(e)),$=(e,r=!1)=>r?P(q(e)):q(e),z=e=>$(e,!0),V=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,Z=e=>{switch(e.length){case 4:var r=((7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3))-65536;return D(55296+(r>>>10))+D(56320+(1023&r));case 3:return D((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return D((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},Q=e=>e.replace(V,Z),W=e=>{if(e=e.replace(/\s+/g,""),!B.test(e))throw new TypeError("malformed base64.");e+="==".slice(2-(3&e.length));let r,n,t,i="";for(let o=0;o<e.length;)r=C[e.charAt(o++)]<<18|C[e.charAt(o++)]<<12|(n=C[e.charAt(o++)])<<6|(t=C[e.charAt(o++)]),i+=64===n?D(r>>16&255):64===t?D(r>>16&255,r>>8&255):D(r>>16&255,r>>8&255,255&r);return i},J=T?e=>atob(R(e)):x?e=>Buffer.from(e,"base64").toString("binary"):W,X=x?e=>I(Buffer.from(e,"base64")):e=>I(J(e),e=>e.charCodeAt(0)),K=x?e=>Buffer.from(e,"base64").toString("utf8"):_?e=>_.decode(X(e)):e=>Q(J(e)),Y=e=>R(e.replace(/[-_]/g,e=>"-"==e?"+":"/")),ee=e=>K(Y(e)),re=$,ne=z,te=ee;var ie=function(e){return te(e)},oe=function(e){for(var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=[],t=0;t<e.length;t++)n.push((e[t]>>>4).toString(16)),n.push((15&e[t]).toString(16));return r?n.join("").toUpperCase():n.join("")},ae=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;if(0===n)return"";var t=e;if(0!==r){var i=null===n?e.length-r:n;ce(t,i,r),t=e.slice(r,r+i)}return decodeURIComponent(escape(String.fromCharCode.apply(null,Array.from(t))))};function ce(e,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(n<0)throw new Error("Start index should not be negative");if(e.length<n+r)throw new Error("Need at least "+r+" bytes to convert to an integer");return n}String.prototype.padStart||(String.prototype.padStart=function(e,r){return e>>=0,r=String(void 0!==r?r:" "),this.length>=e?String(this):((e-=this.length)>r.length&&(r+=r.repeat(e/r.length)),r.slice(0,e)+String(this))});var ue,le=function(e){for(var r=e.multipliedBy(-1).toString(2);r.length%8;)r="0"+r;var n="1"===r[0]&&-1!==r.slice(1).indexOf("1")?"11111111":"";return r=r.split("").map((function(e){return"0"===e?"1":"0"})).join(""),new A(n+r,2).plus(1)},se=function(e){if(e.length%2)throw new Error("Invalid Hex String: ".concat(e));for(var r=new Uint8Array(e.length/2),n=0;n<e.length;n+=2){var t=parseInt(e.substr(n,2),16);if(Number.isNaN(t))throw new Error("Invalid Hex String: ".concat(e));r[n/2]=t}return r},fe=function(e){return ae(se(e))},he=function(e){if(null==e||""===e)throw new Error("Invalid argument");return parseFloat(e)/1e8},pe=function(e){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return r?ne(e):re(e)},ge=function(e){for(var r=unescape(encodeURIComponent(e)),n=new Uint8Array(r.length),t=0;t<r.length;++t)n[t]=r.charCodeAt(t);return n},de=function(e){return oe(ge(e))};(ue=e.EncoderFormat||(e.EncoderFormat={}))[ue.Text=0]="Text",ue[ue.Hexadecimal=1]="Hexadecimal",ue[ue.Base64=2]="Base64";var ve=/^fruits.?(.+)?:\/\/(v.+?)\??/i;e.Amount=k,e.BTCSymbol="BTC",e.ChainTime=o,e.CurrencyPlanckSymbol="frts",e.CurrencySymbol="FRTS",e.ETHSymbol="ETH",e.FeeQuantPlanck=5e6,e.OneFrtsPlanck=1e8,e.asyncRetry=function e(r){return n=this,t=void 0,o=function*(){var n=r.asyncFn,t=r.onFailureAsync,i=r.retryCount,o=void 0===i?1:i,a=r.maxRetrials,c=void 0===a?20:a;try{return yield n()}catch(r){if(o>c)throw r;if(!(yield t(r,o)))throw r;yield e({asyncFn:n,onFailureAsync:t,retryCount:o+1})}},new((i=void 0)||(i=Promise))((function(e,r){function a(e){try{u(o.next(e))}catch(e){r(e)}}function c(e){try{u(o.throw(e))}catch(e){r(e)}}function u(r){r.done?e(r.value):new i((function(e){e(r.value)})).then(a,c)}u((o=o.apply(n,t||[])).next())}));var n,t,i,o},e.convertBase36StringToHexString=function(e){return new A(e,36).toString(16)},e.convertBase64StringToString=ie,e.convertByteArrayToHexString=oe,e.convertByteArrayToString=ae,e.convertDecStringToHexString=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,n="string"==typeof e?new A(e):e;if(n.isNaN())throw new Error("Invalid decimal argument: [".concat(e,"] - Expected a valid decimal value"));if(r<0)throw new Error("Invalid padding argument: [".concat(r,"] - Expected a positive value"));var t=n.lt(0);t&&(n=le(n));var i=n.toString(16),o=Math.ceil(i.length/r);return i.padStart(o*r,t?"f":"0")},e.convertHexEndianess=function(e){for(var r="",n=e,t=n.length-1;t>=0;t-=2)r+=n[t-1]+n[t];return r},e.convertHexStringToBase36String=function(e){return new A(e,16).toString(36)},e.convertHexStringToByteArray=se,e.convertHexStringToDecString=function(e){var r,n,t,i=[0];for(r=0;r<e.length;r+=1){for(t=parseInt(e.charAt(r),16),n=0;n<i.length;n+=1)i[n]=16*i[n]+t,t=i[n]/10|0,i[n]%=10;for(;t>0;)i.push(t%10),t=t/10|0}return i.reverse().join("")},e.convertHexStringToString=fe,e.convertNQTStringToNumber=he,e.convertNumberToNQTString=function(e){if(null==e)throw new Error("Invalid argument");return parseFloat(e.toString()).toFixed(8).replace(".","")},e.convertStringToBase64String=pe,e.convertStringToByteArray=ge,e.convertStringToHexString=de,e.convertToQNT=function(e,r){var n=(e=String(e)).split("."),t=n[0];if(1===n.length){if(r)for(var i=0;i<r;i++)t+="0"}else{if(2!==n.length)throw new Error("Invalid input.");var o=n[1];if(o.length>r)throw new Error("Fraction can only have "+r+"decimals max.");if(o.length<r)for(var a=o.length;a<r;a++)o+="0";t+=o}if(!/^\d+$/.test(t))throw new Error("Invalid input. Only numbers and a dot are accepted.");return t.replace(/^0+/,"")},e.createDeeplink=function(r){var n=r.encoderFormat,t=void 0===n?e.EncoderFormat.Base64:n,i=r.domain,o=r.action,a=r.payload,c=i?"fruits.".concat(i,"://v1"):"fruits://v1";return o&&(c+="?action=".concat(o)),a&&(c+="&payload=".concat(function(r,n){var t=r;switch("string"!=typeof r&&(t=JSON.stringify(r)),n){case e.EncoderFormat.Hexadecimal:return de(t);case e.EncoderFormat.Base64:return pe(t);case e.EncoderFormat.Text:default:return t}}(a,t))),c},e.gTokenSymbol="GT",e.parseDeeplink=function(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.EncoderFormat.Base64,t=function(){throw new Error("Invalid deeplink: "+r)},i=function(r,n){var t=r;switch(n){case e.EncoderFormat.Hexadecimal:t=fe(r);break;case e.EncoderFormat.Base64:t=ie(r);break;case e.EncoderFormat.Text:}try{return JSON.parse(t)}catch(e){return t}},o=function(e,r){return e.startsWith(r+"=")||t(),e.split("=")[1]},a=r.match(ve);a&&3===a.length||t();var c={domain:a[1],version:a[2],action:void 0,payload:void 0,decodedPayload:void 0};try{var u=r.indexOf("?");if(-1!==u){var l=r.substring(u+1).split("&");l.length>=1&&(l.length>2&&t(),c.action=o(l[0],"action"),2===l.length&&(c.payload=o(l[1],"payload"),c.decodedPayload=i(c.payload,n)))}}catch(e){t()}return c},e.sumNQTStringToNumber=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return r.reduce((function(e,r){return e+he(r)}),0)},Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=fruitsjs.util.min.js.map