aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.ts
diff options
context:
space:
mode:
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";
+}