Comparing version 1.5.5 to 1.5.6
{ | ||
"name": "numeral", | ||
"repo": "adamwdraper/Numeral-js", | ||
"version": "1.5.5", | ||
"version": "1.5.6", | ||
"description": "Format and manipulate numbers.", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
{ | ||
"name": "numeral", | ||
"repo": "adamwdraper/Numeral-js", | ||
"version": "1.5.5", | ||
"version": "1.5.6", | ||
"description": "Format and manipulate numbers.", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
/*! @preserve | ||
* numeral.js | ||
* version : 1.5.5 | ||
* version : 1.5.6 | ||
* author : Adam Draper | ||
@@ -8,2 +8,2 @@ * license : MIT | ||
*/ | ||
(function(){function a(a){this._value=a}function b(a,b,c,d){var e,f,g,h,i=a.toString().split("."),j=b-(d||0);return e=2===i.length?Math.min(Math.max(i[1].length,j),b):j,g=Math.pow(10,e),h=(c(a*g)/g).toFixed(e),d>b-e&&(f=new RegExp("\\.?0{1,"+(d-(b-e))+"}$"),h=h.replace(f,"")),h}function c(a,b,c){var d;return d=b.indexOf("$")>-1?e(a,b,c):b.indexOf("%")>-1?f(a,b,c):b.indexOf(":")>-1?g(a,b):i(a._value,b,c)}function d(a,b){var c,d,e,f,g,i=b,j=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],l=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===q.zeroFormat||b===q.nullFormat)a._value=0;else{for("."!==o[q.currentLanguage].delimiters.decimal&&(b=b.replace(/\./g,"").replace(o[q.currentLanguage].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+o[q.currentLanguage].abbreviations.thousand+"(?:\\)|(\\"+o[q.currentLanguage].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+o[q.currentLanguage].abbreviations.million+"(?:\\)|(\\"+o[q.currentLanguage].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+o[q.currentLanguage].abbreviations.billion+"(?:\\)|(\\"+o[q.currentLanguage].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+o[q.currentLanguage].abbreviations.trillion+"(?:\\)|(\\"+o[q.currentLanguage].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(l=b.indexOf(j[g])>-1||b.indexOf(k[g])>-1?Math.pow(1024,g+1):!1);g++);a._value=(l?l:1)*(i.match(c)?Math.pow(10,3):1)*(i.match(d)?Math.pow(10,6):1)*(i.match(e)?Math.pow(10,9):1)*(i.match(f)?Math.pow(10,12):1)*(b.indexOf("%")>-1?.01:1)*((b.split("-").length+Math.min(b.split("(").length-1,b.split(")").length-1))%2?1:-1)*Number(b.replace(/[^0-9\.]+/g,"")),a._value=l?Math.ceil(a._value):a._value}return a._value}function e(a,b,c){var d,e,f=b.indexOf("$"),g=b.indexOf("("),h=b.indexOf("-"),j="";return b.indexOf(" $")>-1?(j=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(j=" ",b=b.replace("$ ","")):b=b.replace("$",""),e=i(a._value,b,c),1>=f?e.indexOf("(")>-1||e.indexOf("-")>-1?(e=e.split(""),d=1,(g>f||h>f)&&(d=0),e.splice(d,0,o[q.currentLanguage].currency.symbol+j),e=e.join("")):e=o[q.currentLanguage].currency.symbol+j+e:e.indexOf(")")>-1?(e=e.split(""),e.splice(-1,0,j+o[q.currentLanguage].currency.symbol),e=e.join("")):e=e+j+o[q.currentLanguage].currency.symbol,e}function f(a,b,c){var d,e="",f=100*a._value;return b.indexOf(" %")>-1?(e=" ",b=b.replace(" %","")):b=b.replace("%",""),d=i(f,b,c),d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,e+"%"),d=d.join("")):d=d+e+"%",d}function g(a){var b=Math.floor(a._value/60/60),c=Math.floor((a._value-60*b*60)/60),d=Math.round(a._value-60*b*60-60*c);return b+":"+(10>c?"0"+c:c)+":"+(10>d?"0"+d:d)}function h(a){var b=a.split(":"),c=0;return 3===b.length?(c+=60*Number(b[0])*60,c+=60*Number(b[1]),c+=Number(b[2])):2===b.length&&(c+=60*Number(b[0]),c+=Number(b[1])),Number(c)}function i(a,c,d){var e,f,g,h,i,j,k=!1,l=!1,m=!1,n="",p=!1,r=!1,s=!1,t=!1,u=!1,v="",w="",x=Math.abs(a),y=["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],z=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],A="",B=!1,C=!1;if(0===a&&null!==q.zeroFormat)return q.zeroFormat;if(null===a&&null!==q.nullFormat)return q.nullFormat;if(c.indexOf("(")>-1?(k=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(l=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(p=c.indexOf("aK")>=0,r=c.indexOf("aM")>=0,s=c.indexOf("aB")>=0,t=c.indexOf("aT")>=0,u=p||r||s||t,c.indexOf(" a")>-1&&(n=" "),c=c.replace(new RegExp(n+"a[KMBT]?"),""),x>=Math.pow(10,12)&&!u||t?(n+=o[q.currentLanguage].abbreviations.trillion,a/=Math.pow(10,12)):x<Math.pow(10,12)&&x>=Math.pow(10,9)&&!u||s?(n+=o[q.currentLanguage].abbreviations.billion,a/=Math.pow(10,9)):x<Math.pow(10,9)&&x>=Math.pow(10,6)&&!u||r?(n+=o[q.currentLanguage].abbreviations.million,a/=Math.pow(10,6)):(x<Math.pow(10,6)&&x>=Math.pow(10,3)&&!u||p)&&(n+=o[q.currentLanguage].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf("ib")>-1&&(C=!0),c.indexOf(" b")>-1||c.indexOf(" ib")>-1?(v=" ",c=c.replace(" ib","").replace(" b","")):c=c.replace("ib","").replace("b",""),g=0;g<=z.length;g++)if(e=Math.pow(1024,g),f=Math.pow(1024,g+1),a>=e&&f>a){v+=C?y[g]:z[g],e>0&&(a/=e);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(w=" ",c=c.replace(" o","")):c=c.replace("o",""),w+=o[q.currentLanguage].ordinal(a)),c.indexOf("[.]")>-1&&(m=!0,c=c.replace("[.]",".")),h=a.toString().split(".")[0],i=c.split(".")[1],j=c.indexOf(","),i?(i.indexOf("[")>-1?(i=i.replace("]",""),i=i.split("["),A=b(a,i[0].length+i[1].length,d,i[1].length)):A=b(a,i.length,d),h=A.split(".")[0],A=A.indexOf(".")>-1?o[q.currentLanguage].delimiters.decimal+A.split(".")[1]:"",m&&0===Number(A.slice(1))&&(A="")):h=b(a,null,d),h.indexOf("-")>-1&&(h=h.slice(1),B=!0),j>-1&&(h=h.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+o[q.currentLanguage].delimiters.thousands)),0===c.indexOf(".")&&(h=""),(k&&B?"(":"")+(!k&&B?"-":"")+(!B&&l?"+":"")+h+A+(w?w:"")+(n?n:"")+(v?v:"")+(k&&B?")":"")}function j(a,b){o[a]=b}function k(a){var b=a.toString().split(".");return b.length<2?1:Math.pow(10,b[1].length)}function l(){var a=Array.prototype.slice.call(arguments);return a.reduce(function(a,b){var c=k(a),d=k(b);return c>d?c:d},-(1/0))}var m,n="1.5.5",o={},p={currentLanguage:"en",zeroFormat:null,nullFormat:null,defaultFormat:"0,0"},q={currentLanguage:p.currentLanguage,zeroFormat:p.zeroFormat,nullFormat:p.nullFormat,defaultFormat:p.defaultFormat};m=function(b){return m.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:null===b?b=null:Number(b)||(b=m.fn.unformat(b)),new a(b)},m.version=n,m.isNumeral=function(b){return b instanceof a},m.language=function(a,b){if(!a)return q.currentLanguage;if(a=a.toLowerCase(),a&&!b){if(!o[a])throw new Error("Unknown language : "+a);q.currentLanguage=a}return(b||!o[a])&&j(a,b),m},m.reset=function(){for(var a in p)q[a]=p[a]},m.languageData=function(a){if(!a)return o[q.currentLanguage];if(!o[a])throw new Error("Unknown language : "+a);return o[a]},m.language("en",{delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===~~(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th"},currency:{symbol:"$"}}),m.zeroFormat=function(a){q.zeroFormat="string"==typeof a?a:null},m.nullFormat=function(a){q.nullFormat="string"==typeof a?a:null},m.defaultFormat=function(a){q.defaultFormat="string"==typeof a?a:"0.0"},m.validate=function(a,b){var c,d,e,f,g,h,i,j;if("string"!=typeof a&&(a+="",console.warn&&console.warn("Numeral.js: Value is not string. It has been co-erced to: ",a)),a=a.trim(),a.match(/^\d+$/))return!0;if(""===a)return!1;try{i=m.languageData(b)}catch(k){i=m.languageData(m.language())}return e=i.currency.symbol,g=i.abbreviations,c=i.delimiters.decimal,d="."===i.delimiters.thousands?"\\.":i.delimiters.thousands,j=a.match(/^[^\d]+/),null!==j&&(a=a.substr(1),j[0]!==e)?!1:(j=a.match(/[^\d]+$/),null!==j&&(a=a.slice(0,-1),j[0]!==g.thousand&&j[0]!==g.million&&j[0]!==g.billion&&j[0]!==g.trillion)?!1:(h=new RegExp(d+"{2}"),a.match(/[^\d.,]/g)?!1:(f=a.split(c),f.length>2?!1:f.length<2?!!f[0].match(/^\d+.*\d$/)&&!f[0].match(h):1===f[0].length?!!f[0].match(/^\d+$/)&&!f[0].match(h)&&!!f[1].match(/^\d+$/):!!f[0].match(/^\d+.*\d$/)&&!f[0].match(h)&&!!f[1].match(/^\d+$/))))},Array.prototype.reduce||(Array.prototype.reduce=function(a){"use strict";if(null===this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof a)throw new TypeError(a+" is not a function");var b,c=Object(this),d=c.length>>>0,e=0;if(2===arguments.length)b=arguments[1];else{for(;d>e&&!(e in c);)e++;if(e>=d)throw new TypeError("Reduce of empty array with no initial value");b=c[e++]}for(;d>e;e++)e in c&&(b=a(b,c[e],e,c));return b}),m.fn=a.prototype={clone:function(){return m(this)},format:function(a,b){return c(this,a?a:q.defaultFormat,void 0!==b?b:Math.round)},unformat:function(a){return"[object Number]"===Object.prototype.toString.call(a)?a:d(this,a?a:q.defaultFormat)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){function b(a,b,d,e){return a+c*b}var c=l.call(null,this._value,a);return this._value=[this._value,a].reduce(b,0)/c,this},subtract:function(a){function b(a,b,d,e){return a-c*b}var c=l.call(null,this._value,a);return this._value=[a].reduce(b,this._value*c)/c,this},multiply:function(a){function b(a,b,c,d){var e=l(a,b);return a*e*(b*e)/(e*e)}return this._value=[this._value,a].reduce(b,1),this},divide:function(a){function b(a,b,c,d){var e=l(a,b);return a*e/(b*e)}return this._value=[this._value,a].reduce(b),this},difference:function(a){return Math.abs(m(this._value).subtract(a).value())}},"undefined"!=typeof module&&module.exports&&(module.exports=m),"undefined"==typeof ender&&(this.numeral=m),"function"==typeof define&&define.amd&&define([],function(){return m})}).call(this); | ||
(function(){function a(a){this._value=a}function b(a,b,c,d){var e,f,g,h,i=a.toString().split("."),j=b-(d||0);return e=2===i.length?Math.min(Math.max(i[1].length,j),b):j,g=Math.pow(10,e),h=(c(a*g)/g).toFixed(e),d>b-e&&(f=new RegExp("\\.?0{1,"+(d-(b-e))+"}$"),h=h.replace(f,"")),h}function c(a,b,c){var j;return j=0===a._value&&null!==s.zeroFormat?s.zeroFormat:null===a._value&&null!==s.nullFormat?s.nullFormat:b.indexOf("$")>-1?d(a,b,c):b.indexOf("%")>-1?e(a,b,c):b.indexOf(":")>-1?h(a,b):b.indexOf("b")>-1||b.indexOf("ib")>-1?f(a,b,c):b.indexOf("o")>-1?g(a,b,c):i(a._value,b,c)}function d(a,b,c){var d,e,f=b.indexOf("$"),g=b.indexOf("("),h=b.indexOf("-"),j="";return b.indexOf(" $")>-1?(j=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(j=" ",b=b.replace("$ ","")):b=b.replace("$",""),e=i(a._value,b,c,!1),1>=f?e.indexOf("(")>-1||e.indexOf("-")>-1?(e=e.split(""),d=1,(g>f||h>f)&&(d=0),e.splice(d,0,q[s.currentLanguage].currency.symbol+j),e=e.join("")):e=q[s.currentLanguage].currency.symbol+j+e:e.indexOf(")")>-1?(e=e.split(""),e.splice(-1,0,j+q[s.currentLanguage].currency.symbol),e=e.join("")):e=e+j+q[s.currentLanguage].currency.symbol,e}function e(a,b,c){var d,e="",f=100*a._value;return b.indexOf(" %")>-1?(e=" ",b=b.replace(" %","")):b=b.replace("%",""),d=i(f,b,c),d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,e+"%"),d=d.join("")):d=d+e+"%",d}function f(a,b,c){var d,e,f,g,h=b.indexOf("ib")>-1?t.iec:t.bytes,j=a._value,k="";for(b.indexOf(" b")>-1||b.indexOf(" ib")>-1?(k=" ",b=b.replace(" ib","").replace(" b","")):b=b.replace("ib","").replace("b",""),e=0;e<=h.length;e++)if(f=Math.pow(1024,e),g=Math.pow(1024,e+1),null===j||0===j||j>=f&&g>j){k+=h[e],f>0&&(j/=f);break}return d=i(j,b,c),d+k}function g(a,b,c){var d,e="";return b.indexOf(" o")>-1?(e=" ",b=b.replace(" o","")):b=b.replace("o",""),e+=q[s.currentLanguage].ordinal(a._value),d=i(a._value,b,c),d+e}function h(a){var b=Math.floor(a._value/60/60),c=Math.floor((a._value-60*b*60)/60),d=Math.round(a._value-60*b*60-60*c);return b+":"+(10>c?"0"+c:c)+":"+(10>d?"0"+d:d)}function i(a,c,d){var e,f,g,h,i=!1,j=!1,k=!1,l="",m=!1,n=!1,o=!1,p=!1,r=!1,t="",u=!1;return null===a&&(a=0),e=Math.abs(a),c.indexOf("(")>-1?(i=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(j=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(m=c.indexOf("aK")>=0,n=c.indexOf("aM")>=0,o=c.indexOf("aB")>=0,p=c.indexOf("aT")>=0,r=m||n||o||p,c.indexOf(" a")>-1&&(l=" "),c=c.replace(new RegExp(l+"a[KMBT]?"),""),e>=Math.pow(10,12)&&!r||p?(l+=q[s.currentLanguage].abbreviations.trillion,a/=Math.pow(10,12)):e<Math.pow(10,12)&&e>=Math.pow(10,9)&&!r||o?(l+=q[s.currentLanguage].abbreviations.billion,a/=Math.pow(10,9)):e<Math.pow(10,9)&&e>=Math.pow(10,6)&&!r||n?(l+=q[s.currentLanguage].abbreviations.million,a/=Math.pow(10,6)):(e<Math.pow(10,6)&&e>=Math.pow(10,3)&&!r||m)&&(l+=q[s.currentLanguage].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("[.]")>-1&&(k=!0,c=c.replace("[.]",".")),f=a.toString().split(".")[0],g=c.split(".")[1],h=c.indexOf(","),g?(g.indexOf("[")>-1?(g=g.replace("]",""),g=g.split("["),t=b(a,g[0].length+g[1].length,d,g[1].length)):t=b(a,g.length,d),f=t.split(".")[0],t=t.indexOf(".")>-1?q[s.currentLanguage].delimiters.decimal+t.split(".")[1]:"",k&&0===Number(t.slice(1))&&(t="")):f=b(a,null,d),f.indexOf("-")>-1&&(f=f.slice(1),u=!0),h>-1&&(f=f.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+q[s.currentLanguage].delimiters.thousands)),0===c.indexOf(".")&&(f=""),(i&&u?"(":"")+(!i&&u?"-":"")+(!u&&j?"+":"")+f+t+(l?l:"")+(i&&u?")":"")}function j(a,b){var c,d,e,f,g,h,i=b,j=!1;if(b.indexOf(":")>-1)h=k(b);else if(b===s.zeroFormat||b===s.nullFormat)h=0;else{for("."!==q[s.currentLanguage].delimiters.decimal&&(b=b.replace(/\./g,"").replace(q[s.currentLanguage].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+q[s.currentLanguage].abbreviations.thousand+"(?:\\)|(\\"+q[s.currentLanguage].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+q[s.currentLanguage].abbreviations.million+"(?:\\)|(\\"+q[s.currentLanguage].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+q[s.currentLanguage].abbreviations.billion+"(?:\\)|(\\"+q[s.currentLanguage].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+q[s.currentLanguage].abbreviations.trillion+"(?:\\)|(\\"+q[s.currentLanguage].currency.symbol+")?(?:\\))?)?$"),g=1;g<=t.bytes.length&&!(j=b.indexOf(t.bytes[g])>-1||b.indexOf(t.iec[g])>-1?Math.pow(1024,g):!1);g++);h=j?j:1,h*=i.match(c)?Math.pow(10,3):1,h*=i.match(d)?Math.pow(10,6):1,h*=i.match(e)?Math.pow(10,9):1,h*=i.match(f)?Math.pow(10,12):1,h*=b.indexOf("%")>-1?.01:1,h*=(b.split("-").length+Math.min(b.split("(").length-1,b.split(")").length-1))%2?1:-1,h*=Number(b.replace(/[^0-9\.]+/g,"")),h=j?Math.ceil(h):h}return a._value=h,a._value}function k(a){var b=a.split(":"),c=0;return 3===b.length?(c+=60*Number(b[0])*60,c+=60*Number(b[1]),c+=Number(b[2])):2===b.length&&(c+=60*Number(b[0]),c+=Number(b[1])),Number(c)}function l(a,b){q[a]=b}function m(a){var b=a.toString().split(".");return b.length<2?1:Math.pow(10,b[1].length)}function n(){var a=Array.prototype.slice.call(arguments);return a.reduce(function(a,b){var c=m(a),d=m(b);return c>d?c:d},-(1/0))}var o,p="1.5.5",q={},r={currentLanguage:"en",zeroFormat:null,nullFormat:null,defaultFormat:"0,0"},s={currentLanguage:r.currentLanguage,zeroFormat:r.zeroFormat,nullFormat:r.nullFormat,defaultFormat:r.defaultFormat},t={bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"],iec:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]};o=function(b){return b=o.isNumeral(b)?b.value():0===b||"undefined"==typeof b?0:null===b?null:Number(b)?Number(b):o.fn.unformat(b),new a(b)},o.version=p,o.isNumeral=function(b){return b instanceof a},o.language=function(a,b){if(!a)return s.currentLanguage;if(a=a.toLowerCase(),a&&!b){if(!q[a])throw new Error("Unknown language : "+a);s.currentLanguage=a}return(b||!q[a])&&l(a,b),o},o.reset=function(){for(var a in r)s[a]=r[a]},o.languageData=function(a){if(!a)return q[s.currentLanguage];if(!q[a])throw new Error("Unknown language : "+a);return q[a]},o.language("en",{delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===~~(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th"},currency:{symbol:"$"}}),o.zeroFormat=function(a){s.zeroFormat="string"==typeof a?a:null},o.nullFormat=function(a){s.nullFormat="string"==typeof a?a:null},o.defaultFormat=function(a){s.defaultFormat="string"==typeof a?a:"0.0"},o.validate=function(a,b){var c,d,e,f,g,h,i,j;if("string"!=typeof a&&(a+="",console.warn&&console.warn("Numeral.js: Value is not string. It has been co-erced to: ",a)),a=a.trim(),a.match(/^\d+$/))return!0;if(""===a)return!1;try{i=o.languageData(b)}catch(k){i=o.languageData(o.language())}return e=i.currency.symbol,g=i.abbreviations,c=i.delimiters.decimal,d="."===i.delimiters.thousands?"\\.":i.delimiters.thousands,j=a.match(/^[^\d]+/),null!==j&&(a=a.substr(1),j[0]!==e)?!1:(j=a.match(/[^\d]+$/),null!==j&&(a=a.slice(0,-1),j[0]!==g.thousand&&j[0]!==g.million&&j[0]!==g.billion&&j[0]!==g.trillion)?!1:(h=new RegExp(d+"{2}"),a.match(/[^\d.,]/g)?!1:(f=a.split(c),f.length>2?!1:f.length<2?!!f[0].match(/^\d+.*\d$/)&&!f[0].match(h):1===f[0].length?!!f[0].match(/^\d+$/)&&!f[0].match(h)&&!!f[1].match(/^\d+$/):!!f[0].match(/^\d+.*\d$/)&&!f[0].match(h)&&!!f[1].match(/^\d+$/))))},Array.prototype.reduce||(Array.prototype.reduce=function(a){"use strict";if(null===this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof a)throw new TypeError(a+" is not a function");var b,c=Object(this),d=c.length>>>0,e=0;if(2===arguments.length)b=arguments[1];else{for(;d>e&&!(e in c);)e++;if(e>=d)throw new TypeError("Reduce of empty array with no initial value");b=c[e++]}for(;d>e;e++)e in c&&(b=a(b,c[e],e,c));return b}),o.fn=a.prototype={clone:function(){return o(this)},format:function(a,b){return c(this,a?a:s.defaultFormat,void 0!==b?b:Math.round)},unformat:function(a){return"[object Number]"===Object.prototype.toString.call(a)?a:j(this,a?a:s.defaultFormat)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){function b(a,b,d,e){return a+c*b}var c=n.call(null,this._value,a);return this._value=[this._value,a].reduce(b,0)/c,this},subtract:function(a){function b(a,b,d,e){return a-c*b}var c=n.call(null,this._value,a);return this._value=[a].reduce(b,this._value*c)/c,this},multiply:function(a){function b(a,b,c,d){var e=n(a,b);return a*e*(b*e)/(e*e)}return this._value=[this._value,a].reduce(b,1),this},divide:function(a){function b(a,b,c,d){var e=n(a,b);return a*e/(b*e)}return this._value=[this._value,a].reduce(b),this},difference:function(a){return Math.abs(o(this._value).subtract(a).value())}},"undefined"!=typeof module&&module.exports&&(module.exports=o),"undefined"==typeof ender&&(this.numeral=o),"function"==typeof define&&define.amd&&define([],function(){return o})}).call(this); |
460
numeral.js
/*! @preserve | ||
* numeral.js | ||
* version : 1.5.5 | ||
* version : 1.5.6 | ||
* author : Adam Draper | ||
@@ -16,3 +16,3 @@ * license : MIT | ||
var numeral, | ||
VERSION = '1.5.5', | ||
VERSION = '1.5.6', | ||
// internal storage for language config files | ||
@@ -31,2 +31,6 @@ languages = {}, | ||
defaultFormat: defaults.defaultFormat | ||
}, | ||
byteSuffixes = { | ||
bytes: ['B','KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | ||
iec: ['B','KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] | ||
}; | ||
@@ -88,62 +92,24 @@ | ||
// figure out what kind of format we are dealing with | ||
if (format.indexOf('$') > -1) { // currency!!!!! | ||
output = formatCurrency(n, format, roundingFunction); | ||
} else if (format.indexOf('%') > -1) { // percentage | ||
output = formatPercentage(n, format, roundingFunction); | ||
} else if (format.indexOf(':') > -1) { // time | ||
output = formatTime(n, format); | ||
} else { // plain ol' numbers or bytes | ||
output = formatNumber(n._value, format, roundingFunction); | ||
} | ||
// return string | ||
return output; | ||
} | ||
// revert to number | ||
function unformatNumeral(n, string) { | ||
var stringOriginal = string, | ||
thousandRegExp, | ||
millionRegExp, | ||
billionRegExp, | ||
trillionRegExp, | ||
suffixes = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | ||
iecSuffixes = ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'], | ||
bytesMultiplier = false, | ||
power; | ||
if (string.indexOf(':') > -1) { | ||
n._value = unformatTime(string); | ||
if (n._value === 0 && options.zeroFormat !== null) { | ||
output = options.zeroFormat; | ||
} else if (n._value === null && options.nullFormat !== null) { | ||
output = options.nullFormat; | ||
} else { | ||
if (string === options.zeroFormat || string === options.nullFormat) { | ||
n._value = 0; | ||
// figure out what kind of format we are dealing with | ||
if (format.indexOf('$') > -1) { | ||
output = formatCurrency(n, format, roundingFunction); | ||
} else if (format.indexOf('%') > -1) { | ||
output = formatPercentage(n, format, roundingFunction); | ||
} else if (format.indexOf(':') > -1) { | ||
output = formatTime(n, format); | ||
} else if (format.indexOf('b') > -1 || format.indexOf('ib') > -1) { | ||
output = formatBytes(n, format, roundingFunction); | ||
} else if (format.indexOf('o') > -1) { | ||
output = formatOrdinal(n, format, roundingFunction); | ||
} else { | ||
if (languages[options.currentLanguage].delimiters.decimal !== '.') { | ||
string = string.replace(/\./g, '').replace(languages[options.currentLanguage].delimiters.decimal, '.'); | ||
} | ||
// see if abbreviations are there so that we can multiply to the correct number | ||
thousandRegExp = new RegExp('[^a-zA-Z]' + languages[options.currentLanguage].abbreviations.thousand + '(?:\\)|(\\' + languages[options.currentLanguage].currency.symbol + ')?(?:\\))?)?$'); | ||
millionRegExp = new RegExp('[^a-zA-Z]' + languages[options.currentLanguage].abbreviations.million + '(?:\\)|(\\' + languages[options.currentLanguage].currency.symbol + ')?(?:\\))?)?$'); | ||
billionRegExp = new RegExp('[^a-zA-Z]' + languages[options.currentLanguage].abbreviations.billion + '(?:\\)|(\\' + languages[options.currentLanguage].currency.symbol + ')?(?:\\))?)?$'); | ||
trillionRegExp = new RegExp('[^a-zA-Z]' + languages[options.currentLanguage].abbreviations.trillion + '(?:\\)|(\\' + languages[options.currentLanguage].currency.symbol + ')?(?:\\))?)?$'); | ||
// see if bytes are there so that we can multiply to the correct number | ||
for (power = 0; power <= suffixes.length; power++) { | ||
bytesMultiplier = ((string.indexOf(suffixes[power]) > -1) || (string.indexOf(iecSuffixes[power]) > -1))? Math.pow(1024, power + 1) : false; | ||
if (bytesMultiplier) { | ||
break; | ||
} | ||
} | ||
// do some math to create our number | ||
n._value = ((bytesMultiplier) ? bytesMultiplier : 1) * ((stringOriginal.match(thousandRegExp)) ? Math.pow(10, 3) : 1) * ((stringOriginal.match(millionRegExp)) ? Math.pow(10, 6) : 1) * ((stringOriginal.match(billionRegExp)) ? Math.pow(10, 9) : 1) * ((stringOriginal.match(trillionRegExp)) ? Math.pow(10, 12) : 1) * ((string.indexOf('%') > -1) ? 0.01 : 1) * (((string.split('-').length + Math.min(string.split('(').length - 1, string.split(')').length - 1)) % 2) ? 1 : -1) * Number(string.replace(/[^0-9\.]+/g, '')); | ||
// round if we are talking about bytes | ||
n._value = (bytesMultiplier) ? Math.ceil(n._value) : n._value; | ||
output = formatNumber(n._value, format, roundingFunction); | ||
} | ||
} | ||
return n._value; | ||
return output; | ||
} | ||
@@ -171,3 +137,3 @@ | ||
// format the number | ||
output = formatNumber(n._value, format, roundingFunction); | ||
output = formatNumber(n._value, format, roundingFunction, false); | ||
@@ -227,2 +193,58 @@ // position the symbol | ||
function formatBytes(n, format, roundingFunction) { | ||
var output, | ||
suffixes = format.indexOf('ib') > -1 ? byteSuffixes.iec : byteSuffixes.bytes, | ||
value = n._value, | ||
suffix = '', | ||
power, | ||
min, | ||
max; | ||
// check for space before | ||
if (format.indexOf(' b') > -1 || format.indexOf(' ib') > -1) { | ||
suffix = ' '; | ||
format = format.replace(' ib', '').replace(' b', ''); | ||
} else { | ||
format = format.replace('ib', '').replace('b', ''); | ||
} | ||
for (power = 0; power <= suffixes.length; power++) { | ||
min = Math.pow(1024, power); | ||
max = Math.pow(1024, power + 1); | ||
if (value === null || value === 0 || value >= min && value < max) { | ||
suffix += suffixes[power]; | ||
if (min > 0) { | ||
value = value / min; | ||
} | ||
break; | ||
} | ||
} | ||
output = formatNumber(value, format, roundingFunction); | ||
return output + suffix; | ||
} | ||
function formatOrdinal(n, format, roundingFunction) { | ||
var output, | ||
ordinal = ''; | ||
// check for space before | ||
if (format.indexOf(' o') > -1) { | ||
ordinal = ' '; | ||
format = format.replace(' o', ''); | ||
} else { | ||
format = format.replace('o', ''); | ||
} | ||
ordinal += languages[options.currentLanguage].ordinal(n._value); | ||
output = formatNumber(n._value, format, roundingFunction); | ||
return output + ordinal; | ||
} | ||
function formatTime(n) { | ||
@@ -232,31 +254,6 @@ var hours = Math.floor(n._value / 60 / 60), | ||
seconds = Math.round(n._value - (hours * 60 * 60) - (minutes * 60)); | ||
return hours + ':' + ((minutes < 10) ? '0' + minutes : minutes) + ':' + ((seconds < 10) ? '0' + seconds : seconds); | ||
} | ||
function unformatTime(string) { | ||
var timeArray = string.split(':'), | ||
seconds = 0; | ||
// turn hours and minutes into seconds and add them all up | ||
if (timeArray.length === 3) { | ||
// hours | ||
seconds = seconds + (Number(timeArray[0]) * 60 * 60); | ||
// minutes | ||
seconds = seconds + (Number(timeArray[1]) * 60); | ||
// seconds | ||
seconds = seconds + Number(timeArray[2]); | ||
} else if (timeArray.length === 2) { | ||
// minutes | ||
seconds = seconds + (Number(timeArray[0]) * 60); | ||
// seconds | ||
seconds = seconds + Number(timeArray[1]); | ||
} | ||
return Number(seconds); | ||
} | ||
/* format keys: | ||
* a - abbreviation | ||
* ib - binary bytes | ||
* b - decimal bytes | ||
* o - ordinal | ||
*/ | ||
function formatNumber(value, format, roundingFunction) { | ||
@@ -272,7 +269,3 @@ var negP = false, | ||
abbrForce = false, // force abbreviation | ||
bytes = '', | ||
ord = '', | ||
abs = Math.abs(value), | ||
iecSuffixes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'], | ||
suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | ||
abs, | ||
min, | ||
@@ -285,150 +278,189 @@ max, | ||
d = '', | ||
neg = false, | ||
iecBinary = false; | ||
neg = false; | ||
// check if number is zero and a custom zero format has been set | ||
if (value === 0 && options.zeroFormat !== null) { | ||
return options.zeroFormat; | ||
} else if (value === null && options.nullFormat !== null) { | ||
return options.nullFormat; | ||
} else { | ||
// see if we should use parentheses for negative number or if we should prefix with a sign | ||
// if both are present we default to parentheses | ||
if (format.indexOf('(') > -1) { | ||
negP = true; | ||
format = format.slice(1, -1); | ||
} else if (format.indexOf('+') > -1) { | ||
signed = true; | ||
format = format.replace(/\+/g, ''); | ||
} | ||
if (value === null) { | ||
value = 0; | ||
} | ||
// see if abbreviation is wanted | ||
if (format.indexOf('a') > -1) { | ||
// check if abbreviation is specified | ||
abbrK = format.indexOf('aK') >= 0; | ||
abbrM = format.indexOf('aM') >= 0; | ||
abbrB = format.indexOf('aB') >= 0; | ||
abbrT = format.indexOf('aT') >= 0; | ||
abbrForce = abbrK || abbrM || abbrB || abbrT; | ||
abs = Math.abs(value); | ||
// check for space before abbreviation | ||
if (format.indexOf(' a') > -1) { | ||
abbr = ' '; | ||
} | ||
// see if we should use parentheses for negative number or if we should prefix with a sign | ||
// if both are present we default to parentheses | ||
if (format.indexOf('(') > -1) { | ||
negP = true; | ||
format = format.slice(1, -1); | ||
} else if (format.indexOf('+') > -1) { | ||
signed = true; | ||
format = format.replace(/\+/g, ''); | ||
} | ||
format = format.replace(new RegExp(abbr + 'a[KMBT]?'), ''); | ||
// see if abbreviation is wanted | ||
if (format.indexOf('a') > -1) { | ||
// check if abbreviation is specified | ||
abbrK = format.indexOf('aK') >= 0; | ||
abbrM = format.indexOf('aM') >= 0; | ||
abbrB = format.indexOf('aB') >= 0; | ||
abbrT = format.indexOf('aT') >= 0; | ||
abbrForce = abbrK || abbrM || abbrB || abbrT; | ||
if (abs >= Math.pow(10, 12) && !abbrForce || abbrT) { | ||
// trillion | ||
abbr = abbr + languages[options.currentLanguage].abbreviations.trillion; | ||
value = value / Math.pow(10, 12); | ||
} else if (abs < Math.pow(10, 12) && abs >= Math.pow(10, 9) && !abbrForce || abbrB) { | ||
// billion | ||
abbr = abbr + languages[options.currentLanguage].abbreviations.billion; | ||
value = value / Math.pow(10, 9); | ||
} else if (abs < Math.pow(10, 9) && abs >= Math.pow(10, 6) && !abbrForce || abbrM) { | ||
// million | ||
abbr = abbr + languages[options.currentLanguage].abbreviations.million; | ||
value = value / Math.pow(10, 6); | ||
} else if (abs < Math.pow(10, 6) && abs >= Math.pow(10, 3) && !abbrForce || abbrK) { | ||
// thousand | ||
abbr = abbr + languages[options.currentLanguage].abbreviations.thousand; | ||
value = value / Math.pow(10, 3); | ||
} | ||
// check for space before abbreviation | ||
if (format.indexOf(' a') > -1) { | ||
abbr = ' '; | ||
} | ||
// see if we are formatting bytes | ||
if (format.indexOf('b') > -1) { | ||
format = format.replace(new RegExp(abbr + 'a[KMBT]?'), ''); | ||
// check for IEC Binary byte notation | ||
if (format.indexOf('ib') > -1) { | ||
iecBinary = true; | ||
} | ||
if (abs >= Math.pow(10, 12) && !abbrForce || abbrT) { | ||
// trillion | ||
abbr = abbr + languages[options.currentLanguage].abbreviations.trillion; | ||
value = value / Math.pow(10, 12); | ||
} else if (abs < Math.pow(10, 12) && abs >= Math.pow(10, 9) && !abbrForce || abbrB) { | ||
// billion | ||
abbr = abbr + languages[options.currentLanguage].abbreviations.billion; | ||
value = value / Math.pow(10, 9); | ||
} else if (abs < Math.pow(10, 9) && abs >= Math.pow(10, 6) && !abbrForce || abbrM) { | ||
// million | ||
abbr = abbr + languages[options.currentLanguage].abbreviations.million; | ||
value = value / Math.pow(10, 6); | ||
} else if (abs < Math.pow(10, 6) && abs >= Math.pow(10, 3) && !abbrForce || abbrK) { | ||
// thousand | ||
abbr = abbr + languages[options.currentLanguage].abbreviations.thousand; | ||
value = value / Math.pow(10, 3); | ||
} | ||
} | ||
// check for space before | ||
if (format.indexOf(' b') > -1 || format.indexOf(' ib') > -1) { | ||
bytes = ' '; | ||
format = format.replace(' ib', '').replace(' b', ''); | ||
} else { | ||
format = format.replace('ib', '').replace('b', ''); | ||
} | ||
for (power = 0; power <= suffixes.length; power++) { | ||
min = Math.pow(1024, power); | ||
max = Math.pow(1024, power+1); | ||
if (format.indexOf('[.]') > -1) { | ||
optDec = true; | ||
format = format.replace('[.]', '.'); | ||
} | ||
if (value >= min && value < max) { | ||
bytes = bytes + (iecBinary ? iecSuffixes[power] : suffixes[power]); | ||
if (min > 0) { | ||
value = value / min; | ||
} | ||
break; | ||
} | ||
} | ||
w = value.toString().split('.')[0]; | ||
precision = format.split('.')[1]; | ||
thousands = format.indexOf(','); | ||
if (precision) { | ||
if (precision.indexOf('[') > -1) { | ||
precision = precision.replace(']', ''); | ||
precision = precision.split('['); | ||
d = toFixed(value, (precision[0].length + precision[1].length), roundingFunction, precision[1].length); | ||
} else { | ||
d = toFixed(value, precision.length, roundingFunction); | ||
} | ||
// see if ordinal is wanted | ||
if (format.indexOf('o') > -1) { | ||
// check for space before | ||
if (format.indexOf(' o') > -1) { | ||
ord = ' '; | ||
format = format.replace(' o', ''); | ||
} else { | ||
format = format.replace('o', ''); | ||
} | ||
w = d.split('.')[0]; | ||
ord = ord + languages[options.currentLanguage].ordinal(value); | ||
if (d.indexOf('.') > -1) { | ||
d = languages[options.currentLanguage].delimiters.decimal + d.split('.')[1]; | ||
} else { | ||
d = ''; | ||
} | ||
if (format.indexOf('[.]') > -1) { | ||
optDec = true; | ||
format = format.replace('[.]', '.'); | ||
if (optDec && Number(d.slice(1)) === 0) { | ||
d = ''; | ||
} | ||
} else { | ||
w = toFixed(value, null, roundingFunction); | ||
} | ||
w = value.toString().split('.')[0]; | ||
precision = format.split('.')[1]; | ||
thousands = format.indexOf(','); | ||
// format number | ||
if (w.indexOf('-') > -1) { | ||
w = w.slice(1); | ||
neg = true; | ||
} | ||
if (precision) { | ||
if (precision.indexOf('[') > -1) { | ||
precision = precision.replace(']', ''); | ||
precision = precision.split('['); | ||
d = toFixed(value, (precision[0].length + precision[1].length), roundingFunction, precision[1].length); | ||
} else { | ||
d = toFixed(value, precision.length, roundingFunction); | ||
} | ||
if (thousands > -1) { | ||
w = w.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + languages[options.currentLanguage].delimiters.thousands); | ||
} | ||
w = d.split('.')[0]; | ||
if (format.indexOf('.') === 0) { | ||
w = ''; | ||
} | ||
if (d.indexOf('.') > -1) { | ||
d = languages[options.currentLanguage].delimiters.decimal + d.split('.')[1]; | ||
} else { | ||
d = ''; | ||
return ((negP && neg) ? '(' : '') + ((!negP && neg) ? '-' : '') + ((!neg && signed) ? '+' : '') + w + d + ((abbr) ? abbr : '') + ((negP && neg) ? ')' : ''); | ||
} | ||
/************************************ | ||
Unformatting | ||
************************************/ | ||
// revert to number | ||
function unformatNumeral(n, string) { | ||
var stringOriginal = string, | ||
thousandRegExp, | ||
millionRegExp, | ||
billionRegExp, | ||
trillionRegExp, | ||
bytesMultiplier = false, | ||
power, | ||
value; | ||
if (string.indexOf(':') > -1) { | ||
value = unformatTime(string); | ||
} else { | ||
if (string === options.zeroFormat || string === options.nullFormat) { | ||
value = 0; | ||
} else { | ||
if (languages[options.currentLanguage].delimiters.decimal !== '.') { | ||
string = string.replace(/\./g, '').replace(languages[options.currentLanguage].delimiters.decimal, '.'); | ||
} | ||
if (optDec && Number(d.slice(1)) === 0) { | ||
d = ''; | ||
// see if abbreviations are there so that we can multiply to the correct number | ||
thousandRegExp = new RegExp('[^a-zA-Z]' + languages[options.currentLanguage].abbreviations.thousand + '(?:\\)|(\\' + languages[options.currentLanguage].currency.symbol + ')?(?:\\))?)?$'); | ||
millionRegExp = new RegExp('[^a-zA-Z]' + languages[options.currentLanguage].abbreviations.million + '(?:\\)|(\\' + languages[options.currentLanguage].currency.symbol + ')?(?:\\))?)?$'); | ||
billionRegExp = new RegExp('[^a-zA-Z]' + languages[options.currentLanguage].abbreviations.billion + '(?:\\)|(\\' + languages[options.currentLanguage].currency.symbol + ')?(?:\\))?)?$'); | ||
trillionRegExp = new RegExp('[^a-zA-Z]' + languages[options.currentLanguage].abbreviations.trillion + '(?:\\)|(\\' + languages[options.currentLanguage].currency.symbol + ')?(?:\\))?)?$'); | ||
// see if bytes are there so that we can multiply to the correct number | ||
for (power = 1; power <= byteSuffixes.bytes.length; power++) { | ||
bytesMultiplier = ((string.indexOf(byteSuffixes.bytes[power]) > -1) || (string.indexOf(byteSuffixes.iec[power]) > -1))? Math.pow(1024, power) : false; | ||
if (bytesMultiplier) { | ||
break; | ||
} | ||
} | ||
} else { | ||
w = toFixed(value, null, roundingFunction); | ||
} | ||
// format number | ||
if (w.indexOf('-') > -1) { | ||
w = w.slice(1); | ||
neg = true; | ||
// do some math to create our number | ||
value = bytesMultiplier ? bytesMultiplier : 1; | ||
value *= stringOriginal.match(thousandRegExp) ? Math.pow(10, 3) : 1; | ||
value *= stringOriginal.match(millionRegExp) ? Math.pow(10, 6) : 1; | ||
value *= stringOriginal.match(billionRegExp) ? Math.pow(10, 9) : 1; | ||
value *= stringOriginal.match(trillionRegExp) ? Math.pow(10, 12) : 1; | ||
// check for percentage | ||
value *= string.indexOf('%') > -1 ? 0.01 : 1; | ||
// check for negative number | ||
value *= (string.split('-').length + Math.min(string.split('(').length - 1, string.split(')').length - 1)) % 2 ? 1 : -1; | ||
// remove non numbers | ||
value *= Number(string.replace(/[^0-9\.]+/g, '')); | ||
// round if we are talking about bytes | ||
value = bytesMultiplier ? Math.ceil(value) : value; | ||
} | ||
} | ||
if (thousands > -1) { | ||
w = w.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + languages[options.currentLanguage].delimiters.thousands); | ||
} | ||
n._value = value; | ||
if (format.indexOf('.') === 0) { | ||
w = ''; | ||
} | ||
return ((negP && neg) ? '(' : '') + ((!negP && neg) ? '-' : '') + ((!neg && signed) ? '+' : '') + w + d + ((ord) ? ord : '') + ((abbr) ? abbr : '') + ((bytes) ? bytes : '') + ((negP && neg) ? ')' : ''); | ||
return n._value; | ||
} | ||
function unformatTime(string) { | ||
var timeArray = string.split(':'), | ||
seconds = 0; | ||
// turn hours and minutes into seconds and add them all up | ||
if (timeArray.length === 3) { | ||
// hours | ||
seconds = seconds + (Number(timeArray[0]) * 60 * 60); | ||
// minutes | ||
seconds = seconds + (Number(timeArray[1]) * 60); | ||
// seconds | ||
seconds = seconds + Number(timeArray[2]); | ||
} else if (timeArray.length === 2) { | ||
// minutes | ||
seconds = seconds + (Number(timeArray[0]) * 60); | ||
// seconds | ||
seconds = seconds + Number(timeArray[1]); | ||
} | ||
return Number(seconds); | ||
} | ||
/************************************ | ||
@@ -447,2 +479,4 @@ Top Level Functions | ||
input = numeral.fn.unformat(input); | ||
} else { | ||
input = Number(input); | ||
} | ||
@@ -544,3 +578,2 @@ | ||
numeral.validate = function(val, culture) { | ||
var _decimalSep, | ||
@@ -725,13 +758,14 @@ _thousandSep, | ||
format : function (inputString, roundingFunction) { | ||
format: function (inputString, roundingFunction) { | ||
return formatNumeral(this, | ||
inputString ? inputString : options.defaultFormat, | ||
(roundingFunction !== undefined) ? roundingFunction : Math.round | ||
); | ||
inputString ? inputString : options.defaultFormat, | ||
roundingFunction !== undefined ? roundingFunction : Math.round | ||
); | ||
}, | ||
unformat : function (inputString) { | ||
unformat: function (inputString) { | ||
if (Object.prototype.toString.call(inputString) === '[object Number]') { | ||
return inputString; | ||
} | ||
return unformatNumeral(this, inputString ? inputString : options.defaultFormat); | ||
@@ -738,0 +772,0 @@ }, |
{ | ||
"name": "numeral", | ||
"version": "1.5.5", | ||
"version": "1.5.6", | ||
"description": "Format and manipulate numbers.", | ||
@@ -5,0 +5,0 @@ "homepage": "http://numeraljs.com", |
@@ -20,3 +20,3 @@ # [Numeral.js](http://numeraljs.com/) | ||
#### Please submit all pull requests to the `develop` branch. | ||
#### Important: Please create your branch from and submit pull requests to the `develop` branch. | ||
@@ -51,4 +51,12 @@ 1. Fork the library | ||
### 1.5.6 | ||
Bug fix: numeral converts strings to numbers | ||
Bug fix: Null values return same as 0 | ||
### 1.5.5 | ||
Contained breaking changes, recommended to use 1.5.6 | ||
Bug fix: Switch bytes back to `b` and change iecBinary to `ib`, and calculate both using 1024 for backwards compatibility | ||
@@ -58,2 +66,4 @@ | ||
Contained breaking changes, recommended to use 1.5.6 | ||
Tests: Changed all tests to use Mocha and Chai | ||
@@ -60,0 +70,0 @@ |
@@ -22,19 +22,13 @@ | ||
describe('Value', function() { | ||
it('should return a value', function() { | ||
it('should return a value as correct type', function() { | ||
var tests = [ | ||
'0,0.00', | ||
'$0,0.00', | ||
'0b', | ||
'0,0%', | ||
'00:00:00' | ||
[1234.56,'number'], | ||
['1234.56','number'], | ||
[0,'number'], | ||
[null,'object'] | ||
], | ||
value = 12345.6, | ||
n = numeral(value), | ||
format, | ||
test; | ||
i; | ||
for (i = 0; i < tests.length; i++) { | ||
format = n.format(tests[i]); | ||
expect(n.value()).to.equal(value); | ||
expect(typeof numeral(tests[i][0]).value()).to.equal(tests[i][1]); | ||
} | ||
@@ -47,2 +41,5 @@ }); | ||
var tests = [ | ||
[0, null, '0'], | ||
[0, '0.00', '0.00'], | ||
[null, null, '0'], | ||
[10000,'0,0.0000','10,000.0000'], | ||
@@ -74,2 +71,9 @@ [10000.23,'0,0','10,000'], | ||
[1.0501,'0.00[0]','1.05'], | ||
// ordinals | ||
[1,'0o','1st'], | ||
[52,'0 o','52 nd'], | ||
[23,'0o','23rd'], | ||
[100,'0o','100th'], | ||
[1234,'0,0o','1,234th'], | ||
// abbreviations | ||
[2000000000,'0.0a','2.0b'], | ||
@@ -79,10 +83,5 @@ [1230974,'0.0a','1.2m'], | ||
[-104000,'0 a','-104 k'], | ||
[1,'0o','1st'], | ||
[52,'0 o','52 nd'], | ||
[23,'0o','23rd'], | ||
[100,'0o','100th'], | ||
// specified abbreviations | ||
// forced abbreviations | ||
[-5444333222111, '0,0 aK', '-5,444,333,222 k'], | ||
[-5444333222111, '0,0 aM', '-5,444,333 m'], | ||
[5444333222111, '0,0 aM', '5,444,333 m'], | ||
[-5444333222111, '0,0 aB', '-5,444 b'], | ||
@@ -92,6 +91,13 @@ [-5444333222111, '0,0 aT', '-5 t'], | ||
], | ||
i; | ||
i, | ||
n, | ||
output; | ||
for (i = 0; i < tests.length; i++) { | ||
expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); | ||
n = numeral(tests[i][0]); | ||
output = n.format(tests[i][1]); | ||
expect(output).to.equal(tests[i][2]); | ||
expect(typeof output).to.equal('string'); | ||
} | ||
@@ -104,2 +110,5 @@ }); | ||
var tests = [ | ||
[0,'$0.00','$0.00'], | ||
[null,'$0.00','$0.00'], | ||
[0.99,'$0,0.00','$0.99'], | ||
[1000.234,'$0,0.00','$1,000.23'], | ||
@@ -141,2 +150,4 @@ [1001,'$ 0,0.[00]','$ 1,001'], | ||
var tests = [ | ||
[0,'0b','0B'], | ||
[null,'0 b','0 B'], | ||
[100,'0b','100B'], | ||
@@ -165,2 +176,4 @@ [1024*2,'0 ib','2 KiB'], | ||
var tests = [ | ||
[0,'0%','0%'], | ||
[null,'0 %','0 %'], | ||
[1,'0%','100%'], | ||
@@ -182,2 +195,4 @@ [0.974878234,'0.000%','97.488%'], | ||
var tests = [ | ||
[0,'00:00:00','0:00:00'], | ||
[null,'00:00:00','0:00:00'], | ||
[25,'00:00:00','0:00:25'], | ||
@@ -199,10 +214,10 @@ [238,'00:00:00','0:03:58'], | ||
var tests = [ | ||
// value, format string, expected w/ floor, expected w/ ceil | ||
[2280002, '0.00a', '2.28m', '2.29m'], | ||
[10000.23,'0,0','10,000', '10,001'], | ||
[1000.234,'$0,0.00','$1,000.23', '$1,000.24'], | ||
[0.974878234,'0.000%','97.487%','97.488%'], | ||
[-0.433,'0 %','-44 %', '-43 %'] | ||
], | ||
i; | ||
// value, format string, expected w/ floor, expected w/ ceil | ||
[2280002, '0.00a', '2.28m', '2.29m'], | ||
[10000.23,'0,0','10,000', '10,001'], | ||
[1000.234,'$0,0.00','$1,000.23', '$1,000.24'], | ||
[0.974878234,'0.000%','97.487%','97.488%'], | ||
[-0.433,'0 %','-44 %', '-43 %'] | ||
], | ||
i; | ||
@@ -209,0 +224,0 @@ for (i = 0; i < tests.length; i++) { |
@@ -50,4 +50,11 @@ // Node | ||
var tests = [ | ||
[0,'N/A','N/A'], | ||
[0,'',''] | ||
[0,null,'0','0'], | ||
[0,null,'$0.00','$0.00'], | ||
[0,null,'0 b','0 B'], | ||
[0,null,'0:00','0:00:00'], | ||
[0,'N/A','0','N/A'], | ||
[0,'N/A','$0.00','N/A'], | ||
[0,'N/A','0 b','N/A'], | ||
[0,'N/A','0:00','N/A'], | ||
[0,'','',''] | ||
]; | ||
@@ -58,3 +65,3 @@ | ||
expect(numeral(tests[i][0]).format('0')).to.equal(tests[i][2]); | ||
expect(numeral(tests[i][0]).format(tests[i][2])).to.equal(tests[i][3]); | ||
} | ||
@@ -67,4 +74,11 @@ }); | ||
var tests = [ | ||
[null,'N/A','N/A'], | ||
[null,'',''] | ||
[null,null,'0','0'], | ||
[null,null,'$0.00','$0.00'], | ||
[null,null,'0 b','0 B'], | ||
[null,null,'0:00','0:00:00'], | ||
[null,'N/A','0','N/A'], | ||
[null,'N/A','$0.00','N/A'], | ||
[null,'N/A','0 b','N/A'], | ||
[null,'N/A','0:00','N/A'], | ||
[null,'','',''] | ||
]; | ||
@@ -75,3 +89,3 @@ | ||
expect(numeral(tests[i][0]).format('0')).to.equal(tests[i][2]); | ||
expect(numeral(tests[i][0]).format(tests[i][2])).to.equal(tests[i][3]); | ||
} | ||
@@ -78,0 +92,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
251979
6492
249