index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. 'use strict';
  2. const escapeStringRegexp = require('escape-string-regexp');
  3. const {platform} = process;
  4. const main = {
  5. tick: '✔',
  6. cross: '✖',
  7. star: '★',
  8. square: '▇',
  9. squareSmall: '◻',
  10. squareSmallFilled: '◼',
  11. play: '▶',
  12. circle: '◯',
  13. circleFilled: '◉',
  14. circleDotted: '◌',
  15. circleDouble: '◎',
  16. circleCircle: 'ⓞ',
  17. circleCross: 'ⓧ',
  18. circlePipe: 'Ⓘ',
  19. circleQuestionMark: '?⃝',
  20. bullet: '●',
  21. dot: '․',
  22. line: '─',
  23. ellipsis: '…',
  24. pointer: '❯',
  25. pointerSmall: '›',
  26. info: 'ℹ',
  27. warning: '⚠',
  28. hamburger: '☰',
  29. smiley: '㋡',
  30. mustache: '෴',
  31. heart: '♥',
  32. nodejs: '⬢',
  33. arrowUp: '↑',
  34. arrowDown: '↓',
  35. arrowLeft: '←',
  36. arrowRight: '→',
  37. radioOn: '◉',
  38. radioOff: '◯',
  39. checkboxOn: '☒',
  40. checkboxOff: '☐',
  41. checkboxCircleOn: 'ⓧ',
  42. checkboxCircleOff: 'Ⓘ',
  43. questionMarkPrefix: '?⃝',
  44. oneHalf: '½',
  45. oneThird: '⅓',
  46. oneQuarter: '¼',
  47. oneFifth: '⅕',
  48. oneSixth: '⅙',
  49. oneSeventh: '⅐',
  50. oneEighth: '⅛',
  51. oneNinth: '⅑',
  52. oneTenth: '⅒',
  53. twoThirds: '⅔',
  54. twoFifths: '⅖',
  55. threeQuarters: '¾',
  56. threeFifths: '⅗',
  57. threeEighths: '⅜',
  58. fourFifths: '⅘',
  59. fiveSixths: '⅚',
  60. fiveEighths: '⅝',
  61. sevenEighths: '⅞'
  62. };
  63. const windows = {
  64. tick: '√',
  65. cross: '×',
  66. star: '*',
  67. square: '█',
  68. squareSmall: '[ ]',
  69. squareSmallFilled: '[█]',
  70. play: '►',
  71. circle: '( )',
  72. circleFilled: '(*)',
  73. circleDotted: '( )',
  74. circleDouble: '( )',
  75. circleCircle: '(○)',
  76. circleCross: '(×)',
  77. circlePipe: '(│)',
  78. circleQuestionMark: '(?)',
  79. bullet: '*',
  80. dot: '.',
  81. line: '─',
  82. ellipsis: '...',
  83. pointer: '>',
  84. pointerSmall: '»',
  85. info: 'i',
  86. warning: '‼',
  87. hamburger: '≡',
  88. smiley: '☺',
  89. mustache: '┌─┐',
  90. heart: main.heart,
  91. nodejs: '♦',
  92. arrowUp: main.arrowUp,
  93. arrowDown: main.arrowDown,
  94. arrowLeft: main.arrowLeft,
  95. arrowRight: main.arrowRight,
  96. radioOn: '(*)',
  97. radioOff: '( )',
  98. checkboxOn: '[×]',
  99. checkboxOff: '[ ]',
  100. checkboxCircleOn: '(×)',
  101. checkboxCircleOff: '( )',
  102. questionMarkPrefix: '?',
  103. oneHalf: '1/2',
  104. oneThird: '1/3',
  105. oneQuarter: '1/4',
  106. oneFifth: '1/5',
  107. oneSixth: '1/6',
  108. oneSeventh: '1/7',
  109. oneEighth: '1/8',
  110. oneNinth: '1/9',
  111. oneTenth: '1/10',
  112. twoThirds: '2/3',
  113. twoFifths: '2/5',
  114. threeQuarters: '3/4',
  115. threeFifths: '3/5',
  116. threeEighths: '3/8',
  117. fourFifths: '4/5',
  118. fiveSixths: '5/6',
  119. fiveEighths: '5/8',
  120. sevenEighths: '7/8'
  121. };
  122. if (platform === 'linux') {
  123. // The main one doesn't look that good on Ubuntu.
  124. main.questionMarkPrefix = '?';
  125. }
  126. const figures = platform === 'win32' ? windows : main;
  127. const fn = string => {
  128. if (figures === main) {
  129. return string;
  130. }
  131. for (const [key, value] of Object.entries(main)) {
  132. if (value === figures[key]) {
  133. continue;
  134. }
  135. string = string.replace(new RegExp(escapeStringRegexp(value), 'g'), figures[key]);
  136. }
  137. return string;
  138. };
  139. module.exports = Object.assign(fn, figures);
  140. module.exports.main = main;
  141. module.exports.windows = windows;