diff --git a/source/Ox/js/Format.js b/source/Ox/js/Format.js index 440acc4a..81b29351 100644 --- a/source/Ox/js/Format.js +++ b/source/Ox/js/Format.js @@ -16,6 +16,20 @@ Ox.formatArea = function(number, decimals) { ) + ' ' + k + 'm\u00B2'; }; +/*@ +Ox.formatCount 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 Formats a number with a currency symbol > Ox.formatCurrency(1000, '$', 2)