pineafan | 1dc1572 | 2022-03-14 21:27:34 +0000 | [diff] [blame] | 1 | const forceCaps = [ |
2 | "ID", | ||||
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 3 | "NSFW", |
4 | "URL" | ||||
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 5 | ]; |
pineafan | 1dc1572 | 2022-03-14 21:27:34 +0000 | [diff] [blame] | 6 | |
7 | export function capitalize(s: string) { | ||||
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 8 | s = s.replace(/([A-Z])/g, " $1"); |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 9 | s = s.split(" ").map(word => { |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 10 | return forceCaps.includes(word.toUpperCase()) ? word.toUpperCase() : (word[0] ?? "") |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 11 | .toUpperCase() + word.slice(1) |
12 | .toLowerCase() | ||||
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 13 | .replace("discord", "Discord"); |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 14 | }).join(" "); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 15 | return s; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 16 | } |
17 | |||||
18 | export function toCapitals(s: string) { | ||||
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 19 | if (s[0] === undefined) return ""; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 20 | return s[0].toUpperCase() + s.slice(1).toLowerCase(); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 21 | } |
22 | |||||
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 23 | function keyValueList(data: Record<string, string>) { |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 24 | let out = ""; |
25 | Object.entries(data).map(([key, value]) => { | ||||
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 26 | out += `**${capitalize(key)}:** ${value}\n`; |
27 | }); | ||||
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 28 | return out; |
29 | } | ||||
30 | |||||
31 | export default keyValueList; |