(
count: number,
word: string,
{ includeCount = true }: { includeCount?: boolean } = {},
)
| 181 | ]) |
| 182 | |
| 183 | export const pluralize = ( |
| 184 | count: number, |
| 185 | word: string, |
| 186 | { includeCount = true }: { includeCount?: boolean } = {}, |
| 187 | ) => { |
| 188 | let pluralWord: string |
| 189 | const lowerWord = word.toLowerCase() |
| 190 | |
| 191 | if (count === 1) { |
| 192 | pluralWord = word |
| 193 | } else if (word === word.toUpperCase() && word.length > 1) { |
| 194 | // Acronyms (API, SDK, URL, etc.) - just add 's' |
| 195 | pluralWord = word + 's' |
| 196 | } else if (IRREGULAR_PLURALS[lowerWord]) { |
| 197 | // Check irregular plurals first (truly irregular words) |
| 198 | pluralWord = IRREGULAR_PLURALS[lowerWord] |
| 199 | } else if (UNCHANGING_PLURALS.has(lowerWord)) { |
| 200 | // Specific words that don't change |
| 201 | pluralWord = word |
| 202 | } else if (lowerWord.endsWith('ware')) { |
| 203 | // Rule: -ware words stay unchanged (software, hardware, firmware, malware, etc.) |
| 204 | pluralWord = word |
| 205 | } else if (lowerWord.endsWith('ics')) { |
| 206 | // Rule: -ics words stay unchanged (analytics, graphics, physics, statistics, etc.) |
| 207 | pluralWord = word |
| 208 | } else if (lowerWord.endsWith('sis')) { |
| 209 | // Rule: -sis → -ses (analysis→analyses, basis→bases, crisis→crises, etc.) |
| 210 | pluralWord = word.slice(0, -2) + 'es' |
| 211 | } else if (lowerWord.endsWith('xis')) { |
| 212 | // Rule: -xis → -xes (axis→axes) |
| 213 | pluralWord = word.slice(0, -2) + 'es' |
| 214 | } else if (F_EXCEPTIONS.has(lowerWord)) { |
| 215 | // -f words that just add -s |
| 216 | pluralWord = word + 's' |
| 217 | } else if (word.endsWith('f')) { |
| 218 | // Handle words ending in -f → -ves |
| 219 | pluralWord = word.slice(0, -1) + 'ves' |
| 220 | } else if (word.endsWith('fe')) { |
| 221 | // Handle words ending in -fe → -ves |
| 222 | pluralWord = word.slice(0, -2) + 'ves' |
| 223 | } else if (word.endsWith('y') && !word.match(/[aeiou]y$/)) { |
| 224 | // Handle words ending in 'y' (unless preceded by a vowel) |
| 225 | pluralWord = word.slice(0, -1) + 'ies' |
| 226 | } else if (O_EXCEPTIONS.has(lowerWord)) { |
| 227 | // -o words that just add -s |
| 228 | pluralWord = word + 's' |
| 229 | } else if (word.match(/[cs]h$/) || word.match(/o$/)) { |
| 230 | // Handle words ending in sh, ch, o → add -es |
| 231 | pluralWord = word + 'es' |
| 232 | } else if (word.match(/[^z]z$/)) { |
| 233 | // Single z at end (not zz) → double the z and add -es (quiz → quizzes) |
| 234 | pluralWord = word + 'zes' |
| 235 | } else if (word.match(/[sxz]$/)) { |
| 236 | // Handle words ending in s, x, zz → add -es |
| 237 | pluralWord = word + 'es' |
| 238 | } else { |
| 239 | pluralWord = word + 's' |
| 240 | } |
no outgoing calls
no test coverage detected