Files
yaak-mountain-loop/src-web/lib/pluralize.ts
2024-03-19 13:43:33 -07:00

21 lines
431 B
TypeScript

export function pluralize(word: string, count: number): string {
if (count === 1) {
return word;
}
return `${word}s`;
}
export function count(
word: string,
count: number,
opt: { omitSingle?: boolean; noneWord?: string } = {},
): string {
if (opt.omitSingle && count === 1) {
return word;
}
if (opt.noneWord && count === 0) {
return opt.noneWord;
}
return `${count} ${pluralize(word, count)}`;
}