aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.ts
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2024-07-11 04:14:48 +0100
committerGravatar GitHub <[email protected]>2024-07-11 04:14:48 +0100
commit1d1afff8c0e7a5ee6f39a0d3888d8acd6d459cf7 (patch)
tree7267f41035be6d62c92729577aec98183e25cf39 /src/utils.ts
parentMerge pull request #637 from python-discord/dependabot/npm_and_yarn/sentry/re... (diff)
parentRe-map slugged vote options to human form when upstreaming to form (diff)
Merge pull request #638 from python-discord/jb3/components/vote-field
Vote component
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";
+}