aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.ts
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2024-07-11 02:23:51 +0100
committerGravatar Joe Banks <[email protected]>2024-07-11 02:23:51 +0100
commit58310afba4e89db6966fbf8f32cd4a44a52a6ca6 (patch)
treedd9d5e3d1e75629871e57e7ce97381eca1bffd58 /src/utils.ts
parentAdd new package for animated list reorders (diff)
Add new vote component and voting redux store
Diffstat (limited to 'src/utils.ts')
-rw-r--r--src/utils.ts24
1 files changed, 24 insertions, 0 deletions
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";
+}