add Ox.formatCount

This commit is contained in:
rolux 2012-11-14 15:10:04 +01:00
parent c03efd71fe
commit 48f2c4f9ee

View file

@ -16,6 +16,20 @@ Ox.formatArea = function(number, decimals) {
) + ' ' + k + 'm\u00B2';
};
/*@
Ox.formatCount <f> Returns a string like "2 items", "1 item" or "no items".
> Ox.formatCount(0, 'item')
'no items'
> Ox.formatCount(1, 'item')
'1 item'
> Ox.formatCount(1000, 'country', 'countries')
'1,000 countries'
@*/
Ox.formatCount = function(number, singular, plural) {
return (number === 0 ? 'no' : Ox.formatNumber(number)) + ' '
+ ((number === 1) ? singular : plural || singular + 's');
};
/*@
Ox.formatCurrency <f> Formats a number with a currency symbol
> Ox.formatCurrency(1000, '$', 2)