summaryrefslogtreecommitdiff
path: root/source/libs/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'source/libs/utils.ts')
-rw-r--r--source/libs/utils.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/source/libs/utils.ts b/source/libs/utils.ts
index 73b5fb09..8f0729e0 100644
--- a/source/libs/utils.ts
+++ b/source/libs/utils.ts
@@ -27,6 +27,18 @@ export const getDiscussionNumber = (): string | undefined => {
return undefined;
};
+export const pluralize = (count: number, single: string, plural: string, zero?: string): string => {
+ if (count === 0 && zero) {
+ return zero.replace('$$', '0');
+ }
+
+ if (count === 1) {
+ return single.replace('$$', '1');
+ }
+
+ return plural.replace('$$', String(count));
+};
+
// Drops leading and trailing slash to avoid /\/?/ everywhere
export const getCleanPathname = (): string => location.pathname.replace(/^[/]|[/]$/g, '');