Skip to content

Instantly share code, notes, and snippets.

@lkptrzk
Created January 9, 2014 03:42
Show Gist options
  • Select an option

  • Save lkptrzk/8329044 to your computer and use it in GitHub Desktop.

Select an option

Save lkptrzk/8329044 to your computer and use it in GitHub Desktop.
pluralize.js
// arguments are `value`, `singular`, `plural`
// if `plural` is left out, it's just `singular` with an 's' appended
/*
pluralize(0, 'hour') // '0 hours'
pluralize(1, 'hour') // '1 hour'
pluralize(0, 'mouse', 'mice') // '0 mice'
pluralize(1, 'mouse', 'mice') // '1 mouse'
*/
;(function () {
if (!(typeof window.pluralize === 'undefined'))
throw new Error('window.pluralize already exists')
window.pluralize = function (value, singular, plural) {
if (plural == null) plural = singular + 's'
if (value === 1) {
return value + ' ' + singular
} else {
return value + ' ' + plural
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment