MCPcopy
hub / github.com/CodebuffAI/codebuff / pluralize

Function pluralize

common/src/util/string.ts:183–243  ·  view source on GitHub ↗
(
  count: number,
  word: string,
  { includeCount = true }: { includeCount?: boolean } = {},
)

Source from the content-addressed store, hash-verified

181])
182
183export 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 }

Callers 15

buildToolDescriptionFunction · 0.90
PublishContainerFunction · 0.90
ValidationErrorPopoverFunction · 0.90
AgentChecklistFunction · 0.90
AskUserBranchFunction · 0.90
announceLoadedAgentsFunction · 0.90
getLoadedAgentsMessageFunction · 0.90
useQueueUiFunction · 0.90
calculateDAUFunction · 0.90
exportUserEmailsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected