Comparing version 1.7.1 to 1.8.0
@@ -0,1 +1,14 @@ | ||
### 1.8.0 | ||
- Fix #180: Add culture function, deprecate language. Thanks @wereHamster. | ||
- Fix #170: Add the ability to determine units without formatting. Thanks @pickypg. | ||
- Fix #162: Add TypeScript declaration file. Thanks @wereHamster. | ||
- Fix #163: unformat: return undefined when value can't be parsed. Thanks @wereHamster. | ||
- Fix #173: Added two latest stable node versions to Travis build. Thanks @therebelrobot. | ||
- Fix #176: default pt-BR currency is prefix, not postfix. Thanks @luisrudge. | ||
- Fix #175: Zero byte unit fix, take 2. Thanks @therebelrobot. | ||
- Fix #135: Fix fr-CA currency format. Thanks @killfish. | ||
- Fix #174: Set versions for all deps. Thanks @BenjaminVanRyseghem. | ||
- Fix #152: Use zeros() function instead of multiple inline implementations. Thanks @MarkHerhold. | ||
### 1.7.1 | ||
@@ -10,3 +23,3 @@ | ||
- Fix decimal rounding issue. Thanks @Shraymonks. | ||
- Fix decimal rounding issue. Thangrks @Shraymonks. | ||
- Fix #114: webpack bundling. Thanks @mmollick. | ||
@@ -13,0 +26,0 @@ - Add ko-KR & zh-TW support. Thanks @rocketedaway and @rWilander. |
@@ -635,3 +635,4 @@ /*! | ||
symbol: '$', | ||
position: 'prefix' | ||
position: 'postfix', | ||
spaceSeparated : true | ||
}, | ||
@@ -1272,3 +1273,3 @@ defaults: { | ||
symbol: 'R$', | ||
position: 'postfix' | ||
position: 'prefix' | ||
}, | ||
@@ -1275,0 +1276,0 @@ defaults: { |
@@ -132,3 +132,3 @@ /*! | ||
*/ | ||
function(){"use strict";var a={langLocaleCode:"fr-CA",cultureCode:"fr-CA",delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"M",billion:"G",trillion:"T"},ordinal:function(a){return 1===a?"er":"ème"},currency:{symbol:"$",position:"prefix"},defaults:{currencyFormat:",4 a"},formats:{fourDigits:"4 a",fullWithTwoDecimals:"$ ,0.00",fullWithTwoDecimalsNoCurrency:",0.00",fullWithNoDecimals:"$ ,0"}}; | ||
function(){"use strict";var a={langLocaleCode:"fr-CA",cultureCode:"fr-CA",delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"M",billion:"G",trillion:"T"},ordinal:function(a){return 1===a?"er":"ème"},currency:{symbol:"$",position:"postfix",spaceSeparated:!0},defaults:{currencyFormat:",4 a"},formats:{fourDigits:"4 a",fullWithTwoDecimals:"$ ,0.00",fullWithTwoDecimalsNoCurrency:",0.00",fullWithNoDecimals:"$ ,0"}}; | ||
// CommonJS | ||
@@ -266,3 +266,3 @@ "undefined"!=typeof module&&module.exports&&(module.exports=a), | ||
*/ | ||
function(){"use strict";var a={langLocaleCode:"pt-BR",cultureCode:"pt-BR",delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"mil",million:"milhões",billion:"b",trillion:"t"},ordinal:function(){return"º"},currency:{symbol:"R$",position:"postfix"},defaults:{currencyFormat:",4 a"},formats:{fourDigits:"4 a",fullWithTwoDecimals:",0.00 $",fullWithTwoDecimalsNoCurrency:",0.00",fullWithNoDecimals:",0 $"}}; | ||
function(){"use strict";var a={langLocaleCode:"pt-BR",cultureCode:"pt-BR",delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"mil",million:"milhões",billion:"b",trillion:"t"},ordinal:function(){return"º"},currency:{symbol:"R$",position:"prefix"},defaults:{currencyFormat:",4 a"},formats:{fourDigits:"4 a",fullWithTwoDecimals:",0.00 $",fullWithTwoDecimalsNoCurrency:",0.00",fullWithNoDecimals:",0 $"}}; | ||
// CommonJS | ||
@@ -269,0 +269,0 @@ "undefined"!=typeof module&&module.exports&&(module.exports=a), |
@@ -7,3 +7,3 @@ /*! | ||
*/ | ||
(function(){"use strict";var a={langLocaleCode:"fr-CA",cultureCode:"fr-CA",delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"M",billion:"G",trillion:"T"},ordinal:function(a){return 1===a?"er":"ème"},currency:{symbol:"$",position:"prefix"},defaults:{currencyFormat:",4 a"},formats:{fourDigits:"4 a",fullWithTwoDecimals:"$ ,0.00",fullWithTwoDecimalsNoCurrency:",0.00",fullWithNoDecimals:"$ ,0"}}; | ||
(function(){"use strict";var a={langLocaleCode:"fr-CA",cultureCode:"fr-CA",delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"M",billion:"G",trillion:"T"},ordinal:function(a){return 1===a?"er":"ème"},currency:{symbol:"$",position:"postfix",spaceSeparated:!0},defaults:{currencyFormat:",4 a"},formats:{fourDigits:"4 a",fullWithTwoDecimals:"$ ,0.00",fullWithTwoDecimalsNoCurrency:",0.00",fullWithNoDecimals:"$ ,0"}}; | ||
// CommonJS | ||
@@ -10,0 +10,0 @@ "undefined"!=typeof module&&module.exports&&(module.exports=a), |
@@ -7,3 +7,3 @@ /*! | ||
*/ | ||
(function(){"use strict";var a={langLocaleCode:"pt-BR",cultureCode:"pt-BR",delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"mil",million:"milhões",billion:"b",trillion:"t"},ordinal:function(){return"º"},currency:{symbol:"R$",position:"postfix"},defaults:{currencyFormat:",4 a"},formats:{fourDigits:"4 a",fullWithTwoDecimals:",0.00 $",fullWithTwoDecimalsNoCurrency:",0.00",fullWithNoDecimals:",0 $"}}; | ||
(function(){"use strict";var a={langLocaleCode:"pt-BR",cultureCode:"pt-BR",delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"mil",million:"milhões",billion:"b",trillion:"t"},ordinal:function(){return"º"},currency:{symbol:"R$",position:"prefix"},defaults:{currencyFormat:",4 a"},formats:{fourDigits:"4 a",fullWithTwoDecimals:",0.00 $",fullWithTwoDecimalsNoCurrency:",0.00",fullWithNoDecimals:",0 $"}}; | ||
// CommonJS | ||
@@ -10,0 +10,0 @@ "undefined"!=typeof module&&module.exports&&(module.exports=a), |
/*! | ||
* numbro.js | ||
* version : 1.7.1 | ||
* version : 1.8.0 | ||
* author : Företagsplatsen AB | ||
@@ -17,3 +17,12 @@ * license : MIT | ||
var numbro, | ||
VERSION = '1.7.1', | ||
VERSION = '1.8.0', | ||
binarySuffixes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'], | ||
decimalSuffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | ||
bytes = { | ||
general: { scale: 1024, suffixes: decimalSuffixes, marker: 'bd' }, | ||
binary: { scale: 1024, suffixes: binarySuffixes, marker: 'b' }, | ||
decimal: { scale: 1000, suffixes: decimalSuffixes, marker: 'd' } | ||
}, | ||
// general must be before the others because it reuses their characters! | ||
byteFormatOrder = [ bytes.general, bytes.binary, bytes.decimal ], | ||
// internal storage for culture config files | ||
@@ -199,4 +208,2 @@ cultures = {}, | ||
trillionRegExp, | ||
binarySuffixes = ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'], | ||
decimalSuffixes = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | ||
bytesMultiplier = false, | ||
@@ -226,23 +233,30 @@ power; | ||
// see if bytes are there so that we can multiply to the correct number | ||
for (power = 0; power <= binarySuffixes.length && !bytesMultiplier; power++) { | ||
for (power = 1; power < binarySuffixes.length && !bytesMultiplier; ++power) { | ||
if (string.indexOf(binarySuffixes[power]) > -1) { | ||
bytesMultiplier = Math.pow(1024, power + 1); | ||
bytesMultiplier = Math.pow(1024, power); | ||
} else if (string.indexOf(decimalSuffixes[power]) > -1) { | ||
bytesMultiplier = Math.pow(1000, power + 1); | ||
bytesMultiplier = Math.pow(1000, power); | ||
} | ||
} | ||
// do some math to create our number | ||
n._value = ((bytesMultiplier) ? bytesMultiplier : 1) * | ||
((stringOriginal.match(thousandRegExp)) ? Math.pow(10, 3) : 1) * | ||
((stringOriginal.match(millionRegExp)) ? Math.pow(10, 6) : 1) * | ||
((stringOriginal.match(billionRegExp)) ? Math.pow(10, 9) : 1) * | ||
((stringOriginal.match(trillionRegExp)) ? Math.pow(10, 12) : 1) * | ||
((string.indexOf('%') > -1) ? 0.01 : 1) * | ||
(((string.split('-').length + | ||
Math.min(string.split('(').length - 1, string.split(')').length - 1)) % 2) ? 1 : -1) * | ||
Number(string.replace(/[^0-9\.]+/g, '')); | ||
var str = string.replace(/[^0-9\.]+/g, ''); | ||
if (str === '') { | ||
// An empty string is not a number. | ||
n._value = NaN; | ||
// round if we are talking about bytes | ||
n._value = (bytesMultiplier) ? Math.ceil(n._value) : n._value; | ||
} else { | ||
// do some math to create our number | ||
n._value = ((bytesMultiplier) ? bytesMultiplier : 1) * | ||
((stringOriginal.match(thousandRegExp)) ? Math.pow(10, 3) : 1) * | ||
((stringOriginal.match(millionRegExp)) ? Math.pow(10, 6) : 1) * | ||
((stringOriginal.match(billionRegExp)) ? Math.pow(10, 9) : 1) * | ||
((stringOriginal.match(trillionRegExp)) ? Math.pow(10, 12) : 1) * | ||
((string.indexOf('%') > -1) ? 0.01 : 1) * | ||
(((string.split('-').length + | ||
Math.min(string.split('(').length - 1, string.split(')').length - 1)) % 2) ? 1 : -1) * | ||
Number(str); | ||
// round if we are talking about bytes | ||
n._value = (bytesMultiplier) ? Math.ceil(n._value) : n._value; | ||
} | ||
} | ||
@@ -402,2 +416,31 @@ } | ||
function formatByteUnits (value, suffixes, scale) { | ||
var suffix = suffixes[0], | ||
power, | ||
min, | ||
max, | ||
abs = Math.abs(value); | ||
if (abs >= scale) { | ||
for (power = 1; power < suffixes.length; ++power) { | ||
min = Math.pow(scale, power); | ||
max = Math.pow(scale, power + 1); | ||
if (abs >= min && abs < max) { | ||
suffix = suffixes[power]; | ||
value = value / min; | ||
break; | ||
} | ||
} | ||
// values greater than or equal to [scale] YB never set the suffix | ||
if (suffix === suffixes[0]) { | ||
value = value / Math.pow(scale, suffixes.length - 1); | ||
suffix = suffixes[suffixes.length - 1]; | ||
} | ||
} | ||
return { value: value, suffix: suffix }; | ||
} | ||
function formatNumber (value, format, roundingFunction, sep) { | ||
@@ -408,3 +451,2 @@ var negP = false, | ||
abbr = '', | ||
i, | ||
abbrK = false, // force abbreviation to thousands | ||
@@ -416,9 +458,6 @@ abbrM = false, // force abbreviation to millions | ||
bytes = '', | ||
byteFormat, | ||
units, | ||
ord = '', | ||
abs = Math.abs(value), | ||
binarySuffixes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'], | ||
decimalSuffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | ||
min, | ||
max, | ||
power, | ||
totalLength, | ||
@@ -441,3 +480,4 @@ length, | ||
paren = '', | ||
minlen; | ||
minlen, | ||
i; | ||
@@ -536,5 +576,3 @@ // check if number is zero and a custom zero format has been set | ||
for (i = 0; i < size; i++) { | ||
format += '0'; | ||
} | ||
format += zeroes(size); | ||
} | ||
@@ -564,47 +602,22 @@ } | ||
// see if we are formatting binary bytes | ||
if (format.indexOf('b') > -1) { | ||
// check for space before | ||
if (format.indexOf(' b') > -1) { | ||
bytes = ' '; | ||
format = format.replace(' b', ''); | ||
} else { | ||
format = format.replace('b', ''); | ||
} | ||
// see if we are formatting | ||
// binary-decimal bytes (1024 MB), binary bytes (1024 MiB), or decimal bytes (1000 MB) | ||
for (i = 0; i < byteFormatOrder.length; ++i) { | ||
byteFormat = byteFormatOrder[i]; | ||
for (power = 0; power <= binarySuffixes.length; power++) { | ||
min = Math.pow(1024, power); | ||
max = Math.pow(1024, power + 1); | ||
if (value >= min && value < max) { | ||
bytes = bytes + binarySuffixes[power]; | ||
if (min > 0) { | ||
value = value / min; | ||
} | ||
break; | ||
if (format.indexOf(byteFormat.marker) > -1) { | ||
// check for space before | ||
if (format.indexOf(' ' + byteFormat.marker) >-1) { | ||
bytes = ' '; | ||
} | ||
} | ||
} | ||
// see if we are formatting decimal bytes | ||
if (format.indexOf('d') > -1) { | ||
// check for space before | ||
if (format.indexOf(' d') > -1) { | ||
bytes = ' '; | ||
format = format.replace(' d', ''); | ||
} else { | ||
format = format.replace('d', ''); | ||
} | ||
// remove the marker (with the space if it had one) | ||
format = format.replace(bytes + byteFormat.marker, ''); | ||
for (power = 0; power <= decimalSuffixes.length; power++) { | ||
min = Math.pow(1000, power); | ||
max = Math.pow(1000, power + 1); | ||
units = formatByteUnits(value, byteFormat.suffixes, byteFormat.scale); | ||
if (value >= min && value < max) { | ||
bytes = bytes + decimalSuffixes[power]; | ||
if (min > 0) { | ||
value = value / min; | ||
} | ||
break; | ||
} | ||
value = units.value; | ||
bytes = bytes + units.suffix; | ||
break; | ||
} | ||
@@ -674,3 +687,3 @@ } | ||
if (w.length < minlen) { | ||
w = new Array(minlen - w.length + 1).join('0') + w; | ||
w = zeroes(minlen - w.length) + w; | ||
} | ||
@@ -757,3 +770,3 @@ | ||
* the culture does not exist. If no fallback culture is provided, | ||
* it fallbacks to "en-US". | ||
* it falls back to "en-US". | ||
*/ | ||
@@ -1036,3 +1049,3 @@ numbro.setCulture = function(newCulture, fallbackCulture) { | ||
(process.browser === undefined) && | ||
(process.title === 'node' || process.title === 'grunt' || process.title === 'gulp') && | ||
(process.title.indexOf('node') === 0 || process.title === 'grunt' || process.title === 'gulp') && | ||
(typeof require !== 'undefined'); | ||
@@ -1149,8 +1162,27 @@ } | ||
unformat: function(inputString) { | ||
if (Object.prototype.toString.call(inputString) === '[object Number]') { | ||
if (typeof inputString === 'number') { | ||
return inputString; | ||
} else if (typeof inputString === 'string') { | ||
var result = unformatNumbro(this, inputString); | ||
// Any unparseable string (represented as NaN in the result) is | ||
// converted into undefined. | ||
return isNaN(result) ? undefined : result; | ||
} else { | ||
return undefined; | ||
} | ||
return unformatNumbro(this, inputString ? inputString : defaultFormat); | ||
}, | ||
binaryByteUnits: function() { | ||
return formatByteUnits(this._value, bytes.binary.suffixes, bytes.binary.scale).suffix; | ||
}, | ||
byteUnits: function() { | ||
return formatByteUnits(this._value, bytes.general.suffixes, bytes.general.scale).suffix; | ||
}, | ||
decimalByteUnits: function() { | ||
return formatByteUnits(this._value, bytes.decimal.suffixes, bytes.decimal.scale).suffix; | ||
}, | ||
value: function() { | ||
@@ -1157,0 +1189,0 @@ return this._value; |
/*! | ||
* numbro.js | ||
* version : 1.7.1 | ||
* version : 1.8.0 | ||
* author : Företagsplatsen AB | ||
@@ -42,19 +42,21 @@ * license : MIT | ||
// currency!!!!! | ||
return d=e.indexOf("$")>-1?g(a,b,c):e.indexOf("%")>-1?h(a,b,c):e.indexOf(":")>-1?i(a,b):k(a._value,b,c)} | ||
return d=e.indexOf("$")>-1?g(a,b,c):e.indexOf("%")>-1?h(a,b,c):e.indexOf(":")>-1?i(a,b):l(a._value,b,c)} | ||
// revert to number | ||
function f(a,b){var c,d,e,f,g,h=b,i=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],k=["KB","MB","GB","TB","PB","EB","ZB","YB"],l=!1;if(b.indexOf(":")>-1)a._value=j(b);else if(b===v)a._value=0;else{ | ||
function f(a,b){var c,d,e,f,g,h=b,i=!1;if(b.indexOf(":")>-1)a._value=j(b);else if(b===A)a._value=0;else{ | ||
// see if bytes are there so that we can multiply to the correct number | ||
for("."!==s[u].delimiters.decimal&&(b=b.replace(/\./g,"").replace(s[u].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+s[u].abbreviations.thousand+"(?:\\)|(\\"+s[u].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+s[u].abbreviations.million+"(?:\\)|(\\"+s[u].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+s[u].abbreviations.billion+"(?:\\)|(\\"+s[u].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+s[u].abbreviations.trillion+"(?:\\)|(\\"+s[u].currency.symbol+")?(?:\\))?)?$"),g=0;g<=i.length&&!l;g++)b.indexOf(i[g])>-1?l=Math.pow(1024,g+1):b.indexOf(k[g])>-1&&(l=Math.pow(1e3,g+1)); | ||
for("."!==x[z].delimiters.decimal&&(b=b.replace(/\./g,"").replace(x[z].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+x[z].abbreviations.thousand+"(?:\\)|(\\"+x[z].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+x[z].abbreviations.million+"(?:\\)|(\\"+x[z].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+x[z].abbreviations.billion+"(?:\\)|(\\"+x[z].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+x[z].abbreviations.trillion+"(?:\\)|(\\"+x[z].currency.symbol+")?(?:\\))?)?$"),g=1;g<t.length&&!i;++g)b.indexOf(t[g])>-1?i=Math.pow(1024,g):b.indexOf(u[g])>-1&&(i=Math.pow(1e3,g));var k=b.replace(/[^0-9\.]+/g,"");""===k? | ||
// An empty string is not a number. | ||
a._value=NaN:( | ||
// do some math to create our number | ||
a._value=(l?l:1)*(h.match(c)?Math.pow(10,3):1)*(h.match(d)?Math.pow(10,6):1)*(h.match(e)?Math.pow(10,9):1)*(h.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=(i?i:1)*(h.match(c)?Math.pow(10,3):1)*(h.match(d)?Math.pow(10,6):1)*(h.match(e)?Math.pow(10,9):1)*(h.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(k), | ||
// round if we are talking about bytes | ||
a._value=l?Math.ceil(a._value):a._value}return a._value}function g(a,b,c){var d,e,f=b,g=f.indexOf("$"),h=f.indexOf("("),i=f.indexOf("+"),j=f.indexOf("-"),l="",m="";if(-1===f.indexOf("$")? | ||
a._value=i?Math.ceil(a._value):a._value)}return a._value}function g(a,b,c){var d,e,f=b,g=f.indexOf("$"),h=f.indexOf("("),i=f.indexOf("+"),j=f.indexOf("-"),k="",m="";if(-1===f.indexOf("$")? | ||
// Use defaults instead of the format provided | ||
"infix"===s[u].currency.position?(m=s[u].currency.symbol,s[u].currency.spaceSeparated&&(m=" "+m+" ")):s[u].currency.spaceSeparated&&(l=" "):f.indexOf(" $")>-1?(l=" ",f=f.replace(" $","")):f.indexOf("$ ")>-1?(l=" ",f=f.replace("$ ","")):f=f.replace("$",""),e=k(a._value,f,c,m),-1===b.indexOf("$")) | ||
"infix"===x[z].currency.position?(m=x[z].currency.symbol,x[z].currency.spaceSeparated&&(m=" "+m+" ")):x[z].currency.spaceSeparated&&(k=" "):f.indexOf(" $")>-1?(k=" ",f=f.replace(" $","")):f.indexOf("$ ")>-1?(k=" ",f=f.replace("$ ","")):f=f.replace("$",""),e=l(a._value,f,c,m),-1===b.indexOf("$")) | ||
// Use defaults instead of the format provided | ||
switch(s[u].currency.position){case"postfix":e.indexOf(")")>-1?(e=e.split(""),e.splice(-1,0,l+s[u].currency.symbol),e=e.join("")):e=e+l+s[u].currency.symbol;break;case"infix":break;case"prefix":e.indexOf("(")>-1||e.indexOf("-")>-1?(e=e.split(""),d=Math.max(h,j)+1,e.splice(d,0,s[u].currency.symbol+l),e=e.join("")):e=s[u].currency.symbol+l+e;break;default:throw Error('Currency position should be among ["prefix", "infix", "postfix"]')}else | ||
switch(x[z].currency.position){case"postfix":e.indexOf(")")>-1?(e=e.split(""),e.splice(-1,0,k+x[z].currency.symbol),e=e.join("")):e=e+k+x[z].currency.symbol;break;case"infix":break;case"prefix":e.indexOf("(")>-1||e.indexOf("-")>-1?(e=e.split(""),d=Math.max(h,j)+1,e.splice(d,0,x[z].currency.symbol+k),e=e.join("")):e=x[z].currency.symbol+k+e;break;default:throw Error('Currency position should be among ["prefix", "infix", "postfix"]')}else | ||
// position the symbol | ||
1>=g?e.indexOf("(")>-1||e.indexOf("+")>-1||e.indexOf("-")>-1?(e=e.split(""),d=1,(h>g||i>g||j>g)&&(d=0),e.splice(d,0,s[u].currency.symbol+l),e=e.join("")):e=s[u].currency.symbol+l+e:e.indexOf(")")>-1?(e=e.split(""),e.splice(-1,0,l+s[u].currency.symbol),e=e.join("")):e=e+l+s[u].currency.symbol;return e}function h(a,b,c){var d,e="",f=100*a._value; | ||
1>=g?e.indexOf("(")>-1||e.indexOf("+")>-1||e.indexOf("-")>-1?(e=e.split(""),d=1,(h>g||i>g||j>g)&&(d=0),e.splice(d,0,x[z].currency.symbol+k),e=e.join("")):e=x[z].currency.symbol+k+e:e.indexOf(")")>-1?(e=e.split(""),e.splice(-1,0,k+x[z].currency.symbol),e=e.join("")):e=e+k+x[z].currency.symbol;return e}function h(a,b,c){var d,e="",f=100*a._value; | ||
// check for space before % | ||
return b.indexOf(" %")>-1?(e=" ",b=b.replace(" %","")):b=b.replace("%",""),d=k(f,b,c),d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,e+"%"),d=d.join("")):d=d+e+"%",d}function i(a){var b=Math.floor(a._value/60/60),c=Math.floor((a._value-60*b*60)/60),d=Math.round(a._value-60*b*60-60*c);return b+":"+(10>c?"0"+c:c)+":"+(10>d?"0"+d:d)}function j(a){var b=a.split(":"),c=0; | ||
return b.indexOf(" %")>-1?(e=" ",b=b.replace(" %","")):b=b.replace("%",""),d=l(f,b,c),d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,e+"%"),d=d.join("")):d=d+e+"%",d}function i(a){var b=Math.floor(a._value/60/60),c=Math.floor((a._value-60*b*60)/60),d=Math.round(a._value-60*b*60-60*c);return b+":"+(10>c?"0"+c:c)+":"+(10>d?"0"+d:d)}function j(a){var b=a.split(":"),c=0; | ||
// turn hours and minutes into seconds and add them all up | ||
@@ -66,31 +68,30 @@ // hours | ||
// seconds | ||
return 3===b.length?(c+=60*Number(b[0])*60,c+=60*Number(b[1]),c+=Number(b[2])):2===b.length&&(c+=60*Number(b[0]),c+=Number(b[1])),Number(c)}function k(a,b,c,e){var f,g,h,i,j,k,l,m,n,o,p,q,r,t,w,x,y,z,A=!1,B=!1,C=!1,D="",E=!1,// force abbreviation to thousands | ||
F=!1,// force abbreviation to millions | ||
G=!1,// force abbreviation to billions | ||
H=!1,// force abbreviation to trillions | ||
I=!1,// force abbreviation | ||
J="",K="",L=Math.abs(a),M=["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],N=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],O="",P=!1,Q=!1,R=""; | ||
return 3===b.length?(c+=60*Number(b[0])*60,c+=60*Number(b[1]),c+=Number(b[2])):2===b.length&&(c+=60*Number(b[0]),c+=Number(b[1])),Number(c)}function k(a,b,c){var d,e,f,g=b[0],h=Math.abs(a);if(h>=c){for(d=1;d<b.length;++d)if(e=Math.pow(c,d),f=Math.pow(c,d+1),h>=e&&f>h){g=b[d],a/=e;break} | ||
// values greater than or equal to [scale] YB never set the suffix | ||
g===b[0]&&(a/=Math.pow(c,b.length-1),g=b[b.length-1])}return{value:a,suffix:g}}function l(a,c,e,f){var g,h,i,j,l,m,n,o,p,q,r,s,t,u,v,y,B,C=!1,D=!1,E=!1,F="",G=!1,// force abbreviation to thousands | ||
H=!1,// force abbreviation to millions | ||
I=!1,// force abbreviation to billions | ||
J=!1,// force abbreviation to trillions | ||
K=!1,// force abbreviation | ||
L="",M="",N=Math.abs(a),O="",P=!1,Q=!1,R=""; | ||
// check if number is zero and a custom zero format has been set | ||
if(0===a&&null!==v)return v;if(!isFinite(a))return""+a;if(0===b.indexOf("{")){var S=b.indexOf("}");if(-1===S)throw Error('Format should also contain a "}"');q=b.slice(1,S),b=b.slice(S+1)}else q="";if(b.indexOf("}")===b.length-1){var T=b.indexOf("{");if(-1===T)throw Error('Format should also contain a "{"');r=b.slice(T+1,-1),b=b.slice(0,T+1)}else r=""; | ||
if(0===a&&null!==A)return A;if(!isFinite(a))return""+a;if(0===c.indexOf("{")){var S=c.indexOf("}");if(-1===S)throw Error('Format should also contain a "}"');q=c.slice(1,S),c=c.slice(S+1)}else q="";if(c.indexOf("}")===c.length-1){var T=c.indexOf("{");if(-1===T)throw Error('Format should also contain a "{"');r=c.slice(T+1,-1),c=c.slice(0,T+1)}else r=""; | ||
// check for min length | ||
var U; | ||
// see if abbreviation is wanted | ||
if(U=-1===b.indexOf(".")?b.match(/([0-9]+).*/):b.match(/([0-9]+)\..*/),z=null===U?-1:U[1].length,-1!==b.indexOf("-")&&(P=!0),b.indexOf("(")>-1?(A=!0,b=b.slice(1,-1)):b.indexOf("+")>-1&&(B=!0,b=b.replace(/\+/g,"")),b.indexOf("a")>-1){if(o=b.split(".")[0].match(/[0-9]+/g)||["0"],o=parseInt(o[0],10),E=b.indexOf("aK")>=0,F=b.indexOf("aM")>=0,G=b.indexOf("aB")>=0,H=b.indexOf("aT")>=0,I=E||F||G||H,b.indexOf(" a")>-1?(D=" ",b=b.replace(" a","")):b=b.replace("a",""),j=Math.floor(Math.log(L)/Math.LN10)+1,l=j%3,l=0===l?3:l,o&&0!==L&&(k=Math.floor(Math.log(L)/Math.LN10)+1-o,m=3*~~((Math.min(o,j)-l)/3),L/=Math.pow(10,m),-1===b.indexOf(".")&&o>3))for(b+="[.]",x=0===k?0:3*~~(k/3)-k,x=0>x?x+3:x,f=0;x>f;f++)b+="0";Math.floor(Math.log(Math.abs(a))/Math.LN10)+1!==o&&(L>=Math.pow(10,12)&&!I||H?(D+=s[u].abbreviations.trillion,a/=Math.pow(10,12)):L<Math.pow(10,12)&&L>=Math.pow(10,9)&&!I||G?(D+=s[u].abbreviations.billion,a/=Math.pow(10,9)):L<Math.pow(10,9)&&L>=Math.pow(10,6)&&!I||F?(D+=s[u].abbreviations.million,a/=Math.pow(10,6)):(L<Math.pow(10,6)&&L>=Math.pow(10,3)&&!I||E)&&(D+=s[u].abbreviations.thousand,a/=Math.pow(10,3)))} | ||
// see if we are formatting binary bytes | ||
if(b.indexOf("b")>-1)for( | ||
// see if we are formatting | ||
// binary-decimal bytes (1024 MB), binary bytes (1024 MiB), or decimal bytes (1000 MB) | ||
for(U=-1===c.indexOf(".")?c.match(/([0-9]+).*/):c.match(/([0-9]+)\..*/),y=null===U?-1:U[1].length,-1!==c.indexOf("-")&&(P=!0),c.indexOf("(")>-1?(C=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(D=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(o=c.split(".")[0].match(/[0-9]+/g)||["0"],o=parseInt(o[0],10),G=c.indexOf("aK")>=0,H=c.indexOf("aM")>=0,I=c.indexOf("aB")>=0,J=c.indexOf("aT")>=0,K=G||H||I||J,c.indexOf(" a")>-1?(F=" ",c=c.replace(" a","")):c=c.replace("a",""),i=Math.floor(Math.log(N)/Math.LN10)+1,l=i%3,l=0===l?3:l,o&&0!==N&&(j=Math.floor(Math.log(N)/Math.LN10)+1-o,m=3*~~((Math.min(o,i)-l)/3),N/=Math.pow(10,m),-1===c.indexOf(".")&&o>3&&(c+="[.]",u=0===j?0:3*~~(j/3)-j,u=0>u?u+3:u,c+=b(u))),Math.floor(Math.log(Math.abs(a))/Math.LN10)+1!==o&&(N>=Math.pow(10,12)&&!K||J?(F+=x[z].abbreviations.trillion,a/=Math.pow(10,12)):N<Math.pow(10,12)&&N>=Math.pow(10,9)&&!K||I?(F+=x[z].abbreviations.billion,a/=Math.pow(10,9)):N<Math.pow(10,9)&&N>=Math.pow(10,6)&&!K||H?(F+=x[z].abbreviations.million,a/=Math.pow(10,6)):(N<Math.pow(10,6)&&N>=Math.pow(10,3)&&!K||G)&&(F+=x[z].abbreviations.thousand,a/=Math.pow(10,3)))),B=0;B<w.length;++B)if(g=w[B],c.indexOf(g.marker)>-1){ | ||
// check for space before | ||
b.indexOf(" b")>-1?(J=" ",b=b.replace(" b","")):b=b.replace("b",""),i=0;i<=M.length;i++)if(g=Math.pow(1024,i),h=Math.pow(1024,i+1),a>=g&&h>a){J+=M[i],g>0&&(a/=g);break} | ||
// see if we are formatting decimal bytes | ||
if(b.indexOf("d")>-1)for( | ||
// check for space before | ||
b.indexOf(" d")>-1?(J=" ",b=b.replace(" d","")):b=b.replace("d",""),i=0;i<=N.length;i++)if(g=Math.pow(1e3,i),h=Math.pow(1e3,i+1),a>=g&&h>a){J+=N[i],g>0&&(a/=g);break}if( | ||
c.indexOf(" "+g.marker)>-1&&(L=" "), | ||
// remove the marker (with the space if it had one) | ||
c=c.replace(L+g.marker,""),h=k(a,g.suffixes,g.scale),a=h.value,L+=h.suffix;break}if( | ||
// see if ordinal is wanted | ||
b.indexOf("o")>-1&&( | ||
c.indexOf("o")>-1&&( | ||
// check for space before | ||
b.indexOf(" o")>-1?(K=" ",b=b.replace(" o","")):b=b.replace("o",""),s[u].ordinal&&(K+=s[u].ordinal(a))),b.indexOf("[.]")>-1&&(C=!0,b=b.replace("[.]",".")),n=a.toString().split(".")[0],p=b.split(".")[1],t=b.indexOf(","),p){if(-1!==p.indexOf("*")?O=d(a,a.toString().split(".")[1].length,c):p.indexOf("[")>-1?(p=p.replace("]",""),p=p.split("["),O=d(a,p[0].length+p[1].length,c,p[1].length)):O=d(a,p.length,c),n=O.split(".")[0],O.split(".")[1].length){var V=e?D+e:s[u].delimiters.decimal;O=V+O.split(".")[1]}else O="";C&&0===Number(O.slice(1))&&(O="")}else n=d(a,0,c); | ||
c.indexOf(" o")>-1?(M=" ",c=c.replace(" o","")):c=c.replace("o",""),x[z].ordinal&&(M+=x[z].ordinal(a))),c.indexOf("[.]")>-1&&(E=!0,c=c.replace("[.]",".")),n=a.toString().split(".")[0],p=c.split(".")[1],s=c.indexOf(","),p){if(-1!==p.indexOf("*")?O=d(a,a.toString().split(".")[1].length,e):p.indexOf("[")>-1?(p=p.replace("]",""),p=p.split("["),O=d(a,p[0].length+p[1].length,e,p[1].length)):O=d(a,p.length,e),n=O.split(".")[0],O.split(".")[1].length){var V=f?F+f:x[z].delimiters.decimal;O=V+O.split(".")[1]}else O="";E&&0===Number(O.slice(1))&&(O="")}else n=d(a,0,e); | ||
// format number | ||
return n.indexOf("-")>-1&&(n=n.slice(1),Q=!0),n.length<z&&(n=new Array(z-n.length+1).join("0")+n),t>-1&&(n=n.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+s[u].delimiters.thousands)),0===b.indexOf(".")&&(n=""),w=b.indexOf("("),y=b.indexOf("-"),R=y>w?(A&&Q?"(":"")+(P&&Q||!A&&Q?"-":""):(P&&Q||!A&&Q?"-":"")+(A&&Q?"(":""),q+R+(!Q&&B&&0!==a?"+":"")+n+O+(K?K:"")+(D&&!e?D:"")+(J?J:"")+(A&&Q?")":"")+r}/************************************ | ||
return n.indexOf("-")>-1&&(n=n.slice(1),Q=!0),n.length<y&&(n=b(y-n.length)+n),s>-1&&(n=n.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+x[z].delimiters.thousands)),0===c.indexOf(".")&&(n=""),t=c.indexOf("("),v=c.indexOf("-"),R=v>t?(C&&Q?"(":"")+(P&&Q||!C&&Q?"-":""):(P&&Q||!C&&Q?"-":"")+(C&&Q?"(":""),q+R+(!Q&&D&&0!==a?"+":"")+n+O+(M?M:"")+(F&&!f?F:"")+(L?L:"")+(C&&Q?")":"")+r}/************************************ | ||
Helpers | ||
************************************/ | ||
function l(a,b){s[a]=b}function m(a){u=a;var b=s[a].defaults;b&&b.format&&q.defaultFormat(b.format),b&&b.currencyFormat&&q.defaultCurrencyFormat(b.currencyFormat)}function n(){return"undefined"!=typeof process&&void 0===process.browser&&("node"===process.title||"grunt"===process.title||"gulp"===process.title)&&"undefined"!=typeof require}/** | ||
function m(a,b){x[a]=b}function n(a){z=a;var b=x[a].defaults;b&&b.format&&r.defaultFormat(b.format),b&&b.currencyFormat&&r.defaultCurrencyFormat(b.currencyFormat)}function o(){return"undefined"!=typeof process&&void 0===process.browser&&(0===process.title.indexOf("node")||"grunt"===process.title||"gulp"===process.title)&&"undefined"!=typeof require}/** | ||
* Computes the multiplier necessary to make x >= 1, | ||
@@ -100,3 +101,3 @@ * effectively eliminating miscalculations caused by | ||
*/ | ||
function o(a){var b=a.toString().split(".");return b.length<2?1:Math.pow(10,b[1].length)}/** | ||
function p(a){var b=a.toString().split(".");return b.length<2?1:Math.pow(10,b[1].length)}/** | ||
* Given a variable number of arguments, returns the maximum | ||
@@ -106,13 +107,15 @@ * multiplier that must be used to normalize an operation involving | ||
*/ | ||
function p(){var a=Array.prototype.slice.call(arguments);return a.reduce(function(a,b){var c=o(a),d=o(b);return c>d?c:d},-(1/0))}/************************************ | ||
function q(){var a=Array.prototype.slice.call(arguments);return a.reduce(function(a,b){var c=p(a),d=p(b);return c>d?c:d},-(1/0))}/************************************ | ||
Constants | ||
************************************/ | ||
var q,r="1.7.1", | ||
var r,s="1.8.0",t=["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],u=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],v={general:{scale:1024,suffixes:u,marker:"bd"},binary:{scale:1024,suffixes:t,marker:"b"},decimal:{scale:1e3,suffixes:u,marker:"d"}}, | ||
// general must be before the others because it reuses their characters! | ||
w=[v.general,v.binary,v.decimal], | ||
// internal storage for culture config files | ||
s={}, | ||
x={}, | ||
// Todo: Remove in 2.0.0 | ||
t=s,u="en-US",v=null,w="0,0",x="0$", | ||
y=x,z="en-US",A=null,B="0,0",C="0$", | ||
// check for nodeJS | ||
y="undefined"!=typeof module&&module.exports, | ||
D="undefined"!=typeof module&&module.exports, | ||
// default culture | ||
z={delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===~~(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th"},currency:{symbol:"$",position:"prefix"},defaults:{currencyFormat:",0000 a"},formats:{fourDigits:"0000 a",fullWithTwoDecimals:"$ ,0.00",fullWithTwoDecimalsNoCurrency:",0.00"}};q=function(b){return q.isNumbro(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=q.fn.unformat(b)),new a(Number(b))},q.version=r,q.isNumbro=function(b){return b instanceof a},q.setLanguage=function(a,b){console.warn("`setLanguage` is deprecated since version 1.6.0. Use `setCulture` instead");var c=a,d=a.split("-")[0],e=null;t[c]||(Object.keys(t).forEach(function(a){e||a.split("-")[0]!==d||(e=a)}),c=e||b||"en-US"),m(c)},q.setCulture=function(a,b){var c=a,d=a.split("-")[1],e=null;s[c]||(d&&Object.keys(s).forEach(function(a){e||a.split("-")[1]!==d||(e=a)}),c=e||b||"en-US"),m(c)},q.language=function(a,b){if(console.warn("`language` is deprecated since version 1.6.0. Use `culture` instead"),!a)return u;if(a&&!b){if(!t[a])throw new Error("Unknown language : "+a);m(a)}return!b&&t[a]||l(a,b),q},q.culture=function(a,b){if(!a)return u;if(a&&!b){if(!s[a])throw new Error("Unknown culture : "+a);m(a)}return!b&&s[a]||l(a,b),q},q.languageData=function(a){if(console.warn("`languageData` is deprecated since version 1.6.0. Use `cultureData` instead"),!a)return t[u];if(!t[a])throw new Error("Unknown language : "+a);return t[a]},q.cultureData=function(a){if(!a)return s[u];if(!s[a])throw new Error("Unknown culture : "+a);return s[a]},q.culture("en-US",z),q.languages=function(){return console.warn("`languages` is deprecated since version 1.6.0. Use `cultures` instead"),t},q.cultures=function(){return s},q.zeroFormat=function(a){v="string"==typeof a?a:null},q.defaultFormat=function(a){w="string"==typeof a?a:"0.0"},q.defaultCurrencyFormat=function(a){x="string"==typeof a?a:"0$"},q.validate=function(a,b){var c,d,e,f,g,h,i,j;if("string"!=typeof a&&(a+="",console.warn&&console.warn("Numbro.js: Value is not string. It has been co-erced to: ",a)),a=a.trim(),a.match(/^\d+$/))return!0;if(""===a)return!1;try{i=q.cultureData(b)}catch(k){i=q.cultureData(q.culture())}return e=i.currency.symbol,g=i.abbreviations,c=i.delimiters.decimal,d="."===i.delimiters.thousands?"\\.":i.delimiters.thousands,j=a.match(/^[^\d]+/),null!==j&&(a=a.substr(1),j[0]!==e)?!1:(j=a.match(/[^\d]+$/),null!==j&&(a=a.slice(0,-1),j[0]!==g.thousand&&j[0]!==g.million&&j[0]!==g.billion&&j[0]!==g.trillion)?!1:(h=new RegExp(d+"{2}"),a.match(/[^\d.,]/g)?!1:(f=a.split(c),f.length>2?!1:f.length<2?!!f[0].match(/^\d+.*\d$/)&&!f[0].match(h):1===f[0].length?!!f[0].match(/^\d+$/)&&!f[0].match(h)&&!!f[1].match(/^\d+$/):!!f[0].match(/^\d+.*\d$/)&&!f[0].match(h)&&!!f[1].match(/^\d+$/))))},q.loadLanguagesInNode=function(){console.warn("`loadLanguagesInNode` is deprecated since version 1.6.0. Use `loadCulturesInNode` instead"),q.loadCulturesInNode()},q.loadCulturesInNode=function(){var a=require("./languages");for(var b in a)b&&q.culture(b,a[b])},"function"!=typeof Array.prototype.reduce&&(Array.prototype.reduce=function(a,b){if(null===this||"undefined"==typeof this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof a)throw new TypeError(a+" is not a function");var c,d,e=this.length>>>0,f=!1;for(1<arguments.length&&(d=b,f=!0),c=0;e>c;++c)this.hasOwnProperty(c)&&(f?d=a(d,this[c],c,this):(d=this[c],f=!0));if(!f)throw new TypeError("Reduce of empty array with no initial value");return d}),q.fn=a.prototype={clone:function(){return q(this)},format:function(a,b){return e(this,a?a:w,void 0!==b?b:Math.round)},formatCurrency:function(a,b){return g(this,a?a:x,void 0!==b?b:Math.round)},unformat:function(a){return"[object Number]"===Object.prototype.toString.call(a)?a:f(this,a?a:w)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){function b(a,b){return a+c*b}var c=p.call(null,this._value,a);return this._value=[this._value,a].reduce(b,0)/c,this},subtract:function(a){function b(a,b){return a-c*b}var c=p.call(null,this._value,a);return this._value=[a].reduce(b,this._value*c)/c,this},multiply:function(a){function b(a,b){var c=p(a,b),d=a*c;return d*=b*c,d/=c*c}return this._value=[this._value,a].reduce(b,1),this},divide:function(a){function b(a,b){var c=p(a,b);return a*c/(b*c)}return this._value=[this._value,a].reduce(b),this},difference:function(a){return Math.abs(q(this._value).subtract(a).value())}},n()&&q.loadCulturesInNode(),y?module.exports=q:("undefined"==typeof ender&&(this.numbro=q),"function"==typeof define&&define.amd&&define([],function(){return q}))}).call("undefined"==typeof window?this:window); | ||
E={delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===~~(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th"},currency:{symbol:"$",position:"prefix"},defaults:{currencyFormat:",0000 a"},formats:{fourDigits:"0000 a",fullWithTwoDecimals:"$ ,0.00",fullWithTwoDecimalsNoCurrency:",0.00"}};r=function(b){return r.isNumbro(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=r.fn.unformat(b)),new a(Number(b))},r.version=s,r.isNumbro=function(b){return b instanceof a},r.setLanguage=function(a,b){console.warn("`setLanguage` is deprecated since version 1.6.0. Use `setCulture` instead");var c=a,d=a.split("-")[0],e=null;y[c]||(Object.keys(y).forEach(function(a){e||a.split("-")[0]!==d||(e=a)}),c=e||b||"en-US"),n(c)},r.setCulture=function(a,b){var c=a,d=a.split("-")[1],e=null;x[c]||(d&&Object.keys(x).forEach(function(a){e||a.split("-")[1]!==d||(e=a)}),c=e||b||"en-US"),n(c)},r.language=function(a,b){if(console.warn("`language` is deprecated since version 1.6.0. Use `culture` instead"),!a)return z;if(a&&!b){if(!y[a])throw new Error("Unknown language : "+a);n(a)}return!b&&y[a]||m(a,b),r},r.culture=function(a,b){if(!a)return z;if(a&&!b){if(!x[a])throw new Error("Unknown culture : "+a);n(a)}return!b&&x[a]||m(a,b),r},r.languageData=function(a){if(console.warn("`languageData` is deprecated since version 1.6.0. Use `cultureData` instead"),!a)return y[z];if(!y[a])throw new Error("Unknown language : "+a);return y[a]},r.cultureData=function(a){if(!a)return x[z];if(!x[a])throw new Error("Unknown culture : "+a);return x[a]},r.culture("en-US",E),r.languages=function(){return console.warn("`languages` is deprecated since version 1.6.0. Use `cultures` instead"),y},r.cultures=function(){return x},r.zeroFormat=function(a){A="string"==typeof a?a:null},r.defaultFormat=function(a){B="string"==typeof a?a:"0.0"},r.defaultCurrencyFormat=function(a){C="string"==typeof a?a:"0$"},r.validate=function(a,b){var c,d,e,f,g,h,i,j;if("string"!=typeof a&&(a+="",console.warn&&console.warn("Numbro.js: Value is not string. It has been co-erced to: ",a)),a=a.trim(),a.match(/^\d+$/))return!0;if(""===a)return!1;try{i=r.cultureData(b)}catch(k){i=r.cultureData(r.culture())}return e=i.currency.symbol,g=i.abbreviations,c=i.delimiters.decimal,d="."===i.delimiters.thousands?"\\.":i.delimiters.thousands,j=a.match(/^[^\d]+/),null!==j&&(a=a.substr(1),j[0]!==e)?!1:(j=a.match(/[^\d]+$/),null!==j&&(a=a.slice(0,-1),j[0]!==g.thousand&&j[0]!==g.million&&j[0]!==g.billion&&j[0]!==g.trillion)?!1:(h=new RegExp(d+"{2}"),a.match(/[^\d.,]/g)?!1:(f=a.split(c),f.length>2?!1:f.length<2?!!f[0].match(/^\d+.*\d$/)&&!f[0].match(h):1===f[0].length?!!f[0].match(/^\d+$/)&&!f[0].match(h)&&!!f[1].match(/^\d+$/):!!f[0].match(/^\d+.*\d$/)&&!f[0].match(h)&&!!f[1].match(/^\d+$/))))},r.loadLanguagesInNode=function(){console.warn("`loadLanguagesInNode` is deprecated since version 1.6.0. Use `loadCulturesInNode` instead"),r.loadCulturesInNode()},r.loadCulturesInNode=function(){var a=require("./languages");for(var b in a)b&&r.culture(b,a[b])},"function"!=typeof Array.prototype.reduce&&(Array.prototype.reduce=function(a,b){if(null===this||"undefined"==typeof this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof a)throw new TypeError(a+" is not a function");var c,d,e=this.length>>>0,f=!1;for(1<arguments.length&&(d=b,f=!0),c=0;e>c;++c)this.hasOwnProperty(c)&&(f?d=a(d,this[c],c,this):(d=this[c],f=!0));if(!f)throw new TypeError("Reduce of empty array with no initial value");return d}),r.fn=a.prototype={clone:function(){return r(this)},format:function(a,b){return e(this,a?a:B,void 0!==b?b:Math.round)},formatCurrency:function(a,b){return g(this,a?a:C,void 0!==b?b:Math.round)},unformat:function(a){if("number"==typeof a)return a;if("string"==typeof a){var b=f(this,a);return isNaN(b)?void 0:b}},binaryByteUnits:function(){return k(this._value,v.binary.suffixes,v.binary.scale).suffix},byteUnits:function(){return k(this._value,v.general.suffixes,v.general.scale).suffix},decimalByteUnits:function(){return k(this._value,v.decimal.suffixes,v.decimal.scale).suffix},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){function b(a,b){return a+c*b}var c=q.call(null,this._value,a);return this._value=[this._value,a].reduce(b,0)/c,this},subtract:function(a){function b(a,b){return a-c*b}var c=q.call(null,this._value,a);return this._value=[a].reduce(b,this._value*c)/c,this},multiply:function(a){function b(a,b){var c=q(a,b),d=a*c;return d*=b*c,d/=c*c}return this._value=[this._value,a].reduce(b,1),this},divide:function(a){function b(a,b){var c=q(a,b);return a*c/(b*c)}return this._value=[this._value,a].reduce(b),this},difference:function(a){return Math.abs(r(this._value).subtract(a).value())}},o()&&r.loadCulturesInNode(),D?module.exports=r:("undefined"==typeof ender&&(this.numbro=r),"function"==typeof define&&define.amd&&define([],function(){return r}))}).call("undefined"==typeof window?this:window); |
@@ -28,3 +28,4 @@ /*! | ||
symbol: '$', | ||
position: 'prefix' | ||
position: 'postfix', | ||
spaceSeparated : true | ||
}, | ||
@@ -31,0 +32,0 @@ defaults: { |
@@ -28,3 +28,3 @@ /*! | ||
symbol: 'R$', | ||
position: 'postfix' | ||
position: 'prefix' | ||
}, | ||
@@ -31,0 +31,0 @@ defaults: { |
180
numbro.js
/*! | ||
* numbro.js | ||
* version : 1.7.1 | ||
* version : 1.8.0 | ||
* author : Företagsplatsen AB | ||
@@ -17,3 +17,12 @@ * license : MIT | ||
var numbro, | ||
VERSION = '1.7.1', | ||
VERSION = '1.8.0', | ||
binarySuffixes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'], | ||
decimalSuffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | ||
bytes = { | ||
general: { scale: 1024, suffixes: decimalSuffixes, marker: 'bd' }, | ||
binary: { scale: 1024, suffixes: binarySuffixes, marker: 'b' }, | ||
decimal: { scale: 1000, suffixes: decimalSuffixes, marker: 'd' } | ||
}, | ||
// general must be before the others because it reuses their characters! | ||
byteFormatOrder = [ bytes.general, bytes.binary, bytes.decimal ], | ||
// internal storage for culture config files | ||
@@ -199,4 +208,2 @@ cultures = {}, | ||
trillionRegExp, | ||
binarySuffixes = ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'], | ||
decimalSuffixes = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | ||
bytesMultiplier = false, | ||
@@ -226,23 +233,30 @@ power; | ||
// see if bytes are there so that we can multiply to the correct number | ||
for (power = 0; power <= binarySuffixes.length && !bytesMultiplier; power++) { | ||
for (power = 1; power < binarySuffixes.length && !bytesMultiplier; ++power) { | ||
if (string.indexOf(binarySuffixes[power]) > -1) { | ||
bytesMultiplier = Math.pow(1024, power + 1); | ||
bytesMultiplier = Math.pow(1024, power); | ||
} else if (string.indexOf(decimalSuffixes[power]) > -1) { | ||
bytesMultiplier = Math.pow(1000, power + 1); | ||
bytesMultiplier = Math.pow(1000, power); | ||
} | ||
} | ||
// do some math to create our number | ||
n._value = ((bytesMultiplier) ? bytesMultiplier : 1) * | ||
((stringOriginal.match(thousandRegExp)) ? Math.pow(10, 3) : 1) * | ||
((stringOriginal.match(millionRegExp)) ? Math.pow(10, 6) : 1) * | ||
((stringOriginal.match(billionRegExp)) ? Math.pow(10, 9) : 1) * | ||
((stringOriginal.match(trillionRegExp)) ? Math.pow(10, 12) : 1) * | ||
((string.indexOf('%') > -1) ? 0.01 : 1) * | ||
(((string.split('-').length + | ||
Math.min(string.split('(').length - 1, string.split(')').length - 1)) % 2) ? 1 : -1) * | ||
Number(string.replace(/[^0-9\.]+/g, '')); | ||
var str = string.replace(/[^0-9\.]+/g, ''); | ||
if (str === '') { | ||
// An empty string is not a number. | ||
n._value = NaN; | ||
// round if we are talking about bytes | ||
n._value = (bytesMultiplier) ? Math.ceil(n._value) : n._value; | ||
} else { | ||
// do some math to create our number | ||
n._value = ((bytesMultiplier) ? bytesMultiplier : 1) * | ||
((stringOriginal.match(thousandRegExp)) ? Math.pow(10, 3) : 1) * | ||
((stringOriginal.match(millionRegExp)) ? Math.pow(10, 6) : 1) * | ||
((stringOriginal.match(billionRegExp)) ? Math.pow(10, 9) : 1) * | ||
((stringOriginal.match(trillionRegExp)) ? Math.pow(10, 12) : 1) * | ||
((string.indexOf('%') > -1) ? 0.01 : 1) * | ||
(((string.split('-').length + | ||
Math.min(string.split('(').length - 1, string.split(')').length - 1)) % 2) ? 1 : -1) * | ||
Number(str); | ||
// round if we are talking about bytes | ||
n._value = (bytesMultiplier) ? Math.ceil(n._value) : n._value; | ||
} | ||
} | ||
@@ -402,2 +416,31 @@ } | ||
function formatByteUnits (value, suffixes, scale) { | ||
var suffix = suffixes[0], | ||
power, | ||
min, | ||
max, | ||
abs = Math.abs(value); | ||
if (abs >= scale) { | ||
for (power = 1; power < suffixes.length; ++power) { | ||
min = Math.pow(scale, power); | ||
max = Math.pow(scale, power + 1); | ||
if (abs >= min && abs < max) { | ||
suffix = suffixes[power]; | ||
value = value / min; | ||
break; | ||
} | ||
} | ||
// values greater than or equal to [scale] YB never set the suffix | ||
if (suffix === suffixes[0]) { | ||
value = value / Math.pow(scale, suffixes.length - 1); | ||
suffix = suffixes[suffixes.length - 1]; | ||
} | ||
} | ||
return { value: value, suffix: suffix }; | ||
} | ||
function formatNumber (value, format, roundingFunction, sep) { | ||
@@ -408,3 +451,2 @@ var negP = false, | ||
abbr = '', | ||
i, | ||
abbrK = false, // force abbreviation to thousands | ||
@@ -416,9 +458,6 @@ abbrM = false, // force abbreviation to millions | ||
bytes = '', | ||
byteFormat, | ||
units, | ||
ord = '', | ||
abs = Math.abs(value), | ||
binarySuffixes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'], | ||
decimalSuffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | ||
min, | ||
max, | ||
power, | ||
totalLength, | ||
@@ -441,3 +480,4 @@ length, | ||
paren = '', | ||
minlen; | ||
minlen, | ||
i; | ||
@@ -536,5 +576,3 @@ // check if number is zero and a custom zero format has been set | ||
for (i = 0; i < size; i++) { | ||
format += '0'; | ||
} | ||
format += zeroes(size); | ||
} | ||
@@ -564,47 +602,22 @@ } | ||
// see if we are formatting binary bytes | ||
if (format.indexOf('b') > -1) { | ||
// check for space before | ||
if (format.indexOf(' b') > -1) { | ||
bytes = ' '; | ||
format = format.replace(' b', ''); | ||
} else { | ||
format = format.replace('b', ''); | ||
} | ||
// see if we are formatting | ||
// binary-decimal bytes (1024 MB), binary bytes (1024 MiB), or decimal bytes (1000 MB) | ||
for (i = 0; i < byteFormatOrder.length; ++i) { | ||
byteFormat = byteFormatOrder[i]; | ||
for (power = 0; power <= binarySuffixes.length; power++) { | ||
min = Math.pow(1024, power); | ||
max = Math.pow(1024, power + 1); | ||
if (value >= min && value < max) { | ||
bytes = bytes + binarySuffixes[power]; | ||
if (min > 0) { | ||
value = value / min; | ||
} | ||
break; | ||
if (format.indexOf(byteFormat.marker) > -1) { | ||
// check for space before | ||
if (format.indexOf(' ' + byteFormat.marker) >-1) { | ||
bytes = ' '; | ||
} | ||
} | ||
} | ||
// see if we are formatting decimal bytes | ||
if (format.indexOf('d') > -1) { | ||
// check for space before | ||
if (format.indexOf(' d') > -1) { | ||
bytes = ' '; | ||
format = format.replace(' d', ''); | ||
} else { | ||
format = format.replace('d', ''); | ||
} | ||
// remove the marker (with the space if it had one) | ||
format = format.replace(bytes + byteFormat.marker, ''); | ||
for (power = 0; power <= decimalSuffixes.length; power++) { | ||
min = Math.pow(1000, power); | ||
max = Math.pow(1000, power + 1); | ||
units = formatByteUnits(value, byteFormat.suffixes, byteFormat.scale); | ||
if (value >= min && value < max) { | ||
bytes = bytes + decimalSuffixes[power]; | ||
if (min > 0) { | ||
value = value / min; | ||
} | ||
break; | ||
} | ||
value = units.value; | ||
bytes = bytes + units.suffix; | ||
break; | ||
} | ||
@@ -674,3 +687,3 @@ } | ||
if (w.length < minlen) { | ||
w = new Array(minlen - w.length + 1).join('0') + w; | ||
w = zeroes(minlen - w.length) + w; | ||
} | ||
@@ -757,3 +770,3 @@ | ||
* the culture does not exist. If no fallback culture is provided, | ||
* it fallbacks to "en-US". | ||
* it falls back to "en-US". | ||
*/ | ||
@@ -1036,3 +1049,3 @@ numbro.setCulture = function(newCulture, fallbackCulture) { | ||
(process.browser === undefined) && | ||
(process.title === 'node' || process.title === 'grunt' || process.title === 'gulp') && | ||
(process.title.indexOf('node') === 0 || process.title === 'grunt' || process.title === 'gulp') && | ||
(typeof require !== 'undefined'); | ||
@@ -1149,8 +1162,27 @@ } | ||
unformat: function(inputString) { | ||
if (Object.prototype.toString.call(inputString) === '[object Number]') { | ||
if (typeof inputString === 'number') { | ||
return inputString; | ||
} else if (typeof inputString === 'string') { | ||
var result = unformatNumbro(this, inputString); | ||
// Any unparseable string (represented as NaN in the result) is | ||
// converted into undefined. | ||
return isNaN(result) ? undefined : result; | ||
} else { | ||
return undefined; | ||
} | ||
return unformatNumbro(this, inputString ? inputString : defaultFormat); | ||
}, | ||
binaryByteUnits: function() { | ||
return formatByteUnits(this._value, bytes.binary.suffixes, bytes.binary.scale).suffix; | ||
}, | ||
byteUnits: function() { | ||
return formatByteUnits(this._value, bytes.general.suffixes, bytes.general.scale).suffix; | ||
}, | ||
decimalByteUnits: function() { | ||
return formatByteUnits(this._value, bytes.decimal.suffixes, bytes.decimal.scale).suffix; | ||
}, | ||
value: function() { | ||
@@ -1157,0 +1189,0 @@ return this._value; |
{ | ||
"name": "numbro", | ||
"version": "1.7.1", | ||
"version": "1.8.0", | ||
"description": "Format and manipulate numbers.", | ||
@@ -21,2 +21,3 @@ "homepage": "http://numbrojs.com", | ||
"main": "./numbro.js", | ||
"typings": "./numbro.d.ts", | ||
"engines": { | ||
@@ -38,13 +39,13 @@ "node": "*" | ||
"devDependencies": { | ||
"grunt": "0.4.5", | ||
"grunt-bump": "latest", | ||
"grunt-confirm": "latest", | ||
"grunt-contrib-concat": "latest", | ||
"grunt-contrib-copy": "latest", | ||
"grunt-contrib-jshint": "latest", | ||
"grunt-contrib-nodeunit": "latest", | ||
"grunt-contrib-uglify": "latest", | ||
"grunt-jscs": "^1.8.0", | ||
"grunt-release": "latest", | ||
"uglify-js": "latest" | ||
"grunt": "^1.0.1", | ||
"grunt-bump": "^0.8.0", | ||
"grunt-confirm": "^1.0.5", | ||
"grunt-contrib-concat": "^1.0.1", | ||
"grunt-contrib-copy": "^1.0.0", | ||
"grunt-contrib-jshint": "^1.0.0", | ||
"grunt-contrib-nodeunit": "^1.0.0", | ||
"grunt-contrib-uglify": "^1.0.1", | ||
"grunt-jscs": "^2.8.0", | ||
"grunt-release": "^0.13.1", | ||
"uglify-js": "^2.6.2" | ||
}, | ||
@@ -60,2 +61,3 @@ "scripts": { | ||
"numbro.js", | ||
"numbro.d.ts", | ||
"languages", | ||
@@ -62,0 +64,0 @@ "dist" |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
274457
86
6616
0