!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof module&&module.exports?module.exports=r():e.numeral=r()}(this,function(){function o(e,r){this._input=e,this._value=r}var a,u,s,l={},d={},r={currentLocale:"en",zeroFormat:null,nullFormat:null,defaultFormat:"0,0"},c={currentLocale:r.currentLocale,zeroFormat:r.zeroFormat,nullFormat:r.nullFormat,defaultFormat:r.defaultFormat},b=function(e){var r,t,n,i;if(b.isNumeral(e))r=e.value();else if(0===e||void 0===e)r=0;else if(null===e||a.isNaN(e))r=null;else if("string"==typeof e)if(c.zeroFormat&&e===c.zeroFormat)r=0;else if(c.nullFormat&&e===c.nullFormat||!e.replace(/[^0-9]+/g,"").length)r=null;else{for(t in l)if(i="function"==typeof l[t].regexps.unformat?l[t].regexps.unformat():l[t].regexps.unformat,i&&e.match(i)){n=l[t].unformat;break}r=(n=n||b._.stringToNumber)(e)}else r=Number(e)||null;return new o(e,r)};return b.version="2.0.4",b.isNumeral=function(e){return e instanceof o},b._=a={numberToFormat:function(e,r,t){var n,i,o,a,l=d[b.options.currentLocale],u=!1,s=!1,c="",f=1e12,m="",h=!1;if(e=e||0,a=Math.abs(e),b._.includes(r,"(")?(u=!0,r=r.replace(/[\(|\)]/g,"")):(b._.includes(r,"+")||b._.includes(r,"-"))&&(i=b._.includes(r,"+")?r.indexOf("+"):e<0?r.indexOf("-"):-1,r=r.replace(/[\+|\-]/g,"")),b._.includes(r,"a")&&(n=!!(n=r.match(/a(k|m|b|t)?/))&&n[1],b._.includes(r," a")&&(c=" "),r=r.replace(new RegExp(c+"a[kmbt]?"),""),f<=a&&!n||"t"===n?(c+=l.abbreviations.trillion,e/=f):a<f&&1e9<=a&&!n||"b"===n?(c+=l.abbreviations.billion,e/=1e9):a<1e9&&1e6<=a&&!n||"m"===n?(c+=l.abbreviations.million,e/=1e6):(a<1e6&&1e3<=a&&!n||"k"===n)&&(c+=l.abbreviations.thousand,e/=1e3)),b._.includes(r,"[.]")&&(s=!0,r=r.replace("[.]",".")),f=e.toString().split(".")[0],a=r.split(".")[1],o=r.indexOf(","),a?(f=(m=b._.includes(a,"[")?(a=(a=a.replace("]","")).split("["),b._.toFixed(e,a[0].length+a[1].length,t,a[1].length)):b._.toFixed(e,a.length,t)).split(".")[0],m=b._.includes(m,".")?l.delimiters.decimal+m.split(".")[1]:"",s&&0===Number(m.slice(1))&&(m="")):f=b._.toFixed(e,null,t),c&&!n&&1e3<=Number(f)&&c!==l.abbreviations.trillion)switch(f=String(Number(f)/1e3),c){case l.abbreviations.thousand:c=l.abbreviations.million;break;case l.abbreviations.million:c=l.abbreviations.billion;break;case l.abbreviations.billion:c=l.abbreviations.trillion}return b._.includes(f,"-")&&(f=f.slice(1),h=!0),-1<o&&(f=f.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+l.delimiters.thousands)),a=(f=0===r.indexOf(".")?"":f)+m+(c||""),u?a=(u&&h?"(":"")+a+(u&&h?")":""):0<=i?a=0===i?(h?"-":"+")+a:a+(h?"-":"+"):h&&(a="-"+a),a},stringToNumber:function(e){var r,t,n,i=d[c.currentLocale],o=e,a={thousand:3,million:6,billion:9,trillion:12};if(c.zeroFormat&&e===c.zeroFormat)t=0;else if(c.nullFormat&&e===c.nullFormat||!e.replace(/[^0-9]+/g,"").length)t=null;else{for(r in t=1,"."!==i.delimiters.decimal&&(e=e.replace(/\./g,"").replace(i.delimiters.decimal,".")),a)if(n=new RegExp("[^a-zA-Z]"+i.abbreviations[r]+"(?:\\)|(\\"+i.currency.symbol+")?(?:\\))?)?$"),o.match(n)){t*=Math.pow(10,a[r]);break}t*=(e.split("-").length+Math.min(e.split("(").length-1,e.split(")").length-1))%2?1:-1,e=e.replace(/[^0-9\.]+/g,""),t*=Number(e)}return t},isNaN:function(e){return"number"==typeof e&&isNaN(e)},includes:function(e,r){return-1!==e.indexOf(r)},insert:function(e,r,t){return e.slice(0,t)+r+e.slice(t)},reduce:function(e,r){if(null===this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof r)throw new TypeError(r+" is not a function");var t,n=Object(e),i=n.length>>>0,o=0;if(3===arguments.length)t=arguments[2];else{for(;o<i&&!(o in n);)o++;if(i<=o)throw new TypeError("Reduce of empty array with no initial value");t=n[o++]}for(;o<i;o++)o in n&&(t=r(t,n[o],o,n));return t},multiplier:function(e){e=e.toString().split(".");return e.length<2?1:Math.pow(10,e[1].length)},correctionFactor:function(){return Array.prototype.slice.call(arguments).reduce(function(e,r){r=a.multiplier(r);return r<e?e:r},1)},toFixed:function(e,r,t,n){var i=e.toString().split("."),o=r-(n||0),i=2===i.length?Math.min(Math.max(i[1].length,o),r):o,o=Math.pow(10,i),t=(t(e*o)/o).toFixed(i);return r-i<n&&(e=new RegExp("\\.?0{1,"+(n-(r-i))+"}$"),t=t.replace(e,"")),t}},b.options=c,b.formats=l,b.locales=d,b.locale=function(e){return e&&(c.currentLocale=e.toLowerCase()),c.currentLocale},b.localeData=function(e){if(!e)return d[c.currentLocale];if(e=e.toLowerCase(),d[e])return d[e];throw new Error("Unknown locale : "+e)},b.reset=function(){for(var e in r)c[e]=r[e]},b.zeroFormat=function(e){c.zeroFormat="string"==typeof e?e:null},b.nullFormat=function(e){c.nullFormat="string"==typeof e?e:null},b.defaultFormat=function(e){c.defaultFormat="string"==typeof e?e:"0.0"},b.register=function(e,r,t){if(r=r.toLowerCase(),this[e+"s"][r])throw new TypeError(r+" "+e+" already registered.");return this[e+"s"][r]=t},b.validate=function(e,r){var t,n,i,o;if("string"!=typeof e&&(e+="",console.warn)&&console.warn("Numeral.js: Value is not string. It has been co-erced to: ",e),(e=e.trim()).match(/^\d+$/))return!0;if(""===e)return!1;try{i=b.localeData(r)}catch(e){i=b.localeData(b.locale())}return r=i.currency.symbol,n=i.abbreviations,t=i.delimiters.decimal,i="."===i.delimiters.thousands?"\\.":i.delimiters.thousands,!(null!==(o=e.match(/^[^\d]+/))&&(e=e.substr(1),o[0]!==r)||null!==(o=e.match(/[^\d]+$/))&&(e=e.slice(0,-1),o[0]!==n.thousand)&&o[0]!==n.million&&o[0]!==n.billion&&o[0]!==n.trillion||(r=new RegExp(i+"{2}"),e.match(/[^\d.,]/g))||2<(o=e.split(t)).length||(o.length<2?!o[0].match(/^\d+.*\d$/)||o[0].match(r):1===o[0].length?!o[0].match(/^\d+$/)||o[0].match(r)||!o[1].match(/^\d+$/):!o[0].match(/^\d+.*\d$/)||o[0].match(r)||!o[1].match(/^\d+$/)))},b.fn=o.prototype={clone:function(){return b(this)},format:function(e,r){var t,n,i,o=this._value,a=e||c.defaultFormat;if(r=r||Math.round,0===o&&null!==c.zeroFormat)n=c.zeroFormat;else if(null===o&&null!==c.nullFormat)n=c.nullFormat;else{for(t in l)if(a.match(l[t].regexps.format)){i=l[t].format;break}n=(i=i||b._.numberToFormat)(o,a,r)}return n},value:function(){return this._value},input:function(){return this._input},set:function(e){return this._value=Number(e),this},add:function(e){var i=a.correctionFactor.call(null,this._value,e);return this._value=a.reduce([this._value,e],function(e,r,t,n){return e+Math.round(i*r)},0)/i,this},subtract:function(e){var i=a.correctionFactor.call(null,this._value,e);return this._value=a.reduce([e],function(e,r,t,n){return e-Math.round(i*r)},Math.round(this._value*i))/i,this},multiply:function(e){return this._value=a.reduce([this._value,e],function(e,r,t,n){var i=a.correctionFactor(e,r);return Math.round(e*i)*Math.round(r*i)/Math.round(i*i)},1),this},divide:function(e){return this._value=a.reduce([this._value,e],function(e,r,t,n){var i=a.correctionFactor(e,r);return Math.round(e*i)/Math.round(r*i)}),this},difference:function(e){return Math.abs(b(this._value).subtract(e).value())}},b.register("locale","en",{delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(e){var r=e%10;return 1==~~(e%100/10)?"th":1==r?"st":2==r?"nd":3==r?"rd":"th"},currency:{symbol:"$"}}),u={base:1e3,suffixes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]},s={base:1024,suffixes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},b.register("format","bytes",{regexps:{format:/([0\s]i?b)/,unformat:new RegExp("("+u.suffixes.concat(s.suffixes).join("|")+")")},format:function(e,r,t){var n,i,o,a=b._.includes(r,"ib")?s:u,l=b._.includes(r," b")||b._.includes(r," ib")?" ":"";for(r=r.replace(/\s?i?b/,""),n=0;n<=a.suffixes.length;n++)if(i=Math.pow(a.base,n),o=Math.pow(a.base,n+1),null===e||0===e||i<=e&&e<o){l+=a.suffixes[n],0<i&&(e/=i);break}return b._.numberToFormat(e,r,t)+l},unformat:function(e){var r,t,n=b._.stringToNumber(e);if(n){for(r=u.suffixes.length-1;0<=r;r--){if(b._.includes(e,u.suffixes[r])){t=Math.pow(u.base,r);break}if(b._.includes(e,s.suffixes[r])){t=Math.pow(s.base,r);break}}n*=t||1}return n}}),b.register("format","currency",{regexps:{format:/(\$)/},format:function(e,r,t){var n,i,o=b.locales[b.options.currentLocale],a={before:r.match(/^([\+|\-|\(|\s|\$]*)/)[0],after:r.match(/([\+|\-|\)|\s|\$]*)$/)[0]};for(r=r.replace(/\s?\$\s?/,""),n=b._.numberToFormat(e,r,t),0<=e?(a.before=a.before.replace(/[\-\(]/,""),a.after=a.after.replace(/[\-\)]/,"")):e<0&&!b._.includes(a.before,"-")&&!b._.includes(a.before,"(")&&(a.before="-"+a.before),i=0;i<a.before.length;i++)switch(a.before[i]){case"$":n=b._.insert(n,o.currency.symbol,i);break;case" ":n=b._.insert(n," ",i)}for(i=a.after.length-1;0<=i;i--)switch(a.after[i]){case"$":n=i===a.after.length-1?n+o.currency.symbol:b._.insert(n,o.currency.symbol,-(a.after.length-(1+i)));break;case" ":n=i===a.after.length-1?n+" ":b._.insert(n," ",-(a.after.length-(1+i)))}return n}}),b.register("format","exponential",{regexps:{format:/(e\+|e-)/,unformat:/(e\+|e-)/},format:function(e,r,t){e=("number"!=typeof e||b._.isNaN(e)?"0e+0":e.toExponential()).split("e");return r=r.replace(/e[\+|\-]{1}0/,""),b._.numberToFormat(Number(e[0]),r,t)+"e"+e[1]},unformat:function(e){var r=b._.includes(e,"e+")?e.split("e+"):e.split("e-"),t=Number(r[0]),r=Number(r[1]),r=b._.includes(e,"e-")?-1*r:r;return b._.reduce([t,Math.pow(10,r)],function(e,r,t,n){var i=b._.correctionFactor(e,r);return e*i*(r*i)/(i*i)},1)}}),b.register("format","ordinal",{regexps:{format:/(o)/},format:function(e,r,t){var n=b.locales[b.options.currentLocale],i=b._.includes(r," o")?" ":"";return r=r.replace(/\s?o/,""),i+=n.ordinal(e),b._.numberToFormat(e,r,t)+i}}),b.register("format","percentage",{regexps:{format:/(%)/,unformat:/(%)/},format:function(e,r,t){var n=b._.includes(r," %")?" ":"";return e*=100,r=r.replace(/\s?\%/,""),e=b._.numberToFormat(e,r,t),e=b._.includes(e,")")?((e=e.split("")).splice(-1,0,n+"%"),e.join("")):e+n+"%"},unformat:function(e){return.01*b._.stringToNumber(e)}}),b.register("format","time",{regexps:{format:/(:)/,unformat:/(:)/},format:function(e,r,t){var n=Math.floor(e/60/60),i=Math.floor((e-60*n*60)/60),e=Math.round(e-60*n*60-60*i);return n+":"+(i<10?"0"+i:i)+":"+(e<10?"0"+e:e)},unformat:function(e){var e=e.split(":"),r=0;return 3===e.length?r=(r=(r+=60*Number(e[0])*60)+60*Number(e[1]))+Number(e[2]):2===e.length&&(r=(r+=60*Number(e[0]))+Number(e[1])),Number(r)}}),b});