|
| 1 | +import chalk from 'chalk'; |
| 2 | + |
| 3 | +/* eslint-disable no-console */ |
| 4 | + |
| 5 | +const prettify = { |
| 6 | + /* ------------------------------- |
| 7 | + Apply color to the whole message |
| 8 | + in console.log() |
| 9 | + --------------------------------*/ |
| 10 | + log: { |
| 11 | + success: (message) => { |
| 12 | + console.log( prettify.text.success(message) ); |
| 13 | + }, |
| 14 | + warning: (message) => { |
| 15 | + console.log( prettify.text.warning(message) ); |
| 16 | + }, |
| 17 | + error: (message) => { |
| 18 | + console.log( prettify.text.error(message) ); |
| 19 | + }, |
| 20 | + color: { |
| 21 | + none: (message) => { |
| 22 | + console.log(message); |
| 23 | + }, |
| 24 | + //---------------------------------- |
| 25 | + redBold: (message, err) => { |
| 26 | + console.log( prettify.text.color.redBold(message), err ); |
| 27 | + }, |
| 28 | + //---------------------------------- |
| 29 | + cyanBright: (message) => { |
| 30 | + console.log( prettify.text.color.cyanBright(message) ); |
| 31 | + }, |
| 32 | + green: (message) => { |
| 33 | + return prettify.text.color.green(message); |
| 34 | + } |
| 35 | + }, |
| 36 | + }, |
| 37 | + /* ------------------------------------------ |
| 38 | + Helpers for coloring all text within methods |
| 39 | + that use console.log() or for coloring some |
| 40 | + part of console message text |
| 41 | + -------------------------------------------*/ |
| 42 | + text: { |
| 43 | + success: (message) => { |
| 44 | + return chalk.greenBright(message); |
| 45 | + }, |
| 46 | + warning: (message) => { |
| 47 | + return chalk.yellowBright(message); |
| 48 | + }, |
| 49 | + error: (message) => { |
| 50 | + return chalk.redBright(message); |
| 51 | + }, |
| 52 | + color: { |
| 53 | + redBold: (message) => { |
| 54 | + return chalk.red.bold(message); |
| 55 | + }, |
| 56 | + cyanBright: (message) => { |
| 57 | + return chalk.cyanBright(message); |
| 58 | + }, |
| 59 | + green: (message) => { |
| 60 | + return chalk.green(message); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +const { log } = prettify; |
| 67 | +const { success, warning, error } = log; |
| 68 | + |
| 69 | +export { |
| 70 | + prettify, |
| 71 | + success, |
| 72 | + warning, |
| 73 | + error, |
| 74 | +}; |
0 commit comments