You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

2 years ago
  1. 'use strict';
  2. let styles = {
  3. 'nomarl':['',''],
  4. 'bold': ['\x1B[1m', '\x1B[22m'],
  5. 'italic': ['\x1B[3m', '\x1B[23m'],
  6. 'underline': ['\x1B[4m', '\x1B[24m'],
  7. 'inverse': ['\x1B[7m', '\x1B[27m'],
  8. 'strikethrough': ['\x1B[9m', '\x1B[29m'],
  9. 'white': ['\x1B[37m', '\x1B[39m'],
  10. 'grey': ['\x1B[90m', '\x1B[39m'],
  11. 'black': ['\x1B[30m', '\x1B[39m'],
  12. 'blue': ['\x1B[34m', '\x1B[39m'],
  13. 'cyan': ['\x1B[36m', '\x1B[39m'],
  14. 'green': ['\x1B[32m', '\x1B[39m'],
  15. 'magenta': ['\x1B[35m', '\x1B[39m'],
  16. 'red': ['\x1B[31m', '\x1B[39m'],
  17. 'yellow': ['\x1B[33m', '\x1B[39m'],
  18. 'whiteBG': ['\x1B[47m', '\x1B[49m'],
  19. 'greyBG': ['\x1B[49;5;8m', '\x1B[49m'],
  20. 'blackBG': ['\x1B[40m', '\x1B[49m'],
  21. 'blueBG': ['\x1B[44m', '\x1B[49m'],
  22. 'cyanBG': ['\x1B[46m', '\x1B[49m'],
  23. 'greenBG': ['\x1B[42m', '\x1B[49m'],
  24. 'magentaBG': ['\x1B[45m', '\x1B[49m'],
  25. 'redBG': ['\x1B[41m', '\x1B[49m'],
  26. 'yellowBG': ['\x1B[43m', '\x1B[49m']
  27. };
  28. function clog(obj, key='black') {
  29. if (typeof obj === 'string') {
  30. console.log(styles[key][0] + '%s' + styles[key][1], obj)
  31. } else if (typeof obj === 'object') {
  32. console.log(styles[key][0] + '%o' + styles[key][1], obj)
  33. } else {
  34. console.log(styles[key][0] + '%s' + styles[key][1], obj)
  35. }
  36. }
  37. module.exports = clog;