diff --git a/locales.js b/locales.js index 1f89d5a2..dd5cb62b 100644 --- a/locales.js +++ b/locales.js @@ -1,846 +1,879 @@ -/*! @preserve - * numeral.js - * locales : 2.0.6 - * license : MIT - * http://adamwdraper.github.com/Numeral-js/ - */ - -(function (global, factory) { - if (typeof define === 'function' && define.amd) { - define(['numeral'], factory); - } else if (typeof module === 'object' && module.exports) { - factory(require('./numeral')); - } else { - factory(global.numeral); - } -}(this, function (numeral) { - -(function() { - numeral.register('locale', 'bg', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { // I found these here http://www.unicode.org/cldr/charts/28/verify/numbers/bg.html - thousand: 'хил', - million: 'млн', - billion: 'млрд', - trillion: 'трлн' - }, - ordinal: function (number) { - // google translate suggests: - // 1st=1-ви; 2nd=2-ри; 7th=7-ми; - // 8th=8-ми and many others end with -ти - // for example 3rd=3-ти - // However since I've seen suggestions that in - // Bulgarian the ordinal can be taken in - // different forms (masculine, feminine, neuter) - // I've opted to wimp out on commiting that to code - return ''; - }, - currency: { - symbol: 'лв' - } - }); -})(); - - -(function() { - - numeral.register('locale', 'chs', { - delimiters: { - thousands: ',', - decimal: '.' - }, - abbreviations: { - thousand: '千', - million: '百万', - billion: '十亿', - trillion: '兆' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: '¥' - } - }); -})(); - - -(function() { - numeral.register('locale', 'cs', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'tis.', - million: 'mil.', - billion: 'b', - trillion: 't' - }, - ordinal: function () { - return '.'; - }, - currency: { - symbol: 'Kč' - } - }); -})(); - - -(function() { - numeral.register('locale', 'da-dk', { - delimiters: { - thousands: '.', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'mio', - billion: 'mia', - trillion: 'b' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: 'DKK' - } - }); -})(); - - -(function() { - numeral.register('locale', 'de-ch', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: 'CHF' - } - }); -})(); - - -(function() { - numeral.register('locale', 'de', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: '€' - } - }); -})(); - - -(function() { - numeral.register('locale', 'en-au', { - delimiters: { - thousands: ',', - decimal: '.' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - var b = number % 10; - return (~~ (number % 100 / 10) === 1) ? 'th' : - (b === 1) ? 'st' : - (b === 2) ? 'nd' : - (b === 3) ? 'rd' : 'th'; - }, - currency: { - symbol: '$' - } - }); -})(); - - -(function() { - numeral.register('locale', 'en-gb', { - delimiters: { - thousands: ',', - decimal: '.' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - var b = number % 10; - return (~~ (number % 100 / 10) === 1) ? 'th' : - (b === 1) ? 'st' : - (b === 2) ? 'nd' : - (b === 3) ? 'rd' : 'th'; - }, - currency: { - symbol: '£' - } - }); -})(); - - -(function() { - numeral.register('locale', 'en-za', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - var b = number % 10; - return (~~ (number % 100 / 10) === 1) ? 'th' : - (b === 1) ? 'st' : - (b === 2) ? 'nd' : - (b === 3) ? 'rd' : 'th'; - }, - currency: { - symbol: 'R' - } - }); -})(); - - -(function() { - numeral.register('locale', 'es-es', { - delimiters: { - thousands: '.', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'mm', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - var b = number % 10; - return (b === 1 || b === 3) ? 'er' : - (b === 2) ? 'do' : - (b === 7 || b === 0) ? 'mo' : - (b === 8) ? 'vo' : - (b === 9) ? 'no' : 'to'; - }, - currency: { - symbol: '€' - } - }); -})(); - - -(function() { - numeral.register('locale', 'es', { - delimiters: { - thousands: '.', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'mm', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - var b = number % 10; - return (b === 1 || b === 3) ? 'er' : - (b === 2) ? 'do' : - (b === 7 || b === 0) ? 'mo' : - (b === 8) ? 'vo' : - (b === 9) ? 'no' : 'to'; - }, - currency: { - symbol: '$' - } - }); -})(); - - -(function() { - numeral.register('locale', 'et', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: ' tuh', - million: ' mln', - billion: ' mld', - trillion: ' trl' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: '€' - } - }); -})(); - - -(function() { - numeral.register('locale', 'fi', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'M', - billion: 'G', - trillion: 'T' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: '€' - } - }); -})(); - - -(function() { - numeral.register('locale', 'fr-ca', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'M', - billion: 'G', - trillion: 'T' - }, - ordinal : function (number) { - return number === 1 ? 'er' : 'e'; - }, - currency: { - symbol: '$' - } - }); -})(); - - -(function() { - numeral.register('locale', 'fr-ch', { - delimiters: { - thousands: '\'', - decimal: '.' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal : function (number) { - return number === 1 ? 'er' : 'e'; - }, - currency: { - symbol: 'CHF' - } - }); -})(); - - -(function() { - numeral.register('locale', 'fr', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal : function (number) { - return number === 1 ? 'er' : 'e'; - }, - currency: { - symbol: '€' - } - }); -})(); - - -(function() { - numeral.register('locale', 'hu', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'E', // ezer - million: 'M', // millió - billion: 'Mrd', // milliárd - trillion: 'T' // trillió - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: ' Ft' - } - }); -})(); - - -(function() { - numeral.register('locale', 'it', { - delimiters: { - thousands: '.', - decimal: ',' - }, - abbreviations: { - thousand: 'mila', - million: 'mil', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - return 'º'; - }, - currency: { - symbol: '€' - } - }); -})(); - - -(function() { - numeral.register('locale', 'ja', { - delimiters: { - thousands: ',', - decimal: '.' - }, - abbreviations: { - thousand: '千', - million: '百万', - billion: '十億', - trillion: '兆' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: '¥' - } - }); -})(); - - -(function() { - numeral.register('locale', 'lv', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: ' tūkst.', - million: ' milj.', - billion: ' mljrd.', - trillion: ' trilj.' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: '€' - } - }); -})(); - - -(function() { - numeral.register('locale', 'nl-be', { - delimiters: { - thousands: ' ', - decimal : ',' - }, - abbreviations: { - thousand : 'k', - million : ' mln', - billion : ' mld', - trillion : ' bln' - }, - ordinal : function (number) { - var remainder = number % 100; - - return (number !== 0 && remainder <= 1 || remainder === 8 || remainder >= 20) ? 'ste' : 'de'; - }, - currency: { - symbol: '€ ' - } - }); -})(); - - -(function() { - numeral.register('locale', 'nl-nl', { - 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: '€ ' - } - }); -})(); - - -(function() { - numeral.register('locale', 'no', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: 'kr' - } - }); -})(); - - -(function() { - numeral.register('locale', 'pl', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'tys.', - million: 'mln', - billion: 'mld', - trillion: 'bln' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: 'PLN' - } - }); -})(); - - -(function() { - numeral.register('locale', 'pt-br', { - delimiters: { - thousands: '.', - decimal: ',' - }, - abbreviations: { - thousand: 'mil', - million: 'milhões', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - return 'º'; - }, - currency: { - symbol: 'R$' - } - }); -})(); - - -(function() { - numeral.register('locale', 'pt-pt', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal : function (number) { - return 'º'; - }, - currency: { - symbol: '€' - } - }); -})(); - - -(function() { - numeral.register('locale', 'ru-ua', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'тыс.', - million: 'млн', - billion: 'b', - trillion: 't' - }, - ordinal: function () { - // not ideal, but since in Russian it can taken on - // different forms (masculine, feminine, neuter) - // this is all we can do - return '.'; - }, - currency: { - symbol: '\u20B4' - } - }); -})(); - - -(function() { - numeral.register('locale', 'ru', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'тыс.', - million: 'млн.', - billion: 'млрд.', - trillion: 'трлн.' - }, - ordinal: function () { - // not ideal, but since in Russian it can taken on - // different forms (masculine, feminine, neuter) - // this is all we can do - return '.'; - }, - currency: { - symbol: 'руб.' - } - }); -})(); - - -(function() { - numeral.register('locale', 'sk', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'tis.', - million: 'mil.', - billion: 'b', - trillion: 't' - }, - ordinal: function () { - return '.'; - }, - currency: { - symbol: '€' - } - }); -})(); - - -(function() { - numeral.register('locale', 'sl', { - delimiters: { - thousands: '.', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'mio', - billion: 'mrd', - trillion: 'trilijon' - }, - ordinal: function () { - return '.'; - }, - currency: { - symbol: '€' - } - }); -})(); - - -(function() { - - - numeral.register('locale', 'th', { - delimiters: { - thousands: ',', - decimal: '.' - }, - abbreviations: { - thousand: 'พัน', - million: 'ล้าน', - billion: 'พันล้าน', - trillion: 'ล้านล้าน' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: '฿' - } - }); -})(); - - -(function() { - var suffixes = { - 1: '\'inci', - 5: '\'inci', - 8: '\'inci', - 70: '\'inci', - 80: '\'inci', - - 2: '\'nci', - 7: '\'nci', - 20: '\'nci', - 50: '\'nci', - - 3: '\'üncü', - 4: '\'üncü', - 100: '\'üncü', - - 6: '\'ncı', - - 9: '\'uncu', - 10: '\'uncu', - 30: '\'uncu', - - 60: '\'ıncı', - 90: '\'ıncı' - }; - - numeral.register('locale', 'tr', { - delimiters: { - thousands: '.', - decimal: ',' - }, - abbreviations: { - thousand: 'bin', - million: 'milyon', - billion: 'milyar', - trillion: 'trilyon' - }, - ordinal: function (number) { - if (number === 0) { // special case for zero - return '\'ıncı'; - } - - var a = number % 10, - b = number % 100 - a, - c = number >= 100 ? 100 : null; - - return suffixes[a] || suffixes[b] || suffixes[c]; - }, - currency: { - symbol: '\u20BA' - } - }); -})(); - - -(function() { - numeral.register('locale', 'uk-ua', { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'тис.', - million: 'млн', - billion: 'млрд', - trillion: 'блн' - }, - ordinal: function () { - // not ideal, but since in Ukrainian it can taken on - // different forms (masculine, feminine, neuter) - // this is all we can do - return ''; - }, - currency: { - symbol: '\u20B4' - } - }); -})(); - - -(function() { - - numeral.register('locale', 'vi', { - delimiters: { - thousands: '.', - decimal: ',' - }, - abbreviations: { - thousand: ' nghìn', - million: ' triệu', - billion: ' tỷ', - trillion: ' nghìn tỷ' - }, - ordinal: function () { - return '.'; - }, - currency: { - symbol: '₫' - } - }); -})(); - - -})); +/*! @preserve + * numeral.js + * locales : 2.0.6 + * license : MIT + * http://adamwdraper.github.com/Numeral-js/ + */ + +(function (global, factory) { + if (typeof define === 'function' && define.amd) { + define(['numeral'], factory); + } else if (typeof module === 'object' && module.exports) { + factory(require('./numeral')); + } else { + factory(global.numeral); + } +}(this, function (numeral) { + +(function() { + + numeral.register('locale', 'bg', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { // I found these here http://www.unicode.org/cldr/charts/28/verify/numbers/bg.html + thousand: 'хил', + million: 'млн', + billion: 'млрд', + trillion: 'трлн' + }, + ordinal: function (number) { + // google translate suggests: + // 1st=1-ви; 2nd=2-ри; 7th=7-ми; + // 8th=8-ми and many others end with -ти + // for example 3rd=3-ти + // However since I've seen suggestions that in + // Bulgarian the ordinal can be taken in + // different forms (masculine, feminine, neuter) + // I've opted to wimp out on commiting that to code + return ''; + }, + currency: { + symbol: 'лв' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'chs', { + delimiters: { + thousands: ',', + decimal: '.' + }, + abbreviations: { + thousand: '千', + million: '百万', + billion: '十亿', + trillion: '兆' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: '¥' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'cs', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'tis.', + million: 'mil.', + billion: 'b', + trillion: 't' + }, + ordinal: function () { + return '.'; + }, + currency: { + symbol: 'Kč' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'da-dk', { + delimiters: { + thousands: '.', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'mio', + billion: 'mia', + trillion: 'b' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: 'DKK' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'de-ch', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: 'CHF' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'de', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: '€' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'en-au', { + delimiters: { + thousands: ',', + decimal: '.' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal: function (number) { + var b = number % 10; + return (~~ (number % 100 / 10) === 1) ? 'th' : + (b === 1) ? 'st' : + (b === 2) ? 'nd' : + (b === 3) ? 'rd' : 'th'; + }, + currency: { + symbol: '$' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'en-gb', { + delimiters: { + thousands: ',', + decimal: '.' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal: function (number) { + var b = number % 10; + return (~~ (number % 100 / 10) === 1) ? 'th' : + (b === 1) ? 'st' : + (b === 2) ? 'nd' : + (b === 3) ? 'rd' : 'th'; + }, + currency: { + symbol: '£' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'en-za', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal: function (number) { + var b = number % 10; + return (~~ (number % 100 / 10) === 1) ? 'th' : + (b === 1) ? 'st' : + (b === 2) ? 'nd' : + (b === 3) ? 'rd' : 'th'; + }, + currency: { + symbol: 'R' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'es-es', { + delimiters: { + thousands: '.', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'mm', + billion: 'b', + trillion: 't' + }, + ordinal: function (number) { + var b = number % 10; + return (b === 1 || b === 3) ? 'er' : + (b === 2) ? 'do' : + (b === 7 || b === 0) ? 'mo' : + (b === 8) ? 'vo' : + (b === 9) ? 'no' : 'to'; + }, + currency: { + symbol: '€' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'es', { + delimiters: { + thousands: '.', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'mm', + billion: 'b', + trillion: 't' + }, + ordinal: function (number) { + var b = number % 10; + return (b === 1 || b === 3) ? 'er' : + (b === 2) ? 'do' : + (b === 7 || b === 0) ? 'mo' : + (b === 8) ? 'vo' : + (b === 9) ? 'no' : 'to'; + }, + currency: { + symbol: '$' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'et', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: ' tuh', + million: ' mln', + billion: ' mld', + trillion: ' trl' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: '€' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'fi', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'M', + billion: 'G', + trillion: 'T' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: '€' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'fr-ca', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'M', + billion: 'G', + trillion: 'T' + }, + ordinal : function (number) { + return number === 1 ? 'er' : 'e'; + }, + currency: { + symbol: '$' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'fr-ch', { + delimiters: { + thousands: '\'', + decimal: '.' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal : function (number) { + return number === 1 ? 'er' : 'e'; + }, + currency: { + symbol: 'CHF' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'fr', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal : function (number) { + return number === 1 ? 'er' : 'e'; + }, + currency: { + symbol: '€' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'hu', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'E', // ezer + million: 'M', // millió + billion: 'Mrd', // milliárd + trillion: 'T' // trillió + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: ' Ft' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'it', { + delimiters: { + thousands: '.', + decimal: ',' + }, + abbreviations: { + thousand: 'mila', + million: 'mil', + billion: 'b', + trillion: 't' + }, + ordinal: function (number) { + return 'º'; + }, + currency: { + symbol: '€' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'ja', { + delimiters: { + thousands: ',', + decimal: '.' + }, + abbreviations: { + thousand: '千', + million: '百万', + billion: '十億', + trillion: '兆' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: '¥' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'lv', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: ' tūkst.', + million: ' milj.', + billion: ' mljrd.', + trillion: ' trilj.' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: '€' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'nl-be', { + delimiters: { + thousands: ' ', + decimal : ',' + }, + abbreviations: { + thousand : 'k', + million : ' mln', + billion : ' mld', + trillion : ' bln' + }, + ordinal : function (number) { + var remainder = number % 100; + + return (number !== 0 && remainder <= 1 || remainder === 8 || remainder >= 20) ? 'ste' : 'de'; + }, + currency: { + symbol: '€ ' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'nl-nl', { + 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: '€ ' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'no', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: 'kr' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'pl', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'tys.', + million: 'mln', + billion: 'mld', + trillion: 'bln' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: 'PLN' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'pt-br', { + delimiters: { + thousands: '.', + decimal: ',' + }, + abbreviations: { + thousand: 'mil', + million: 'milhões', + billion: 'b', + trillion: 't' + }, + ordinal: function (number) { + return 'º'; + }, + currency: { + symbol: 'R$' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'pt-pt', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal : function (number) { + return 'º'; + }, + currency: { + symbol: '€' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'ru-ua', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'тыс.', + million: 'млн', + billion: 'b', + trillion: 't' + }, + ordinal: function () { + // not ideal, but since in Russian it can taken on + // different forms (masculine, feminine, neuter) + // this is all we can do + return '.'; + }, + currency: { + symbol: '\u20B4' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'ru', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'тыс.', + million: 'млн.', + billion: 'млрд.', + trillion: 'трлн.' + }, + ordinal: function () { + // not ideal, but since in Russian it can taken on + // different forms (masculine, feminine, neuter) + // this is all we can do + return '.'; + }, + currency: { + symbol: 'руб.' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'sk', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'tis.', + million: 'mil.', + billion: 'b', + trillion: 't' + }, + ordinal: function () { + return '.'; + }, + currency: { + symbol: '€' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'sl', { + delimiters: { + thousands: '.', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'mio', + billion: 'mrd', + trillion: 'trilijon' + }, + ordinal: function () { + return '.'; + }, + currency: { + symbol: '€' + } + }); +})(); + + +(function() { + + + + numeral.register('locale', 'th', { + delimiters: { + thousands: ',', + decimal: '.' + }, + abbreviations: { + thousand: 'พัน', + million: 'ล้าน', + billion: 'พันล้าน', + trillion: 'ล้านล้าน' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: '฿' + } + }); +})(); + + +(function() { + + var suffixes = { + 1: '\'inci', + 5: '\'inci', + 8: '\'inci', + 70: '\'inci', + 80: '\'inci', + + 2: '\'nci', + 7: '\'nci', + 20: '\'nci', + 50: '\'nci', + + 3: '\'üncü', + 4: '\'üncü', + 100: '\'üncü', + + 6: '\'ncı', + + 9: '\'uncu', + 10: '\'uncu', + 30: '\'uncu', + + 60: '\'ıncı', + 90: '\'ıncı' + }; + + numeral.register('locale', 'tr', { + delimiters: { + thousands: '.', + decimal: ',' + }, + abbreviations: { + thousand: 'bin', + million: 'milyon', + billion: 'milyar', + trillion: 'trilyon' + }, + ordinal: function (number) { + if (number === 0) { // special case for zero + return '\'ıncı'; + } + + var a = number % 10, + b = number % 100 - a, + c = number >= 100 ? 100 : null; + + return suffixes[a] || suffixes[b] || suffixes[c]; + }, + currency: { + symbol: '\u20BA' + } + }); +})(); + + +(function() { + + numeral.register('locale', 'uk-ua', { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'тис.', + million: 'млн', + billion: 'млрд', + trillion: 'блн' + }, + ordinal: function () { + // not ideal, but since in Ukrainian it can taken on + // different forms (masculine, feminine, neuter) + // this is all we can do + return ''; + }, + currency: { + symbol: '\u20B4' + } + }); +})(); + + +(function() { + + + numeral.register('locale', 'vi', { + delimiters: { + thousands: '.', + decimal: ',' + }, + abbreviations: { + thousand: ' nghìn', + million: ' triệu', + billion: ' tỷ', + trillion: ' nghìn tỷ' + }, + ordinal: function () { + return '.'; + }, + currency: { + symbol: '₫' + } + }); +})(); + + +})); diff --git a/numeral.js b/numeral.js index 22726c9e..82e847ae 100644 --- a/numeral.js +++ b/numeral.js @@ -1,1013 +1,1022 @@ -/*! @preserve - * numeral.js - * version : 2.0.6 - * author : Adam Draper - * license : MIT - * http://adamwdraper.github.com/Numeral-js/ - */ - -(function (global, factory) { - if (typeof define === 'function' && define.amd) { - define(factory); - } else if (typeof module === 'object' && module.exports) { - module.exports = factory(); - } else { - global.numeral = factory(); - } -}(this, function () { - /************************************ - Variables - ************************************/ - - var numeral, - _, - VERSION = '2.0.6', - formats = {}, - locales = {}, - defaults = { - currentLocale: 'en', - zeroFormat: null, - nullFormat: null, - defaultFormat: '0,0', - scalePercentBy100: true - }, - options = { - currentLocale: defaults.currentLocale, - zeroFormat: defaults.zeroFormat, - nullFormat: defaults.nullFormat, - defaultFormat: defaults.defaultFormat, - scalePercentBy100: defaults.scalePercentBy100 - }; - - - /************************************ - Constructors - ************************************/ - - // Numeral prototype object - function Numeral(input, number) { - this._input = input; - - this._value = number; - } - - numeral = function(input) { - var value, - kind, - unformatFunction, - regexp; - - if (numeral.isNumeral(input)) { - value = input.value(); - } else if (input === 0 || typeof input === 'undefined') { - value = 0; - } else if (input === null || _.isNaN(input)) { - value = null; - } else if (typeof input === 'string') { - if (options.zeroFormat && input === options.zeroFormat) { - value = 0; - } else if (options.nullFormat && input === options.nullFormat || !input.replace(/[^0-9]+/g, '').length) { - value = null; - } else { - for (kind in formats) { - regexp = typeof formats[kind].regexps.unformat === 'function' ? formats[kind].regexps.unformat() : formats[kind].regexps.unformat; - - if (regexp && input.match(regexp)) { - unformatFunction = formats[kind].unformat; - - break; - } - } - - unformatFunction = unformatFunction || numeral._.stringToNumber; - - value = unformatFunction(input); - } - } else { - value = Number(input)|| null; - } - - return new Numeral(input, value); - }; - - // version number - numeral.version = VERSION; - - // compare numeral object - numeral.isNumeral = function(obj) { - return obj instanceof Numeral; - }; - - // helper functions - numeral._ = _ = { - // formats numbers separators, decimals places, signs, abbreviations - numberToFormat: function(value, format, roundingFunction) { - var locale = locales[numeral.options.currentLocale], - negP = false, - optDec = false, - leadingCount = 0, - abbr = '', - trillion = 1000000000000, - billion = 1000000000, - million = 1000000, - thousand = 1000, - decimal = '', - neg = false, - abbrForce, // force abbreviation - abs, - min, - max, - power, - int, - precision, - signed, - thousands, - output; - - // make sure we never format a null value - value = value || 0; - - abs = Math.abs(value); - - // see if we should use parentheses for negative number or if we should prefix with a sign - // if both are present we default to parentheses - if (numeral._.includes(format, '(')) { - negP = true; - format = format.replace(/[\(|\)]/g, ''); - } else if (numeral._.includes(format, '+') || numeral._.includes(format, '-')) { - signed = numeral._.includes(format, '+') ? format.indexOf('+') : value < 0 ? format.indexOf('-') : -1; - format = format.replace(/[\+|\-]/g, ''); - } - - // see if abbreviation is wanted - if (numeral._.includes(format, 'a')) { - abbrForce = format.match(/a(k|m|b|t)?/); - - abbrForce = abbrForce ? abbrForce[1] : false; - - // check for space before abbreviation - if (numeral._.includes(format, ' a')) { - abbr = ' '; - } - - format = format.replace(new RegExp(abbr + 'a[kmbt]?'), ''); - - if (abs >= trillion && !abbrForce || abbrForce === 't') { - // trillion - abbr += locale.abbreviations.trillion; - value = value / trillion; - } else if (abs < trillion && abs >= billion && !abbrForce || abbrForce === 'b') { - // billion - abbr += locale.abbreviations.billion; - value = value / billion; - } else if (abs < billion && abs >= million && !abbrForce || abbrForce === 'm') { - // million - abbr += locale.abbreviations.million; - value = value / million; - } else if (abs < million && abs >= thousand && !abbrForce || abbrForce === 'k') { - // thousand - abbr += locale.abbreviations.thousand; - value = value / thousand; - } - } - - // check for optional decimals - if (numeral._.includes(format, '[.]')) { - optDec = true; - format = format.replace('[.]', '.'); - } - - // break number and format - int = value.toString().split('.')[0]; - precision = format.split('.')[1]; - thousands = format.indexOf(','); - leadingCount = (format.split('.')[0].split(',')[0].match(/0/g) || []).length; - - if (precision) { - if (numeral._.includes(precision, '[')) { - precision = precision.replace(']', ''); - precision = precision.split('['); - decimal = numeral._.toFixed(value, (precision[0].length + precision[1].length), roundingFunction, precision[1].length); - } else { - decimal = numeral._.toFixed(value, precision.length, roundingFunction); - } - - int = decimal.split('.')[0]; - - if (numeral._.includes(decimal, '.')) { - decimal = locale.delimiters.decimal + decimal.split('.')[1]; - } else { - decimal = ''; - } - - if (optDec && Number(decimal.slice(1)) === 0) { - decimal = ''; - } - } else { - int = numeral._.toFixed(value, 0, roundingFunction); - } - - // check abbreviation again after rounding - if (abbr && !abbrForce && Number(int) >= 1000 && abbr !== locale.abbreviations.trillion) { - int = String(Number(int) / 1000); - - switch (abbr) { - case locale.abbreviations.thousand: - abbr = locale.abbreviations.million; - break; - case locale.abbreviations.million: - abbr = locale.abbreviations.billion; - break; - case locale.abbreviations.billion: - abbr = locale.abbreviations.trillion; - break; - } - } - - - // format number - if (numeral._.includes(int, '-')) { - int = int.slice(1); - neg = true; - } - - if (int.length < leadingCount) { - for (var i = leadingCount - int.length; i > 0; i--) { - int = '0' + int; - } - } - - if (thousands > -1) { - int = int.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + locale.delimiters.thousands); - } - - if (format.indexOf('.') === 0) { - int = ''; - } - - output = int + decimal + (abbr ? abbr : ''); - - if (negP) { - output = (negP && neg ? '(' : '') + output + (negP && neg ? ')' : ''); - } else { - if (signed >= 0) { - output = signed === 0 ? (neg ? '-' : '+') + output : output + (neg ? '-' : '+'); - } else if (neg) { - output = '-' + output; - } - } - - return output; - }, - // unformats numbers separators, decimals places, signs, abbreviations - stringToNumber: function(string) { - var locale = locales[options.currentLocale], - stringOriginal = string, - abbreviations = { - thousand: 3, - million: 6, - billion: 9, - trillion: 12 - }, - abbreviation, - value, - i, - regexp; - - if (options.zeroFormat && string === options.zeroFormat) { - value = 0; - } else if (options.nullFormat && string === options.nullFormat || !string.replace(/[^0-9]+/g, '').length) { - value = null; - } else { - value = 1; - - if (locale.delimiters.decimal !== '.') { - string = string.replace(/\./g, '').replace(locale.delimiters.decimal, '.'); - } - - for (abbreviation in abbreviations) { - regexp = new RegExp('[^a-zA-Z]' + locale.abbreviations[abbreviation] + '(?:\\)|(\\' + locale.currency.symbol + ')?(?:\\))?)?$'); - - if (stringOriginal.match(regexp)) { - value *= Math.pow(10, abbreviations[abbreviation]); - break; - } - } - - // check for negative number - value *= (string.split('-').length + Math.min(string.split('(').length - 1, string.split(')').length - 1)) % 2 ? 1 : -1; - - // remove non numbers - string = string.replace(/[^0-9\.]+/g, ''); - - value *= Number(string); - } - - return value; - }, - isNaN: function(value) { - return typeof value === 'number' && isNaN(value); - }, - includes: function(string, search) { - return string.indexOf(search) !== -1; - }, - insert: function(string, subString, start) { - return string.slice(0, start) + subString + string.slice(start); - }, - reduce: function(array, callback /*, initialValue*/) { - if (this === null) { - throw new TypeError('Array.prototype.reduce called on null or undefined'); - } - - if (typeof callback !== 'function') { - throw new TypeError(callback + ' is not a function'); - } - - var t = Object(array), - len = t.length >>> 0, - k = 0, - value; - - if (arguments.length === 3) { - value = arguments[2]; - } else { - while (k < len && !(k in t)) { - k++; - } - - if (k >= len) { - throw new TypeError('Reduce of empty array with no initial value'); - } - - value = t[k++]; - } - for (; k < len; k++) { - if (k in t) { - value = callback(value, t[k], k, t); - } - } - return value; - }, - /** - * Computes the multiplier necessary to make x >= 1, - * effectively eliminating miscalculations caused by - * finite precision. - */ - multiplier: function (x) { - var parts = x.toString().split('.'); - - return parts.length < 2 ? 1 : Math.pow(10, parts[1].length); - }, - /** - * Given a variable number of arguments, returns the maximum - * multiplier that must be used to normalize an operation involving - * all of them. - */ - correctionFactor: function () { - var args = Array.prototype.slice.call(arguments); - - return args.reduce(function(accum, next) { - var mn = _.multiplier(next); - return accum > mn ? accum : mn; - }, 1); - }, - /** - * Implementation of toFixed() that treats floats more like decimals - * - * Fixes binary rounding issues (eg. (0.615).toFixed(2) === '0.61') that present - * problems for accounting- and finance-related software. - */ - toFixed: function(value, maxDecimals, roundingFunction, optionals) { - var splitValue = value.toString().split('.'), - minDecimals = maxDecimals - (optionals || 0), - boundedPrecision, - optionalsRegExp, - power, - output; - - // Use the smallest precision value possible to avoid errors from floating point representation - if (splitValue.length === 2) { - boundedPrecision = Math.min(Math.max(splitValue[1].length, minDecimals), maxDecimals); - } else { - boundedPrecision = minDecimals; - } - - power = Math.pow(10, boundedPrecision); - - // Multiply up by precision, round accurately, then divide and use native toFixed(): - output = (roundingFunction(value + 'e+' + boundedPrecision) / power).toFixed(boundedPrecision); - - if (optionals > maxDecimals - boundedPrecision) { - optionalsRegExp = new RegExp('\\.?0{1,' + (optionals - (maxDecimals - boundedPrecision)) + '}$'); - output = output.replace(optionalsRegExp, ''); - } - - return output; - } - }; - - // avaliable options - numeral.options = options; - - // avaliable formats - numeral.formats = formats; - - // avaliable formats - numeral.locales = locales; - - // This function sets the current locale. If - // no arguments are passed in, it will simply return the current global - // locale key. - numeral.locale = function(key) { - if (key) { - options.currentLocale = key.toLowerCase(); - } - - return options.currentLocale; - }; - - // This function provides access to the loaded locale data. If - // no arguments are passed in, it will simply return the current - // global locale object. - numeral.localeData = function(key) { - if (!key) { - return locales[options.currentLocale]; - } - - key = key.toLowerCase(); - - if (!locales[key]) { - throw new Error('Unknown locale : ' + key); - } - - return locales[key]; - }; - - numeral.reset = function() { - for (var property in defaults) { - options[property] = defaults[property]; - } - }; - - numeral.zeroFormat = function(format) { - options.zeroFormat = typeof(format) === 'string' ? format : null; - }; - - numeral.nullFormat = function (format) { - options.nullFormat = typeof(format) === 'string' ? format : null; - }; - - numeral.defaultFormat = function(format) { - options.defaultFormat = typeof(format) === 'string' ? format : '0.0'; - }; - - numeral.register = function(type, name, format) { - name = name.toLowerCase(); - - if (this[type + 's'][name]) { - throw new TypeError(name + ' ' + type + ' already registered.'); - } - - this[type + 's'][name] = format; - - return format; - }; - - - numeral.validate = function(val, culture) { - var _decimalSep, - _thousandSep, - _currSymbol, - _valArray, - _abbrObj, - _thousandRegEx, - localeData, - temp; - - //coerce val to string - if (typeof val !== 'string') { - val += ''; - - if (console.warn) { - console.warn('Numeral.js: Value is not string. It has been co-erced to: ', val); - } - } - - //trim whitespaces from either sides - val = val.trim(); - - //if val is just digits return true - if (!!val.match(/^\d+$/)) { - return true; - } - - //if val is empty return false - if (val === '') { - return false; - } - - //get the decimal and thousands separator from numeral.localeData - try { - //check if the culture is understood by numeral. if not, default it to current locale - localeData = numeral.localeData(culture); - } catch (e) { - localeData = numeral.localeData(numeral.locale()); - } - - //setup the delimiters and currency symbol based on culture/locale - _currSymbol = localeData.currency.symbol; - _abbrObj = localeData.abbreviations; - _decimalSep = localeData.delimiters.decimal; - if (localeData.delimiters.thousands === '.') { - _thousandSep = '\\.'; - } else { - _thousandSep = localeData.delimiters.thousands; - } - - // validating currency symbol - temp = val.match(/^[^\d]+/); - if (temp !== null) { - val = val.substr(1); - if (temp[0] !== _currSymbol) { - return false; - } - } - - //validating abbreviation symbol - temp = val.match(/[^\d]+$/); - if (temp !== null) { - val = val.slice(0, -1); - if (temp[0] !== _abbrObj.thousand && temp[0] !== _abbrObj.million && temp[0] !== _abbrObj.billion && temp[0] !== _abbrObj.trillion) { - return false; - } - } - - _thousandRegEx = new RegExp(_thousandSep + '{2}'); - - if (!val.match(/[^\d.,]/g)) { - _valArray = val.split(_decimalSep); - if (_valArray.length > 2) { - return false; - } else { - if (_valArray.length < 2) { - return ( !! _valArray[0].match(/^\d+.*\d$/) && !_valArray[0].match(_thousandRegEx)); - } else { - if (_valArray[0].length === 1) { - return ( !! _valArray[0].match(/^\d+$/) && !_valArray[0].match(_thousandRegEx) && !! _valArray[1].match(/^\d+$/)); - } else { - return ( !! _valArray[0].match(/^\d+.*\d$/) && !_valArray[0].match(_thousandRegEx) && !! _valArray[1].match(/^\d+$/)); - } - } - } - } - - return false; - }; - - - /************************************ - Numeral Prototype - ************************************/ - - numeral.fn = Numeral.prototype = { - clone: function() { - return numeral(this); - }, - format: function(inputString, roundingFunction) { - var value = this._value, - format = inputString || options.defaultFormat, - kind, - output, - formatFunction; - - // make sure we have a roundingFunction - roundingFunction = roundingFunction || Math.round; - - // format based on value - if (value === 0 && options.zeroFormat !== null) { - output = options.zeroFormat; - } else if (value === null && options.nullFormat !== null) { - output = options.nullFormat; - } else { - for (kind in formats) { - if (format.match(formats[kind].regexps.format)) { - formatFunction = formats[kind].format; - - break; - } - } - - formatFunction = formatFunction || numeral._.numberToFormat; - - output = formatFunction(value, format, roundingFunction); - } - - return output; - }, - value: function() { - return this._value; - }, - input: function() { - return this._input; - }, - set: function(value) { - this._value = Number(value); - - return this; - }, - add: function(value) { - var corrFactor = _.correctionFactor.call(null, this._value, value); - - function cback(accum, curr, currI, O) { - return accum + Math.round(corrFactor * curr); - } - - this._value = _.reduce([this._value, value], cback, 0) / corrFactor; - - return this; - }, - subtract: function(value) { - var corrFactor = _.correctionFactor.call(null, this._value, value); - - function cback(accum, curr, currI, O) { - return accum - Math.round(corrFactor * curr); - } - - this._value = _.reduce([value], cback, Math.round(this._value * corrFactor)) / corrFactor; - - return this; - }, - multiply: function(value) { - function cback(accum, curr, currI, O) { - var corrFactor = _.correctionFactor(accum, curr); - return Math.round(accum * corrFactor) * Math.round(curr * corrFactor) / Math.round(corrFactor * corrFactor); - } - - this._value = _.reduce([this._value, value], cback, 1); - - return this; - }, - divide: function(value) { - function cback(accum, curr, currI, O) { - var corrFactor = _.correctionFactor(accum, curr); - return Math.round(accum * corrFactor) / Math.round(curr * corrFactor); - } - - this._value = _.reduce([this._value, value], cback); - - return this; - }, - difference: function(value) { - return Math.abs(numeral(this._value).subtract(value).value()); - } - }; - - /************************************ - Default Locale && Format - ************************************/ - - numeral.register('locale', 'en', { - delimiters: { - thousands: ',', - decimal: '.' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal: function(number) { - var b = number % 10; - return (~~(number % 100 / 10) === 1) ? 'th' : - (b === 1) ? 'st' : - (b === 2) ? 'nd' : - (b === 3) ? 'rd' : 'th'; - }, - currency: { - symbol: '$' - } - }); - +/*! @preserve + * numeral.js + * version : 2.0.6 + * author : Adam Draper + * license : MIT + * http://adamwdraper.github.com/Numeral-js/ + */ + +(function (global, factory) { + if (typeof define === 'function' && define.amd) { + define(factory); + } else if (typeof module === 'object' && module.exports) { + module.exports = factory(); + } else { + global.numeral = factory(); + } +}(this, function () { + /************************************ + Variables + ************************************/ + + var numeral, + _, + VERSION = '2.0.6', + formats = {}, + locales = {}, + defaults = { + currentLocale: 'en', + zeroFormat: null, + nullFormat: null, + defaultFormat: '0,0', + scalePercentBy100: true + }, + options = { + currentLocale: defaults.currentLocale, + zeroFormat: defaults.zeroFormat, + nullFormat: defaults.nullFormat, + defaultFormat: defaults.defaultFormat, + scalePercentBy100: defaults.scalePercentBy100 + }; + + + /************************************ + Constructors + ************************************/ + + // Numeral prototype object + function Numeral(input, number) { + this._input = input; + + this._value = number; + } + + numeral = function(input) { + var value, + kind, + unformatFunction, + regexp; + + if (numeral.isNumeral(input)) { + value = input.value(); + } else if (input === 0 || typeof input === 'undefined') { + value = 0; + } else if (input === null || _.isNaN(input)) { + value = null; + } else if (typeof input === 'string') { + if (options.zeroFormat && input === options.zeroFormat) { + value = 0; + } else if (options.nullFormat && input === options.nullFormat || !input.replace(/[^0-9]+/g, '').length) { + value = null; + } else { + for (kind in formats) { + regexp = typeof formats[kind].regexps.unformat === 'function' ? formats[kind].regexps.unformat() : formats[kind].regexps.unformat; + + if (regexp && input.match(regexp)) { + unformatFunction = formats[kind].unformat; + + break; + } + } + + unformatFunction = unformatFunction || numeral._.stringToNumber; + + value = unformatFunction(input); + } + } else { + value = Number(input)|| null; + } + + return new Numeral(input, value); + }; + + // version number + numeral.version = VERSION; + + // compare numeral object + numeral.isNumeral = function(obj) { + return obj instanceof Numeral; + }; + + // helper functions + numeral._ = _ = { + // formats numbers separators, decimals places, signs, abbreviations + numberToFormat: function(value, format, roundingFunction) { + var locale = locales[numeral.options.currentLocale], + negP = false, + optDec = false, + leadingCount = 0, + abbr = '', + trillion = 1000000000000, + billion = 1000000000, + million = 1000000, + thousand = 1000, + decimal = '', + neg = false, + abbrForce, // force abbreviation + abs, + min, + max, + power, + int, + precision, + signed, + thousands, + output; + + // make sure we never format a null value + value = value || 0; + + abs = Math.abs(value); + + // see if we should use parentheses for negative number or if we should prefix with a sign + // if both are present we default to parentheses + if (numeral._.includes(format, '(')) { + negP = true; + format = format.replace(/[\(|\)]/g, ''); + } else if (numeral._.includes(format, '+') || numeral._.includes(format, '-')) { + signed = numeral._.includes(format, '+') ? format.indexOf('+') : value < 0 ? format.indexOf('-') : -1; + format = format.replace(/[\+|\-]/g, ''); + } + + // see if abbreviation is wanted + if (numeral._.includes(format, 'a')) { + abbrForce = format.match(/a(k|m|b|t)?/); + + abbrForce = abbrForce ? abbrForce[1] : false; + + // check for space before abbreviation + if (numeral._.includes(format, ' a')) { + abbr = ' '; + } + + format = format.replace(new RegExp(abbr + 'a[kmbt]?'), ''); + + if (abs >= trillion && !abbrForce || abbrForce === 't') { + // trillion + abbr += locale.abbreviations.trillion; + value = value / trillion; + } else if (abs < trillion && abs >= billion && !abbrForce || abbrForce === 'b') { + // billion + abbr += locale.abbreviations.billion; + value = value / billion; + } else if (abs < billion && abs >= million && !abbrForce || abbrForce === 'm') { + // million + abbr += locale.abbreviations.million; + value = value / million; + } else if (abs < million && abs >= thousand && !abbrForce || abbrForce === 'k') { + // thousand + abbr += locale.abbreviations.thousand; + value = value / thousand; + } + } + + // check for optional decimals + if (numeral._.includes(format, '[.]')) { + optDec = true; + format = format.replace('[.]', '.'); + } + + // break number and format + int = value.toString().split('.')[0]; + precision = format.split('.')[1]; + thousands = format.indexOf(','); + leadingCount = (format.split('.')[0].split(',')[0].match(/0/g) || []).length; + + if (precision) { + if (numeral._.includes(precision, '[')) { + precision = precision.replace(']', ''); + precision = precision.split('['); + decimal = numeral._.toFixed(value, (precision[0].length + precision[1].length), roundingFunction, precision[1].length); + } else { + decimal = numeral._.toFixed(value, precision.length, roundingFunction); + } + + int = decimal.split('.')[0]; + + if (numeral._.includes(decimal, '.')) { + decimal = locale.delimiters.decimal + decimal.split('.')[1]; + } else { + decimal = ''; + } + + if (optDec && Number(decimal.slice(1)) === 0) { + decimal = ''; + } + } else { + int = numeral._.toFixed(value, 0, roundingFunction); + } + + // check abbreviation again after rounding + if (abbr && !abbrForce && Number(int) >= 1000 && abbr !== locale.abbreviations.trillion) { + int = String(Number(int) / 1000); + + switch (abbr) { + case locale.abbreviations.thousand: + abbr = locale.abbreviations.million; + break; + case locale.abbreviations.million: + abbr = locale.abbreviations.billion; + break; + case locale.abbreviations.billion: + abbr = locale.abbreviations.trillion; + break; + } + } + + + // format number + if (numeral._.includes(int, '-')) { + int = int.slice(1); + neg = true; + } + + if (int.length < leadingCount) { + for (var i = leadingCount - int.length; i > 0; i--) { + int = '0' + int; + } + } + + if (thousands > -1) { + int = int.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + locale.delimiters.thousands); + } + + if (format.indexOf('.') === 0) { + int = ''; + } + + output = int + decimal + (abbr ? abbr : ''); + + if (negP) { + output = (negP && neg ? '(' : '') + output + (negP && neg ? ')' : ''); + } else { + if (signed >= 0) { + output = signed === 0 ? (neg ? '-' : '+') + output : output + (neg ? '-' : '+'); + } else if (neg) { + output = '-' + output; + } + } + + return output; + }, + // unformats numbers separators, decimals places, signs, abbreviations + stringToNumber: function(string) { + var locale = locales[options.currentLocale], + stringOriginal = string, + abbreviations = { + thousand: 3, + million: 6, + billion: 9, + trillion: 12 + }, + abbreviation, + value, + i, + regexp; + + if (options.zeroFormat && string === options.zeroFormat) { + value = 0; + } else if (options.nullFormat && string === options.nullFormat || !string.replace(/[^0-9]+/g, '').length) { + value = null; + } else { + value = 1; + + if (locale.delimiters.decimal !== '.') { + string = string.replace(/\./g, '').replace(locale.delimiters.decimal, '.'); + } + + for (abbreviation in abbreviations) { + regexp = new RegExp('[^a-zA-Z]' + locale.abbreviations[abbreviation] + '(?:\\)|(\\' + locale.currency.symbol + ')?(?:\\))?)?$'); + + if (stringOriginal.match(regexp)) { + value *= Math.pow(10, abbreviations[abbreviation]); + break; + } + } + + // check for negative number + value *= (string.split('-').length + Math.min(string.split('(').length - 1, string.split(')').length - 1)) % 2 ? 1 : -1; + + // remove non numbers + string = string.replace(/[^0-9\.]+/g, ''); + + value *= Number(string); + } + + return value; + }, + isNaN: function(value) { + return typeof value === 'number' && isNaN(value); + }, + includes: function(string, search) { + return string.indexOf(search) !== -1; + }, + insert: function(string, subString, start) { + return string.slice(0, start) + subString + string.slice(start); + }, + reduce: function(array, callback /*, initialValue*/) { + if (this === null) { + throw new TypeError('Array.prototype.reduce called on null or undefined'); + } + + if (typeof callback !== 'function') { + throw new TypeError(callback + ' is not a function'); + } + + var t = Object(array), + len = t.length >>> 0, + k = 0, + value; + + if (arguments.length === 3) { + value = arguments[2]; + } else { + while (k < len && !(k in t)) { + k++; + } + + if (k >= len) { + throw new TypeError('Reduce of empty array with no initial value'); + } + + value = t[k++]; + } + for (; k < len; k++) { + if (k in t) { + value = callback(value, t[k], k, t); + } + } + return value; + }, + /** + * Computes the multiplier necessary to make x >= 1, + * effectively eliminating miscalculations caused by + * finite precision. + */ + multiplier: function (x) { + var parts = x.toString().split('.'); + + return parts.length < 2 ? 1 : Math.pow(10, parts[1].length); + }, + /** + * Given a variable number of arguments, returns the maximum + * multiplier that must be used to normalize an operation involving + * all of them. + */ + correctionFactor: function () { + var args = Array.prototype.slice.call(arguments); + + return args.reduce(function(accum, next) { + var mn = _.multiplier(next); + return accum > mn ? accum : mn; + }, 1); + }, + /** + * Implementation of toFixed() that treats floats more like decimals + * + * Fixes binary rounding issues (eg. (0.615).toFixed(2) === '0.61') that present + * problems for accounting- and finance-related software. + */ + toFixed: function(value, maxDecimals, roundingFunction, optionals) { + var splitValue = value.toString().split('.'), + minDecimals = maxDecimals - (optionals || 0), + boundedPrecision, + optionalsRegExp, + power, + output; + + // Use the smallest precision value possible to avoid errors from floating point representation + if (splitValue.length === 2) { + boundedPrecision = Math.min(Math.max(splitValue[1].length, minDecimals), maxDecimals); + } else { + boundedPrecision = minDecimals; + } + + power = Math.pow(10, boundedPrecision); + + // Multiply up by precision, round accurately, then divide and use native toFixed(): + output = (roundingFunction(value + 'e+' + boundedPrecision) / power).toFixed(boundedPrecision); + + if (optionals > maxDecimals - boundedPrecision) { + optionalsRegExp = new RegExp('\\.?0{1,' + (optionals - (maxDecimals - boundedPrecision)) + '}$'); + output = output.replace(optionalsRegExp, ''); + } + + return output; + } + }; + + // avaliable options + numeral.options = options; + + // avaliable formats + numeral.formats = formats; + + // avaliable formats + numeral.locales = locales; + + // This function sets the current locale. If + // no arguments are passed in, it will simply return the current global + // locale key. + numeral.locale = function(key) { + if (key) { + options.currentLocale = key.toLowerCase(); + } + + return options.currentLocale; + }; + + // This function provides access to the loaded locale data. If + // no arguments are passed in, it will simply return the current + // global locale object. + numeral.localeData = function(key) { + if (!key) { + return locales[options.currentLocale]; + } + + key = key.toLowerCase(); + + if (!locales[key]) { + throw new Error('Unknown locale : ' + key); + } + + return locales[key]; + }; + + numeral.reset = function() { + for (var property in defaults) { + options[property] = defaults[property]; + } + }; + + numeral.zeroFormat = function(format) { + options.zeroFormat = typeof(format) === 'string' ? format : null; + }; + + numeral.nullFormat = function (format) { + options.nullFormat = typeof(format) === 'string' ? format : null; + }; + + numeral.defaultFormat = function(format) { + options.defaultFormat = typeof(format) === 'string' ? format : '0.0'; + }; + + numeral.register = function(type, name, format) { + name = name.toLowerCase(); + + if (this[type + 's'][name]) { + throw new TypeError(name + ' ' + type + ' already registered.'); + } + + this[type + 's'][name] = format; + + return format; + }; + + + numeral.validate = function(val, culture) { + var _decimalSep, + _thousandSep, + _currSymbol, + _valArray, + _abbrObj, + _thousandRegEx, + localeData, + temp; + + //coerce val to string + if (typeof val !== 'string') { + val += ''; + + if (console.warn) { + console.warn('Numeral.js: Value is not string. It has been co-erced to: ', val); + } + } + + //trim whitespaces from either sides + val = val.trim(); + + //if val is just digits return true + if (!!val.match(/^\d+$/)) { + return true; + } + + //if val is empty return false + if (val === '') { + return false; + } + + //get the decimal and thousands separator from numeral.localeData + try { + //check if the culture is understood by numeral. if not, default it to current locale + localeData = numeral.localeData(culture); + } catch (e) { + localeData = numeral.localeData(numeral.locale()); + } + + //setup the delimiters and currency symbol based on culture/locale + _currSymbol = localeData.currency.symbol; + _abbrObj = localeData.abbreviations; + _decimalSep = localeData.delimiters.decimal; + if (localeData.delimiters.thousands === '.') { + _thousandSep = '\\.'; + } else { + _thousandSep = localeData.delimiters.thousands; + } + + // validating currency symbol + temp = val.match(/^[^\d]+/); + if (temp !== null) { + val = val.substr(1); + if (temp[0] !== _currSymbol) { + return false; + } + } + + //validating abbreviation symbol + temp = val.match(/[^\d]+$/); + if (temp !== null) { + val = val.slice(0, -1); + if (temp[0] !== _abbrObj.thousand && temp[0] !== _abbrObj.million && temp[0] !== _abbrObj.billion && temp[0] !== _abbrObj.trillion) { + return false; + } + } + + _thousandRegEx = new RegExp(_thousandSep + '{2}'); + + if (!val.match(/[^\d.,]/g)) { + _valArray = val.split(_decimalSep); + if (_valArray.length > 2) { + return false; + } else { + if (_valArray.length < 2) { + return ( !! _valArray[0].match(/^\d+.*\d$/) && !_valArray[0].match(_thousandRegEx)); + } else { + if (_valArray[0].length === 1) { + return ( !! _valArray[0].match(/^\d+$/) && !_valArray[0].match(_thousandRegEx) && !! _valArray[1].match(/^\d+$/)); + } else { + return ( !! _valArray[0].match(/^\d+.*\d$/) && !_valArray[0].match(_thousandRegEx) && !! _valArray[1].match(/^\d+$/)); + } + } + } + } + + return false; + }; + + + /************************************ + Numeral Prototype + ************************************/ + + numeral.fn = Numeral.prototype = { + clone: function() { + return numeral(this); + }, + format: function(inputString, roundingFunction) { + var value = this._value, + format = inputString || options.defaultFormat, + kind, + output, + formatFunction; + + // make sure we have a roundingFunction + roundingFunction = roundingFunction || Math.round; + + // format based on value + if (value === 0 && options.zeroFormat !== null) { + output = options.zeroFormat; + } else if (value === null && options.nullFormat !== null) { + output = options.nullFormat; + } else { + for (kind in formats) { + if (format.match(formats[kind].regexps.format)) { + formatFunction = formats[kind].format; + + break; + } + } + + formatFunction = formatFunction || numeral._.numberToFormat; + + output = formatFunction(value, format, roundingFunction); + } + + return output; + }, + value: function() { + return this._value; + }, + input: function() { + return this._input; + }, + set: function(value) { + this._value = Number(value); + + return this; + }, + add: function(value) { + var corrFactor = _.correctionFactor.call(null, this._value, value); + + function cback(accum, curr, currI, O) { + return accum + Math.round(corrFactor * curr); + } + + this._value = _.reduce([this._value, value], cback, 0) / corrFactor; + + return this; + }, + subtract: function(value) { + var corrFactor = _.correctionFactor.call(null, this._value, value); + + function cback(accum, curr, currI, O) { + return accum - Math.round(corrFactor * curr); + } + + this._value = _.reduce([value], cback, Math.round(this._value * corrFactor)) / corrFactor; + + return this; + }, + multiply: function(value) { + function cback(accum, curr, currI, O) { + var corrFactor = _.correctionFactor(accum, curr); + return Math.round(accum * corrFactor) * Math.round(curr * corrFactor) / Math.round(corrFactor * corrFactor); + } + + this._value = _.reduce([this._value, value], cback, 1); + + return this; + }, + divide: function(value) { + function cback(accum, curr, currI, O) { + var corrFactor = _.correctionFactor(accum, curr); + return Math.round(accum * corrFactor) / Math.round(curr * corrFactor); + } + + this._value = _.reduce([this._value, value], cback); + + return this; + }, + difference: function(value) { + return Math.abs(numeral(this._value).subtract(value).value()); + } + }; + + /************************************ + Default Locale && Format + ************************************/ + + numeral.register('locale', 'en', { + delimiters: { + thousands: ',', + decimal: '.' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal: function(number) { + var b = number % 10; + return (~~(number % 100 / 10) === 1) ? 'th' : + (b === 1) ? 'st' : + (b === 2) ? 'nd' : + (b === 3) ? 'rd' : 'th'; + }, + currency: { + symbol: '$' + } + }); + -(function() { - numeral.register('format', 'bps', { - regexps: { - format: /(BPS)/, - unformat: /(BPS)/ - }, - format: function(value, format, roundingFunction) { - var space = numeral._.includes(format, ' BPS') ? ' ' : '', - output; - - value = value * 10000; - - // check for space before BPS - format = format.replace(/\s?BPS/, ''); - - output = numeral._.numberToFormat(value, format, roundingFunction); - - if (numeral._.includes(output, ')')) { - output = output.split(''); - - output.splice(-1, 0, space + 'BPS'); - - output = output.join(''); - } else { - output = output + space + 'BPS'; - } - - return output; - }, - unformat: function(string) { - return +(numeral._.stringToNumber(string) * 0.0001).toFixed(15); - } - }); -})(); - - -(function() { - var decimal = { - base: 1000, - suffixes: ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] - }, - binary = { - base: 1024, - suffixes: ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] - }; - - var allSuffixes = decimal.suffixes.concat(binary.suffixes.filter(function (item) { - return decimal.suffixes.indexOf(item) < 0; - })); - var unformatRegex = allSuffixes.join('|'); - // Allow support for BPS (http://www.investopedia.com/terms/b/basispoint.asp) - unformatRegex = '(' + unformatRegex.replace('B', 'B(?!PS)') + ')'; - - numeral.register('format', 'bytes', { - regexps: { - format: /([0\s]i?b)/, - unformat: new RegExp(unformatRegex) - }, - format: function(value, format, roundingFunction) { - var output, - bytes = numeral._.includes(format, 'ib') ? binary : decimal, - suffix = numeral._.includes(format, ' b') || numeral._.includes(format, ' ib') ? ' ' : '', - power, - min, - max; - - // check for space before - format = format.replace(/\s?i?b/, ''); - - for (power = 0; power <= bytes.suffixes.length; power++) { - min = Math.pow(bytes.base, power); - max = Math.pow(bytes.base, power + 1); - - if (value === null || value === 0 || value >= min && value < max) { - suffix += bytes.suffixes[power]; - - if (min > 0) { - value = value / min; - } - - break; - } - } - - output = numeral._.numberToFormat(value, format, roundingFunction); - - return output + suffix; - }, - unformat: function(string) { - var value = numeral._.stringToNumber(string), - power, - bytesMultiplier; - - if (value) { - for (power = decimal.suffixes.length - 1; power >= 0; power--) { - if (numeral._.includes(string, decimal.suffixes[power])) { - bytesMultiplier = Math.pow(decimal.base, power); - - break; - } - - if (numeral._.includes(string, binary.suffixes[power])) { - bytesMultiplier = Math.pow(binary.base, power); - - break; - } - } - - value *= (bytesMultiplier || 1); - } - - return value; - } - }); -})(); - - -(function() { - numeral.register('format', 'currency', { - regexps: { - format: /(\$)/ - }, - format: function(value, format, roundingFunction) { - var locale = numeral.locales[numeral.options.currentLocale], - symbols = { - before: format.match(/^([\+|\-|\(|\s|\$]*)/)[0], - after: format.match(/([\+|\-|\)|\s|\$]*)$/)[0] - }, - output, - symbol, - i; - - // strip format of spaces and $ - format = format.replace(/\s?\$\s?/, ''); - - // format the number - output = numeral._.numberToFormat(value, format, roundingFunction); - - // update the before and after based on value - if (value >= 0) { - symbols.before = symbols.before.replace(/[\-\(]/, ''); - symbols.after = symbols.after.replace(/[\-\)]/, ''); - } else if (value < 0 && (!numeral._.includes(symbols.before, '-') && !numeral._.includes(symbols.before, '('))) { - symbols.before = '-' + symbols.before; - } - - // loop through each before symbol - for (i = 0; i < symbols.before.length; i++) { - symbol = symbols.before[i]; - - switch (symbol) { - case '$': - output = numeral._.insert(output, locale.currency.symbol, i); - break; - case ' ': - output = numeral._.insert(output, ' ', i + locale.currency.symbol.length - 1); - break; - } - } - - // loop through each after symbol - for (i = symbols.after.length - 1; i >= 0; i--) { - symbol = symbols.after[i]; - - switch (symbol) { - case '$': - output = i === symbols.after.length - 1 ? output + locale.currency.symbol : numeral._.insert(output, locale.currency.symbol, -(symbols.after.length - (1 + i))); - break; - case ' ': - output = i === symbols.after.length - 1 ? output + ' ' : numeral._.insert(output, ' ', -(symbols.after.length - (1 + i) + locale.currency.symbol.length - 1)); - break; - } - } - - - return output; - } - }); -})(); - - -(function() { - numeral.register('format', 'exponential', { - regexps: { - format: /(e\+|e-)/, - unformat: /(e\+|e-)/ - }, - format: function(value, format, roundingFunction) { - var output, - exponential = typeof value === 'number' && !numeral._.isNaN(value) ? value.toExponential() : '0e+0', - parts = exponential.split('e'); - - format = format.replace(/e[\+|\-]{1}0/, ''); - - output = numeral._.numberToFormat(Number(parts[0]), format, roundingFunction); - - return output + 'e' + parts[1]; - }, - unformat: function(string) { - var parts = numeral._.includes(string, 'e+') ? string.split('e+') : string.split('e-'), - value = Number(parts[0]), - power = Number(parts[1]); - - power = numeral._.includes(string, 'e-') ? power *= -1 : power; - - function cback(accum, curr, currI, O) { - var corrFactor = numeral._.correctionFactor(accum, curr), - num = (accum * corrFactor) * (curr * corrFactor) / (corrFactor * corrFactor); - return num; - } - - return numeral._.reduce([value, Math.pow(10, power)], cback, 1); - } - }); -})(); - - -(function() { - numeral.register('format', 'ordinal', { - regexps: { - format: /(o)/ - }, - format: function(value, format, roundingFunction) { - var locale = numeral.locales[numeral.options.currentLocale], - output, - ordinal = numeral._.includes(format, ' o') ? ' ' : ''; - - // check for space before - format = format.replace(/\s?o/, ''); - - ordinal += locale.ordinal(value); - - output = numeral._.numberToFormat(value, format, roundingFunction); - - return output + ordinal; - } - }); -})(); - - -(function() { - numeral.register('format', 'percentage', { - regexps: { - format: /(%)/, - unformat: /(%)/ - }, - format: function(value, format, roundingFunction) { - var space = numeral._.includes(format, ' %') ? ' ' : '', - output; - - if (numeral.options.scalePercentBy100) { - value = value * 100; - } - - // check for space before % - format = format.replace(/\s?\%/, ''); - - output = numeral._.numberToFormat(value, format, roundingFunction); - - if (numeral._.includes(output, ')')) { - output = output.split(''); - - output.splice(-1, 0, space + '%'); - - output = output.join(''); - } else { - output = output + space + '%'; - } - - return output; - }, - unformat: function(string) { - var number = numeral._.stringToNumber(string); - if (numeral.options.scalePercentBy100) { - return number * 0.01; - } - return number; - } - }); -})(); - - -(function() { - numeral.register('format', 'time', { - regexps: { - format: /(:)/, - unformat: /(:)/ - }, - format: function(value, format, roundingFunction) { - var hours = Math.floor(value / 60 / 60), - minutes = Math.floor((value - (hours * 60 * 60)) / 60), - seconds = Math.round(value - (hours * 60 * 60) - (minutes * 60)); - - return hours + ':' + (minutes < 10 ? '0' + minutes : minutes) + ':' + (seconds < 10 ? '0' + seconds : seconds); - }, - unformat: function(string) { - var timeArray = string.split(':'), - seconds = 0; - - // turn hours and minutes into seconds and add them all up - if (timeArray.length === 3) { - // hours - seconds = seconds + (Number(timeArray[0]) * 60 * 60); - // minutes - seconds = seconds + (Number(timeArray[1]) * 60); - // seconds - seconds = seconds + Number(timeArray[2]); - } else if (timeArray.length === 2) { - // minutes - seconds = seconds + (Number(timeArray[0]) * 60); - // seconds - seconds = seconds + Number(timeArray[1]); - } - return Number(seconds); - } - }); -})(); - -return numeral; -})); +(function() { + + numeral.register('format', 'bps', { + regexps: { + format: /(BPS)/, + unformat: /(BPS)/ + }, + format: function(value, format, roundingFunction) { + var space = numeral._.includes(format, ' BPS') ? ' ' : '', + output; + + value = value * 10000; + + // check for space before BPS + format = format.replace(/\s?BPS/, ''); + + output = numeral._.numberToFormat(value, format, roundingFunction); + + if (numeral._.includes(output, ')')) { + output = output.split(''); + + output.splice(-1, 0, space + 'BPS'); + + output = output.join(''); + } else { + output = output + space + 'BPS'; + } + + return output; + }, + unformat: function(string) { + return +(numeral._.stringToNumber(string) * 0.0001).toFixed(15); + } + }); +})(); + + +(function() { + + var decimal = { + base: 1000, + suffixes: ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] + }, + binary = { + base: 1024, + suffixes: ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] + }; + + var allSuffixes = decimal.suffixes.concat(binary.suffixes.filter(function (item) { + return decimal.suffixes.indexOf(item) < 0; + })); + var unformatRegex = allSuffixes.join('|'); + // Allow support for BPS (http://www.investopedia.com/terms/b/basispoint.asp) + unformatRegex = '(' + unformatRegex.replace('B', 'B(?!PS)') + ')'; + + numeral.register('format', 'bytes', { + regexps: { + format: /([0\s]i?b)/, + unformat: new RegExp(unformatRegex) + }, + format: function(value, format, roundingFunction) { + var output, + bytes = numeral._.includes(format, 'ib') ? binary : decimal, + suffix = numeral._.includes(format, ' b') || numeral._.includes(format, ' ib') ? ' ' : '', + power, + min, + max; + + // check for space before + format = format.replace(/\s?i?b/, ''); + + for (power = 0; power <= bytes.suffixes.length; power++) { + min = Math.pow(bytes.base, power); + max = Math.pow(bytes.base, power + 1); + + if (value === null || value === 0 || value >= min && value < max) { + suffix += bytes.suffixes[power]; + + if (min > 0) { + value = value / min; + } + + break; + } + } + + output = numeral._.numberToFormat(value, format, roundingFunction); + + return output + suffix; + }, + unformat: function(string) { + var value = numeral._.stringToNumber(string), + power, + bytesMultiplier; + + if (value) { + for (power = decimal.suffixes.length - 1; power >= 0; power--) { + if (numeral._.includes(string, decimal.suffixes[power])) { + bytesMultiplier = Math.pow(decimal.base, power); + + break; + } + + if (numeral._.includes(string, binary.suffixes[power])) { + bytesMultiplier = Math.pow(binary.base, power); + + break; + } + } + + value *= (bytesMultiplier || 1); + } + + return value; + } + }); +})(); + + +(function() { + + numeral.register('format', 'currency', { + regexps: { + format: /(\$)/ + }, + format: function(value, format, roundingFunction) { + var locale = numeral.locales[numeral.options.currentLocale], + symbols = { + before: format.match(/^([\+|\-|\(|\s|\$]*)/)[0], + after: format.match(/([\+|\-|\)|\s|\$]*)$/)[0] + }, + output, + symbol, + i; + + // strip format of spaces and $ + format = format.replace(/\s?\$\s?/, ''); + + // format the number + output = numeral._.numberToFormat(value, format, roundingFunction); + + // update the before and after based on value + if (value >= 0) { + symbols.before = symbols.before.replace(/[\-\(]/, ''); + symbols.after = symbols.after.replace(/[\-\)]/, ''); + } else if (value < 0 && (!numeral._.includes(symbols.before, '-') && !numeral._.includes(symbols.before, '('))) { + symbols.before = '-' + symbols.before; + } + + // loop through each before symbol + for (i = 0; i < symbols.before.length; i++) { + symbol = symbols.before[i]; + + switch (symbol) { + case '$': + output = numeral._.insert(output, locale.currency.symbol, i); + break; + case ' ': + output = numeral._.insert(output, ' ', i + locale.currency.symbol.length - 1); + break; + } + } + + // loop through each after symbol + for (i = symbols.after.length - 1; i >= 0; i--) { + symbol = symbols.after[i]; + + switch (symbol) { + case '$': + output = i === symbols.after.length - 1 ? output + locale.currency.symbol : numeral._.insert(output, locale.currency.symbol, -(symbols.after.length - (1 + i))); + break; + case ' ': + output = i === symbols.after.length - 1 ? output + ' ' : numeral._.insert(output, ' ', -(symbols.after.length - (1 + i) + locale.currency.symbol.length - 1)); + break; + } + } + + + return output; + } + }); +})(); + + +(function() { + + numeral.register('format', 'exponential', { + regexps: { + format: /([e,E]\+|[e,E]-)/, + unformat: /([e,E]\+|[e,E]-)/ + + }, + format: function(value, format, roundingFunction) { + var output, + exponential = typeof value === 'number' && !numeral._.isNaN(value) ? value.toExponential() : '0e+0', + parts = exponential.split('e'); + + format = format.replace(/e[\+|\-]{1}0/, ''); + + output = numeral._.numberToFormat(Number(parts[0]), format, roundingFunction); + + return output + 'e' + parts[1]; + }, + unformat: function(string) { + string = string.toLowerCase(); + var parts = numeral._.includes(string, 'e+') ? string.split('e+') : string.split('e-'), + value = Number(parts[0]), + power = Number(parts[1]); + + power = numeral._.includes(string, 'e-') ? power *= -1 : power; + + function cback(accum, curr, currI, O) { + var corrFactor = numeral._.correctionFactor(accum, curr), + num = (accum * corrFactor) * (curr * corrFactor) / (corrFactor * corrFactor); + return num; + } + + return numeral._.reduce([value, Math.pow(10, power)], cback, 1); + } + }); +})(); + + +(function() { + + numeral.register('format', 'ordinal', { + regexps: { + format: /(o)/ + }, + format: function(value, format, roundingFunction) { + var locale = numeral.locales[numeral.options.currentLocale], + output, + ordinal = numeral._.includes(format, ' o') ? ' ' : ''; + + // check for space before + format = format.replace(/\s?o/, ''); + + ordinal += locale.ordinal(value); + + output = numeral._.numberToFormat(value, format, roundingFunction); + + return output + ordinal; + } + }); +})(); + + +(function() { + + numeral.register('format', 'percentage', { + regexps: { + format: /(%)/, + unformat: /(%)/ + }, + format: function(value, format, roundingFunction) { + var space = numeral._.includes(format, ' %') ? ' ' : '', + output; + + if (numeral.options.scalePercentBy100) { + value = value * 100; + } + + // check for space before % + format = format.replace(/\s?\%/, ''); + + output = numeral._.numberToFormat(value, format, roundingFunction); + + if (numeral._.includes(output, ')')) { + output = output.split(''); + + output.splice(-1, 0, space + '%'); + + output = output.join(''); + } else { + output = output + space + '%'; + } + + return output; + }, + unformat: function(string) { + var number = numeral._.stringToNumber(string); + if (numeral.options.scalePercentBy100) { + return number * 0.01; + } + return number; + } + }); +})(); + + +(function() { + + numeral.register('format', 'time', { + regexps: { + format: /(:)/, + unformat: /(:)/ + }, + format: function(value, format, roundingFunction) { + var hours = Math.floor(value / 60 / 60), + minutes = Math.floor((value - (hours * 60 * 60)) / 60), + seconds = Math.round(value - (hours * 60 * 60) - (minutes * 60)); + + return hours + ':' + (minutes < 10 ? '0' + minutes : minutes) + ':' + (seconds < 10 ? '0' + seconds : seconds); + }, + unformat: function(string) { + var timeArray = string.split(':'), + seconds = 0; + + // turn hours and minutes into seconds and add them all up + if (timeArray.length === 3) { + // hours + seconds = seconds + (Number(timeArray[0]) * 60 * 60); + // minutes + seconds = seconds + (Number(timeArray[1]) * 60); + // seconds + seconds = seconds + Number(timeArray[2]); + } else if (timeArray.length === 2) { + // minutes + seconds = seconds + (Number(timeArray[0]) * 60); + // seconds + seconds = seconds + Number(timeArray[1]); + } + return Number(seconds); + } + }); +})(); + +return numeral; +})); diff --git a/src/formats/exponential.js b/src/formats/exponential.js index 21459980..abedb534 100644 --- a/src/formats/exponential.js +++ b/src/formats/exponential.js @@ -13,8 +13,9 @@ }(this, function (numeral) { numeral.register('format', 'exponential', { regexps: { - format: /(e\+|e-)/, - unformat: /(e\+|e-)/ + format: /([e,E]\+|[e,E]-)/, + unformat: /([e,E]\+|[e,E]-)/ + }, format: function(value, format, roundingFunction) { var output, @@ -28,6 +29,7 @@ return output + 'e' + parts[1]; }, unformat: function(string) { + string = string.toLowerCase(); var parts = numeral._.includes(string, 'e+') ? string.split('e+') : string.split('e-'), value = Number(parts[0]), power = Number(parts[1]); diff --git a/tests/formats/exponential.js b/tests/formats/exponential.js index 4ab26fe7..a1df499a 100644 --- a/tests/formats/exponential.js +++ b/tests/formats/exponential.js @@ -35,10 +35,12 @@ describe('Exponential', function() { ['7.712e+1', 77.12], ['7.7e-7', 0.00000077], ['-7.71e-6', -0.00000771], - ['-1.0008e+9', -1000800000] + ['-1.0008e+9', -1000800000], + ['5.296610169491525e-4',0.0005296610169491524], + ['5.296610169491525E-4',0.0005296610169491524], + ['5231.25E-6',0.00523125] ], i; - for (i = 0; i < tests.length; i++) { expect(numeral(tests[i][0]).value()).to.equal(tests[i][1]); }