const forceCaps = ["ID", "NSFW", "URL"];

export function capitalize(s: string) {
    s = s.replace(/([A-Z])/g, " $1");
    s = s
        .split(" ")
        .map((word) => {
            return forceCaps.includes(word.toUpperCase())
                ? word.toUpperCase()
                : (word[0] ?? "").toUpperCase() +
                      word.slice(1).toLowerCase().replace("discord", "Discord");
        })
        .join(" ");
    return s;
}

export function toCapitals(s: string) {
    if (s.startsWith(undefined)) return "";
    return s[0].toUpperCase() + s.slice(1).toLowerCase();
}

function keyValueList(data: Record<string, string>) {
    let out = "";
    Object.entries(data).map(([key, value]) => {
        out += `**${capitalize(key)}:** ${value}\n`;
    });
    return out;
}

export default keyValueList;
