aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.ts
blob: 8067045298e15e2344c140215fce2f211887b6ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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";
}