1 |
|
2 |
|
3 | const ConsoleDecor = require('./console-decorator')
|
4 |
|
5 | const COLOR = {
|
6 | CONCLUSION: { bg: 'BlueBG', fg: 'Yellow', icon: '\u2605', text: ['Blue'] },
|
7 | ERROR: { bg: 'RedBG', fg: 'Black', icon: '\u29BB', text: ['Red'] },
|
8 | INFO: { bg: 'CyanBG', fg: 'Black', icon: '\u2148', text: ['Cyan'] },
|
9 | SUCCESS: { bg: 'GreenBG', fg: 'Black', icon: '\u2713', text: ['Green'] },
|
10 | VALIDATION: { bg: 'MagentaBG', fg: 'Black', icon: '\u22CE', text: ['Magenta'] },
|
11 | WARN: { bg: 'YellowBG', fg: 'Black', icon: '\u25B3', text: ['Yellow'] },
|
12 | }
|
13 |
|
14 | function decorateMsg(msg, d) {
|
15 | ConsoleDecor.Reset
|
16 | d.text.forEach((decor) => ConsoleDecor[decor])
|
17 | return ConsoleDecor.color(msg).Reset.end
|
18 | }
|
19 |
|
20 | function output(messages, d) {
|
21 | const adjustedMessages = messages.map((i) => typeof (i) === 'string' ? decorateMsg(i, d) : i)
|
22 | const icon = ConsoleDecor.Reset[d.bg][d.fg].color(` ${d.icon} `).Reset.end
|
23 | console.log(icon, ...adjustedMessages)
|
24 | }
|
25 |
|
26 | module.exports = {
|
27 | conclusion: (...messages) => output(messages, COLOR.CONCLUSION),
|
28 | error: (...messages) => output(messages, COLOR.ERROR),
|
29 | info: (...messages) => output(messages, COLOR.INFO),
|
30 | normal: console.log,
|
31 | success: (...messages) => output(messages, COLOR.SUCCESS),
|
32 | validation: (...messages) => output(messages, COLOR.VALIDATION),
|
33 | warn: (...messages) => output(messages, COLOR.WARN),
|
34 | }
|