You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

2 lines
4.6 KiB

  1. function H(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)}function A(t,n){if(!isFinite(t)||t===0)return null;var o=(t=n?t.toExponential(n-1):t.toExponential()).indexOf("e"),i=t.slice(0,o);return[i.length>1?i[0]+i.slice(2):i,+t.slice(o+1)]}function J(t){return t=A(Math.abs(t)),t?t[1]:NaN}function K(t,n){return function(o,i){for(var a=o.length,f=[],c=0,s=t[0],M=0;a>0&&s>0&&(M+s+1>i&&(s=Math.max(1,i-M)),f.push(o.substring(a-=s,a+s)),!((M+=s+1)>i));)s=t[c=(c+1)%t.length];return f.reverse().join(n)}}function Q(t){return function(n){return n.replace(/[0-9]/g,function(o){return t[+o]})}}var V=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function F(t){if(!(n=V.exec(t)))throw new Error("invalid format: "+t);var n;return new $({fill:n[1],align:n[2],sign:n[3],symbol:n[4],zero:n[5],width:n[6],comma:n[7],precision:n[8]&&n[8].slice(1),trim:n[9],type:n[10]})}F.prototype=$.prototype;function $(t){this.fill=t.fill===void 0?" ":t.fill+"",this.align=t.align===void 0?">":t.align+"",this.sign=t.sign===void 0?"-":t.sign+"",this.symbol=t.symbol===void 0?"":t.symbol+"",this.zero=!!t.zero,this.width=t.width===void 0?void 0:+t.width,this.comma=!!t.comma,this.precision=t.precision===void 0?void 0:+t.precision,this.trim=!!t.trim,this.type=t.type===void 0?"":t.type+""}$.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function W(t){t:for(var n=t.length,o=1,i=-1,a;o<n;++o)switch(t[o]){case".":i=a=o;break;case"0":i===0&&(i=o),a=o;break;default:if(!+t[o])break t;i>0&&(i=0);break}return i>0?t.slice(0,i)+t.slice(a+1):t}var j;function _(t,n){var o=A(t,n);if(!o)return j=void 0,t.toPrecision(n);var i=o[0],a=o[1],f=a-(j=Math.max(-8,Math.min(8,Math.floor(a/3)))*3)+1,c=i.length;return f===c?i:f>c?i+new Array(f-c+1).join("0"):f>0?i.slice(0,f)+"."+i.slice(f):"0."+new Array(1-f).join("0")+A(t,Math.max(0,n+f-1))[0]}function I(t,n){var o=A(t,n);if(!o)return t+"";var i=o[0],a=o[1];return a<0?"0."+new Array(-a).join("0")+i:i.length>a+1?i.slice(0,a+1)+"."+i.slice(a+1):i+new Array(a-i.length+2).join("0")}const X={"%":(t,n)=>(t*100).toFixed(n),b:t=>Math.round(t).toString(2),c:t=>t+"",d:H,e:(t,n)=>t.toExponential(n),f:(t,n)=>t.toFixed(n),g:(t,n)=>t.toPrecision(n),o:t=>Math.round(t).toString(8),p:(t,n)=>I(t*100,n),r:I,s:_,X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function B(t){return t}var O=Array.prototype.map,R=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function tt(t){var n=t.grouping===void 0||t.thousands===void 0?B:K(O.call(t.grouping,Number),t.thousands+""),o=t.currency===void 0?"":t.currency[0]+"",i=t.currency===void 0?"":t.currency[1]+"",a=t.decimal===void 0?".":t.decimal+"",f=t.numerals===void 0?B:Q(O.call(t.numerals,String)),c=t.percent===void 0?"%":t.percent+"",s=t.minus===void 0?"−":t.minus+"",M=t.nan===void 0?"NaN":t.nan+"";function L(e,g){e=F(e);var b=e.fill,p=e.align,d=e.sign,w=e.symbol,S=e.zero,N=e.width,E=e.comma,y=e.precision,T=e.trim,h=e.type;h==="n"?(E=!0,h="g"):X[h]||(y===void 0&&(y=12),T=!0,h="g"),(S||b==="0"&&p==="=")&&(S=!0,b="0",p="=");var Y=(g&&g.prefix!==void 0?g.prefix:"")+(w==="$"?o:w==="#"&&/[boxX]/.test(h)?"0"+h.toLowerCase():""),Z=(w==="$"?i:/[%p]/.test(h)?c:"")+(g&&g.suffix!==void 0?g.suffix:""),C=X[h],q=/[defgprs%]/.test(h);y=y===void 0?6:/[gprs]/.test(h)?Math.max(1,Math.min(21,y)):Math.max(0,Math.min(20,y));function D(r){var l=Y,m=Z,x,G,v;if(h==="c")m=C(r)+m,r="";else{r=+r;var k=r<0||1/r<0;if(r=isNaN(r)?M:C(Math.abs(r),y),T&&(r=W(r)),k&&+r==0&&d!=="+"&&(k=!1),l=(k?d==="("?d:s:d==="-"||d==="("?"":d)+l,m=(h==="s"&&!isNaN(r)&&j!==void 0?R[8+j/3]:"")+m+(k&&d==="("?")":""),q){for(x=-1,G=r.length;++x<G;)if(v=r.charCodeAt(x),48>v||v>57){m=(v===46?a+r.slice(x+1):r.slice(x))+m,r=r.slice(0,x);break}}}E&&!S&&(r=n(r,1/0));var P=l.length+r.length+m.length,u=P<N?new Array(N-P+1).join(b):"";switch(E&&S&&(r=n(u+r,u.length?N-m.length:1/0),u=""),p){case"<":r=l+r+m+u;break;case"=":r=l+u+r+m;break;case"^":r=u.slice(0,P=u.length>>1)+l+r+m+u.slice(P);break;default:r=u+l+r+m;break}return f(r)}return D.toString=function(){return e+""},D}function U(e,g){var b=Math.max(-8,Math.min(8,Math.floor(J(g)/3)))*3,p=Math.pow(10,-b),d=L((e=F(e),e.type="f",e),{suffix:R[8+b/3]});return function(w){return d(p*w)}}return{format:L,formatPrefix:U}}var z,nt,rt;it({thousands:",",grouping:[3],currency:["$",""]});function it(t){return z=tt(t),nt=z.format,rt=z.formatPrefix,z}export{rt as a,nt as b,J as e,F as f};