Skip to content

refactor(format): add pluralize helper and replace inline plural ternaries#1270

Open
Dexterity104 wants to merge 1 commit into
entrius:testfrom
Dexterity104:refactor/pluralize-helper
Open

refactor(format): add pluralize helper and replace inline plural ternaries#1270
Dexterity104 wants to merge 1 commit into
entrius:testfrom
Dexterity104:refactor/pluralize-helper

Conversation

@Dexterity104
Copy link
Copy Markdown
Contributor

Summary

Adds a pluralize helper to src/utils/format.ts and replaces inline ${n} thing${n !== 1 ? 's' : ''} ternaries at the sites most prone to plural typos. The helper handles regular plurals ('commit''commits') and takes an explicit second form for irregular ones (pluralize(n, 'bounty', 'bounties')).

export const pluralize = (
  count: number,
  singular: string,
  plural?: string,
): string =>
  count === 1 ? `${count} ${singular}` : `${count} ${plural ?? `${singular}s`}`;

No behavior change. Rendered output is byte identical at every call site, including the 0 things and 1 thing edge cases.

Call sites updated:

  • src/components/ContributionHeatmap.tsx
  • src/components/miners/MinerPrScoreDetail.tsx
  • src/pages/dashboard/views/FeaturedWorkRepoCard.tsx
  • src/pages/RepositoriesPage.tsx
  • src/pages/RepositoryDetailsPage.tsx
  • src/pages/search/SearchPage.tsx
  • src/utils/repoConfig.ts

Sites where the count and noun appear in separate positions (split by an adjective or rendered as a fraction) were left alone to avoid restructuring the surrounding markup.

Related Issues

N/A

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Other (describe below)

Screenshots

Not applicable. Pure logic refactor with no visual change.

Checklist

  • New components are modularized/separated where sensible
  • Uses predefined theme (e.g. no hardcoded colors)
  • Responsive/mobile checked
  • Tested against the test API
  • npm run format and npm run lint:fix have been run
  • npm run build passes
  • Screenshots included for any UI/visual changes

@xiao-xiao-mao xiao-xiao-mao Bot added the refactor Code restructuring without behavior change label May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code restructuring without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant