UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 1.31 kB
import enUS from'./locales/en-US';import exponent from'./exponent';import Formatter from'./formatter';import formatGroup from'./format-group';import formatNumerals from'./format-numerals';import FormatSpecifier from'./format-specifier';import{extend2}from'../../../fc-core/src/lib';const identity=a=>a;class NumberConverter{constructor(a){this.localeInfo={group:a.grouping&&a.thousands?formatGroup(a.grouping,a.thousands):identity,prefix:a.prefix,suffix:a.suffix,decimal:a.decimal,numerals:a.numerals?formatNumerals(a.numerals):identity,percent:a.percent||'%',prefixes:a.prefixes||['y','z','a','f','p','n','\xB5','m','','k','M','G','T','P','E','Z','Y']}}formatter(a){return new Formatter(a,this.localeInfo)}formatPrefix(a,b){a=new FormatSpecifier(a),a.type='f';var c=this.localeInfo.prefix,d=this.localeInfo.suffix,g=extend2(extend2({},this.localeInfo),{prefix:'',suffix:''}),h=new Formatter(a,g),f=3*Math.max(-8,Math.min(8,Math.floor(exponent(b)/3))),e=Math.pow(10,-f),i=this.localeInfo.prefixes[8+f/3];return{format:a=>c+h.format(e*a)+i+d,setCustomPrefix:function(a){return h.setCustomPrefix(a),this},getCustomPrefix:a=>h.getCustomPrefix(a),setCustomSuffix:function(a){return h.setCustomSuffix(a),this},getCustomSuffix:a=>h.getCustomSuffix(a)}}}export{NumberConverter};export default new NumberConverter(enUS);