"use strict";var ABBR={th:3,mi:6,bi:9,tr:12},DEFAULT_OPTIONS={zeroFormat:null,nullFormat:null,defaultFormat:"0,0",scalePercentBy100:!0,abbrLabel:{th:"k",mi:"m",bi:"b",tr:"t"}},TRILLION=1e12,BILLION=1e9,MILLION=1e6,THOUSAND=1e3;function numIsNaN(e){return"number"==typeof e&&isNaN(e)}function toFixed(e,t,n,r){var o=e.toString().split("."),i=t-(r||0),a=2===o.length?Math.min(Math.max(o[1].length,i),t):i,l=Math.pow(10,a),f=(n(e+"e+"+a)/l).toFixed(a);if(r>t-a){var m=new RegExp("\\.?0{1,"+(r-(t-a))+"}$");f=f.replace(m,"")}return f}function numberToFormat(e,t,n,r){var o=Math.abs(t),i=!1,a=!1,l="",f="",m=!1,u=void 0,s=void 0;n=n||"",t=t||0,~n.indexOf("(")?(i=!0,n=n.replace(/[(|)]/g,"")):(~n.indexOf("+")||~n.indexOf("-"))&&(s=~n.indexOf("+")?n.indexOf("+"):t<0?n.indexOf("-"):-1,n=n.replace(/[+|-]/g,"")),~n.indexOf("a")&&(u=!!(u=n.match(/a(k|m|b|t)?/))&&u[1],~n.indexOf(" a")&&(l=" "),n=n.replace(new RegExp(l+"a[kmbt]?"),""),o>=TRILLION&&!u||"t"===u?(l+=e.abbrLabel.tr,t/=TRILLION):o=BILLION&&!u||"b"===u?(l+=e.abbrLabel.bi,t/=BILLION):o=MILLION&&!u||"m"===u?(l+=e.abbrLabel.mi,t/=MILLION):(o=THOUSAND&&!u||"k"===u)&&(l+=e.abbrLabel.th,t/=THOUSAND)),~n.indexOf("[.]")&&(a=!0,n=n.replace("[.]","."));var p=t.toString().split(".")[0],d=n.split(".")[1],O=n.indexOf(","),c=(n.split(".")[0].split(",")[0].match(/0/g)||[]).length;if(d?(p=(f=~d.indexOf("[")?toFixed(t,(d=(d=d.replace("]","")).split("["))[0].length+d[1].length,r,d[1].length):toFixed(t,d.length,r)).split(".")[0],f=~f.indexOf(".")?"."+f.split(".")[1]:"",a&&0==+f.slice(1)&&(f="")):p=toFixed(t,0,r),l&&!u&&+p>=1e3&&l!==ABBR.trillion&&(p=""+ +p/1e3,l=ABBR.million),~p.indexOf("-")&&(p=p.slice(1),m=!0),p.length0;b--)p="0"+p;O>-1&&(p=p.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,")),n.indexOf(".")||(p="");var L=p+f+(l||"");return i?L=(i&&m?"(":"")+L+(i&&m?")":""):s>=0?L=0===s?(m?"-":"+")+L:L+(m?"-":"+"):m&&(L="-"+L),L}function extend(e,t){Object.keys(t).forEach(function(n){e[n]=t[n]})}var numerifyPercent={regexp:/%/,format:function(e,t,n,r){var o=~t.indexOf(" %")?" ":"",i=void 0;return r.options.scalePercentBy100&&(e*=100),t=t.replace(/\s?%/,""),~(i=r._numberToFormat(e,t,n)).indexOf(")")?((i=i.split("")).splice(-1,0,o+"%"),i=i.join("")):i=i+o+"%",i}},options={},formats={};function format(e,t,n){t=t||options.defaultFormat,n=n||Math.round;var r=void 0,o=void 0;if(0===e&&null!==options.zeroFormat)r=options.zeroFormat;else if(null===e&&null!==options.nullFormat)r=options.nullFormat;else{for(var i in formats)if(formats[i]&&t.match(formats[i].regexp)){o=formats[i].format;break}r=(o=o||numberToFormat.bind(null,options))(e,t,n,numerify)}return r}function numerify(e,t,n){return format(0===e||void 0===e?0:null===e||numIsNaN(e)?null:"string"==typeof e?options.zeroFormat&&e===options.zeroFormat?0:options.nullFormat&&e===options.nullFormat||!e.replace(/[^0-9]+/g,"").length?null:+e:+e||null,t,n)}extend(options,DEFAULT_OPTIONS),numerify.options=options,numerify._numberToFormat=numberToFormat.bind(null,options),numerify.register=function(e,t){formats[e]=t},numerify.unregister=function(e){formats[e]=null},numerify.setOptions=function(e){extend(options,e)},numerify.reset=function(){extend(options,DEFAULT_OPTIONS)},numerify.register("percentage",numerifyPercent),module.exports=numerify;