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 => { |
| 10 | return forceCaps.includes(word.toUpperCase()) ? word.toUpperCase() : word[0] |
| 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) { |
| 19 | return s[0].toUpperCase() + s.slice(1).toLowerCase(); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | function keyValueList(data) { |
| 23 | let out = ""; |
| 24 | Object.entries(data).map(([key, value]) => { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 25 | out += `**${capitalize(key)}:** ${value}\n`; |
| 26 | }); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 27 | return out; |
| 28 | } |
| 29 | |
| 30 | export default keyValueList; |