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