diff --git a/lib/utils/text-utils.js b/lib/utils/text-utils.js index 573536fc6..ef3c32cc8 100644 --- a/lib/utils/text-utils.js +++ b/lib/utils/text-utils.js @@ -1,47 +1,44 @@ // @flow function pluralize( nouns: $ReadOnlyArray, maxNumberOfNouns: number = 3, ): string { if (nouns.length === 0) { return ''; } else if (nouns.length === 1) { return nouns[0]; } else if (maxNumberOfNouns === 1) { - return `${nouns.length} ${nouns.length > 1 ? 'users' : 'user'}`; + return `${nouns.length} users`; } const comma = maxNumberOfNouns > 2 && nouns.length > 2 ? ',' : ''; if (nouns.length <= maxNumberOfNouns) { const prefix = nouns.slice(0, -1).join(', '); return `${prefix}${comma} and ${nouns[nouns.length - 1]}`; - } else { - const prefix = nouns.slice(0, maxNumberOfNouns - 1).join(', '); - return `${prefix}${comma} and ${ - nouns.length - maxNumberOfNouns + 1 - } others`; } + const prefix = nouns.slice(0, maxNumberOfNouns - 1).join(', '); + return `${prefix}${comma} and ${nouns.length - maxNumberOfNouns + 1} others`; } function trimText(text: string, maxLength: number): string { if (text.length <= maxLength) { return text; } return text.substr(0, maxLength - 3) + '...'; } function pluralizeAndTrim( nouns: $ReadOnlyArray, maxLength: number, ): string { for (let maxNumberOfNouns = 3; maxNumberOfNouns >= 2; --maxNumberOfNouns) { const text = pluralize(nouns, maxNumberOfNouns); if (text.length <= maxLength) { return text; } } return pluralize(nouns, 1); } export { pluralize, trimText, pluralizeAndTrim };