All files / src/utils Logger.js

9.52% Statements 2/21
0% Branches 0/12
0% Functions 0/9
10% Lines 2/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 611x                                                                                                               1x        
const chalk = require('chalk')
 
class Logger {
 
  red(str) {
    this.log('red', str)
  }
 
  redWithSuggestion(str) {
    this.log('red', str, 'red', '\n>>', 'grey', 'Press TAB for suggestions.')
  }
 
  yellow(str) {
    this.log('yellow', str)
  }
 
  grey(str) {
    this.log('grey', str)
  }
 
  green(str) {
    this.log('green', str)
  }
 
  cyan(str) {
    this.log('cyan', str)
  }
 
  black(str) {
    this.log('cyan', str)
  }
 
  bold(str) {
    this.log('bold', str)
  }
 
  log(...data) {
    let message = ''
    let prev
    for (let i = 0; i < data.length; i += 2) {
      if (typeof data[i + 1] === 'undefined') {
        break
      }
      let sep = prev ? ' ' : ''
      if (prev && ['bold', 'italic', 'dim', 'underline'].includes(data[i])) {
        message += sep + chalk[prev][data[i] || 'reset'](data[i + 1])
      } else {
        message += sep + chalk[data[i] || 'reset'](data[i + 1])
      }
      prev = data[i]
    }
    console.info(message)
  }
 
}
 
module.exports = new Logger