blob: a158391317ae6e6b69d9879e12941f73320e0be5 [file] [log] [blame]
Skyler Grey75ea9172022-08-06 10:22:23 +01001const forceCaps = ["ID", "NSFW", "URL"];
pineafan1dc15722022-03-14 21:27:34 +00002
3export function capitalize(s: string) {
pineafan63fc5e22022-08-04 22:04:10 +01004 s = s.replace(/([A-Z])/g, " $1");
Skyler Grey75ea9172022-08-06 10:22:23 +01005 s = s
6 .split(" ")
7 .map((word) => {
8 return forceCaps.includes(word.toUpperCase())
9 ? word.toUpperCase()
10 : (word[0] ?? "").toUpperCase() +
11 word.slice(1).toLowerCase().replace("discord", "Discord");
12 })
13 .join(" ");
pineafan63fc5e22022-08-04 22:04:10 +010014 return s;
pineafan377794f2022-04-18 19:01:01 +010015}
16
17export function toCapitals(s: string) {
Skyler Grey75ea9172022-08-06 10:22:23 +010018 if (s.startsWith(undefined)) return "";
pineafan377794f2022-04-18 19:01:01 +010019 return s[0].toUpperCase() + s.slice(1).toLowerCase();
pineafan4f164f32022-02-26 22:07:12 +000020}
21
pineafanbd02b4a2022-08-05 22:01:38 +010022function keyValueList(data: Record<string, string>) {
pineafan4f164f32022-02-26 22:07:12 +000023 let out = "";
24 Object.entries(data).map(([key, value]) => {
pineafan63fc5e22022-08-04 22:04:10 +010025 out += `**${capitalize(key)}:** ${value}\n`;
26 });
pineafan4f164f32022-02-26 22:07:12 +000027 return out;
28}
29
Skyler Grey75ea9172022-08-06 10:22:23 +010030export default keyValueList;