-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.ts
280 lines (251 loc) · 12.1 KB
/
utils.ts
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/**
* @description Coloring functions for `console.log` or other outputs. These functions apply ANSI color codes to text, enhancing readability or for aesthetic purposes in the console. Each method in this class takes a string as input and returns the string formatted with the corresponding ANSI color code.
*
* Basic usage:
* ```js
* console.log(coloring.red('Hello World!')); // Displays text in red
* ```
*
* Using template literals to combine multiple colors:
* ```js
* console.log(`${coloring.blue("I'm blue dabedidabedai")}, ${coloring.green("And if I'm green I will die")}...`);
* ```
*
* @class coloring
* This class contains static methods for text and background colors. Each method modifies the color of the input or background for the terminal.
*/
export class coloring {
/**
* @description Makes the input bright.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static bright = (input?: unknown, preventStylePropagation = true) =>
'\x1b[1m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input dim.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static dim = (input?: unknown, preventStylePropagation = true) =>
'\x1b[2m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Underlines the input.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static underscore = (input?: unknown, preventStylePropagation = true) =>
'\x1b[4m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input blink.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static blink = (input?: unknown, preventStylePropagation = true) =>
'\x1b[5m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Reverses the input color and background.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static reverse = (input?: unknown, preventStylePropagation = true) =>
'\x1b[7m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input hidden.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static hidden = (input?: unknown, preventStylePropagation = true) =>
'\x1b[8m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input black.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static black = (input?: unknown, preventStylePropagation = true) =>
'\x1b[30m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input red.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static red = (input?: unknown, preventStylePropagation = true) =>
'\x1b[31m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input green.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static green = (input?: unknown, preventStylePropagation = true) =>
'\x1b[32m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input yellow.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static yellow = (input?: unknown, preventStylePropagation = true) =>
'\x1b[33m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input blue.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static blue = (input?: unknown, preventStylePropagation = true) =>
'\x1b[34m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input magenta.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static magenta = (input?: unknown, preventStylePropagation = true) =>
'\x1b[35m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input cyan.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static cyan = (input?: unknown, preventStylePropagation = true) =>
'\x1b[36m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input white.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static white = (input?: unknown, preventStylePropagation = true) =>
'\x1b[37m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input gray.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static gray = (input?: unknown, preventStylePropagation = true) =>
'\x1b[90m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input's background black.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static bgBlack = (input?: unknown, preventStylePropagation = true) =>
'\x1b[40m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input's background red.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static bgRed = (input?: unknown, preventStylePropagation = true) =>
'\x1b[41m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input's background green.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static bgGreen = (input?: unknown, preventStylePropagation = true) =>
'\x1b[42m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input's background yellow.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static bgYellow = (input?: unknown, preventStylePropagation = true) =>
'\x1b[43m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input's background blue.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static bgBlue = (input?: unknown, preventStylePropagation = true) =>
'\x1b[44m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input's background magenta.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static bgMagenta = (input?: unknown, preventStylePropagation = true) =>
'\x1b[45m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input's background cyan.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static bgCyan = (input?: unknown, preventStylePropagation = true) =>
'\x1b[46m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input's background white.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static bgWhite = (input?: unknown, preventStylePropagation = true) =>
'\x1b[47m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
/**
* @description Makes the input's background gray.
* @param {unknown} input - The value to be formatted.
* @param {boolean} preventStylePropagation - Either if the styling should reset after function execution or not.
* @returns {string} The formatted text.
*/
static bgGray = (input?: unknown, preventStylePropagation = true) =>
'\x1b[100m' + (input ? input : '') + (preventStylePropagation && !!input ? '\x1b[0m' : '');
}
export class superConsole {
static log(message: unknown, id = 'Adadas'): void {
console.log(`[${this.superTimestamp()}][${id}] - ${message}`);
}
static warn(message: unknown, id = 'Adadas'): void {
console.log(
coloring.yellow(
`[${this.superTimestamp()}][${coloring.reverse('WARN')}${coloring.yellow()}][${id}] - ${message}`
)
);
}
static info(message: unknown, id = 'Adadas'): void {
console.log(
coloring.blue(
`[${this.superTimestamp()}][${coloring.reverse('INFO')}${coloring.blue()}][${id}] - ${message}`
)
);
}
static error(message: unknown, id = 'Adadas'): void {
console.log(
coloring.red(
`[${this.superTimestamp()}][${coloring.reverse('ERROR')}${coloring.red()}][${id}] - ${message}`
)
);
}
static ready(message: unknown, id = 'Adadas'): void {
console.log(
coloring.green(
`[${this.superTimestamp()}][${coloring.reverse('READY')}${coloring.green()}][${id}] - ${message}`
)
);
}
private static superTimestamp(): string {
const date = new Date(Date.now());
return (
`${date.getUTCMonth()}/${date.getUTCDate()}/${date.getUTCFullYear()}` +
' ' +
`${date.getUTCHours()}:${date.getUTCMinutes()}:${date.getUTCSeconds()}`
);
}
}