index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use strict';
  2. function assembleStyles () {
  3. var styles = {
  4. modifiers: {
  5. reset: [0, 0],
  6. bold: [1, 22], // 21 isn't widely supported and 22 does the same thing
  7. dim: [2, 22],
  8. italic: [3, 23],
  9. underline: [4, 24],
  10. inverse: [7, 27],
  11. hidden: [8, 28],
  12. strikethrough: [9, 29]
  13. },
  14. colors: {
  15. black: [30, 39],
  16. red: [31, 39],
  17. green: [32, 39],
  18. yellow: [33, 39],
  19. blue: [34, 39],
  20. magenta: [35, 39],
  21. cyan: [36, 39],
  22. white: [37, 39],
  23. gray: [90, 39]
  24. },
  25. bgColors: {
  26. bgBlack: [40, 49],
  27. bgRed: [41, 49],
  28. bgGreen: [42, 49],
  29. bgYellow: [43, 49],
  30. bgBlue: [44, 49],
  31. bgMagenta: [45, 49],
  32. bgCyan: [46, 49],
  33. bgWhite: [47, 49]
  34. }
  35. };
  36. // fix humans
  37. styles.colors.grey = styles.colors.gray;
  38. Object.keys(styles).forEach(function (groupName) {
  39. var group = styles[groupName];
  40. Object.keys(group).forEach(function (styleName) {
  41. var style = group[styleName];
  42. styles[styleName] = group[styleName] = {
  43. open: '\u001b[' + style[0] + 'm',
  44. close: '\u001b[' + style[1] + 'm'
  45. };
  46. });
  47. Object.defineProperty(styles, groupName, {
  48. value: group,
  49. enumerable: false
  50. });
  51. });
  52. return styles;
  53. }
  54. Object.defineProperty(module, 'exports', {
  55. enumerable: true,
  56. get: assembleStyles
  57. });