Skip to content

Instantly share code, notes, and snippets.

@JacobJaffe
Created June 27, 2022 17:50
Show Gist options
  • Save JacobJaffe/0a15f276f07d01c5023c7cf1d7bdc44f to your computer and use it in GitHub Desktop.
Save JacobJaffe/0a15f276f07d01c5023c7cf1d7bdc44f to your computer and use it in GitHub Desktop.
type PluralOptions = {
pluralForm?: string;
};
export const formatPlural = (
noun: string,
count: number,
options: PluralOptions = {}
) => {
return `${count} ${pluralize(noun, count, options)}`;
};
export const pluralize = (
noun: string,
count: number,
options: PluralOptions = {}
) => {
if (count === 1) return noun;
return options?.pluralForm ?? `${noun}s`;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment