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) {
    return s[0].toUpperCase() + s.slice(1).toLowerCase();
}

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

export default keyValueList;