blob: a093ab7f3ee2d1758266d09e095049434fd9a34f [file] [log] [blame]
pineafan1dc15722022-03-14 21:27:34 +00001const forceCaps = [
2 "ID",
pineafan73a7c4a2022-07-24 10:38:04 +01003 "NSFW",
4 "URL"
pineafan63fc5e22022-08-04 22:04:10 +01005];
pineafan1dc15722022-03-14 21:27:34 +00006
7export function capitalize(s: string) {
pineafan63fc5e22022-08-04 22:04:10 +01008 s = s.replace(/([A-Z])/g, " $1");
pineafan73a7c4a2022-07-24 10:38:04 +01009 s = s.split(" ").map(word => {
pineafanbd02b4a2022-08-05 22:01:38 +010010 return forceCaps.includes(word.toUpperCase()) ? word.toUpperCase() : (word[0] ?? "")
pineafan73a7c4a2022-07-24 10:38:04 +010011 .toUpperCase() + word.slice(1)
12 .toLowerCase()
pineafan63fc5e22022-08-04 22:04:10 +010013 .replace("discord", "Discord");
pineafan73a7c4a2022-07-24 10:38:04 +010014 }).join(" ");
pineafan63fc5e22022-08-04 22:04:10 +010015 return s;
pineafan377794f2022-04-18 19:01:01 +010016}
17
18export function toCapitals(s: string) {
pineafanbd02b4a2022-08-05 22:01:38 +010019 if (s[0] === undefined) return "";
pineafan377794f2022-04-18 19:01:01 +010020 return s[0].toUpperCase() + s.slice(1).toLowerCase();
pineafan4f164f32022-02-26 22:07:12 +000021}
22
pineafanbd02b4a2022-08-05 22:01:38 +010023function keyValueList(data: Record<string, string>) {
pineafan4f164f32022-02-26 22:07:12 +000024 let out = "";
25 Object.entries(data).map(([key, value]) => {
pineafan63fc5e22022-08-04 22:04:10 +010026 out += `**${capitalize(key)}:** ${value}\n`;
27 });
pineafan4f164f32022-02-26 22:07:12 +000028 return out;
29}
30
31export default keyValueList;