From 58310afba4e89db6966fbf8f32cd4a44a52a6ca6 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Thu, 11 Jul 2024 02:23:51 +0100 Subject: Add new vote component and voting redux store --- src/utils.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/utils.ts (limited to 'src/utils.ts') diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..8067045 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,24 @@ +export function slugify(str: string) { + str = str.replace(/^\s+|\s+$/g, ""); + str = str.toLowerCase(); + str = str + .replace(/[^a-z0-9 -]/g, "") + .replace(/\s+/g, "-") + .replace(/-+/g, "-"); + return str; +} + +export function humanize(num: number) { + if (num % 100 >= 11 && num % 100 <= 13) return num + "th"; + + switch (num % 10) { + case 1: + return num + "st"; + case 2: + return num + "nd"; + case 3: + return num + "rd"; + } + + return num + "th"; +} -- cgit v1.2.3