add Ox.formatCount
This commit is contained in:
parent
c03efd71fe
commit
48f2c4f9ee
1 changed files with 14 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue