summaryrefslogtreecommitdiff
path: root/source/helpers/pluralize.ts
blob: c56b62526e063b662b92689b44be376405b7dcc7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function regular(single: string): string {
	return single + 's';
}

export default function pluralize(
	count: number,
	single: string,
	plural = regular(single),
	zero?: string,
): string {
	if (count === 0 && zero) {
		return zero.replace('$$', '0');
	}

	if (count === 1) {
		return single.replace('$$', '1');
	}

	return plural.replace('$$', String(count));
}