blob: d67c97c6eeee23c481d5d68c1a7601f409c9bc60 [file] [log] [blame]
(function(){function n(n){this._n=n}function e(n,e,t){var i,r=Math.pow(10,e);if(i=(Math.round(n*r)/r).toFixed(e),t){var a=new RegExp("0{1,"+t+"}$");i=i.replace(a,"")}return i}function t(n,e){var t;return t=e.indexOf("$")>-1?r(n,e):e.indexOf("%")>-1?a(n,e):e.indexOf(":")>-1?o(n,e):u(n,e)}function i(n,e){if(e.indexOf(":")>-1)n._n=l(e);else if(e===p)n._n=0;else{var t=e;"."!==d[h].delimiters.decimal&&(e=e.replace(/\./g,"").replace(d[h].delimiters.decimal,"."));for(var i=new RegExp(d[h].abbreviations.thousand+"(?:\\)|(\\"+d[h].currency.symbol+")?(?:\\))?)?$"),r=new RegExp(d[h].abbreviations.million+"(?:\\)|(\\"+d[h].currency.symbol+")?(?:\\))?)?$"),a=new RegExp(d[h].abbreviations.billion+"(?:\\)|(\\"+d[h].currency.symbol+")?(?:\\))?)?$"),o=new RegExp(d[h].abbreviations.trillion+"(?:\\)|(\\"+d[h].currency.symbol+")?(?:\\))?)?$"),u=["KB","MB","GB","TB","PB","EB","ZB","YB"],c=!1,f=0;f<=u.length&&!(c=e.indexOf(u[f])>-1?Math.pow(1024,f+1):!1);f++);n._n=(c?c:1)*(t.match(i)?Math.pow(10,3):1)*(t.match(r)?Math.pow(10,6):1)*(t.match(a)?Math.pow(10,9):1)*(t.match(o)?Math.pow(10,12):1)*(e.indexOf("%")>-1?.01:1)*Number((e.indexOf("(")>-1?"-":"")+e.replace(/[^0-9\.-]+/g,"")),n._n=c?Math.ceil(n._n):n._n}return n._n}function r(n,e){var i=e.indexOf("$")<=1?!0:!1,r="";e.indexOf(" $")>-1?(r=" ",e=e.replace(" $","")):e.indexOf("$ ")>-1?(r=" ",e=e.replace("$ ","")):e=e.replace("$","");var a=t(n,e);return i?a.indexOf("(")>-1||a.indexOf("-")>-1?(a=a.split(""),a.splice(1,0,d[h].currency.symbol+r),a=a.join("")):a=d[h].currency.symbol+r+a:a.indexOf(")")>-1?(a=a.split(""),a.splice(-1,0,r+d[h].currency.symbol),a=a.join("")):a=a+r+d[h].currency.symbol,a}function a(n,e){var i="";e.indexOf(" %")>-1?(i=" ",e=e.replace(" %","")):e=e.replace("%",""),n._n=100*n._n;var r=t(n,e);return r.indexOf(")")>-1?(r=r.split(""),r.splice(-1,0,i+"%"),r=r.join("")):r=r+i+"%",r}function o(n,e){var t=Math.floor(n._n/60/60),i=Math.floor((n._n-60*t*60)/60),r=Math.round(n._n-60*t*60-60*i);return t+":"+(10>i?"0"+i:i)+":"+(10>r?"0"+r:r)}function l(n){var e=n.split(":"),t=0;return 3===e.length?(t+=60*Number(e[0])*60,t+=60*Number(e[1]),t+=Number(e[2])):2===e.lenght&&(t+=60*Number(e[0]),t+=Number(e[1])),Number(t)}function u(n,t){var i=!1,r=!1,a="",o="",l="",u=Math.abs(n._n);if(0===n._n&&null!==p)return p;if(t.indexOf("(")>-1&&(i=!0,t=t.slice(1,-1)),t.indexOf("a")>-1&&(t.indexOf(" a")>-1?(a=" ",t=t.replace(" a","")):t=t.replace("a",""),u>=Math.pow(10,12)?(a+=d[h].abbreviations.trillion,n._n=n._n/Math.pow(10,12)):u<Math.pow(10,12)&&u>=Math.pow(10,9)?(a+=d[h].abbreviations.billion,n._n=n._n/Math.pow(10,9)):u<Math.pow(10,9)&&u>=Math.pow(10,6)?(a+=d[h].abbreviations.million,n._n=n._n/Math.pow(10,6)):u<Math.pow(10,6)&&u>=Math.pow(10,3)&&(a+=d[h].abbreviations.thousand,n._n=n._n/Math.pow(10,3))),t.indexOf("b")>-1){t.indexOf(" b")>-1?(o=" ",t=t.replace(" b","")):t=t.replace("b","");for(var c,f,s=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],m=0;m<=s.length;m++)if(c=Math.pow(1024,m),f=Math.pow(1024,m+1),n._n>=c&&n._n<f){o+=s[m],c>0&&(n._n=n._n/c);break}}t.indexOf("o")>-1&&(t.indexOf(" o")>-1?(l=" ",t=t.replace(" o","")):t=t.replace("o",""),l+=d[h].ordinal(n._n)),t.indexOf("[.]")>-1&&(r=!0,t=t.replace("[.]","."));var b=n._n.toString().split(".")[0],_=t.split(".")[1],x=t.indexOf(","),v="",O=!1;return _?(_.indexOf("[")>-1?(_=_.replace("]",""),_=_.split("["),v=e(n._n,_[0].length+_[1].length,_[1].length)):v=e(n._n,_.length),b=v.split(".")[0],v=v.split(".")[1].length?d[h].delimiters.decimal+v.split(".")[1]:"",r&&0===Number(v)&&(v="")):b=e(n._n,null),b.indexOf("-")>-1&&(b=b.slice(1),O=!0),x>-1&&(b=b.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+d[h].delimiters.thousands)),0===t.indexOf(".")&&(b=""),(i&&O?"(":"")+(!i&&O?"-":"")+b+v+(l?l:"")+(a?a:"")+(o?o:"")+(i&&O?")":"")}function c(n,e){d[n]=e}var f,s="1.4.7",d={},h="en",p=null,m="undefined"!=typeof module&&module.exports;f=function(e){return f.isNumeral(e)?e=e.value():Number(e)||(e=0),new n(Number(e))},f.version=s,f.isNumeral=function(e){return e instanceof n},f.language=function(n,e){return n?(n&&!e&&(h=n),(e||!d[n])&&c(n,e),f):h},f.language("en",{delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(n){var e=n%10;return 1===~~(n%100/10)?"th":1===e?"st":2===e?"nd":3===e?"rd":"th"},currency:{symbol:"$"}}),f.zeroFormat=function(n){p="string"==typeof n?n:null},f.fn=n.prototype={clone:function(){return f(this)},format:function(n){return t(this,n?n:f.defaultFormat)},unformat:function(n){return i(this,n?n:f.defaultFormat)},value:function(){return this._n},valueOf:function(){return this._n},set:function(n){return this._n=Number(n),this},add:function(n){return this._n=this._n+Number(n),this},subtract:function(n){return this._n=this._n-Number(n),this},multiply:function(n){return this._n=this._n*Number(n),this},divide:function(n){return this._n=this._n/Number(n),this},difference:function(n){var e=this._n-Number(n);return 0>e&&(e=-e),e}},m&&(module.exports=f),"undefined"==typeof ender&&(this.numeral=f),"function"==typeof define&&define.amd&&define([],function(){return f})}).call(this);