UNPKG

6.09 kBJavaScriptView Raw
1!function(n,r){"use strict";function t(n,r){if((t=(n=r?n.toExponential(r-1):n.toExponential()).indexOf("e"))<0)return null;var t,e=n.slice(0,t);return[e.length>1?e[0]+e.slice(2):e,+n.slice(t+1)]}function e(n){return n=t(Math.abs(n)),n?n[1]:NaN}function i(n,r){return function(t,e){for(var i=t.length,o=[],a=0,u=n[0],c=0;i>0&&u>0&&(c+u+1>e&&(u=Math.max(1,e-c)),o.push(t.substring(i-=u,i+u)),!((c+=u+1)>e));)u=n[a=(a+1)%n.length];return o.reverse().join(r)}}function o(n,r){var e=t(n,r);if(!e)return n+"";var i=e[0],o=e[1],a=o-(p=3*Math.max(-8,Math.min(8,Math.floor(o/3))))+1,u=i.length;return a===u?i:a>u?i+new Array(a-u+1).join("0"):a>0?i.slice(0,a)+"."+i.slice(a):"0."+new Array(1-a).join("0")+t(n,Math.max(0,r+a-1))[0]}function a(n,r){var e=t(n,r);if(!e)return n+"";var i=e[0],o=e[1];return 0>o?"0."+new Array(-o).join("0")+i:i.length>o+1?i.slice(0,o+1)+"."+i.slice(o+1):i+new Array(o-i.length+2).join("0")}function u(n,r){n=n.toPrecision(r);n:for(var t,e=n.length,i=1,o=-1;e>i;++i)switch(n[i]){case".":o=t=i;break;case"0":0===o&&(o=i),t=i;break;case"e":break n;default:o>0&&(o=0)}return o>0?n.slice(0,o)+n.slice(t+1):n}function c(n){return new s(n)}function s(n){if(!(r=X.exec(n)))throw new Error("invalid format: "+n);var r,t=r[1]||" ",e=r[2]||">",i=r[3]||"-",o=r[4]||"",a=!!r[5],u=r[6]&&+r[6],c=!!r[7],s=r[8]&&+r[8].slice(1),h=r[9]||"";"n"===h?(c=!0,h="g"):K[h]||(h=""),(a||"0"===t&&"="===e)&&(a=!0,t="0",e="="),this.fill=t,this.align=e,this.sign=i,this.symbol=o,this.zero=a,this.width=u,this.comma=c,this.precision=s,this.type=h}function h(n){return n}function l(n){function r(n){n=c(n);var r=n.fill,t=n.align,e=n.sign,i=n.symbol,s=n.zero,h=n.width,l=n.comma,f=n.precision,g=n.type,d="$"===i?a[0]:"#"===i&&/[boxX]/.test(g)?"0"+g.toLowerCase():"",m="$"===i?a[1]:/[%p]/.test(g)?"%":"",y=K[g],M=!g||/[defgprs%]/.test(g);return f=null==f?g?6:12:/[gprs]/.test(g)?Math.max(1,Math.min(21,f)):Math.max(0,Math.min(20,f)),function(n){var i=d,a=m;if("c"===g)a=y(n)+a,n="";else{n=+n;var c=(0>n||0>1/n)&&(n*=-1,!0);if(n=y(n,f),c){var x,v=-1,b=n.length;for(c=!1;++v<b;)if(x=n.charCodeAt(v),x>48&&58>x||"x"===g&&x>96&&103>x||"X"===g&&x>64&&71>x){c=!0;break}}if(i=(c?"("===e?e:"-":"-"===e||"("===e?"":e)+i,a=a+("s"===g?B[8+p/3]:"")+(c&&"("===e?")":""),M)for(var x,v=-1,b=n.length;++v<b;)if(x=n.charCodeAt(v),48>x||x>57){a=(46===x?u+n.slice(v+1):n.slice(v))+a,n=n.slice(0,v);break}}l&&!s&&(n=o(n,1/0));var w=i.length+n.length+a.length,S=h>w?new Array(h-w+1).join(r):"";switch(l&&s&&(n=o(S+n,S.length?h-a.length:1/0),S=""),t){case"<":return i+n+a+S;case"=":return i+S+n+a;case"^":return S.slice(0,w=S.length>>1)+i+n+a+S.slice(w)}return S+i+n+a}}function t(n,t){var i=r((n=c(n),n.type="f",n)),o=3*Math.max(-8,Math.min(8,Math.floor(e(t)/3))),a=Math.pow(10,-o),u=B[8+o/3];return function(n){return i(a*n)+u}}var o=n.grouping&&n.thousands?i(n.grouping,n.thousands):h,a=n.currency,u=n.decimal;return{format:r,formatPrefix:t}}function f(n){return Math.max(0,-e(Math.abs(n)))}function g(n,r){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(e(r)/3)))-e(Math.abs(n)))}function d(n,r){return Math.max(0,e(Math.abs(r))-e(Math.abs(n)))+1}function m(n){if("string"==typeof n){if(!G.hasOwnProperty(n))return null;n=G[n]}return l(n)}var p,y={decimal:".",thousands:",",grouping:[3],currency:["¥",""]},M={decimal:",",thousands:" ",grouping:[3],currency:["","SEK"]},x={decimal:",",thousands:" ",grouping:[3],currency:[""," руб."]},v={decimal:",",thousands:".",grouping:[3],currency:["R$",""]},b={decimal:",",thousands:".",grouping:[3],currency:["","zł"]},w={decimal:",",thousands:".",grouping:[3],currency:["€ ",""]},S={decimal:",",thousands:".",grouping:[3],currency:[""," ден."]},E={decimal:".",thousands:",",grouping:[3],currency:["₩",""]},P={decimal:".",thousands:",",grouping:[3],currency:["","円"]},A={decimal:",",thousands:".",grouping:[3],currency:["€",""]},C={decimal:",",thousands:" ",grouping:[3],currency:[""," Ft"]},j={decimal:".",thousands:",",grouping:[3],currency:["₪",""]},k={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},F={decimal:",",thousands:" ",grouping:[3],currency:["","$"]},$={decimal:",",thousands:" ",grouping:[3],currency:[""," €"]},z={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},R={decimal:".",thousands:",",grouping:[3],currency:["$",""]},L={decimal:".",thousands:",",grouping:[3],currency:["£",""]},N={decimal:".",thousands:",",grouping:[3],currency:["$",""]},U={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},H={decimal:",",thousands:"'",grouping:[3],currency:[""," CHF"]},I={decimal:",",thousands:".",grouping:[3],currency:[""," €"]},K={"":u,"%":function(n,r){return(100*n).toFixed(r)},b:function(n){return Math.round(n).toString(2)},c:function(n){return n+""},d:function(n){return Math.round(n).toString(10)},e:function(n,r){return n.toExponential(r)},f:function(n,r){return n.toFixed(r)},g:function(n,r){return n.toPrecision(r)},o:function(n){return Math.round(n).toString(8)},p:function(n,r){return a(100*n,r)},r:a,s:o,X:function(n){return Math.round(n).toString(16).toUpperCase()},x:function(n){return Math.round(n).toString(16)}},X=/^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;s.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(null==this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(null==this.precision?"":"."+Math.max(0,0|this.precision))+this.type};var B=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"],G={"ca-ES":I,"de-CH":H,"de-DE":U,"en-CA":N,"en-GB":L,"en-US":R,"es-ES":z,"fi-FI":$,"fr-CA":F,"fr-FR":k,"he-IL":j,"hu-HU":C,"it-IT":A,"ja-JP":P,"ko-KR":E,"mk-MK":S,"nl-NL":w,"pl-PL":b,"pt-BR":v,"ru-RU":x,"sv-SE":M,"zh-CN":y},O=l(R),T=O.format,D=O.formatPrefix;r.format=T,r.formatPrefix=D,r.localeFormat=m,r.formatSpecifier=c,r.precisionFixed=f,r.precisionPrefix=g,r.precisionRound=d,r.version="0.3.5","function"==typeof define&&define.amd?(n.format=r,define("format",[],function(){return r})):"object"==typeof module&&module.exports?module.exports=r:n.format=r}(this,{});
\No newline at end of file