* @private * Colorizes text for the console.
| 7 | * Colorizes text for the console. |
| 8 | */ |
| 9 | class Colorize { |
| 10 | /** |
| 11 | * Replaces the current line with the given text. |
| 12 | * @param text The text to replace the current line with. |
| 13 | */ |
| 14 | static replaceLine(text) { |
| 15 | return '\x1b[A\x1b[2K' + text; |
| 16 | } |
| 17 | /** |
| 18 | * Renders the given text as error text. |
| 19 | * @param error Error text to render. |
| 20 | */ |
| 21 | static error(error) { |
| 22 | if (typeof error === 'string') { |
| 23 | return `\x1b[31;1m${error}\x1b[0m`; |
| 24 | } |
| 25 | else { |
| 26 | return `\x1b[31;1m${error.message}\x1b[0m`; |
| 27 | } |
| 28 | } |
| 29 | /** |
| 30 | * Renders the given text with a highlight to call attention. |
| 31 | * @param message Text to highlight. |
| 32 | */ |
| 33 | static highlight(message) { |
| 34 | return `\x1b[34;1m${message}\x1b[0m`; |
| 35 | } |
| 36 | /** |
| 37 | * Renders the given text as general output text. |
| 38 | * @param output Text to render. |
| 39 | * @param quote Optional. Quote to use for strings. Defaults to `''`. |
| 40 | * @param units Optional. Units to use for numbers. Defaults to `''`. |
| 41 | */ |
| 42 | static output(output, quote = '', units = '') { |
| 43 | if (typeof output === 'string') { |
| 44 | return `\x1b[32m${quote}${output}${quote}\x1b[0m`; |
| 45 | } |
| 46 | else if (typeof output === 'object' && output !== null) { |
| 47 | return colorizer(output, { |
| 48 | pretty: true, |
| 49 | colors: { |
| 50 | BRACE: 'white', |
| 51 | BRACKET: 'white', |
| 52 | COLON: 'white', |
| 53 | COMMA: 'white', |
| 54 | STRING_KEY: 'white', |
| 55 | STRING_LITERAL: 'green', |
| 56 | NUMBER_LITERAL: 'blue', |
| 57 | BOOLEAN_LITERAL: 'blue', |
| 58 | NULL_LITERAL: 'blue' |
| 59 | } |
| 60 | }); |
| 61 | } |
| 62 | else if (typeof output == 'number') { |
| 63 | return `\x1b[34m${output}${units}\x1b[0m`; |
| 64 | } |
| 65 | else { |
| 66 | return `\x1b[34m${output}\x1b[0m`; |
nothing calls this directly
no outgoing calls
no test coverage detected