UNPKG

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