Created
June 27, 2022 17:50
-
-
Save JacobJaffe/0a15f276f07d01c5023c7cf1d7bdc44f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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