-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
182 lines (163 loc) · 3.93 KB
/
index.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// RGB ansi format: \x1b[38;understand;r;g;b;0m[STRING]\x1b[0m
// RGB background ansi format: \x1b[48;2;r;g;b;0m[STRING]\x1b[0m
/**
* Returns a string with red colored text.
* @param {String} str
*/
function red(str) {
// 255, 0, 0
return `\x1b[38;2;255;0;0m${str}\x1b[0m`;
}
/**
* Returns a string with red colored background.
* @param {String} str
*/
function redBg(str) {
// 255, 0, 0
return `\x1b[48;2;255;0;0m${str}\x1b[0m`;
}
/**
* Returns a string with yellow colored text.
* @param {String} str
*/
function yellow(str) {
// 255, 247, 0
return `\x1b[38;2;255;257;0m${str}\x1b[0m`;
}
/**
* Returns a string with yellow colored background.
* @param {String} str
*/
function yellowBg(str) {
// 255, 247, 0
return `\x1b[48;2;255;257;0m${str}\x1b[0m`;
}
/**
* Returns a string with green colored text.
* @param {String} str
*/
function green(str) {
// 0, 255, 0
return `\x1b[38;2;0;255;0m${str}\x1b[0m`;
}
/**
* Returns a string with green colored background.
* @param {String} str
*/
function greenBg(str) {
// 0, 255, 0
return `\x1b[48;2;0;255;0m${str}\x1b[0m`;
}
/**
* Returns a string with blue colored text.
* @param {String} str
*/
function blue(str) {
// 0, 115, 255
return `\x1b[38;2;0;115;255m${str}\x1b[0m`;
}
/**
* Returns a string with blue colored background.
* @param {String} str
*/
function blueBg(str) {
// 0, 115, 255
return `\x1b[48;2;0;115;255m${str}\x1b[0m`;
}
/**
* Returns a string with purple colored text.
* @param {String} str
*/
function purple(str) {
// 132, 0, 255
return `\x1b[38;2;132;0;255m${str}\x1b[0m`;
}
/**
* Returns a string with purple colored background.
* @param {String} str
*/
function purpleBg(str) {
// 132, 0, 255
return `\x1b[48;2;132;0;255m${str}\x1b[0m`;
}
/**
* Returns a string with pink colored text.
* @param {String} str
*/
function pink(str) {
// 255, 0, 217
return `\x1b[38;2;255;0;217m${str}\x1b[0m`;
}
/**
* Returns a string with pink colored background.
* @param {String} str
*/
function pinkBg(str) {
// 255, 0, 217
return `\x1b[48;2;255;0;217m${str}\x1b[0m`;
}
/**
* Returns a string with bold styled text.
* @param {String} str
*/
function bold(str) {
return `\x1b[1m${str}\x1b[0m`;
}
/**
* Returns a string with underline styled text.
* @param {String} str
*/
function underline(str) {
return `\x1b[4m${str}\x1b[0m`;
}
/**
* Returns a string with inverse styled text.
* @param {String} str
*/
function inverse(str) {
return `\x1b[7m${str}\x1b[0m`;
}
/**
* Returns a string with text colored with the specified color.
* @param {String} str
*/
function rgb(r, g, b, str) {
return `\x1b[38;2;${r};${g};${b}m${str}\x1b[0m`;
}
/**
* Returns a string with the background colored with the specified color.
* @param {String} str
*/
function rgbBg(r, g, b, str) {
return `\x1b[48;2;${r};${g};${b}m${str}\x1b[0m`;
}
/*
---testing---
console.log(red('\n\nred'), redBg('red'));
console.log(yellow('yellow'), yellowBg('yellow'));
console.log(green('green'), greenBg('green'));
console.log(blue('blue'), blueBg('blue'));
console.log(purple('purple'), purpleBg('purple'));
console.log(pink('pink'), pinkBg('pink'));
console.log(underline('underline'), inverse('inverse'), bold('bold'));
console.log(rgb(255, 0, 0, 'rgb'), rgbBg(255, 0, 0, 'rgb'), rgb(255, 0, 0, 'rgb'), rgbBg(0, 255, 0, 'rgb'), rgb(0, 0, 255, 'rgb'), rgbBg(0, 0, 255, 'rgb'))
*/
module.exports = {
red: red,
redBg: redBg,
yellow: yellow,
yellowBg: yellowBg,
green: green,
greenBg: greenBg,
blue: blue,
blueBg: blueBg,
purple: purple,
purpleBg: purpleBg,
pink: pink,
pinkBg: pinkBg,
bold: bold,
underline: underline,
inverse: inverse,
rgb: rgb,
rgb: rgbBg,
}