From 7b080b60ab8f8f22f7b9d6391c705114ae595af8 Mon Sep 17 00:00:00 2001 From: Benjamin Van Ryseghem Date: Thu, 2 Jul 2015 17:18:09 +0200 Subject: [PATCH] Release 1.3.3 --- CHANGELOG.md | 4 ++++ bower.json | 2 +- component.json | 2 +- dist/numbro.js | 12 +++++++----- dist/numbro.min.js | 4 ++-- numbro.js | 4 ++-- package.json | 2 +- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec201be9..0ec1a69d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 1.3.3 + +- #64 multiply loses accuracy on minification. Thanks @rafde + ### 1.3.2 - Fix issue with the release process diff --git a/bower.json b/bower.json index e2687744..486aaf02 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "numbro", "repo": "foretagsplatsen/numbro", - "version": "1.3.2", + "version": "1.3.3", "description": "Format and manipulate numbers.", "keywords": [ "numeral", diff --git a/component.json b/component.json index c1ca69be..1728b558 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "numbro", "repo": "foretagsplatsen/numbro", - "version": "1.3.2", + "version": "1.3.3", "description": "Format and manipulate numbers.", "keywords": [ "numeral", diff --git a/dist/numbro.js b/dist/numbro.js index 829e6b22..3511e640 100644 --- a/dist/numbro.js +++ b/dist/numbro.js @@ -1,6 +1,6 @@ /*! * numbro.js - * version : 1.3.2 + * version : 1.3.3 * author : Företagsplatsen AB * license : MIT * http://www.foretagsplatsen.se @@ -14,7 +14,7 @@ ************************************/ var numbro, - VERSION = '1.3.2', + VERSION = '1.3.3', // internal storage for language config files languages = {}, currentLanguage = 'en-US', @@ -929,9 +929,11 @@ multiply: function(value) { function cback(accum, curr) { - var corrFactor = correctionFactor(accum, curr); - return (accum * corrFactor) * (curr * corrFactor) / - (corrFactor * corrFactor); + var corrFactor = correctionFactor(accum, curr), + result = accum * corrFactor; + result *= curr * corrFactor; + result /= corrFactor * corrFactor; + return result; } this._value = [this._value, value].reduce(cback, 1); return this; diff --git a/dist/numbro.min.js b/dist/numbro.min.js index 55a2ab02..b11a1a99 100644 --- a/dist/numbro.min.js +++ b/dist/numbro.min.js @@ -1,8 +1,8 @@ /*! * numbro.js - * version : 1.3.2 + * version : 1.3.3 * author : Företagsplatsen AB * license : MIT * http://www.foretagsplatsen.se */ -(function(){"use strict";function a(a){this._value=a}function b(a,b,c,d){var e,f,g=Math.pow(10,b);return f=(c(a*g)/g).toFixed(b),d&&(e=new RegExp("0{1,"+d+"}$"),f=f.replace(e,"")),f}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=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],k=["KB","MB","GB","TB","PB","EB","ZB","YB"],l=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===q)a._value=0;else{for("."!==o[p].delimiters.decimal&&(b=b.replace(/\./g,"").replace(o[p].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+o[p].abbreviations.thousand+"(?:\\)|(\\"+o[p].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+o[p].abbreviations.million+"(?:\\)|(\\"+o[p].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+o[p].abbreviations.billion+"(?:\\)|(\\"+o[p].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+o[p].abbreviations.trillion+"(?:\\)|(\\"+o[p].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!l;g++)b.indexOf(j[g])>-1?l=Math.pow(1024,g+1):b.indexOf(k[g])>-1&&(l=Math.pow(1e3,g+1));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,g=f.indexOf("$"),h=f.indexOf("("),j=f.indexOf("-"),k="",l="";if(-1===f.indexOf("$")?"infix"===o[p].currency.position?(l=o[p].currency.symbol,o[p].currency.spaceSeparated&&(l=" "+l+" ")):o[p].currency.spaceSeparated&&(k=" "):f.indexOf(" $")>-1?(k=" ",f=f.replace(" $","")):f.indexOf("$ ")>-1?(k=" ",f=f.replace("$ ","")):f=f.replace("$",""),e=i(a._value,f,c,l),-1===b.indexOf("$"))switch(o[p].currency.position){case"postfix":e.indexOf(")")>-1?(e=e.split(""),e.splice(-1,0,k+o[p].currency.symbol),e=e.join("")):e=e+k+o[p].currency.symbol;break;case"infix":break;case"prefix":e.indexOf("(")>-1||e.indexOf("-")>-1?(e=e.split(""),d=Math.max(h,j)+1,e.splice(d,0,o[p].currency.symbol+k),e=e.join("")):e=o[p].currency.symbol+k+e;break;default:throw Error('Currency position should be among ["prefix", "infix", "postfix"]')}else 1>=g?e.indexOf("(")>-1||e.indexOf("-")>-1?(e=e.split(""),d=1,(h>g||j>g)&&(d=0),e.splice(d,0,o[p].currency.symbol+k),e=e.join("")):e=o[p].currency.symbol+k+e:e.indexOf(")")>-1?(e=e.split(""),e.splice(-1,0,k+o[p].currency.symbol),e=e.join("")):e=e+k+o[p].currency.symbol;return 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,e){var f,g,h,i,j,k,l,m,n,r,s,t,u,v,w=!1,x=!1,y=!1,z="",A=!1,B=!1,C=!1,D=!1,E=!1,F="",G="",H=Math.abs(a),I=["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],J=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],K="",L=!1,M=!1,N=-1,O=-1,P="";if(0===a&&null!==q)return q;if(isFinite(a)){if(-1!==c.indexOf("-")&&(L=!0),c.indexOf("(")>-1?(w=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(x=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1){if(r=c.split(".")[0].match(/[0-9]+/g)||["0"],r=parseInt(r[0],10),A=c.indexOf("aK")>=0,B=c.indexOf("aM")>=0,C=c.indexOf("aB")>=0,D=c.indexOf("aT")>=0,E=A||B||C||D,c.indexOf(" a")>-1?(z=" ",c=c.replace(" a","")):c=c.replace("a",""),j=Math.floor(Math.log(H)/Math.LN10)+1,l=j%3,l=0===l?3:l,r&&(k=Math.floor(Math.log(H)/Math.LN10)+1-r,m=3*~~((Math.min(r,j)-l)/3),H/=Math.pow(10,m),-1===c.indexOf(".")&&r>3))for(c+="[.]",v=0===k?0:3*~~(k/3)-k,v=0>v?v+3:v,f=0;v>f;f++)c+="0";Math.floor(Math.log(Math.abs(a))/Math.LN10)+1!==r&&(H>=Math.pow(10,12)&&!E||D?(z+=o[p].abbreviations.trillion,a/=Math.pow(10,12)):H=Math.pow(10,9)&&!E||C?(z+=o[p].abbreviations.billion,a/=Math.pow(10,9)):H=Math.pow(10,6)&&!E||B?(z+=o[p].abbreviations.million,a/=Math.pow(10,6)):(H=Math.pow(10,3)&&!E||A)&&(z+=o[p].abbreviations.thousand,a/=Math.pow(10,3)))}if(c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(F=" ",c=c.replace(" b","")):c=c.replace("b",""),i=0;i<=I.length;i++)if(g=Math.pow(1024,i),h=Math.pow(1024,i+1),a>=g&&h>a){F+=I[i],g>0&&(a/=g);break}if(c.indexOf("d")>-1)for(c.indexOf(" d")>-1?(F=" ",c=c.replace(" d","")):c=c.replace("d",""),i=0;i<=J.length;i++)if(g=Math.pow(1e3,i),h=Math.pow(1e3,i+1),a>=g&&h>a){F+=J[i],g>0&&(a/=g);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(G=" ",c=c.replace(" o","")):c=c.replace("o",""),o[p].ordinal&&(G+=o[p].ordinal(a))),c.indexOf("[.]")>-1&&(y=!0,c=c.replace("[.]",".")),n=a.toString().split(".")[0],s=c.split(".")[1],u=c.indexOf(","),s?(s.indexOf("[")>-1?(s=s.replace("]",""),s=s.split("["),K=b(a,s[0].length+s[1].length,d,s[1].length)):K=b(a,s.length,d),n=K.split(".")[0],K.split(".")[1].length?(t=e?z+e:o[p].delimiters.decimal,K=t+K.split(".")[1]):K="",y&&0===Number(K.slice(1))&&(K="")):n=b(a,null,d),n.indexOf("-")>-1&&(n=n.slice(1),M=!0),u>-1&&(n=n.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+o[p].delimiters.thousands)),0===c.indexOf(".")&&(n=""),N=c.indexOf("("),O=c.indexOf("-"),P=O>N?(w&&M?"(":"")+(L&&M||!w&&M?"-":""):(L&&M||!w&&M?"-":"")+(w&&M?"(":""),P+(!M&&x?"+":"")+n+K+(G?G:"")+(z&&!e?z:"")+(F?F:"")+(w&&M?")":"")}return""+a}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.3.2",o={},p="en-US",q=null,r="0,0",s="0$",t="undefined"!=typeof module&&module.exports;m=function(b){return m.isNumbro(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=m.fn.unformat(b)),new a(Number(b))},m.version=n,m.isNumbro=function(b){return b instanceof a},m.language=function(a,b){if(!a)return p;if(a&&!b){if(!o[a])throw new Error("Unknown language : "+a);p=a;var c=o[a].defaults;c&&c.format&&m.defaultFormat(c.format),c&&c.currencyFormat&&m.defaultCurrencyFormat(c.currencyFormat)}return(b||!o[a])&&j(a,b),m},m.setLanguage=function(a,b){var c=a,d=a.split("-")[0],e=null;o[c]||(Object.keys(o).forEach(function(a){e||a.split("-")[0]!==d||(e=a)}),c=e||b||"en-US"),m.language(c)},m.languageData=function(a){if(!a)return o[p];if(!o[a])throw new Error("Unknown language : "+a);return o[a]},m.language("en-US",{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:"$",position:"prefix"},defaults:{currencyFormat:",0000 a"},formats:{fourDigits:"0000 a",fullWithTwoDecimals:"$ ,0.00",fullWithTwoDecimalsNoCurrency:",0.00"}}),m.languages=function(){return o},m.zeroFormat=function(a){q="string"==typeof a?a:null},m.defaultFormat=function(a){r="string"==typeof a?a:"0.0"},m.defaultCurrencyFormat=function(a){s="string"==typeof a?a:"0$"},m.validate=function(a,b){var c,d,e,f,g,h,i,j;if("string"!=typeof a&&(a+="",console.warn&&console.warn("Numbro.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+$/))))},"function"!=typeof Array.prototype.reduce&&(Array.prototype.reduce=function(a,b){if(null===this||"undefined"==typeof 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 c,d,e=this.length>>>0,f=!1;for(1c;++c)this.hasOwnProperty(c)&&(f?d=a(d,this[c],c,this):(d=this[c],f=!0));if(!f)throw new TypeError("Reduce of empty array with no initial value");return d}),m.fn=a.prototype={clone:function(){return m(this)},format:function(a,b){return c(this,a?a:r,void 0!==b?b:Math.round)},formatCurrency:function(a,b){return e(this,a?a:s,void 0!==b?b:Math.round)},unformat:function(a){return"[object Number]"===Object.prototype.toString.call(a)?a:d(this,a?a:r)},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){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){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){var c=l(a,b);return a*c*b*c/(c*c)}return this._value=[this._value,a].reduce(b,1),this},divide:function(a){function b(a,b){var c=l(a,b);return a*c/(b*c)}return this._value=[this._value,a].reduce(b),this},difference:function(a){return Math.abs(m(this._value).subtract(a).value())}},t&&(module.exports=m),"undefined"==typeof ender&&(this.numbro=m),"function"==typeof define&&define.amd&&define([],function(){return m})}).call("undefined"==typeof window?this:window); \ No newline at end of file +(function(){"use strict";function a(a){this._value=a}function b(a,b,c,d){var e,f,g=Math.pow(10,b);return f=(c(a*g)/g).toFixed(b),d&&(e=new RegExp("0{1,"+d+"}$"),f=f.replace(e,"")),f}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=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],k=["KB","MB","GB","TB","PB","EB","ZB","YB"],l=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===q)a._value=0;else{for("."!==o[p].delimiters.decimal&&(b=b.replace(/\./g,"").replace(o[p].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+o[p].abbreviations.thousand+"(?:\\)|(\\"+o[p].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+o[p].abbreviations.million+"(?:\\)|(\\"+o[p].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+o[p].abbreviations.billion+"(?:\\)|(\\"+o[p].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+o[p].abbreviations.trillion+"(?:\\)|(\\"+o[p].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!l;g++)b.indexOf(j[g])>-1?l=Math.pow(1024,g+1):b.indexOf(k[g])>-1&&(l=Math.pow(1e3,g+1));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,g=f.indexOf("$"),h=f.indexOf("("),j=f.indexOf("-"),k="",l="";if(-1===f.indexOf("$")?"infix"===o[p].currency.position?(l=o[p].currency.symbol,o[p].currency.spaceSeparated&&(l=" "+l+" ")):o[p].currency.spaceSeparated&&(k=" "):f.indexOf(" $")>-1?(k=" ",f=f.replace(" $","")):f.indexOf("$ ")>-1?(k=" ",f=f.replace("$ ","")):f=f.replace("$",""),e=i(a._value,f,c,l),-1===b.indexOf("$"))switch(o[p].currency.position){case"postfix":e.indexOf(")")>-1?(e=e.split(""),e.splice(-1,0,k+o[p].currency.symbol),e=e.join("")):e=e+k+o[p].currency.symbol;break;case"infix":break;case"prefix":e.indexOf("(")>-1||e.indexOf("-")>-1?(e=e.split(""),d=Math.max(h,j)+1,e.splice(d,0,o[p].currency.symbol+k),e=e.join("")):e=o[p].currency.symbol+k+e;break;default:throw Error('Currency position should be among ["prefix", "infix", "postfix"]')}else 1>=g?e.indexOf("(")>-1||e.indexOf("-")>-1?(e=e.split(""),d=1,(h>g||j>g)&&(d=0),e.splice(d,0,o[p].currency.symbol+k),e=e.join("")):e=o[p].currency.symbol+k+e:e.indexOf(")")>-1?(e=e.split(""),e.splice(-1,0,k+o[p].currency.symbol),e=e.join("")):e=e+k+o[p].currency.symbol;return 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,e){var f,g,h,i,j,k,l,m,n,r,s,t,u,v,w=!1,x=!1,y=!1,z="",A=!1,B=!1,C=!1,D=!1,E=!1,F="",G="",H=Math.abs(a),I=["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],J=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],K="",L=!1,M=!1,N=-1,O=-1,P="";if(0===a&&null!==q)return q;if(isFinite(a)){if(-1!==c.indexOf("-")&&(L=!0),c.indexOf("(")>-1?(w=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(x=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1){if(r=c.split(".")[0].match(/[0-9]+/g)||["0"],r=parseInt(r[0],10),A=c.indexOf("aK")>=0,B=c.indexOf("aM")>=0,C=c.indexOf("aB")>=0,D=c.indexOf("aT")>=0,E=A||B||C||D,c.indexOf(" a")>-1?(z=" ",c=c.replace(" a","")):c=c.replace("a",""),j=Math.floor(Math.log(H)/Math.LN10)+1,l=j%3,l=0===l?3:l,r&&(k=Math.floor(Math.log(H)/Math.LN10)+1-r,m=3*~~((Math.min(r,j)-l)/3),H/=Math.pow(10,m),-1===c.indexOf(".")&&r>3))for(c+="[.]",v=0===k?0:3*~~(k/3)-k,v=0>v?v+3:v,f=0;v>f;f++)c+="0";Math.floor(Math.log(Math.abs(a))/Math.LN10)+1!==r&&(H>=Math.pow(10,12)&&!E||D?(z+=o[p].abbreviations.trillion,a/=Math.pow(10,12)):H=Math.pow(10,9)&&!E||C?(z+=o[p].abbreviations.billion,a/=Math.pow(10,9)):H=Math.pow(10,6)&&!E||B?(z+=o[p].abbreviations.million,a/=Math.pow(10,6)):(H=Math.pow(10,3)&&!E||A)&&(z+=o[p].abbreviations.thousand,a/=Math.pow(10,3)))}if(c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(F=" ",c=c.replace(" b","")):c=c.replace("b",""),i=0;i<=I.length;i++)if(g=Math.pow(1024,i),h=Math.pow(1024,i+1),a>=g&&h>a){F+=I[i],g>0&&(a/=g);break}if(c.indexOf("d")>-1)for(c.indexOf(" d")>-1?(F=" ",c=c.replace(" d","")):c=c.replace("d",""),i=0;i<=J.length;i++)if(g=Math.pow(1e3,i),h=Math.pow(1e3,i+1),a>=g&&h>a){F+=J[i],g>0&&(a/=g);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(G=" ",c=c.replace(" o","")):c=c.replace("o",""),o[p].ordinal&&(G+=o[p].ordinal(a))),c.indexOf("[.]")>-1&&(y=!0,c=c.replace("[.]",".")),n=a.toString().split(".")[0],s=c.split(".")[1],u=c.indexOf(","),s?(s.indexOf("[")>-1?(s=s.replace("]",""),s=s.split("["),K=b(a,s[0].length+s[1].length,d,s[1].length)):K=b(a,s.length,d),n=K.split(".")[0],K.split(".")[1].length?(t=e?z+e:o[p].delimiters.decimal,K=t+K.split(".")[1]):K="",y&&0===Number(K.slice(1))&&(K="")):n=b(a,null,d),n.indexOf("-")>-1&&(n=n.slice(1),M=!0),u>-1&&(n=n.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+o[p].delimiters.thousands)),0===c.indexOf(".")&&(n=""),N=c.indexOf("("),O=c.indexOf("-"),P=O>N?(w&&M?"(":"")+(L&&M||!w&&M?"-":""):(L&&M||!w&&M?"-":"")+(w&&M?"(":""),P+(!M&&x?"+":"")+n+K+(G?G:"")+(z&&!e?z:"")+(F?F:"")+(w&&M?")":"")}return""+a}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.3.3",o={},p="en-US",q=null,r="0,0",s="0$",t="undefined"!=typeof module&&module.exports;m=function(b){return m.isNumbro(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=m.fn.unformat(b)),new a(Number(b))},m.version=n,m.isNumbro=function(b){return b instanceof a},m.language=function(a,b){if(!a)return p;if(a&&!b){if(!o[a])throw new Error("Unknown language : "+a);p=a;var c=o[a].defaults;c&&c.format&&m.defaultFormat(c.format),c&&c.currencyFormat&&m.defaultCurrencyFormat(c.currencyFormat)}return(b||!o[a])&&j(a,b),m},m.setLanguage=function(a,b){var c=a,d=a.split("-")[0],e=null;o[c]||(Object.keys(o).forEach(function(a){e||a.split("-")[0]!==d||(e=a)}),c=e||b||"en-US"),m.language(c)},m.languageData=function(a){if(!a)return o[p];if(!o[a])throw new Error("Unknown language : "+a);return o[a]},m.language("en-US",{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:"$",position:"prefix"},defaults:{currencyFormat:",0000 a"},formats:{fourDigits:"0000 a",fullWithTwoDecimals:"$ ,0.00",fullWithTwoDecimalsNoCurrency:",0.00"}}),m.languages=function(){return o},m.zeroFormat=function(a){q="string"==typeof a?a:null},m.defaultFormat=function(a){r="string"==typeof a?a:"0.0"},m.defaultCurrencyFormat=function(a){s="string"==typeof a?a:"0$"},m.validate=function(a,b){var c,d,e,f,g,h,i,j;if("string"!=typeof a&&(a+="",console.warn&&console.warn("Numbro.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+$/))))},"function"!=typeof Array.prototype.reduce&&(Array.prototype.reduce=function(a,b){if(null===this||"undefined"==typeof 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 c,d,e=this.length>>>0,f=!1;for(1c;++c)this.hasOwnProperty(c)&&(f?d=a(d,this[c],c,this):(d=this[c],f=!0));if(!f)throw new TypeError("Reduce of empty array with no initial value");return d}),m.fn=a.prototype={clone:function(){return m(this)},format:function(a,b){return c(this,a?a:r,void 0!==b?b:Math.round)},formatCurrency:function(a,b){return e(this,a?a:s,void 0!==b?b:Math.round)},unformat:function(a){return"[object Number]"===Object.prototype.toString.call(a)?a:d(this,a?a:r)},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){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){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){var c=l(a,b),d=a*c;return d*=b*c,d/=c*c}return this._value=[this._value,a].reduce(b,1),this},divide:function(a){function b(a,b){var c=l(a,b);return a*c/(b*c)}return this._value=[this._value,a].reduce(b),this},difference:function(a){return Math.abs(m(this._value).subtract(a).value())}},t&&(module.exports=m),"undefined"==typeof ender&&(this.numbro=m),"function"==typeof define&&define.amd&&define([],function(){return m})}).call("undefined"==typeof window?this:window); \ No newline at end of file diff --git a/numbro.js b/numbro.js index ebf9bbd8..3511e640 100644 --- a/numbro.js +++ b/numbro.js @@ -1,6 +1,6 @@ /*! * numbro.js - * version : 1.3.2 + * version : 1.3.3 * author : Företagsplatsen AB * license : MIT * http://www.foretagsplatsen.se @@ -14,7 +14,7 @@ ************************************/ var numbro, - VERSION = '1.3.2', + VERSION = '1.3.3', // internal storage for language config files languages = {}, currentLanguage = 'en-US', diff --git a/package.json b/package.json index 33a4e115..c5eefe2d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "numbro", - "version": "1.3.2", + "version": "1.3.3", "description": "Format and manipulate numbers.", "homepage": "http://numbrojs.com", "author": {