pissbot-9000/labscore/utils/ansi.js
2022-06-19 14:14:34 +02:00

29 lines
No EOL
596 B
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const ANSI_COLORS = {
"reset": "",
"black": "",
"red": "",
"green": "",
"yellow": "",
"blue": "",
"magenta": "",
"cyan": "",
"white": ""
}
const ALIASES = {
"b": "black",
"r": "red",
"g": "green",
"y": "yellow",
"bl": "blue",
"m": "magenta",
"c": "cyan",
"w": "white",
"rs": "reset"
}
module.exports.format = function(text, color){
if(!ANSI_COLORS[color] && !ALIASES[color]) throw "Invalid ANSI Color"
if(!ANSI_COLORS[color]) color = ALIASES[color]
return `${ANSI_COLORS[color]}${text}${ANSI_COLORS.reset}`
}