blob: b2b33e65e36c808eb11b0ef9475624042b7e7344 [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()
Skyler Grey11236ba2022-08-08 21:13:33 +010010 : (word[0] ?? "").toUpperCase() + word.slice(1).toLowerCase().replace("discord", "Discord");
Skyler Grey75ea9172022-08-06 10:22:23 +010011 })
12 .join(" ");
pineafan63fc5e22022-08-04 22:04:10 +010013 return s;
pineafan377794f2022-04-18 19:01:01 +010014}
15
16export function toCapitals(s: string) {
pineafan3a02ea32022-08-11 21:35:04 +010017 if (s === "") return "";
18 return s[0]!.toUpperCase() + s.slice(1).toLowerCase();
pineafan4f164f32022-02-26 22:07:12 +000019}
20
pineafanbd02b4a2022-08-05 22:01:38 +010021function keyValueList(data: Record<string, string>) {
pineafan4f164f32022-02-26 22:07:12 +000022 let out = "";
23 Object.entries(data).map(([key, value]) => {
pineafan63fc5e22022-08-04 22:04:10 +010024 out += `**${capitalize(key)}:** ${value}\n`;
25 });
pineafan4f164f32022-02-26 22:07:12 +000026 return out;
27}
28
Skyler Grey75ea9172022-08-06 10:22:23 +010029export default keyValueList;