// "crumb" / "crumbs" — the noun alone, for when the count renders separately
export const pluralNoun = (
  count: number,
  singular: string,
  plural = `${singular}s`,
): string => (count === 1 ? singular : plural)

// "1 crumb" / "3 crumbs"
export const pluralize = (
  count: number,
  singular: string,
  plural?: string,
): string => `${count} ${pluralNoun(count, singular, plural)}`

// cut text to at most max chars, ending in an ellipsis when cut
export const truncate = (text: string, max: number): string =>
  text.length <= max ? text : `${text.slice(0, max - 1).trimEnd()}…`

// the part of an email before the @
export const emailLocalPart = (email: string): string =>
  email.split('@')[0] ?? email
