From c7901083a3a1d349c523018dd78f04d454ef9b5b Mon Sep 17 00:00:00 2001 From: Alan Kendall Date: Thu, 5 Sep 2013 12:41:14 -0500 Subject: [PATCH 01/16] added languageData() for getting and setting language props at runtime --- min/numeral.min.js | 2 +- numeral.js | 15 +++++++++++++++ tests/numeral/misc.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/min/numeral.min.js b/min/numeral.min.js index d56e3a39..d710c4ac 100644 --- a/min/numeral.min.js +++ b/min/numeral.min.js @@ -5,4 +5,4 @@ * license : MIT * http://adamwdraper.github.com/Numeral-js/ */ -(function(){function a(a){this._n=a}function b(a,b,c){var d,e,f=Math.pow(10,b);return e=(Math.round(a*f)/f).toFixed(b),c&&(d=new RegExp("0{1,"+c+"}$"),e=e.replace(d,"")),e}function c(a,b){var c;return c=b.indexOf("$")>-1?e(a,b):b.indexOf("%")>-1?f(a,b):b.indexOf(":")>-1?g(a,b):i(a,b)}function d(a,b){var c,d,e,f,g,i=b,j=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._n=h(b);else if(b===o)a._n=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._n=(k?k: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._n=k?Math.ceil(a._n):a._n}return a._n}function e(a,b){var d,e=b.indexOf("$")<=1?!0:!1,f="";return b.indexOf(" $")>-1?(f=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(f=" ",b=b.replace("$ ","")):b=b.replace("$",""),d=c(a,b),e?d.indexOf("(")>-1||d.indexOf("-")>-1?(d=d.split(""),d.splice(1,0,m[n].currency.symbol+f),d=d.join("")):d=m[n].currency.symbol+f+d:d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,f+m[n].currency.symbol),d=d.join("")):d=d+f+m[n].currency.symbol,d}function f(a,b){var d,e="";return b.indexOf(" %")>-1?(e=" ",b=b.replace(" %","")):b=b.replace("%",""),a._n=100*a._n,d=c(a,b),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._n/60/60),c=Math.floor((a._n-60*60*b)/60),d=Math.round(a._n-60*60*b-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*60*Number(b[0]),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){var d,e,f,g,h,i,j=!1,k=!1,l=!1,p="",q="",r="",s=Math.abs(a._n),t=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],u="",v=!1;if(0===a._n&&null!==o)return o;if(c.indexOf("(")>-1?(j=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(k=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(p=" ",c=c.replace(" a","")):c=c.replace("a",""),s>=Math.pow(10,12)?(p+=m[n].abbreviations.trillion,a._n=a._n/Math.pow(10,12)):s=Math.pow(10,9)?(p+=m[n].abbreviations.billion,a._n=a._n/Math.pow(10,9)):s=Math.pow(10,6)?(p+=m[n].abbreviations.million,a._n=a._n/Math.pow(10,6)):s=Math.pow(10,3)&&(p+=m[n].abbreviations.thousand,a._n=a._n/Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(q=" ",c=c.replace(" b","")):c=c.replace("b",""),f=0;f<=t.length;f++)if(d=Math.pow(1024,f),e=Math.pow(1024,f+1),a._n>=d&&a._n0&&(a._n=a._n/d);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(r=" ",c=c.replace(" o","")):c=c.replace("o",""),r+=m[n].ordinal(a._n)),c.indexOf("[.]")>-1&&(l=!0,c=c.replace("[.]",".")),g=a._n.toString().split(".")[0],h=c.split(".")[1],i=c.indexOf(","),h?(h.indexOf("[")>-1?(h=h.replace("]",""),h=h.split("["),u=b(a._n,h[0].length+h[1].length,h[1].length)):u=b(a._n,h.length),g=u.split(".")[0],u=u.split(".")[1].length?m[n].delimiters.decimal+u.split(".")[1]:"",l&&0===Number(u.slice(1))&&(u="")):g=b(a._n,null),g.indexOf("-")>-1&&(g=g.slice(1),v=!0),i>-1&&(g=g.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(g=""),(j&&v?"(":"")+(!j&&v?"-":"")+(!v&&k?"+":"")+g+u+(r?r:"")+(p?p:"")+(q?q:"")+(j&&v?")":"")}function j(a,b){m[a]=b}var k,l="1.5.0",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a){return c(this,a?a:p)},unformat:function(a){return d(this,a?a:p)},value:function(){return this._n},valueOf:function(){return this._n},set:function(a){return this._n=Number(a),this},add:function(a){return this._n=this._n+Number(a),this},subtract:function(a){return this._n=this._n-Number(a),this},multiply:function(a){return this._n=this._n*Number(a),this},divide:function(a){return this._n=this._n/Number(a),this},difference:function(a){var b=this._n-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file +(function(){function a(a){this._n=a}function b(a,b,c){var d,e,f=Math.pow(10,b);return e=(Math.round(a*f)/f).toFixed(b),c&&(d=new RegExp("0{1,"+c+"}$"),e=e.replace(d,"")),e}function c(a,b){var c;return c=b.indexOf("$")>-1?e(a,b):b.indexOf("%")>-1?f(a,b):b.indexOf(":")>-1?g(a,b):i(a,b)}function d(a,b){var c,d,e,f,g,i=b,j=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._n=h(b);else if(b===o)a._n=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._n=(k?k: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._n=k?Math.ceil(a._n):a._n}return a._n}function e(a,b){var d,e=b.indexOf("$")<=1?!0:!1,f="";return b.indexOf(" $")>-1?(f=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(f=" ",b=b.replace("$ ","")):b=b.replace("$",""),d=c(a,b),e?d.indexOf("(")>-1||d.indexOf("-")>-1?(d=d.split(""),d.splice(1,0,m[n].currency.symbol+f),d=d.join("")):d=m[n].currency.symbol+f+d:d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,f+m[n].currency.symbol),d=d.join("")):d=d+f+m[n].currency.symbol,d}function f(a,b){var d,e="";return b.indexOf(" %")>-1?(e=" ",b=b.replace(" %","")):b=b.replace("%",""),a._n=100*a._n,d=c(a,b),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._n/60/60),c=Math.floor((a._n-60*60*b)/60),d=Math.round(a._n-60*60*b-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*60*Number(b[0]),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){var d,e,f,g,h,i,j=!1,k=!1,l=!1,p="",q="",r="",s=Math.abs(a._n),t=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],u="",v=!1;if(0===a._n&&null!==o)return o;if(c.indexOf("(")>-1?(j=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(k=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(p=" ",c=c.replace(" a","")):c=c.replace("a",""),s>=Math.pow(10,12)?(p+=m[n].abbreviations.trillion,a._n=a._n/Math.pow(10,12)):s=Math.pow(10,9)?(p+=m[n].abbreviations.billion,a._n=a._n/Math.pow(10,9)):s=Math.pow(10,6)?(p+=m[n].abbreviations.million,a._n=a._n/Math.pow(10,6)):s=Math.pow(10,3)&&(p+=m[n].abbreviations.thousand,a._n=a._n/Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(q=" ",c=c.replace(" b","")):c=c.replace("b",""),f=0;f<=t.length;f++)if(d=Math.pow(1024,f),e=Math.pow(1024,f+1),a._n>=d&&a._n0&&(a._n=a._n/d);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(r=" ",c=c.replace(" o","")):c=c.replace("o",""),r+=m[n].ordinal(a._n)),c.indexOf("[.]")>-1&&(l=!0,c=c.replace("[.]",".")),g=a._n.toString().split(".")[0],h=c.split(".")[1],i=c.indexOf(","),h?(h.indexOf("[")>-1?(h=h.replace("]",""),h=h.split("["),u=b(a._n,h[0].length+h[1].length,h[1].length)):u=b(a._n,h.length),g=u.split(".")[0],u=u.split(".")[1].length?m[n].delimiters.decimal+u.split(".")[1]:"",l&&0===Number(u.slice(1))&&(u="")):g=b(a._n,null),g.indexOf("-")>-1&&(g=g.slice(1),v=!0),i>-1&&(g=g.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(g=""),(j&&v?"(":"")+(!j&&v?"-":"")+(!v&&k?"+":"")+g+u+(r?r:"")+(p?p:"")+(q?q:"")+(j&&v?")":"")}function j(a,b){m[a]=b}var k,l="1.5.0",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.languageData=function(a){if(!a)return m[n];if(!m[a])throw new Error("Unknown language : "+a);return m[a]},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a){return c(this,a?a:p)},unformat:function(a){return d(this,a?a:p)},value:function(){return this._n},valueOf:function(){return this._n},set:function(a){return this._n=Number(a),this},add:function(a){return this._n=this._n+Number(a),this},subtract:function(a){return this._n=this._n-Number(a),this},multiply:function(a){return this._n=this._n*Number(a),this},divide:function(a){return this._n=this._n/Number(a),this},difference:function(a){var b=this._n-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file diff --git a/numeral.js b/numeral.js index 26c2929c..ed9b563b 100644 --- a/numeral.js +++ b/numeral.js @@ -410,6 +410,21 @@ return numeral; }; + + // This function provides access to the loaded language data. If + // no arguments are passed in, it will simply return the current + // global language object. + numeral.languageData = function (key) { + if (!key) { + return languages[currentLanguage]; + } + + if (!languages[key]) { + throw new Error('Unknown language : ' + key); + } + + return languages[key]; + }; numeral.language('en', { delimiters: { diff --git a/tests/numeral/misc.js b/tests/numeral/misc.js index 1fe7aa23..0a07a482 100644 --- a/tests/numeral/misc.js +++ b/tests/numeral/misc.js @@ -87,6 +87,37 @@ exports.misc = { test.strictEqual(numeral.isNumeral(tests[i][0]), tests[i][1], tests[i][0]); } + test.done(); + }, + + languageData: function(test) { + test.expect(10); + + var cOld = '$', + cNew = '!', + formatTestVal = function() { return numeral('100').format('$0,0') }, + oldCurrencyVal = cOld + '100', + newCurrencyVal = cNew + '100'; + + test.strictEqual(numeral.languageData().currency.symbol, cOld, 'Current language currency is ' + cOld); + test.strictEqual(numeral.languageData('en').currency.symbol, cOld, 'English language currency is ' + cOld); + + numeral.languageData().currency.symbol = cNew; + test.strictEqual(numeral.languageData().currency.symbol, cNew, 'Current language currency is changed to ' + cNew); + test.strictEqual(formatTestVal(), newCurrencyVal, 'Format uses new currency'); + + numeral.languageData().currency.symbol = cOld; + test.strictEqual(numeral.languageData().currency.symbol, '$', 'Current language currency is reset to ' + cOld); + test.strictEqual(formatTestVal(), oldCurrencyVal, 'Format uses old currency'); + + numeral.languageData('en').currency.symbol = cNew; + test.strictEqual(numeral.languageData().currency.symbol, cNew, 'English language currency is changed to ' + cNew); + test.strictEqual(formatTestVal(), newCurrencyVal, 'Format uses new currency'); + + numeral.languageData('en').currency.symbol = cOld; + test.strictEqual(numeral.languageData().currency.symbol, cOld, 'English language currency is reset to ' + cOld); + test.strictEqual(formatTestVal(), oldCurrencyVal, 'Format uses old currency'); + test.done(); } }; \ No newline at end of file From c8592389e9572ae687cdc1c1c5bdb55336b51560 Mon Sep 17 00:00:00 2001 From: Dave Clayton Date: Fri, 20 Sep 2013 14:25:00 +0200 Subject: [PATCH 02/16] Added Netherlands-NL. --- languages/nl-nl.js | 35 +++++++++++++ tests/languages/nl-nl.js | 109 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 languages/nl-nl.js create mode 100644 tests/languages/nl-nl.js diff --git a/languages/nl-nl.js b/languages/nl-nl.js new file mode 100644 index 00000000..172b0f64 --- /dev/null +++ b/languages/nl-nl.js @@ -0,0 +1,35 @@ +/*! + * numeral.js language configuration + * language : netherlands-dutch (nl-nl) + * author : Dave Clayton : https://github.com/davedx + */ +(function () { + var language = { + delimiters: { + thousands: '.', + decimal : ',' + }, + abbreviations: { + thousand : 'k', + million : ' mln', + billion : ' mrd', + trillion : ' bln' + }, + ordinal : function (number) { + var remainder = number % 100; + return (number !== 0 && remainder <= 1 || remainder === 8 || remainder >= 20) ? 'ste' : 'de'; + }, + currency: { + symbol: '€ ' + } + }; + + // Node + if (typeof module !== 'undefined' && module.exports) { + module.exports = language; + } + // Browser + if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { + this.numeral.language('nl-nl', language); + } +}()); \ No newline at end of file diff --git a/tests/languages/nl-nl.js b/tests/languages/nl-nl.js new file mode 100644 index 00000000..8c195b23 --- /dev/null +++ b/tests/languages/nl-nl.js @@ -0,0 +1,109 @@ +var numeral = require('../../numeral'), + language = require('../../languages/nl-nl'); + +numeral.language('nl-nl', language); + +exports['language:nl-nl'] = { + setUp: function (callback) { + numeral.language('nl-nl'); + callback(); + }, + + tearDown: function (callback) { + numeral.language('en'); + callback(); + }, + + format: function (test) { + test.expect(24); + + var tests = [ + [10000,'0,0.0000','10.000,0000'], + [10000.23,'0,0','10.000'], + [-10000,'0,0.0','-10.000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10.000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2 mln'], + [1430974124,'0.0a','1,4 mrd'], + [9123456789234,'0.0a','9,1 bln'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [0,'0o','0de'], + [1,'0o','1ste'], + [2,'0o','2de'], + [8,'0o','8ste'], + [19,'0o','19de'], + [20,'0o','20ste'], + [100,'0o','100ste'], + [102,'0o','102de'], + [108,'0o','108ste'], + [109,'0o','109de'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); + } + + test.done(); + }, + + currency: function (test) { + test.expect(4); + + var tests = [ + [1000.234,'$0,0.00','€ 1.000,23'], + [-1000.234,'($0,0)','(€ 1.000)'], + [-1000.234,'$0.00','-€ 1000,23'], + [1230974,'($0.00a)','€ 1,23 mln'] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); + } + + test.done(); + }, + + percentages: function (test) { + test.expect(4); + + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); + } + + test.done(); + }, + + unformat: function (test) { + test.expect(9); + + var tests = [ + ['10.000,123',10000.123], + ['(0,12345)',-0.12345], + ['(€ 1,23 mln)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23e',23], + ['€ 10.000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); + } + + test.done(); + } +}; \ No newline at end of file From 1f5f5482c8a835d4670bb48cf0275bfd6b364e7a Mon Sep 17 00:00:00 2001 From: Dave Clayton Date: Fri, 20 Sep 2013 14:26:09 +0200 Subject: [PATCH 03/16] Release --- languages.js | 35 +++++++++++++++++++++++++++++++++++ min/languages.min.js | 5 +++++ min/languages/nl-nl.min.js | 6 ++++++ 3 files changed, 46 insertions(+) create mode 100644 min/languages/nl-nl.min.js diff --git a/languages.js b/languages.js index df1e0ed5..602dccfe 100644 --- a/languages.js +++ b/languages.js @@ -461,6 +461,41 @@ } }()); +/*! + * numeral.js language configuration + * language : netherlands-dutch (nl-nl) + * author : Dave Clayton : https://github.com/davedx + */ +(function () { + var language = { + delimiters: { + thousands: '.', + decimal : ',' + }, + abbreviations: { + thousand : 'k', + million : ' mln', + billion : ' mrd', + trillion : ' bln' + }, + ordinal : function (number) { + var remainder = number % 100; + return (number !== 0 && remainder <= 1 || remainder === 8 || remainder >= 20) ? 'ste' : 'de'; + }, + currency: { + symbol: '€ ' + } + }; + + // Node + if (typeof module !== 'undefined' && module.exports) { + module.exports = language; + } + // Browser + if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { + this.numeral.language('nl-nl', language); + } +}()); /*! * numeral.js language configuration * language : polish (pl) diff --git a/min/languages.min.js b/min/languages.min.js index 49e5355d..ce00d733 100644 --- a/min/languages.min.js +++ b/min/languages.min.js @@ -64,6 +64,11 @@ function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand * author : teppeis : https://github.com/teppeis */ function(){var a={delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"千",million:"百万",billion:"十億",trillion:"兆"},ordinal:function(){return"."},currency:{symbol:"¥"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("ja",a)}(),/*! + * numeral.js language configuration + * language : netherlands-dutch (nl-nl) + * author : Dave Clayton : https://github.com/davedx + */ +function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"k",million:" mln",billion:" mrd",trillion:" bln"},ordinal:function(a){var b=a%100;return 0!==a&&1>=b||8===b||b>=20?"ste":"de"},currency:{symbol:"€ "}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("nl-nl",a)}(),/*! * numeral.js language configuration * language : polish (pl) * author : Dominik Bulaj : https://github.com/dominikbulaj diff --git a/min/languages/nl-nl.min.js b/min/languages/nl-nl.min.js new file mode 100644 index 00000000..0076f80d --- /dev/null +++ b/min/languages/nl-nl.min.js @@ -0,0 +1,6 @@ +/*! + * numeral.js language configuration + * language : netherlands-dutch (nl-nl) + * author : Dave Clayton : https://github.com/davedx + */ +!function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"k",million:" mln",billion:" mrd",trillion:" bln"},ordinal:function(a){var b=a%100;return 0!==a&&1>=b||8===b||b>=20?"ste":"de"},currency:{symbol:"€ "}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("nl-nl",a)}(); \ No newline at end of file From c9ba7d0699439a990688f88a246e01c01edd685e Mon Sep 17 00:00:00 2001 From: Dave Clayton Date: Fri, 20 Sep 2013 15:09:07 +0200 Subject: [PATCH 04/16] Update for NL-NL: remove leading space before millions, billions to make it consistent with thousands --- languages.js | 6 +++--- languages/nl-nl.js | 6 +++--- min/languages.min.js | 2 +- min/languages/nl-nl.min.js | 2 +- tests/languages/nl-nl.js | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/languages.js b/languages.js index 602dccfe..800eaeb0 100644 --- a/languages.js +++ b/languages.js @@ -474,9 +474,9 @@ }, abbreviations: { thousand : 'k', - million : ' mln', - billion : ' mrd', - trillion : ' bln' + million : 'mln', + billion : 'mrd', + trillion : 'bln' }, ordinal : function (number) { var remainder = number % 100; diff --git a/languages/nl-nl.js b/languages/nl-nl.js index 172b0f64..ab577867 100644 --- a/languages/nl-nl.js +++ b/languages/nl-nl.js @@ -11,9 +11,9 @@ }, abbreviations: { thousand : 'k', - million : ' mln', - billion : ' mrd', - trillion : ' bln' + million : 'mln', + billion : 'mrd', + trillion : 'bln' }, ordinal : function (number) { var remainder = number % 100; diff --git a/min/languages.min.js b/min/languages.min.js index ce00d733..c6ce345d 100644 --- a/min/languages.min.js +++ b/min/languages.min.js @@ -68,7 +68,7 @@ function(){var a={delimiters:{thousands:",",decimal:"."},abbreviations:{thousand * language : netherlands-dutch (nl-nl) * author : Dave Clayton : https://github.com/davedx */ -function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"k",million:" mln",billion:" mrd",trillion:" bln"},ordinal:function(a){var b=a%100;return 0!==a&&1>=b||8===b||b>=20?"ste":"de"},currency:{symbol:"€ "}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("nl-nl",a)}(),/*! +function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"k",million:"mln",billion:"mrd",trillion:"bln"},ordinal:function(a){var b=a%100;return 0!==a&&1>=b||8===b||b>=20?"ste":"de"},currency:{symbol:"€ "}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("nl-nl",a)}(),/*! * numeral.js language configuration * language : polish (pl) * author : Dominik Bulaj : https://github.com/dominikbulaj diff --git a/min/languages/nl-nl.min.js b/min/languages/nl-nl.min.js index 0076f80d..3321d4a0 100644 --- a/min/languages/nl-nl.min.js +++ b/min/languages/nl-nl.min.js @@ -3,4 +3,4 @@ * language : netherlands-dutch (nl-nl) * author : Dave Clayton : https://github.com/davedx */ -!function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"k",million:" mln",billion:" mrd",trillion:" bln"},ordinal:function(a){var b=a%100;return 0!==a&&1>=b||8===b||b>=20?"ste":"de"},currency:{symbol:"€ "}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("nl-nl",a)}(); \ No newline at end of file +!function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"k",million:"mln",billion:"mrd",trillion:"bln"},ordinal:function(a){var b=a%100;return 0!==a&&1>=b||8===b||b>=20?"ste":"de"},currency:{symbol:"€ "}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("nl-nl",a)}(); \ No newline at end of file diff --git a/tests/languages/nl-nl.js b/tests/languages/nl-nl.js index 8c195b23..ce49b07e 100644 --- a/tests/languages/nl-nl.js +++ b/tests/languages/nl-nl.js @@ -26,9 +26,9 @@ exports['language:nl-nl'] = { [-0.23,'.00','-,23'], [-0.23,'(.00)','(,23)'], [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2 mln'], - [1430974124,'0.0a','1,4 mrd'], - [9123456789234,'0.0a','9,1 bln'], + [1230974,'0.0a','1,2mln'], + [1430974124,'0.0a','1,4mrd'], + [9123456789234,'0.0a','9,1bln'], [1460,'0a','1k'], [-104000,'0a','-104k'], [0,'0o','0de'], @@ -58,7 +58,7 @@ exports['language:nl-nl'] = { [1000.234,'$0,0.00','€ 1.000,23'], [-1000.234,'($0,0)','(€ 1.000)'], [-1000.234,'$0.00','-€ 1000,23'], - [1230974,'($0.00a)','€ 1,23 mln'] + [1230974,'($0.00a)','€ 1,23mln'] ]; for (var i = 0; i < tests.length; i++) { From a0a56e2e2ef65d143178a01954e5e8dc20f62e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Bakondy?= Date: Wed, 25 Sep 2013 20:40:20 +0200 Subject: [PATCH 05/16] hungarian language files --- languages/hu.js | 34 ++++++++++++++ tests/languages/hu.js | 101 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 languages/hu.js create mode 100644 tests/languages/hu.js diff --git a/languages/hu.js b/languages/hu.js new file mode 100644 index 00000000..9710ac23 --- /dev/null +++ b/languages/hu.js @@ -0,0 +1,34 @@ +/*! + * numeral.js language configuration + * language : Hungarian (hu) + * author : Peter Bakondy : https://github.com/pbakondy + */ +(function () { + var language = { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'E', // ezer + million: 'M', // millió + billion: 'Mrd', // milliárd + trillion: 'T' // trillió + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: ' Ft' + } + }; + + // Node + if (typeof module !== 'undefined' && module.exports) { + module.exports = language; + } + // Browser + if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { + this.numeral.language('hu', language); + } +}()); \ No newline at end of file diff --git a/tests/languages/hu.js b/tests/languages/hu.js new file mode 100644 index 00000000..407baaae --- /dev/null +++ b/tests/languages/hu.js @@ -0,0 +1,101 @@ +var numeral = require('../../numeral'), + language = require('../../languages/hu'); + +numeral.language('hu', language); + +exports['language:hu'] = { + setUp: function (callback) { + numeral.language('hu'); + callback(); + }, + + tearDown: function (callback) { + numeral.language('en'); + callback(); + }, + + format: function (test) { + test.expect(16); + + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2M'], + [1460,'0a','1E'], + [-104000,'0a','-104E'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); + } + + test.done(); + }, + + currency: function (test) { + test.expect(4); + + var tests = [ + [1000.234,'0,0.00$','1 000,23 Ft'], + [-1000.234,'(0,0$)','(1 000 Ft)'], + [-1000.234,'0.00$','-1000,23 Ft'], + [1230974,'(0.00a$)','1,23M Ft'] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); + } + + test.done(); + }, + + percentages: function (test) { + test.expect(4); + + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); + } + + test.done(); + }, + + unformat: function (test) { + test.expect(9); + + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(1,23M Ft)',-1230000], + ['10E',10000], + ['-10E',-10000], + ['23.',23], + ['10 000,00 Ft',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); + } + + test.done(); + } +}; \ No newline at end of file From 82557fac21e51c0b8e2fa58a0c8947faf9dec28e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Renaud-Allaire?= Date: Thu, 26 Sep 2013 17:16:23 -0400 Subject: [PATCH 06/16] Add support for French Canadian (fr-CA) --- languages.js | 34 +++++++++++++ languages/fr-CA.js | 34 +++++++++++++ min/languages.min.js | 7 ++- min/languages/fr-CA.min.js | 6 +++ tests/languages/fr-CA.js | 101 +++++++++++++++++++++++++++++++++++++ 5 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 languages/fr-CA.js create mode 100644 min/languages/fr-CA.min.js create mode 100644 tests/languages/fr-CA.js diff --git a/languages.js b/languages.js index df1e0ed5..e00bd19a 100644 --- a/languages.js +++ b/languages.js @@ -323,6 +323,40 @@ } }()); +/*! + * numeral.js language configuration + * language : french (Canada) (fr-CA) + * author : Léo Renaud-Allaire : https://github.com/renaudleo + */ +(function () { + var language = { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'M', + billion: 'G', + trillion: 'T' + }, + ordinal : function (number) { + return number === 1 ? 'er' : 'e'; + }, + currency: { + symbol: '$' + } + }; + + // Node + if (typeof module !== 'undefined' && module.exports) { + module.exports = language; + } + // Browser + if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { + this.numeral.language('fr-CA', language); + } +}()); /*! * numeral.js language configuration * language : french (fr-ch) diff --git a/languages/fr-CA.js b/languages/fr-CA.js new file mode 100644 index 00000000..ea1c9a50 --- /dev/null +++ b/languages/fr-CA.js @@ -0,0 +1,34 @@ +/*! + * numeral.js language configuration + * language : french (Canada) (fr-CA) + * author : Léo Renaud-Allaire : https://github.com/renaudleo + */ +(function () { + var language = { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'M', + billion: 'G', + trillion: 'T' + }, + ordinal : function (number) { + return number === 1 ? 'er' : 'e'; + }, + currency: { + symbol: '$' + } + }; + + // Node + if (typeof module !== 'undefined' && module.exports) { + module.exports = language; + } + // Browser + if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { + this.numeral.language('fr-CA', language); + } +}()); \ No newline at end of file diff --git a/min/languages.min.js b/min/languages.min.js index 49e5355d..e7d903bb 100644 --- a/min/languages.min.js +++ b/min/languages.min.js @@ -43,7 +43,12 @@ function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand * language : Finnish * author : Sami Saada : https://github.com/samitheberber */ -function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"M",billion:"G",trillion:"T"},ordinal:function(){return"."},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("fi",a)}(),/*! +function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"M",billion:"G",trillion:"T"},ordinal:function(){return"."},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("fi",a)}(),/*! + * numeral.js language configuration + * language : french (Canada) (fr-CA) + * author : Léo Renaud-Allaire : https://github.com/renaudleo + */ +function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"M",billion:"G",trillion:"T"},ordinal:function(a){return 1===a?"er":"e"},currency:{symbol:"$"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("fr-CA",a)}(),/*! * numeral.js language configuration * language : french (fr-ch) * author : Adam Draper : https://github.com/adamwdraper diff --git a/min/languages/fr-CA.min.js b/min/languages/fr-CA.min.js new file mode 100644 index 00000000..b687e50e --- /dev/null +++ b/min/languages/fr-CA.min.js @@ -0,0 +1,6 @@ +/*! + * numeral.js language configuration + * language : french (Canada) (fr-CA) + * author : Léo Renaud-Allaire : https://github.com/renaudleo + */ +!function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"M",billion:"G",trillion:"T"},ordinal:function(a){return 1===a?"er":"e"},currency:{symbol:"$"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("fr-CA",a)}(); \ No newline at end of file diff --git a/tests/languages/fr-CA.js b/tests/languages/fr-CA.js new file mode 100644 index 00000000..8ad94bc3 --- /dev/null +++ b/tests/languages/fr-CA.js @@ -0,0 +1,101 @@ +var numeral = require('../../numeral'), + language = require('../../languages/fr-CA'); + +numeral.language('fr-CA', language); + +exports['language:fr'] = { + setUp: function (callback) { + numeral.language('fr-CA'); + callback(); + }, + + tearDown: function (callback) { + numeral.language('en'); + callback(); + }, + + format: function (test) { + test.expect(16); + + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0 a','1,2 M'], + [1460,'0 a','1 k'], + [-104000,'0 a','-104 k'], + [1,'0o','1er'], + [52,'0o','52e'], + [23,'0o','23e'], + [100,'0o','100e'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); + } + + test.done(); + }, + + currency: function (test) { + test.expect(4); + + var tests = [ + [1000.234,'0,0.00 $','1 000,23 $'], + [-1000.234,'(0,0 $)','(1 000 $)'], + [-1000.234,'0.00 $','-1000,23 $'], + [1230974,'(0.00 a$)','1,23 M$'] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); + } + + test.done(); + }, + + percentages: function (test) { + test.expect(4); + + var tests = [ + [1,'0 %','100 %'], + [0.974878234,'0.000 %','97,488 %'], + [-0.43,'0 %','-43 %'], + [0.43,'(0.000 %)','43,000 %'] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); + } + + test.done(); + }, + + unformat: function (test) { + test.expect(9); + + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(1,23 M$)',-1230000], + ['10 k',10000], + ['-10 k',-10000], + ['23e',23], + ['10 000,00 $',10000], + ['-76 %',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); + } + + test.done(); + } +}; \ No newline at end of file From da2d724cd3f4bfdfd2ae4382f6cfa81039439c36 Mon Sep 17 00:00:00 2001 From: Nathanael Abbotts Date: Sat, 19 Oct 2013 23:08:47 +0100 Subject: [PATCH 07/16] Adds an optional argument in Numeral.format for a rounding function. The argument defaults to Math.round if undefined, so this does not change the behaviour of Numeral for any previous use-cases. Tests are included - all existing tests pass. --- min/numeral.min.js | 2 +- numeral.js | 40 ++++++++++++++++++++++------------------ tests/numeral/format.js | 30 ++++++++++++++++++++++++++++-- 3 files changed, 51 insertions(+), 21 deletions(-) diff --git a/min/numeral.min.js b/min/numeral.min.js index 53355b1c..08ce5b87 100644 --- a/min/numeral.min.js +++ b/min/numeral.min.js @@ -5,4 +5,4 @@ * license : MIT * http://adamwdraper.github.com/Numeral-js/ */ -(function(){function a(a){this._value=a}function b(a,b,c){var d,e,f=Math.pow(10,b);return e=(Math.round(a*f)/f).toFixed(b),c&&(d=new RegExp("0{1,"+c+"}$"),e=e.replace(d,"")),e}function c(a,b){var c;return c=b.indexOf("$")>-1?e(a,b):b.indexOf("%")>-1?f(a,b):b.indexOf(":")>-1?g(a,b):i(a._value,b)}function d(a,b){var c,d,e,f,g,i=b,j=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===o)a._value=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._value=(k?k: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=k?Math.ceil(a._value):a._value}return a._value}function e(a,b){var c,d=b.indexOf("$")<=1?!0:!1,e="";return b.indexOf(" $")>-1?(e=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(e=" ",b=b.replace("$ ","")):b=b.replace("$",""),c=i(a._value,b),d?c.indexOf("(")>-1||c.indexOf("-")>-1?(c=c.split(""),c.splice(1,0,m[n].currency.symbol+e),c=c.join("")):c=m[n].currency.symbol+e+c:c.indexOf(")")>-1?(c=c.split(""),c.splice(-1,0,e+m[n].currency.symbol),c=c.join("")):c=c+e+m[n].currency.symbol,c}function f(a,b){var c,d="",e=100*a._value;return b.indexOf(" %")>-1?(d=" ",b=b.replace(" %","")):b=b.replace("%",""),c=i(e,b),c.indexOf(")")>-1?(c=c.split(""),c.splice(-1,0,d+"%"),c=c.join("")):c=c+d+"%",c}function g(a){var b=Math.floor(a._value/60/60),c=Math.floor((a._value-60*60*b)/60),d=Math.round(a._value-60*60*b-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*60*Number(b[0]),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){var d,e,f,g,h,i,j=!1,k=!1,l=!1,p="",q="",r="",s=Math.abs(a),t=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],u="",v=!1;if(0===a&&null!==o)return o;if(c.indexOf("(")>-1?(j=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(k=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(p=" ",c=c.replace(" a","")):c=c.replace("a",""),s>=Math.pow(10,12)?(p+=m[n].abbreviations.trillion,a/=Math.pow(10,12)):s=Math.pow(10,9)?(p+=m[n].abbreviations.billion,a/=Math.pow(10,9)):s=Math.pow(10,6)?(p+=m[n].abbreviations.million,a/=Math.pow(10,6)):s=Math.pow(10,3)&&(p+=m[n].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(q=" ",c=c.replace(" b","")):c=c.replace("b",""),f=0;f<=t.length;f++)if(d=Math.pow(1024,f),e=Math.pow(1024,f+1),a>=d&&e>a){q+=t[f],d>0&&(a/=d);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(r=" ",c=c.replace(" o","")):c=c.replace("o",""),r+=m[n].ordinal(a)),c.indexOf("[.]")>-1&&(l=!0,c=c.replace("[.]",".")),g=a.toString().split(".")[0],h=c.split(".")[1],i=c.indexOf(","),h?(h.indexOf("[")>-1?(h=h.replace("]",""),h=h.split("["),u=b(a,h[0].length+h[1].length,h[1].length)):u=b(a,h.length),g=u.split(".")[0],u=u.split(".")[1].length?m[n].delimiters.decimal+u.split(".")[1]:"",l&&0===Number(u.slice(1))&&(u="")):g=b(a,null),g.indexOf("-")>-1&&(g=g.slice(1),v=!0),i>-1&&(g=g.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(g=""),(j&&v?"(":"")+(!j&&v?"-":"")+(!v&&k?"+":"")+g+u+(r?r:"")+(p?p:"")+(q?q:"")+(j&&v?")":"")}function j(a,b){m[a]=b}var k,l="1.5.1",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a){return c(this,a?a:p)},unformat:function(a){return d(this,a?a:p)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){return this._value=this._value+Number(a),this},subtract:function(a){return this._value=this._value-Number(a),this},multiply:function(a){return this._value=this._value*Number(a),this},divide:function(a){return this._value=this._value/Number(a),this},difference:function(a){var b=this._value-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file +(function(){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=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===o)a._value=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._value=(k?k: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=k?Math.ceil(a._value):a._value}return a._value}function e(a,b,c){var d,e=b.indexOf("$")<=1?!0:!1,f="";return b.indexOf(" $")>-1?(f=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(f=" ",b=b.replace("$ ","")):b=b.replace("$",""),d=i(a._value,b,c),e?d.indexOf("(")>-1||d.indexOf("-")>-1?(d=d.split(""),d.splice(1,0,m[n].currency.symbol+f),d=d.join("")):d=m[n].currency.symbol+f+d:d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,f+m[n].currency.symbol),d=d.join("")):d=d+f+m[n].currency.symbol,d}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*60*b)/60),d=Math.round(a._value-60*60*b-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*60*Number(b[0]),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,p=!1,q="",r="",s="",t=Math.abs(a),u=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],v="",w=!1;if(0===a&&null!==o)return o;if(c.indexOf("(")>-1?(k=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(l=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(q=" ",c=c.replace(" a","")):c=c.replace("a",""),t>=Math.pow(10,12)?(q+=m[n].abbreviations.trillion,a/=Math.pow(10,12)):t=Math.pow(10,9)?(q+=m[n].abbreviations.billion,a/=Math.pow(10,9)):t=Math.pow(10,6)?(q+=m[n].abbreviations.million,a/=Math.pow(10,6)):t=Math.pow(10,3)&&(q+=m[n].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(r=" ",c=c.replace(" b","")):c=c.replace("b",""),g=0;g<=u.length;g++)if(e=Math.pow(1024,g),f=Math.pow(1024,g+1),a>=e&&f>a){r+=u[g],e>0&&(a/=e);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(s=" ",c=c.replace(" o","")):c=c.replace("o",""),s+=m[n].ordinal(a)),c.indexOf("[.]")>-1&&(p=!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("["),v=b(a,i[0].length+i[1].length,d,i[1].length)):v=b(a,i.length,d),h=v.split(".")[0],v=v.split(".")[1].length?m[n].delimiters.decimal+v.split(".")[1]:"",p&&0===Number(v.slice(1))&&(v="")):h=b(a,null,d),h.indexOf("-")>-1&&(h=h.slice(1),w=!0),j>-1&&(h=h.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(h=""),(k&&w?"(":"")+(!k&&w?"-":"")+(!w&&l?"+":"")+h+v+(s?s:"")+(q?q:"")+(r?r:"")+(k&&w?")":"")}function j(a,b){m[a]=b}var k,l="1.5.1",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a,b){return c(this,a?a:p,void 0!==b?b:Math.round)},unformat:function(a){return d(this,a?a:p)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){return this._value=this._value+Number(a),this},subtract:function(a){return this._value=this._value-Number(a),this},multiply:function(a){return this._value=this._value*Number(a),this},divide:function(a){return this._value=this._value/Number(a),this},difference:function(a){var b=this._value-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file diff --git a/numeral.js b/numeral.js index 0cf5532a..c5be71ed 100644 --- a/numeral.js +++ b/numeral.js @@ -39,13 +39,14 @@ * Fixes binary rounding issues (eg. (0.615).toFixed(2) === '0.61') that present * problems for accounting- and finance-related software. */ - function toFixed (value, precision, optionals) { + function toFixed (value, precision, roundingFunction, optionals) { var power = Math.pow(10, precision), optionalsRegExp, output; - + + //roundingFunction = (roundingFunction !== undefined ? roundingFunction : Math.round); // Multiply up by precision, round accurately, then divide and use native toFixed(): - output = (Math.round(value * power) / power).toFixed(precision); + output = (roundingFunction(value * power) / power).toFixed(precision); if (optionals) { optionalsRegExp = new RegExp('0{1,' + optionals + '}$'); @@ -60,18 +61,18 @@ ************************************/ // determine what type of formatting we need to do - function formatNumeral (n, format) { + function formatNumeral (n, format, roundingFunction) { var output; // figure out what kind of format we are dealing with if (format.indexOf('$') > -1) { // currency!!!!! - output = formatCurrency(n, format); + output = formatCurrency(n, format, roundingFunction); } else if (format.indexOf('%') > -1) { // percentage - output = formatPercentage(n, format); + 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); + output = formatNumber(n._value, format, roundingFunction); } // return string @@ -124,7 +125,7 @@ return n._value; } - function formatCurrency (n, format) { + function formatCurrency (n, format, roundingFunction) { var prependSymbol = format.indexOf('$') <= 1 ? true : false, space = '', output; @@ -141,7 +142,7 @@ } // format the number - output = formatNumber(n._value, format); + output = formatNumber(n._value, format, roundingFunction); // position the symbol if (prependSymbol) { @@ -165,7 +166,7 @@ return output; } - function formatPercentage (n, format) { + function formatPercentage (n, format, roundingFunction) { var space = '', output, value = n._value * 100; @@ -178,7 +179,7 @@ format = format.replace('%', ''); } - output = formatNumber(value, format); + output = formatNumber(value, format, roundingFunction); if (output.indexOf(')') > -1 ) { output = output.split(''); @@ -218,7 +219,7 @@ return Number(seconds); } - function formatNumber (value, format) { + function formatNumber (value, format, roundingFunction) { var negP = false, signed = false, optDec = false, @@ -259,7 +260,7 @@ } else { format = format.replace('a', ''); } - + if (abs >= Math.pow(10, 12)) { // trillion abbr = abbr + languages[currentLanguage].abbreviations.trillion; @@ -329,9 +330,9 @@ if (precision.indexOf('[') > -1) { precision = precision.replace(']', ''); precision = precision.split('['); - d = toFixed(value, (precision[0].length + precision[1].length), precision[1].length); + d = toFixed(value, (precision[0].length + precision[1].length), roundingFunction, precision[1].length); } else { - d = toFixed(value, precision.length); + d = toFixed(value, precision.length, roundingFunction); } w = d.split('.')[0]; @@ -346,7 +347,7 @@ d = ''; } } else { - w = toFixed(value, null); + w = toFixed(value, null, roundingFunction); } // format number @@ -464,8 +465,11 @@ return numeral(this); }, - format : function (inputString) { - return formatNumeral(this, inputString ? inputString : defaultFormat); + format : function (inputString, roundingFunction) { + return formatNumeral(this, + inputString ? inputString : defaultFormat, + (roundingFunction !== undefined) ? roundingFunction : Math.round + ); }, unformat : function (inputString) { diff --git a/tests/numeral/format.js b/tests/numeral/format.js index 88dda314..f5754067 100644 --- a/tests/numeral/format.js +++ b/tests/numeral/format.js @@ -151,5 +151,31 @@ exports.format = { } test.done(); - } -}; \ No newline at end of file + }, + + rounding: function (test) { + 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; + + test.expect(tests.length * 2); + + for (i = 0; i < tests.length; i++) { + // floor + test.strictEqual(numeral(tests[i][0]).format(tests[i][1], Math.floor), tests[i][2], tests[i][1] + ", floor"); + + // ceil + test.strictEqual(numeral(tests[i][0]).format(tests[i][1], Math.ceil), tests[i][3], tests[i][1] + ", ceil"); + + } + + test.done(); + + }, +}; From 5831367f60eefe0ce225fa2972c19111609450fb Mon Sep 17 00:00:00 2001 From: Eric Baer Date: Fri, 25 Oct 2013 22:52:04 -0700 Subject: [PATCH 08/16] Unformat should pass through if given a number --- min/numeral.min.js | 2 +- numeral.js | 3 +++ tests/numeral/unformat.js | 12 ++++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/min/numeral.min.js b/min/numeral.min.js index 53355b1c..999fa9b2 100644 --- a/min/numeral.min.js +++ b/min/numeral.min.js @@ -5,4 +5,4 @@ * license : MIT * http://adamwdraper.github.com/Numeral-js/ */ -(function(){function a(a){this._value=a}function b(a,b,c){var d,e,f=Math.pow(10,b);return e=(Math.round(a*f)/f).toFixed(b),c&&(d=new RegExp("0{1,"+c+"}$"),e=e.replace(d,"")),e}function c(a,b){var c;return c=b.indexOf("$")>-1?e(a,b):b.indexOf("%")>-1?f(a,b):b.indexOf(":")>-1?g(a,b):i(a._value,b)}function d(a,b){var c,d,e,f,g,i=b,j=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===o)a._value=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._value=(k?k: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=k?Math.ceil(a._value):a._value}return a._value}function e(a,b){var c,d=b.indexOf("$")<=1?!0:!1,e="";return b.indexOf(" $")>-1?(e=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(e=" ",b=b.replace("$ ","")):b=b.replace("$",""),c=i(a._value,b),d?c.indexOf("(")>-1||c.indexOf("-")>-1?(c=c.split(""),c.splice(1,0,m[n].currency.symbol+e),c=c.join("")):c=m[n].currency.symbol+e+c:c.indexOf(")")>-1?(c=c.split(""),c.splice(-1,0,e+m[n].currency.symbol),c=c.join("")):c=c+e+m[n].currency.symbol,c}function f(a,b){var c,d="",e=100*a._value;return b.indexOf(" %")>-1?(d=" ",b=b.replace(" %","")):b=b.replace("%",""),c=i(e,b),c.indexOf(")")>-1?(c=c.split(""),c.splice(-1,0,d+"%"),c=c.join("")):c=c+d+"%",c}function g(a){var b=Math.floor(a._value/60/60),c=Math.floor((a._value-60*60*b)/60),d=Math.round(a._value-60*60*b-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*60*Number(b[0]),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){var d,e,f,g,h,i,j=!1,k=!1,l=!1,p="",q="",r="",s=Math.abs(a),t=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],u="",v=!1;if(0===a&&null!==o)return o;if(c.indexOf("(")>-1?(j=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(k=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(p=" ",c=c.replace(" a","")):c=c.replace("a",""),s>=Math.pow(10,12)?(p+=m[n].abbreviations.trillion,a/=Math.pow(10,12)):s=Math.pow(10,9)?(p+=m[n].abbreviations.billion,a/=Math.pow(10,9)):s=Math.pow(10,6)?(p+=m[n].abbreviations.million,a/=Math.pow(10,6)):s=Math.pow(10,3)&&(p+=m[n].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(q=" ",c=c.replace(" b","")):c=c.replace("b",""),f=0;f<=t.length;f++)if(d=Math.pow(1024,f),e=Math.pow(1024,f+1),a>=d&&e>a){q+=t[f],d>0&&(a/=d);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(r=" ",c=c.replace(" o","")):c=c.replace("o",""),r+=m[n].ordinal(a)),c.indexOf("[.]")>-1&&(l=!0,c=c.replace("[.]",".")),g=a.toString().split(".")[0],h=c.split(".")[1],i=c.indexOf(","),h?(h.indexOf("[")>-1?(h=h.replace("]",""),h=h.split("["),u=b(a,h[0].length+h[1].length,h[1].length)):u=b(a,h.length),g=u.split(".")[0],u=u.split(".")[1].length?m[n].delimiters.decimal+u.split(".")[1]:"",l&&0===Number(u.slice(1))&&(u="")):g=b(a,null),g.indexOf("-")>-1&&(g=g.slice(1),v=!0),i>-1&&(g=g.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(g=""),(j&&v?"(":"")+(!j&&v?"-":"")+(!v&&k?"+":"")+g+u+(r?r:"")+(p?p:"")+(q?q:"")+(j&&v?")":"")}function j(a,b){m[a]=b}var k,l="1.5.1",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a){return c(this,a?a:p)},unformat:function(a){return d(this,a?a:p)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){return this._value=this._value+Number(a),this},subtract:function(a){return this._value=this._value-Number(a),this},multiply:function(a){return this._value=this._value*Number(a),this},divide:function(a){return this._value=this._value/Number(a),this},difference:function(a){var b=this._value-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file +(function(){function a(a){this._value=a}function b(a,b,c){var d,e,f=Math.pow(10,b);return e=(Math.round(a*f)/f).toFixed(b),c&&(d=new RegExp("0{1,"+c+"}$"),e=e.replace(d,"")),e}function c(a,b){var c;return c=b.indexOf("$")>-1?e(a,b):b.indexOf("%")>-1?f(a,b):b.indexOf(":")>-1?g(a,b):i(a._value,b)}function d(a,b){var c,d,e,f,g,i=b,j=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===o)a._value=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._value=(k?k: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=k?Math.ceil(a._value):a._value}return a._value}function e(a,b){var c,d=b.indexOf("$")<=1?!0:!1,e="";return b.indexOf(" $")>-1?(e=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(e=" ",b=b.replace("$ ","")):b=b.replace("$",""),c=i(a._value,b),d?c.indexOf("(")>-1||c.indexOf("-")>-1?(c=c.split(""),c.splice(1,0,m[n].currency.symbol+e),c=c.join("")):c=m[n].currency.symbol+e+c:c.indexOf(")")>-1?(c=c.split(""),c.splice(-1,0,e+m[n].currency.symbol),c=c.join("")):c=c+e+m[n].currency.symbol,c}function f(a,b){var c,d="",e=100*a._value;return b.indexOf(" %")>-1?(d=" ",b=b.replace(" %","")):b=b.replace("%",""),c=i(e,b),c.indexOf(")")>-1?(c=c.split(""),c.splice(-1,0,d+"%"),c=c.join("")):c=c+d+"%",c}function g(a){var b=Math.floor(a._value/60/60),c=Math.floor((a._value-60*60*b)/60),d=Math.round(a._value-60*60*b-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*60*Number(b[0]),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){var d,e,f,g,h,i,j=!1,k=!1,l=!1,p="",q="",r="",s=Math.abs(a),t=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],u="",v=!1;if(0===a&&null!==o)return o;if(c.indexOf("(")>-1?(j=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(k=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(p=" ",c=c.replace(" a","")):c=c.replace("a",""),s>=Math.pow(10,12)?(p+=m[n].abbreviations.trillion,a/=Math.pow(10,12)):s=Math.pow(10,9)?(p+=m[n].abbreviations.billion,a/=Math.pow(10,9)):s=Math.pow(10,6)?(p+=m[n].abbreviations.million,a/=Math.pow(10,6)):s=Math.pow(10,3)&&(p+=m[n].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(q=" ",c=c.replace(" b","")):c=c.replace("b",""),f=0;f<=t.length;f++)if(d=Math.pow(1024,f),e=Math.pow(1024,f+1),a>=d&&e>a){q+=t[f],d>0&&(a/=d);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(r=" ",c=c.replace(" o","")):c=c.replace("o",""),r+=m[n].ordinal(a)),c.indexOf("[.]")>-1&&(l=!0,c=c.replace("[.]",".")),g=a.toString().split(".")[0],h=c.split(".")[1],i=c.indexOf(","),h?(h.indexOf("[")>-1?(h=h.replace("]",""),h=h.split("["),u=b(a,h[0].length+h[1].length,h[1].length)):u=b(a,h.length),g=u.split(".")[0],u=u.split(".")[1].length?m[n].delimiters.decimal+u.split(".")[1]:"",l&&0===Number(u.slice(1))&&(u="")):g=b(a,null),g.indexOf("-")>-1&&(g=g.slice(1),v=!0),i>-1&&(g=g.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(g=""),(j&&v?"(":"")+(!j&&v?"-":"")+(!v&&k?"+":"")+g+u+(r?r:"")+(p?p:"")+(q?q:"")+(j&&v?")":"")}function j(a,b){m[a]=b}var k,l="1.5.1",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a){return c(this,a?a:p)},unformat:function(a){return"[object Number]"===Object.prototype.toString.call(a)?a:d(this,a?a:p)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){return this._value=this._value+Number(a),this},subtract:function(a){return this._value=this._value-Number(a),this},multiply:function(a){return this._value=this._value*Number(a),this},divide:function(a){return this._value=this._value/Number(a),this},difference:function(a){var b=this._value-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file diff --git a/numeral.js b/numeral.js index 0cf5532a..e55c3973 100644 --- a/numeral.js +++ b/numeral.js @@ -469,6 +469,9 @@ }, unformat : function (inputString) { + if (Object.prototype.toString.call(inputString) === '[object Number]') { + return inputString; + } return unformatNumeral(this, inputString ? inputString : defaultFormat); }, diff --git a/tests/numeral/unformat.js b/tests/numeral/unformat.js index 7f14d9b8..f0b059b9 100644 --- a/tests/numeral/unformat.js +++ b/tests/numeral/unformat.js @@ -7,7 +7,7 @@ exports.unformat = { }, numbers: function (test) { - test.expect(9); + test.expect(15); var tests = [ ['10,000.123', 10000.123], @@ -18,7 +18,15 @@ exports.unformat = { ['1.23t', 1230000000000], ['N/A', 0], [, 0], - ['', 0] + ['', 0], + + // Pass Through for Numbers + [0, 0], + [1, 1], + [1.1, 1.1], + [-0, 0], + [-1, -1], + [-1.1, -1.1] ]; for (var i = 0; i < tests.length; i++) { From a00de62e2b1c1c60ad704bec5365f0bb09994bf8 Mon Sep 17 00:00:00 2001 From: Ahmed Al Hafoudh Date: Tue, 29 Oct 2013 22:46:48 +0100 Subject: [PATCH 09/16] Added Slovak localization --- languages.js | 35 ++++++++++++++ languages/sk.js | 34 ++++++++++++++ min/languages.min.js | 7 ++- min/languages/sk.min.js | 6 +++ tests/languages/sk.js | 101 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 languages/sk.js create mode 100644 min/languages/sk.min.js create mode 100644 tests/languages/sk.js diff --git a/languages.js b/languages.js index df1e0ed5..0bdcaa7a 100644 --- a/languages.js +++ b/languages.js @@ -638,6 +638,41 @@ } }()); +/*! + * numeral.js language configuration + * language : slovak (sk) + * author : Ahmed Al Hafoudh : http://www.freevision.sk + */ +(function () { + var language = { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'tis.', + million: 'mil.', + billion: 'b', + trillion: 't' + }, + ordinal: function () { + return '.'; + }, + currency: { + symbol: '€' + } + }; + + // Node + if (typeof module !== 'undefined' && module.exports) { + module.exports = language; + } + // Browser + if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { + this.numeral.language('sk', language); + } +}()); + /*! * numeral.js language configuration * language : thai (th) diff --git a/languages/sk.js b/languages/sk.js new file mode 100644 index 00000000..ac48faf7 --- /dev/null +++ b/languages/sk.js @@ -0,0 +1,34 @@ +/*! + * numeral.js language configuration + * language : slovak (sk) + * author : Ahmed Al Hafoudh : http://www.freevision.sk + */ +(function () { + var language = { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'tis.', + million: 'mil.', + billion: 'b', + trillion: 't' + }, + ordinal: function () { + return '.'; + }, + currency: { + symbol: '€' + } + }; + + // Node + if (typeof module !== 'undefined' && module.exports) { + module.exports = language; + } + // Browser + if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { + this.numeral.language('sk', language); + } +}()); diff --git a/min/languages.min.js b/min/languages.min.js index 49e5355d..bdf5f4e8 100644 --- a/min/languages.min.js +++ b/min/languages.min.js @@ -83,7 +83,12 @@ function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand * language : russian (ru) * author : Anatoli Papirovski : https://github.com/apapirovski */ -function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"тыс.",million:"млн",billion:"b",trillion:"t"},ordinal:function(){return"."},currency:{symbol:"руб."}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("ru",a)}(),/*! +function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"тыс.",million:"млн",billion:"b",trillion:"t"},ordinal:function(){return"."},currency:{symbol:"руб."}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("ru",a)}(),/*! + * numeral.js language configuration + * language : slovak (sk) + * author : Ahmed Al Hafoudh : http://www.freevision.sk + */ +function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"tis.",million:"mil.",billion:"b",trillion:"t"},ordinal:function(){return"."},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("sk",a)}(),/*! * numeral.js language configuration * language : thai (th) * author : Sathit Jittanupat : https://github.com/jojosati diff --git a/min/languages/sk.min.js b/min/languages/sk.min.js new file mode 100644 index 00000000..e68e4dc7 --- /dev/null +++ b/min/languages/sk.min.js @@ -0,0 +1,6 @@ +/*! + * numeral.js language configuration + * language : slovak (sk) + * author : Ahmed Al Hafoudh : http://www.freevision.sk + */ +!function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"tis.",million:"mil.",billion:"b",trillion:"t"},ordinal:function(){return"."},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("sk",a)}(); \ No newline at end of file diff --git a/tests/languages/sk.js b/tests/languages/sk.js new file mode 100644 index 00000000..6e40ba0f --- /dev/null +++ b/tests/languages/sk.js @@ -0,0 +1,101 @@ +var numeral = require('../../numeral'), + language = require('../../languages/sk'); + +numeral.language('sk', language); + +exports['language:sk'] = { + setUp: function (callback) { + numeral.language('sk'); + callback(); + }, + + tearDown: function (callback) { + numeral.language('en'); + callback(); + }, + + format: function (test) { + test.expect(16); + + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2mil.'], + [1460,'0a','1tis.'], + [-104000,'0a','-104tis.'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); + } + + test.done(); + }, + + currency: function (test) { + test.expect(4); + + var tests = [ + [1000.234,'$0,0.00','€1 000,23'], + [-1000.234,'($0,0)','(€1 000)'], + [-1000.234,'$0.00','-€1000,23'], + [1230974,'($0.00a)','€1,23mil.'] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); + } + + test.done(); + }, + + percentages: function (test) { + test.expect(4); + + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); + } + + test.done(); + }, + + unformat: function (test) { + test.expect(9); + + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(€1,23mil.)',-1230000], + ['10tis.',10000], + ['-10tis.',-10000], + ['23e',23], + ['€10 000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); + } + + test.done(); + } +}; \ No newline at end of file From c16dcaf863bdc8b736459cf83967b291bae812b8 Mon Sep 17 00:00:00 2001 From: Alan Kendall Date: Thu, 5 Sep 2013 12:41:14 -0500 Subject: [PATCH 10/16] added languageData() for getting and setting language props at runtime --- min/numeral.min.js | 2 +- numeral.js | 15 +++++++++++++++ tests/numeral/misc.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/min/numeral.min.js b/min/numeral.min.js index 53355b1c..ea7cbb14 100644 --- a/min/numeral.min.js +++ b/min/numeral.min.js @@ -5,4 +5,4 @@ * license : MIT * http://adamwdraper.github.com/Numeral-js/ */ -(function(){function a(a){this._value=a}function b(a,b,c){var d,e,f=Math.pow(10,b);return e=(Math.round(a*f)/f).toFixed(b),c&&(d=new RegExp("0{1,"+c+"}$"),e=e.replace(d,"")),e}function c(a,b){var c;return c=b.indexOf("$")>-1?e(a,b):b.indexOf("%")>-1?f(a,b):b.indexOf(":")>-1?g(a,b):i(a._value,b)}function d(a,b){var c,d,e,f,g,i=b,j=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===o)a._value=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._value=(k?k: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=k?Math.ceil(a._value):a._value}return a._value}function e(a,b){var c,d=b.indexOf("$")<=1?!0:!1,e="";return b.indexOf(" $")>-1?(e=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(e=" ",b=b.replace("$ ","")):b=b.replace("$",""),c=i(a._value,b),d?c.indexOf("(")>-1||c.indexOf("-")>-1?(c=c.split(""),c.splice(1,0,m[n].currency.symbol+e),c=c.join("")):c=m[n].currency.symbol+e+c:c.indexOf(")")>-1?(c=c.split(""),c.splice(-1,0,e+m[n].currency.symbol),c=c.join("")):c=c+e+m[n].currency.symbol,c}function f(a,b){var c,d="",e=100*a._value;return b.indexOf(" %")>-1?(d=" ",b=b.replace(" %","")):b=b.replace("%",""),c=i(e,b),c.indexOf(")")>-1?(c=c.split(""),c.splice(-1,0,d+"%"),c=c.join("")):c=c+d+"%",c}function g(a){var b=Math.floor(a._value/60/60),c=Math.floor((a._value-60*60*b)/60),d=Math.round(a._value-60*60*b-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*60*Number(b[0]),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){var d,e,f,g,h,i,j=!1,k=!1,l=!1,p="",q="",r="",s=Math.abs(a),t=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],u="",v=!1;if(0===a&&null!==o)return o;if(c.indexOf("(")>-1?(j=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(k=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(p=" ",c=c.replace(" a","")):c=c.replace("a",""),s>=Math.pow(10,12)?(p+=m[n].abbreviations.trillion,a/=Math.pow(10,12)):s=Math.pow(10,9)?(p+=m[n].abbreviations.billion,a/=Math.pow(10,9)):s=Math.pow(10,6)?(p+=m[n].abbreviations.million,a/=Math.pow(10,6)):s=Math.pow(10,3)&&(p+=m[n].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(q=" ",c=c.replace(" b","")):c=c.replace("b",""),f=0;f<=t.length;f++)if(d=Math.pow(1024,f),e=Math.pow(1024,f+1),a>=d&&e>a){q+=t[f],d>0&&(a/=d);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(r=" ",c=c.replace(" o","")):c=c.replace("o",""),r+=m[n].ordinal(a)),c.indexOf("[.]")>-1&&(l=!0,c=c.replace("[.]",".")),g=a.toString().split(".")[0],h=c.split(".")[1],i=c.indexOf(","),h?(h.indexOf("[")>-1?(h=h.replace("]",""),h=h.split("["),u=b(a,h[0].length+h[1].length,h[1].length)):u=b(a,h.length),g=u.split(".")[0],u=u.split(".")[1].length?m[n].delimiters.decimal+u.split(".")[1]:"",l&&0===Number(u.slice(1))&&(u="")):g=b(a,null),g.indexOf("-")>-1&&(g=g.slice(1),v=!0),i>-1&&(g=g.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(g=""),(j&&v?"(":"")+(!j&&v?"-":"")+(!v&&k?"+":"")+g+u+(r?r:"")+(p?p:"")+(q?q:"")+(j&&v?")":"")}function j(a,b){m[a]=b}var k,l="1.5.1",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a){return c(this,a?a:p)},unformat:function(a){return d(this,a?a:p)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){return this._value=this._value+Number(a),this},subtract:function(a){return this._value=this._value-Number(a),this},multiply:function(a){return this._value=this._value*Number(a),this},divide:function(a){return this._value=this._value/Number(a),this},difference:function(a){var b=this._value-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file +(function(){function a(a){this._n=a}function b(a,b,c){var d,e,f=Math.pow(10,b);return e=(Math.round(a*f)/f).toFixed(b),c&&(d=new RegExp("0{1,"+c+"}$"),e=e.replace(d,"")),e}function c(a,b){var c;return c=b.indexOf("$")>-1?e(a,b):b.indexOf("%")>-1?f(a,b):b.indexOf(":")>-1?g(a,b):i(a,b)}function d(a,b){var c,d,e,f,g,i=b,j=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._n=h(b);else if(b===o)a._n=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._n=(k?k: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._n=k?Math.ceil(a._n):a._n}return a._n}function e(a,b){var d,e=b.indexOf("$")<=1?!0:!1,f="";return b.indexOf(" $")>-1?(f=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(f=" ",b=b.replace("$ ","")):b=b.replace("$",""),d=c(a,b),e?d.indexOf("(")>-1||d.indexOf("-")>-1?(d=d.split(""),d.splice(1,0,m[n].currency.symbol+f),d=d.join("")):d=m[n].currency.symbol+f+d:d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,f+m[n].currency.symbol),d=d.join("")):d=d+f+m[n].currency.symbol,d}function f(a,b){var d,e="";return b.indexOf(" %")>-1?(e=" ",b=b.replace(" %","")):b=b.replace("%",""),a._n=100*a._n,d=c(a,b),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._n/60/60),c=Math.floor((a._n-60*60*b)/60),d=Math.round(a._n-60*60*b-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*60*Number(b[0]),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){var d,e,f,g,h,i,j=!1,k=!1,l=!1,p="",q="",r="",s=Math.abs(a._n),t=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],u="",v=!1;if(0===a._n&&null!==o)return o;if(c.indexOf("(")>-1?(j=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(k=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(p=" ",c=c.replace(" a","")):c=c.replace("a",""),s>=Math.pow(10,12)?(p+=m[n].abbreviations.trillion,a._n=a._n/Math.pow(10,12)):s=Math.pow(10,9)?(p+=m[n].abbreviations.billion,a._n=a._n/Math.pow(10,9)):s=Math.pow(10,6)?(p+=m[n].abbreviations.million,a._n=a._n/Math.pow(10,6)):s=Math.pow(10,3)&&(p+=m[n].abbreviations.thousand,a._n=a._n/Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(q=" ",c=c.replace(" b","")):c=c.replace("b",""),f=0;f<=t.length;f++)if(d=Math.pow(1024,f),e=Math.pow(1024,f+1),a._n>=d&&a._n0&&(a._n=a._n/d);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(r=" ",c=c.replace(" o","")):c=c.replace("o",""),r+=m[n].ordinal(a._n)),c.indexOf("[.]")>-1&&(l=!0,c=c.replace("[.]",".")),g=a._n.toString().split(".")[0],h=c.split(".")[1],i=c.indexOf(","),h?(h.indexOf("[")>-1?(h=h.replace("]",""),h=h.split("["),u=b(a._n,h[0].length+h[1].length,h[1].length)):u=b(a._n,h.length),g=u.split(".")[0],u=u.split(".")[1].length?m[n].delimiters.decimal+u.split(".")[1]:"",l&&0===Number(u.slice(1))&&(u="")):g=b(a._n,null),g.indexOf("-")>-1&&(g=g.slice(1),v=!0),i>-1&&(g=g.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(g=""),(j&&v?"(":"")+(!j&&v?"-":"")+(!v&&k?"+":"")+g+u+(r?r:"")+(p?p:"")+(q?q:"")+(j&&v?")":"")}function j(a,b){m[a]=b}var k,l="1.5.0",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.languageData=function(a){if(!a)return m[n];if(!m[a])throw new Error("Unknown language : "+a);return m[a]},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a){return c(this,a?a:p)},unformat:function(a){return d(this,a?a:p)},value:function(){return this._n},valueOf:function(){return this._n},set:function(a){return this._n=Number(a),this},add:function(a){return this._n=this._n+Number(a),this},subtract:function(a){return this._n=this._n-Number(a),this},multiply:function(a){return this._n=this._n*Number(a),this},divide:function(a){return this._n=this._n/Number(a),this},difference:function(a){var b=this._n-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file diff --git a/numeral.js b/numeral.js index 0cf5532a..ee0de24c 100644 --- a/numeral.js +++ b/numeral.js @@ -412,6 +412,21 @@ return numeral; }; + + // This function provides access to the loaded language data. If + // no arguments are passed in, it will simply return the current + // global language object. + numeral.languageData = function (key) { + if (!key) { + return languages[currentLanguage]; + } + + if (!languages[key]) { + throw new Error('Unknown language : ' + key); + } + + return languages[key]; + }; numeral.language('en', { delimiters: { diff --git a/tests/numeral/misc.js b/tests/numeral/misc.js index 1fe7aa23..0a07a482 100644 --- a/tests/numeral/misc.js +++ b/tests/numeral/misc.js @@ -87,6 +87,37 @@ exports.misc = { test.strictEqual(numeral.isNumeral(tests[i][0]), tests[i][1], tests[i][0]); } + test.done(); + }, + + languageData: function(test) { + test.expect(10); + + var cOld = '$', + cNew = '!', + formatTestVal = function() { return numeral('100').format('$0,0') }, + oldCurrencyVal = cOld + '100', + newCurrencyVal = cNew + '100'; + + test.strictEqual(numeral.languageData().currency.symbol, cOld, 'Current language currency is ' + cOld); + test.strictEqual(numeral.languageData('en').currency.symbol, cOld, 'English language currency is ' + cOld); + + numeral.languageData().currency.symbol = cNew; + test.strictEqual(numeral.languageData().currency.symbol, cNew, 'Current language currency is changed to ' + cNew); + test.strictEqual(formatTestVal(), newCurrencyVal, 'Format uses new currency'); + + numeral.languageData().currency.symbol = cOld; + test.strictEqual(numeral.languageData().currency.symbol, '$', 'Current language currency is reset to ' + cOld); + test.strictEqual(formatTestVal(), oldCurrencyVal, 'Format uses old currency'); + + numeral.languageData('en').currency.symbol = cNew; + test.strictEqual(numeral.languageData().currency.symbol, cNew, 'English language currency is changed to ' + cNew); + test.strictEqual(formatTestVal(), newCurrencyVal, 'Format uses new currency'); + + numeral.languageData('en').currency.symbol = cOld; + test.strictEqual(numeral.languageData().currency.symbol, cOld, 'English language currency is reset to ' + cOld); + test.strictEqual(formatTestVal(), oldCurrencyVal, 'Format uses old currency'); + test.done(); } }; \ No newline at end of file From 8786b7516339a8f094ce480a942790aac391c1a3 Mon Sep 17 00:00:00 2001 From: Adam Draper Date: Tue, 29 Oct 2013 20:38:10 -0700 Subject: [PATCH 11/16] release --- min/numeral.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/min/numeral.min.js b/min/numeral.min.js index ea7cbb14..4257933a 100644 --- a/min/numeral.min.js +++ b/min/numeral.min.js @@ -5,4 +5,4 @@ * license : MIT * http://adamwdraper.github.com/Numeral-js/ */ -(function(){function a(a){this._n=a}function b(a,b,c){var d,e,f=Math.pow(10,b);return e=(Math.round(a*f)/f).toFixed(b),c&&(d=new RegExp("0{1,"+c+"}$"),e=e.replace(d,"")),e}function c(a,b){var c;return c=b.indexOf("$")>-1?e(a,b):b.indexOf("%")>-1?f(a,b):b.indexOf(":")>-1?g(a,b):i(a,b)}function d(a,b){var c,d,e,f,g,i=b,j=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._n=h(b);else if(b===o)a._n=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._n=(k?k: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._n=k?Math.ceil(a._n):a._n}return a._n}function e(a,b){var d,e=b.indexOf("$")<=1?!0:!1,f="";return b.indexOf(" $")>-1?(f=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(f=" ",b=b.replace("$ ","")):b=b.replace("$",""),d=c(a,b),e?d.indexOf("(")>-1||d.indexOf("-")>-1?(d=d.split(""),d.splice(1,0,m[n].currency.symbol+f),d=d.join("")):d=m[n].currency.symbol+f+d:d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,f+m[n].currency.symbol),d=d.join("")):d=d+f+m[n].currency.symbol,d}function f(a,b){var d,e="";return b.indexOf(" %")>-1?(e=" ",b=b.replace(" %","")):b=b.replace("%",""),a._n=100*a._n,d=c(a,b),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._n/60/60),c=Math.floor((a._n-60*60*b)/60),d=Math.round(a._n-60*60*b-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*60*Number(b[0]),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){var d,e,f,g,h,i,j=!1,k=!1,l=!1,p="",q="",r="",s=Math.abs(a._n),t=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],u="",v=!1;if(0===a._n&&null!==o)return o;if(c.indexOf("(")>-1?(j=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(k=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(p=" ",c=c.replace(" a","")):c=c.replace("a",""),s>=Math.pow(10,12)?(p+=m[n].abbreviations.trillion,a._n=a._n/Math.pow(10,12)):s=Math.pow(10,9)?(p+=m[n].abbreviations.billion,a._n=a._n/Math.pow(10,9)):s=Math.pow(10,6)?(p+=m[n].abbreviations.million,a._n=a._n/Math.pow(10,6)):s=Math.pow(10,3)&&(p+=m[n].abbreviations.thousand,a._n=a._n/Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(q=" ",c=c.replace(" b","")):c=c.replace("b",""),f=0;f<=t.length;f++)if(d=Math.pow(1024,f),e=Math.pow(1024,f+1),a._n>=d&&a._n0&&(a._n=a._n/d);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(r=" ",c=c.replace(" o","")):c=c.replace("o",""),r+=m[n].ordinal(a._n)),c.indexOf("[.]")>-1&&(l=!0,c=c.replace("[.]",".")),g=a._n.toString().split(".")[0],h=c.split(".")[1],i=c.indexOf(","),h?(h.indexOf("[")>-1?(h=h.replace("]",""),h=h.split("["),u=b(a._n,h[0].length+h[1].length,h[1].length)):u=b(a._n,h.length),g=u.split(".")[0],u=u.split(".")[1].length?m[n].delimiters.decimal+u.split(".")[1]:"",l&&0===Number(u.slice(1))&&(u="")):g=b(a._n,null),g.indexOf("-")>-1&&(g=g.slice(1),v=!0),i>-1&&(g=g.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(g=""),(j&&v?"(":"")+(!j&&v?"-":"")+(!v&&k?"+":"")+g+u+(r?r:"")+(p?p:"")+(q?q:"")+(j&&v?")":"")}function j(a,b){m[a]=b}var k,l="1.5.0",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.languageData=function(a){if(!a)return m[n];if(!m[a])throw new Error("Unknown language : "+a);return m[a]},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a){return c(this,a?a:p)},unformat:function(a){return d(this,a?a:p)},value:function(){return this._n},valueOf:function(){return this._n},set:function(a){return this._n=Number(a),this},add:function(a){return this._n=this._n+Number(a),this},subtract:function(a){return this._n=this._n-Number(a),this},multiply:function(a){return this._n=this._n*Number(a),this},divide:function(a){return this._n=this._n/Number(a),this},difference:function(a){var b=this._n-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file +(function(){function a(a){this._value=a}function b(a,b,c){var d,e,f=Math.pow(10,b);return e=(Math.round(a*f)/f).toFixed(b),c&&(d=new RegExp("0{1,"+c+"}$"),e=e.replace(d,"")),e}function c(a,b){var c;return c=b.indexOf("$")>-1?e(a,b):b.indexOf("%")>-1?f(a,b):b.indexOf(":")>-1?g(a,b):i(a._value,b)}function d(a,b){var c,d,e,f,g,i=b,j=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===o)a._value=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._value=(k?k: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=k?Math.ceil(a._value):a._value}return a._value}function e(a,b){var c,d=b.indexOf("$")<=1?!0:!1,e="";return b.indexOf(" $")>-1?(e=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(e=" ",b=b.replace("$ ","")):b=b.replace("$",""),c=i(a._value,b),d?c.indexOf("(")>-1||c.indexOf("-")>-1?(c=c.split(""),c.splice(1,0,m[n].currency.symbol+e),c=c.join("")):c=m[n].currency.symbol+e+c:c.indexOf(")")>-1?(c=c.split(""),c.splice(-1,0,e+m[n].currency.symbol),c=c.join("")):c=c+e+m[n].currency.symbol,c}function f(a,b){var c,d="",e=100*a._value;return b.indexOf(" %")>-1?(d=" ",b=b.replace(" %","")):b=b.replace("%",""),c=i(e,b),c.indexOf(")")>-1?(c=c.split(""),c.splice(-1,0,d+"%"),c=c.join("")):c=c+d+"%",c}function g(a){var b=Math.floor(a._value/60/60),c=Math.floor((a._value-60*60*b)/60),d=Math.round(a._value-60*60*b-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*60*Number(b[0]),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){var d,e,f,g,h,i,j=!1,k=!1,l=!1,p="",q="",r="",s=Math.abs(a),t=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],u="",v=!1;if(0===a&&null!==o)return o;if(c.indexOf("(")>-1?(j=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(k=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(p=" ",c=c.replace(" a","")):c=c.replace("a",""),s>=Math.pow(10,12)?(p+=m[n].abbreviations.trillion,a/=Math.pow(10,12)):s=Math.pow(10,9)?(p+=m[n].abbreviations.billion,a/=Math.pow(10,9)):s=Math.pow(10,6)?(p+=m[n].abbreviations.million,a/=Math.pow(10,6)):s=Math.pow(10,3)&&(p+=m[n].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(q=" ",c=c.replace(" b","")):c=c.replace("b",""),f=0;f<=t.length;f++)if(d=Math.pow(1024,f),e=Math.pow(1024,f+1),a>=d&&e>a){q+=t[f],d>0&&(a/=d);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(r=" ",c=c.replace(" o","")):c=c.replace("o",""),r+=m[n].ordinal(a)),c.indexOf("[.]")>-1&&(l=!0,c=c.replace("[.]",".")),g=a.toString().split(".")[0],h=c.split(".")[1],i=c.indexOf(","),h?(h.indexOf("[")>-1?(h=h.replace("]",""),h=h.split("["),u=b(a,h[0].length+h[1].length,h[1].length)):u=b(a,h.length),g=u.split(".")[0],u=u.split(".")[1].length?m[n].delimiters.decimal+u.split(".")[1]:"",l&&0===Number(u.slice(1))&&(u="")):g=b(a,null),g.indexOf("-")>-1&&(g=g.slice(1),v=!0),i>-1&&(g=g.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(g=""),(j&&v?"(":"")+(!j&&v?"-":"")+(!v&&k?"+":"")+g+u+(r?r:"")+(p?p:"")+(q?q:"")+(j&&v?")":"")}function j(a,b){m[a]=b}var k,l="1.5.1",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.languageData=function(a){if(!a)return m[n];if(!m[a])throw new Error("Unknown language : "+a);return m[a]},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a){return c(this,a?a:p)},unformat:function(a){return d(this,a?a:p)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){return this._value=this._value+Number(a),this},subtract:function(a){return this._value=this._value-Number(a),this},multiply:function(a){return this._value=this._value*Number(a),this},divide:function(a){return this._value=this._value/Number(a),this},difference:function(a){var b=this._value-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file From d3692d2eb6cfc527261df6f50e48c57377b77eea Mon Sep 17 00:00:00 2001 From: Adam Draper Date: Tue, 29 Oct 2013 20:45:36 -0700 Subject: [PATCH 12/16] release --- languages.js | 34 ++++++++++++++++++++++++++++++++++ min/languages.min.js | 7 ++++++- min/languages/hu.min.js | 6 ++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 min/languages/hu.min.js diff --git a/languages.js b/languages.js index 800eaeb0..ed435004 100644 --- a/languages.js +++ b/languages.js @@ -392,6 +392,40 @@ this.numeral.language('fr', language); } }()); +/*! + * numeral.js language configuration + * language : Hungarian (hu) + * author : Peter Bakondy : https://github.com/pbakondy + */ +(function () { + var language = { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'E', // ezer + million: 'M', // millió + billion: 'Mrd', // milliárd + trillion: 'T' // trillió + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: ' Ft' + } + }; + + // Node + if (typeof module !== 'undefined' && module.exports) { + module.exports = language; + } + // Browser + if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { + this.numeral.language('hu', language); + } +}()); /*! * numeral.js language configuration * language : italian Italy (it) diff --git a/min/languages.min.js b/min/languages.min.js index c6ce345d..b8f48877 100644 --- a/min/languages.min.js +++ b/min/languages.min.js @@ -53,7 +53,12 @@ function(){var a={delimiters:{thousands:"'",decimal:"."},abbreviations:{thousand * language : french (fr) * author : Adam Draper : https://github.com/adamwdraper */ -function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){return 1===a?"er":"e"},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("fr",a)}(),/*! +function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){return 1===a?"er":"e"},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("fr",a)}(),/*! + * numeral.js language configuration + * language : Hungarian (hu) + * author : Peter Bakondy : https://github.com/pbakondy + */ +function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"E",million:"M",billion:"Mrd",trillion:"T"},ordinal:function(){return"."},currency:{symbol:" Ft"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("hu",a)}(),/*! * numeral.js language configuration * language : italian Italy (it) * author : Giacomo Trombi : http://cinquepunti.it diff --git a/min/languages/hu.min.js b/min/languages/hu.min.js new file mode 100644 index 00000000..084551b2 --- /dev/null +++ b/min/languages/hu.min.js @@ -0,0 +1,6 @@ +/*! + * numeral.js language configuration + * language : Hungarian (hu) + * author : Peter Bakondy : https://github.com/pbakondy + */ +!function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"E",million:"M",billion:"Mrd",trillion:"T"},ordinal:function(){return"."},currency:{symbol:" Ft"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("hu",a)}(); \ No newline at end of file From 9af4d766712f016b14587729e94543e34b28649b Mon Sep 17 00:00:00 2001 From: Adam Draper Date: Tue, 29 Oct 2013 20:56:07 -0700 Subject: [PATCH 13/16] remove whitespace --- numeral.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numeral.js b/numeral.js index c5be71ed..a6189065 100644 --- a/numeral.js +++ b/numeral.js @@ -260,7 +260,7 @@ } else { format = format.replace('a', ''); } - + if (abs >= Math.pow(10, 12)) { // trillion abbr = abbr + languages[currentLanguage].abbreviations.trillion; From cb80270430707d7a9e07abbf0762e524a657d629 Mon Sep 17 00:00:00 2001 From: Adam Draper Date: Tue, 29 Oct 2013 20:57:29 -0700 Subject: [PATCH 14/16] build --- min/numeral.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/min/numeral.min.js b/min/numeral.min.js index 08ce5b87..ebbae50c 100644 --- a/min/numeral.min.js +++ b/min/numeral.min.js @@ -5,4 +5,4 @@ * license : MIT * http://adamwdraper.github.com/Numeral-js/ */ -(function(){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=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===o)a._value=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._value=(k?k: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=k?Math.ceil(a._value):a._value}return a._value}function e(a,b,c){var d,e=b.indexOf("$")<=1?!0:!1,f="";return b.indexOf(" $")>-1?(f=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(f=" ",b=b.replace("$ ","")):b=b.replace("$",""),d=i(a._value,b,c),e?d.indexOf("(")>-1||d.indexOf("-")>-1?(d=d.split(""),d.splice(1,0,m[n].currency.symbol+f),d=d.join("")):d=m[n].currency.symbol+f+d:d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,f+m[n].currency.symbol),d=d.join("")):d=d+f+m[n].currency.symbol,d}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*60*b)/60),d=Math.round(a._value-60*60*b-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*60*Number(b[0]),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,p=!1,q="",r="",s="",t=Math.abs(a),u=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],v="",w=!1;if(0===a&&null!==o)return o;if(c.indexOf("(")>-1?(k=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(l=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(q=" ",c=c.replace(" a","")):c=c.replace("a",""),t>=Math.pow(10,12)?(q+=m[n].abbreviations.trillion,a/=Math.pow(10,12)):t=Math.pow(10,9)?(q+=m[n].abbreviations.billion,a/=Math.pow(10,9)):t=Math.pow(10,6)?(q+=m[n].abbreviations.million,a/=Math.pow(10,6)):t=Math.pow(10,3)&&(q+=m[n].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(r=" ",c=c.replace(" b","")):c=c.replace("b",""),g=0;g<=u.length;g++)if(e=Math.pow(1024,g),f=Math.pow(1024,g+1),a>=e&&f>a){r+=u[g],e>0&&(a/=e);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(s=" ",c=c.replace(" o","")):c=c.replace("o",""),s+=m[n].ordinal(a)),c.indexOf("[.]")>-1&&(p=!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("["),v=b(a,i[0].length+i[1].length,d,i[1].length)):v=b(a,i.length,d),h=v.split(".")[0],v=v.split(".")[1].length?m[n].delimiters.decimal+v.split(".")[1]:"",p&&0===Number(v.slice(1))&&(v="")):h=b(a,null,d),h.indexOf("-")>-1&&(h=h.slice(1),w=!0),j>-1&&(h=h.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(h=""),(k&&w?"(":"")+(!k&&w?"-":"")+(!w&&l?"+":"")+h+v+(s?s:"")+(q?q:"")+(r?r:"")+(k&&w?")":"")}function j(a,b){m[a]=b}var k,l="1.5.1",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a,b){return c(this,a?a:p,void 0!==b?b:Math.round)},unformat:function(a){return d(this,a?a:p)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){return this._value=this._value+Number(a),this},subtract:function(a){return this._value=this._value-Number(a),this},multiply:function(a){return this._value=this._value*Number(a),this},divide:function(a){return this._value=this._value/Number(a),this},difference:function(a){var b=this._value-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file +(function(){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=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===o)a._value=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._value=(k?k: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=k?Math.ceil(a._value):a._value}return a._value}function e(a,b,c){var d,e=b.indexOf("$")<=1?!0:!1,f="";return b.indexOf(" $")>-1?(f=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(f=" ",b=b.replace("$ ","")):b=b.replace("$",""),d=i(a._value,b,c),e?d.indexOf("(")>-1||d.indexOf("-")>-1?(d=d.split(""),d.splice(1,0,m[n].currency.symbol+f),d=d.join("")):d=m[n].currency.symbol+f+d:d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,f+m[n].currency.symbol),d=d.join("")):d=d+f+m[n].currency.symbol,d}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*60*b)/60),d=Math.round(a._value-60*60*b-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*60*Number(b[0]),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,p=!1,q="",r="",s="",t=Math.abs(a),u=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],v="",w=!1;if(0===a&&null!==o)return o;if(c.indexOf("(")>-1?(k=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(l=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(q=" ",c=c.replace(" a","")):c=c.replace("a",""),t>=Math.pow(10,12)?(q+=m[n].abbreviations.trillion,a/=Math.pow(10,12)):t=Math.pow(10,9)?(q+=m[n].abbreviations.billion,a/=Math.pow(10,9)):t=Math.pow(10,6)?(q+=m[n].abbreviations.million,a/=Math.pow(10,6)):t=Math.pow(10,3)&&(q+=m[n].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(r=" ",c=c.replace(" b","")):c=c.replace("b",""),g=0;g<=u.length;g++)if(e=Math.pow(1024,g),f=Math.pow(1024,g+1),a>=e&&f>a){r+=u[g],e>0&&(a/=e);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(s=" ",c=c.replace(" o","")):c=c.replace("o",""),s+=m[n].ordinal(a)),c.indexOf("[.]")>-1&&(p=!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("["),v=b(a,i[0].length+i[1].length,d,i[1].length)):v=b(a,i.length,d),h=v.split(".")[0],v=v.split(".")[1].length?m[n].delimiters.decimal+v.split(".")[1]:"",p&&0===Number(v.slice(1))&&(v="")):h=b(a,null,d),h.indexOf("-")>-1&&(h=h.slice(1),w=!0),j>-1&&(h=h.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(h=""),(k&&w?"(":"")+(!k&&w?"-":"")+(!w&&l?"+":"")+h+v+(s?s:"")+(q?q:"")+(r?r:"")+(k&&w?")":"")}function j(a,b){m[a]=b}var k,l="1.5.1",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.languageData=function(a){if(!a)return m[n];if(!m[a])throw new Error("Unknown language : "+a);return m[a]},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a,b){return c(this,a?a:p,void 0!==b?b:Math.round)},unformat:function(a){return d(this,a?a:p)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){return this._value=this._value+Number(a),this},subtract:function(a){return this._value=this._value-Number(a),this},multiply:function(a){return this._value=this._value*Number(a),this},divide:function(a){return this._value=this._value/Number(a),this},difference:function(a){var b=this._value-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file From c9ba58013e0e19234a900f8f98674a8efba76e85 Mon Sep 17 00:00:00 2001 From: Adam Draper Date: Tue, 29 Oct 2013 21:12:12 -0700 Subject: [PATCH 15/16] build --- min/numeral.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/min/numeral.min.js b/min/numeral.min.js index ebbae50c..5c94bd04 100644 --- a/min/numeral.min.js +++ b/min/numeral.min.js @@ -5,4 +5,4 @@ * license : MIT * http://adamwdraper.github.com/Numeral-js/ */ -(function(){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=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===o)a._value=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._value=(k?k: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=k?Math.ceil(a._value):a._value}return a._value}function e(a,b,c){var d,e=b.indexOf("$")<=1?!0:!1,f="";return b.indexOf(" $")>-1?(f=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(f=" ",b=b.replace("$ ","")):b=b.replace("$",""),d=i(a._value,b,c),e?d.indexOf("(")>-1||d.indexOf("-")>-1?(d=d.split(""),d.splice(1,0,m[n].currency.symbol+f),d=d.join("")):d=m[n].currency.symbol+f+d:d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,f+m[n].currency.symbol),d=d.join("")):d=d+f+m[n].currency.symbol,d}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*60*b)/60),d=Math.round(a._value-60*60*b-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*60*Number(b[0]),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,p=!1,q="",r="",s="",t=Math.abs(a),u=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],v="",w=!1;if(0===a&&null!==o)return o;if(c.indexOf("(")>-1?(k=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(l=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(q=" ",c=c.replace(" a","")):c=c.replace("a",""),t>=Math.pow(10,12)?(q+=m[n].abbreviations.trillion,a/=Math.pow(10,12)):t=Math.pow(10,9)?(q+=m[n].abbreviations.billion,a/=Math.pow(10,9)):t=Math.pow(10,6)?(q+=m[n].abbreviations.million,a/=Math.pow(10,6)):t=Math.pow(10,3)&&(q+=m[n].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(r=" ",c=c.replace(" b","")):c=c.replace("b",""),g=0;g<=u.length;g++)if(e=Math.pow(1024,g),f=Math.pow(1024,g+1),a>=e&&f>a){r+=u[g],e>0&&(a/=e);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(s=" ",c=c.replace(" o","")):c=c.replace("o",""),s+=m[n].ordinal(a)),c.indexOf("[.]")>-1&&(p=!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("["),v=b(a,i[0].length+i[1].length,d,i[1].length)):v=b(a,i.length,d),h=v.split(".")[0],v=v.split(".")[1].length?m[n].delimiters.decimal+v.split(".")[1]:"",p&&0===Number(v.slice(1))&&(v="")):h=b(a,null,d),h.indexOf("-")>-1&&(h=h.slice(1),w=!0),j>-1&&(h=h.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(h=""),(k&&w?"(":"")+(!k&&w?"-":"")+(!w&&l?"+":"")+h+v+(s?s:"")+(q?q:"")+(r?r:"")+(k&&w?")":"")}function j(a,b){m[a]=b}var k,l="1.5.1",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.languageData=function(a){if(!a)return m[n];if(!m[a])throw new Error("Unknown language : "+a);return m[a]},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a,b){return c(this,a?a:p,void 0!==b?b:Math.round)},unformat:function(a){return d(this,a?a:p)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){return this._value=this._value+Number(a),this},subtract:function(a){return this._value=this._value-Number(a),this},multiply:function(a){return this._value=this._value*Number(a),this},divide:function(a){return this._value=this._value/Number(a),this},difference:function(a){var b=this._value-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file +(function(){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=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===o)a._value=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._value=(k?k: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=k?Math.ceil(a._value):a._value}return a._value}function e(a,b,c){var d,e=b.indexOf("$")<=1?!0:!1,f="";return b.indexOf(" $")>-1?(f=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(f=" ",b=b.replace("$ ","")):b=b.replace("$",""),d=i(a._value,b,c),e?d.indexOf("(")>-1||d.indexOf("-")>-1?(d=d.split(""),d.splice(1,0,m[n].currency.symbol+f),d=d.join("")):d=m[n].currency.symbol+f+d:d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,f+m[n].currency.symbol),d=d.join("")):d=d+f+m[n].currency.symbol,d}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*60*b)/60),d=Math.round(a._value-60*60*b-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*60*Number(b[0]),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,p=!1,q="",r="",s="",t=Math.abs(a),u=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],v="",w=!1;if(0===a&&null!==o)return o;if(c.indexOf("(")>-1?(k=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(l=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(q=" ",c=c.replace(" a","")):c=c.replace("a",""),t>=Math.pow(10,12)?(q+=m[n].abbreviations.trillion,a/=Math.pow(10,12)):t=Math.pow(10,9)?(q+=m[n].abbreviations.billion,a/=Math.pow(10,9)):t=Math.pow(10,6)?(q+=m[n].abbreviations.million,a/=Math.pow(10,6)):t=Math.pow(10,3)&&(q+=m[n].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(r=" ",c=c.replace(" b","")):c=c.replace("b",""),g=0;g<=u.length;g++)if(e=Math.pow(1024,g),f=Math.pow(1024,g+1),a>=e&&f>a){r+=u[g],e>0&&(a/=e);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(s=" ",c=c.replace(" o","")):c=c.replace("o",""),s+=m[n].ordinal(a)),c.indexOf("[.]")>-1&&(p=!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("["),v=b(a,i[0].length+i[1].length,d,i[1].length)):v=b(a,i.length,d),h=v.split(".")[0],v=v.split(".")[1].length?m[n].delimiters.decimal+v.split(".")[1]:"",p&&0===Number(v.slice(1))&&(v="")):h=b(a,null,d),h.indexOf("-")>-1&&(h=h.slice(1),w=!0),j>-1&&(h=h.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(h=""),(k&&w?"(":"")+(!k&&w?"-":"")+(!w&&l?"+":"")+h+v+(s?s:"")+(q?q:"")+(r?r:"")+(k&&w?")":"")}function j(a,b){m[a]=b}var k,l="1.5.1",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.languageData=function(a){if(!a)return m[n];if(!m[a])throw new Error("Unknown language : "+a);return m[a]},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a,b){return c(this,a?a:p,void 0!==b?b:Math.round)},unformat:function(a){return"[object Number]"===Object.prototype.toString.call(a)?a:d(this,a?a:p)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){return this._value=this._value+Number(a),this},subtract:function(a){return this._value=this._value-Number(a),this},multiply:function(a){return this._value=this._value*Number(a),this},divide:function(a){return this._value=this._value/Number(a),this},difference:function(a){var b=this._value-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file From 4d0be28efe832c214879c88374f19656cb413bac Mon Sep 17 00:00:00 2001 From: Adam Draper Date: Tue, 29 Oct 2013 22:08:54 -0700 Subject: [PATCH 16/16] update readme and version --- Gruntfile.js | 6 +++++- README.md | 14 +++++++++++--- bower.json | 2 +- component.json | 2 +- min/numeral.min.js | 4 ++-- numeral.js | 4 ++-- package.json | 6 +++--- 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 1cf1ef44..b90e008c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -69,13 +69,17 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-concat'); + grunt.registerTask('default', [ + 'test' + ]); + grunt.registerTask('test', [ 'jshint', 'nodeunit' ]); // P - grunt.registerTask('release', [ + grunt.registerTask('build', [ 'jshint', 'nodeunit', 'concat', diff --git a/README.md b/README.md index bf279546..8c8f430d 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,11 @@ Please submit all pull requests to the `develop` branch. 4. Add your tests to the files in `/tests` -5. To test your tests, run `grunt test` +5. To test your tests, run `grunt` -6. When all your tests are passing, run `grunt release` to minify all files +6. When all your tests are passing, run `grunt build` to minify all files -7. Submit a pull request. +7. Submit a pull request to the `develop` branch. ### Languages @@ -42,6 +42,14 @@ See [the english unit tests](https://github.com/adamwdraper/Numeral-js/blob/mast # Changelog +### 1.5.2 + +Bug fix: Unformat should pass through if given a number + +Added a mechanism to control rounding behaviour + +Added languageData() for getting and setting language props at runtime + ### 1.5.1 Bug fix: Make sure values aren't changed during formatting diff --git a/bower.json b/bower.json index fcc6e981..92ed96e9 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "numeral", "repo": "adamwdraper/Numeral-js", - "version": "1.5.1", + "version": "1.5.2", "description": "Format and manipulate numbers.", "keywords": [ "numeral", diff --git a/component.json b/component.json index 36fb0b87..57d310cd 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "numeral", "repo": "adamwdraper/Numeral-js", - "version": "1.5.1", + "version": "1.5.2", "description": "Format and manipulate numbers.", "keywords": [ "numeral", diff --git a/min/numeral.min.js b/min/numeral.min.js index 5c94bd04..81d4e49b 100644 --- a/min/numeral.min.js +++ b/min/numeral.min.js @@ -1,8 +1,8 @@ /*! * numeral.js - * version : 1.5.1 + * version : 1.5.2 * author : Adam Draper * license : MIT * http://adamwdraper.github.com/Numeral-js/ */ -(function(){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=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===o)a._value=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._value=(k?k: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=k?Math.ceil(a._value):a._value}return a._value}function e(a,b,c){var d,e=b.indexOf("$")<=1?!0:!1,f="";return b.indexOf(" $")>-1?(f=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(f=" ",b=b.replace("$ ","")):b=b.replace("$",""),d=i(a._value,b,c),e?d.indexOf("(")>-1||d.indexOf("-")>-1?(d=d.split(""),d.splice(1,0,m[n].currency.symbol+f),d=d.join("")):d=m[n].currency.symbol+f+d:d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,f+m[n].currency.symbol),d=d.join("")):d=d+f+m[n].currency.symbol,d}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*60*b)/60),d=Math.round(a._value-60*60*b-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*60*Number(b[0]),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,p=!1,q="",r="",s="",t=Math.abs(a),u=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],v="",w=!1;if(0===a&&null!==o)return o;if(c.indexOf("(")>-1?(k=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(l=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(q=" ",c=c.replace(" a","")):c=c.replace("a",""),t>=Math.pow(10,12)?(q+=m[n].abbreviations.trillion,a/=Math.pow(10,12)):t=Math.pow(10,9)?(q+=m[n].abbreviations.billion,a/=Math.pow(10,9)):t=Math.pow(10,6)?(q+=m[n].abbreviations.million,a/=Math.pow(10,6)):t=Math.pow(10,3)&&(q+=m[n].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(r=" ",c=c.replace(" b","")):c=c.replace("b",""),g=0;g<=u.length;g++)if(e=Math.pow(1024,g),f=Math.pow(1024,g+1),a>=e&&f>a){r+=u[g],e>0&&(a/=e);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(s=" ",c=c.replace(" o","")):c=c.replace("o",""),s+=m[n].ordinal(a)),c.indexOf("[.]")>-1&&(p=!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("["),v=b(a,i[0].length+i[1].length,d,i[1].length)):v=b(a,i.length,d),h=v.split(".")[0],v=v.split(".")[1].length?m[n].delimiters.decimal+v.split(".")[1]:"",p&&0===Number(v.slice(1))&&(v="")):h=b(a,null,d),h.indexOf("-")>-1&&(h=h.slice(1),w=!0),j>-1&&(h=h.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(h=""),(k&&w?"(":"")+(!k&&w?"-":"")+(!w&&l?"+":"")+h+v+(s?s:"")+(q?q:"")+(r?r:"")+(k&&w?")":"")}function j(a,b){m[a]=b}var k,l="1.5.1",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.languageData=function(a){if(!a)return m[n];if(!m[a])throw new Error("Unknown language : "+a);return m[a]},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a,b){return c(this,a?a:p,void 0!==b?b:Math.round)},unformat:function(a){return"[object Number]"===Object.prototype.toString.call(a)?a:d(this,a?a:p)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){return this._value=this._value+Number(a),this},subtract:function(a){return this._value=this._value-Number(a),this},multiply:function(a){return this._value=this._value*Number(a),this},divide:function(a){return this._value=this._value/Number(a),this},difference:function(a){var b=this._value-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file +(function(){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=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===o)a._value=0;else{for("."!==m[n].delimiters.decimal&&(b=b.replace(/\./g,"").replace(m[n].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+m[n].abbreviations.thousand+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+m[n].abbreviations.million+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+m[n].abbreviations.billion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+m[n].abbreviations.trillion+"(?:\\)|(\\"+m[n].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1?Math.pow(1024,g+1):!1);g++);a._value=(k?k: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=k?Math.ceil(a._value):a._value}return a._value}function e(a,b,c){var d,e=b.indexOf("$")<=1?!0:!1,f="";return b.indexOf(" $")>-1?(f=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(f=" ",b=b.replace("$ ","")):b=b.replace("$",""),d=i(a._value,b,c),e?d.indexOf("(")>-1||d.indexOf("-")>-1?(d=d.split(""),d.splice(1,0,m[n].currency.symbol+f),d=d.join("")):d=m[n].currency.symbol+f+d:d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,f+m[n].currency.symbol),d=d.join("")):d=d+f+m[n].currency.symbol,d}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*60*b)/60),d=Math.round(a._value-60*60*b-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*60*Number(b[0]),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,p=!1,q="",r="",s="",t=Math.abs(a),u=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],v="",w=!1;if(0===a&&null!==o)return o;if(c.indexOf("(")>-1?(k=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(l=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(c.indexOf(" a")>-1?(q=" ",c=c.replace(" a","")):c=c.replace("a",""),t>=Math.pow(10,12)?(q+=m[n].abbreviations.trillion,a/=Math.pow(10,12)):t=Math.pow(10,9)?(q+=m[n].abbreviations.billion,a/=Math.pow(10,9)):t=Math.pow(10,6)?(q+=m[n].abbreviations.million,a/=Math.pow(10,6)):t=Math.pow(10,3)&&(q+=m[n].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(r=" ",c=c.replace(" b","")):c=c.replace("b",""),g=0;g<=u.length;g++)if(e=Math.pow(1024,g),f=Math.pow(1024,g+1),a>=e&&f>a){r+=u[g],e>0&&(a/=e);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(s=" ",c=c.replace(" o","")):c=c.replace("o",""),s+=m[n].ordinal(a)),c.indexOf("[.]")>-1&&(p=!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("["),v=b(a,i[0].length+i[1].length,d,i[1].length)):v=b(a,i.length,d),h=v.split(".")[0],v=v.split(".")[1].length?m[n].delimiters.decimal+v.split(".")[1]:"",p&&0===Number(v.slice(1))&&(v="")):h=b(a,null,d),h.indexOf("-")>-1&&(h=h.slice(1),w=!0),j>-1&&(h=h.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m[n].delimiters.thousands)),0===c.indexOf(".")&&(h=""),(k&&w?"(":"")+(!k&&w?"-":"")+(!w&&l?"+":"")+h+v+(s?s:"")+(q?q:"")+(r?r:"")+(k&&w?")":"")}function j(a,b){m[a]=b}var k,l="1.5.2",m={},n="en",o=null,p="0,0",q="undefined"!=typeof module&&module.exports;k=function(b){return k.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=k.fn.unformat(b)),new a(Number(b))},k.version=l,k.isNumeral=function(b){return b instanceof a},k.language=function(a,b){if(!a)return n;if(a&&!b){if(!m[a])throw new Error("Unknown language : "+a);n=a}return(b||!m[a])&&j(a,b),k},k.languageData=function(a){if(!a)return m[n];if(!m[a])throw new Error("Unknown language : "+a);return m[a]},k.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:"$"}}),k.zeroFormat=function(a){o="string"==typeof a?a:null},k.defaultFormat=function(a){p="string"==typeof a?a:"0.0"},k.fn=a.prototype={clone:function(){return k(this)},format:function(a,b){return c(this,a?a:p,void 0!==b?b:Math.round)},unformat:function(a){return"[object Number]"===Object.prototype.toString.call(a)?a:d(this,a?a:p)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){return this._value=this._value+Number(a),this},subtract:function(a){return this._value=this._value-Number(a),this},multiply:function(a){return this._value=this._value*Number(a),this},divide:function(a){return this._value=this._value/Number(a),this},difference:function(a){var b=this._value-Number(a);return 0>b&&(b=-b),b}},q&&(module.exports=k),"undefined"==typeof ender&&(this.numeral=k),"function"==typeof define&&define.amd&&define([],function(){return k})}).call(this); \ No newline at end of file diff --git a/numeral.js b/numeral.js index 4b823281..20b51401 100644 --- a/numeral.js +++ b/numeral.js @@ -1,6 +1,6 @@ /*! * numeral.js - * version : 1.5.1 + * version : 1.5.2 * author : Adam Draper * license : MIT * http://adamwdraper.github.com/Numeral-js/ @@ -13,7 +13,7 @@ ************************************/ var numeral, - VERSION = '1.5.1', + VERSION = '1.5.2', // internal storage for language config files languages = {}, currentLanguage = 'en', diff --git a/package.json b/package.json index e2329fd2..3cce61f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "numeral", - "version": "1.5.1", + "version": "1.5.2", "description": "Format and manipulate numbers.", "homepage": "http://numeraljs.com", "author": { @@ -41,7 +41,7 @@ "grunt-contrib-concat": "~0.3.0" }, "ender": "./ender.js", - "readme": "[Numeral.js](http://numeraljs.com)\n=======================================================\n\nA javascript library for formatting and manipulating numbers.\n\n[Website and documentation](http://numeraljs.com)\n\nChangelog\n=========\n\n### 1.5.1\nBug fix: Make sure values aren't changed during formatting### 1.5.0\nAdd defaultFormat(). numeral().format() uses the default to format if no string is provided\n\n.unformat() returns 0 when passed no string\n\nAdded languages.js that contains all languages\n\nBug fix: Fix bug while unformatting ordinals\n\nAdd format option to always show signed value\n\nAdded ability to instantiate numeral with a string value of a number\n### 1.4.9\nBug fix: Fix bug while unformatting ordinals\n### 1.4.8\nBug fix: Throw error if language is not defined\n### 1.4.7\nBug fix: Fix typo for trillion\n### 1.4.6\nBug fix: remove ' from unformatting regex that was causing an error with fr-ch.js\n### 1.4.5\nAdd zeroFormat() function that accepts a string for custom formating of zeros\n\nAdd valueOf() function\n\nChain functionality to language function\n\nMake all minified files have the same .min.js filename ending\n### 1.4.1\nBug fix: Bytes not formatting correctly\n### 1.4.0\nAdd optional format for all decimals\n### 1.3.4\nRemove AMD module id. (This is encouraged by require.js to make the module more portable, and keep it from creating a global)\n### 1.3.3\nAMD define() compatibility.\n### 1.3.2\nBug fix: Formatting some numbers results in the wrong value. Issue #21\n### 1.3.1\nBug fix: Minor fix to unformatting parser\n### 1.3.0\nAdd support for spaces before/after $, a, o, b in a format string\nBug fix: Fix unformat for languages that use '.' in ordinals\nBug fix: Fix round up floating numbers with no precision correctly.\nBug fix: Fix currency signs at the end in unformat\n### 1.2.6\nAdd support for optional decimal places\n### 1.2.5\nAdd support for appending currency symbol\n### 1.2.4\nAdd support for humanized filesizes\n### 1.2.2\nChanged language definition property 'money' to 'currency'\n### 1.2.1\nBug fix: Fix unformatting non-negative abbreviations\n### 1.2.3\nBug Fix: Fix unformatting for languages that use '.' as thousands delimiter\n### 1.2.0\nAdd localization language support\n\nUpdate testing for to include languages\n### 1.1.0\nAdd Tests\n\nBug fix: Fix difference returning negative values\n### 1.0.4\nBug fix: Non negative numbers were displaying as negative when using parentheses\n### 1.0.3\nAdd ordinal formatting using 'o' in the format\n### 1.0.2\nAdd clone functionality\n### 1.0.1\n\nAdded abbreviations for thousands and millions using 'a' in the format\n\n### 1.0.0\n\nInitial release\n\nAcknowlegements\n===============\n\nNumeral.js, while less complex, was inspired by and heavily borrowed from [Moment.js](http://momentjs.com)\n\nLicense\n=======\nNumeral.js is freely distributable under the terms of the MIT license.\nCopyright (c) 2012 Adam Draper\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.", - "_id": "numeral@1.5.1", + "readme": "[Numeral.js](http://numeraljs.com)\n=======================================================\n\nA javascript library for formatting and manipulating numbers.\n\n[Website and documentation](http://numeraljs.com)\n\nChangelog\n=========\n\n### 1.5.2\nBug fix: Unformat should pass through if given a number\n\nAdded a mechanism to control rounding behaviour\n\nAdded languageData() for getting and setting language props at runtime### 1.5.1\nBug fix: Make sure values aren't changed during formatting### 1.5.0\nAdd defaultFormat(). numeral().format() uses the default to format if no string is provided\n\n.unformat() returns 0 when passed no string\n\nAdded languages.js that contains all languages\n\nBug fix: Fix bug while unformatting ordinals\n\nAdd format option to always show signed value\n\nAdded ability to instantiate numeral with a string value of a number\n### 1.4.9\nBug fix: Fix bug while unformatting ordinals\n### 1.4.8\nBug fix: Throw error if language is not defined\n### 1.4.7\nBug fix: Fix typo for trillion\n### 1.4.6\nBug fix: remove ' from unformatting regex that was causing an error with fr-ch.js\n### 1.4.5\nAdd zeroFormat() function that accepts a string for custom formating of zeros\n\nAdd valueOf() function\n\nChain functionality to language function\n\nMake all minified files have the same .min.js filename ending\n### 1.4.1\nBug fix: Bytes not formatting correctly\n### 1.4.0\nAdd optional format for all decimals\n### 1.3.4\nRemove AMD module id. (This is encouraged by require.js to make the module more portable, and keep it from creating a global)\n### 1.3.3\nAMD define() compatibility.\n### 1.3.2\nBug fix: Formatting some numbers results in the wrong value. Issue #21\n### 1.3.1\nBug fix: Minor fix to unformatting parser\n### 1.3.0\nAdd support for spaces before/after $, a, o, b in a format string\nBug fix: Fix unformat for languages that use '.' in ordinals\nBug fix: Fix round up floating numbers with no precision correctly.\nBug fix: Fix currency signs at the end in unformat\n### 1.2.6\nAdd support for optional decimal places\n### 1.2.5\nAdd support for appending currency symbol\n### 1.2.4\nAdd support for humanized filesizes\n### 1.2.2\nChanged language definition property 'money' to 'currency'\n### 1.2.1\nBug fix: Fix unformatting non-negative abbreviations\n### 1.2.3\nBug Fix: Fix unformatting for languages that use '.' as thousands delimiter\n### 1.2.0\nAdd localization language support\n\nUpdate testing for to include languages\n### 1.1.0\nAdd Tests\n\nBug fix: Fix difference returning negative values\n### 1.0.4\nBug fix: Non negative numbers were displaying as negative when using parentheses\n### 1.0.3\nAdd ordinal formatting using 'o' in the format\n### 1.0.2\nAdd clone functionality\n### 1.0.1\n\nAdded abbreviations for thousands and millions using 'a' in the format\n\n### 1.0.0\n\nInitial release\n\nAcknowlegements\n===============\n\nNumeral.js, while less complex, was inspired by and heavily borrowed from [Moment.js](http://momentjs.com)\n\nLicense\n=======\nNumeral.js is freely distributable under the terms of the MIT license.\nCopyright (c) 2012 Adam Draper\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.", + "_id": "numeral@1.5.2", "_from": "numeral" }