Brak opisu

index.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. 'use strict';
  2. var objectAssign = require('object-assign');
  3. var escapeStringRegexp = require('escape-string-regexp');
  4. var platform = process.platform;
  5. var main = {
  6. tick: '✔',
  7. cross: '✖',
  8. star: '★',
  9. square: '▇',
  10. squareSmall: '◻',
  11. squareSmallFilled: '◼',
  12. play: '▶',
  13. circle: '◯',
  14. circleFilled: '◉',
  15. circleDotted: '◌',
  16. circleDouble: '◎',
  17. circleCircle: 'ⓞ',
  18. circleCross: 'ⓧ',
  19. circlePipe: 'Ⓘ',
  20. circleQuestionMark: '?⃝',
  21. bullet: '●',
  22. dot: '․',
  23. line: '─',
  24. ellipsis: '…',
  25. pointer: '❯',
  26. pointerSmall: '›',
  27. info: 'ℹ',
  28. warning: '⚠',
  29. hamburger: '☰',
  30. smiley: '㋡',
  31. mustache: '෴',
  32. heart: '♥',
  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. var win = {
  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. arrowUp: main.arrowUp,
  92. arrowDown: main.arrowDown,
  93. arrowLeft: main.arrowLeft,
  94. arrowRight: main.arrowRight,
  95. radioOn: '(*)',
  96. radioOff: '( )',
  97. checkboxOn: '[×]',
  98. checkboxOff: '[ ]',
  99. checkboxCircleOn: '(×)',
  100. checkboxCircleOff: '( )',
  101. questionMarkPrefix: '?',
  102. oneHalf: '1/2',
  103. oneThird: '1/3',
  104. oneQuarter: '1/4',
  105. oneFifth: '1/5',
  106. oneSixth: '1/6',
  107. oneSeventh: '1/7',
  108. oneEighth: '1/8',
  109. oneNinth: '1/9',
  110. oneTenth: '1/10',
  111. twoThirds: '2/3',
  112. twoFifths: '2/5',
  113. threeQuarters: '3/4',
  114. threeFifths: '3/5',
  115. threeEighths: '3/8',
  116. fourFifths: '4/5',
  117. fiveSixths: '5/6',
  118. fiveEighths: '5/8',
  119. sevenEighths: '7/8'
  120. };
  121. if (platform === 'linux') {
  122. // the main one doesn't look that good on Ubuntu
  123. main.questionMarkPrefix = '?';
  124. }
  125. var figures = platform === 'win32' ? win : main;
  126. var fn = function (str) {
  127. if (figures === main) {
  128. return str;
  129. }
  130. Object.keys(main).forEach(function (key) {
  131. if (main[key] === figures[key]) {
  132. return;
  133. }
  134. str = str.replace(new RegExp(escapeStringRegexp(main[key]), 'g'), figures[key]);
  135. });
  136. return str;
  137. };
  138. module.exports = objectAssign(fn, figures);