1// Second argument is inserted in place of %s
2
3console.log('\x1b[36m%s\x1b[0m', 'I am cyan'); //cyan
4console.log('\x1b[33m%s\x1b[0m', stringToMakeYellow); //yellow
5
6Reset = "\x1b[0m"
7Bright = "\x1b[1m"
8Dim = "\x1b[2m"
9Underscore = "\x1b[4m"
10Blink = "\x1b[5m"
11Reverse = "\x1b[7m"
12Hidden = "\x1b[8m"
13
14FgBlack = "\x1b[30m"
15FgRed = "\x1b[31m"
16FgGreen = "\x1b[32m"
17FgYellow = "\x1b[33m"
18FgBlue = "\x1b[34m"
19FgMagenta = "\x1b[35m"
20FgCyan = "\x1b[36m"
21FgWhite = "\x1b[37m"
22
23BgBlack = "\x1b[40m"
24BgRed = "\x1b[41m"
25BgGreen = "\x1b[42m"
26BgYellow = "\x1b[43m"
27BgBlue = "\x1b[44m"
28BgMagenta = "\x1b[45m"
29BgCyan = "\x1b[46m"
30BgWhite = "\x1b[47m"
1const Colors = {
2 Reset: "\x1b[0m",
3 Bright: "\x1b[1m",
4 Dim: "\x1b[2m",
5 Underscore: "\x1b[4m",
6 Blink: "\x1b[5m",
7 Reverse: "\x1b[7m",
8 Hidden: "\x1b[8m",
9
10 black: "\x1b[30m",
11 red: "\x1b[31m",
12 green: "\x1b[32m",
13 yellow: "\x1b[33m",
14 blue: "\x1b[34m",
15 magenta: "\x1b[35m",
16 cyan: "\x1b[36m",
17 white: "\x1b[37m",
18
19 BgBlack: "\x1b[40m",
20 BgRed: "\x1b[41m",
21 BgGreen: "\x1b[42m",
22 BgYellow: "\x1b[43m",
23 BgBlue: "\x1b[44m",
24 BgMagenta: "\x1b[45m",
25 BgCyan: "\x1b[46m",
26 BgWhite: "\x1b[47m",
27};
28/**
29* Colorize a string of text!
30* @param {String} text The string text to colorize
31* @param {String} options Strings of options (like "white", "red", "BgWhite", "BgRed", "Bold", "Dim", etc.)
32* @returns {String} Colored String
33*/
34function colorize(text = "", ...options) {
35 let opts = "";
36 options = options ?? "white";
37 options.forEach((opt) => {
38 opts += Colors[opt] ?? Colors.white;
39 });
40 return `${opts}${text}${Colors.Reset}`;
41}
1Reset = "\x1b[0m"
2Bright = "\x1b[1m"
3Dim = "\x1b[2m"
4Underscore = "\x1b[4m"
5Blink = "\x1b[5m"
6Reverse = "\x1b[7m"
7Hidden = "\x1b[8m"
8
9FgBlack = "\x1b[30m"
10FgRed = "\x1b[31m"
11FgGreen = "\x1b[32m"
12FgYellow = "\x1b[33m"
13FgBlue = "\x1b[34m"
14FgMagenta = "\x1b[35m"
15FgCyan = "\x1b[36m"
16FgWhite = "\x1b[37m"
17
18BgBlack = "\x1b[40m"
19BgRed = "\x1b[41m"
20BgGreen = "\x1b[42m"
21BgYellow = "\x1b[43m"
22BgBlue = "\x1b[44m"
23BgMagenta = "\x1b[45m"
24BgCyan = "\x1b[46m"
25BgWhite = "\x1b[47m"