Created
January 9, 2014 03:42
-
-
Save lkptrzk/8329044 to your computer and use it in GitHub Desktop.
pluralize.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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