-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorConsole.js
More file actions
44 lines (39 loc) · 817 Bytes
/
ColorConsole.js
File metadata and controls
44 lines (39 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const Text_Color = {
"Black": 30,
"Red": 31,
"Green": 32,
"Yellow": 33,
"Blue": 34,
"Magenta": 35,
"Cyan": 36,
"White": 37,
}
const Bg_Color = {
"Black": 40,
"Red": 41,
"Green": 42,
"Yellow": 43,
"Blue": 44,
"Magenta": 45,
"Cyan": 46,
"White": 47
}
function print(text, color){
const lines = text.split('\n');
color = isValid(color);
lines.forEach(line => console.log(`\x1b[${color}m ${line} \x1b[0m`));
}
function colorText(text, color){
color = isValid(color);
return `\x1b[${color}m${text}\x1b[0m`;
}
function isValid(color){
if(!Number(color) || color < 30 || color > 47 || (color>37 && color <40)) return Text_Color.White;
return color;
}
module.exports = {
Text_Color,
Bg_Color,
print,
colorText
}