index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import isUnicodeSupported from 'is-unicode-supported';
  2. const common = {
  3. circleQuestionMark: '(?)',
  4. questionMarkPrefix: '(?)',
  5. square: '█',
  6. squareDarkShade: '▓',
  7. squareMediumShade: '▒',
  8. squareLightShade: '░',
  9. squareTop: '▀',
  10. squareBottom: '▄',
  11. squareLeft: '▌',
  12. squareRight: '▐',
  13. squareCenter: '■',
  14. bullet: '●',
  15. dot: '․',
  16. ellipsis: '…',
  17. pointerSmall: '›',
  18. triangleUp: '▲',
  19. triangleUpSmall: '▴',
  20. triangleDown: '▼',
  21. triangleDownSmall: '▾',
  22. triangleLeftSmall: '◂',
  23. triangleRightSmall: '▸',
  24. home: '⌂',
  25. heart: '♥',
  26. musicNote: '♪',
  27. musicNoteBeamed: '♫',
  28. arrowUp: '↑',
  29. arrowDown: '↓',
  30. arrowLeft: '←',
  31. arrowRight: '→',
  32. arrowLeftRight: '↔',
  33. arrowUpDown: '↕',
  34. almostEqual: '≈',
  35. notEqual: '≠',
  36. lessOrEqual: '≤',
  37. greaterOrEqual: '≥',
  38. identical: '≡',
  39. infinity: '∞',
  40. subscriptZero: '₀',
  41. subscriptOne: '₁',
  42. subscriptTwo: '₂',
  43. subscriptThree: '₃',
  44. subscriptFour: '₄',
  45. subscriptFive: '₅',
  46. subscriptSix: '₆',
  47. subscriptSeven: '₇',
  48. subscriptEight: '₈',
  49. subscriptNine: '₉',
  50. oneHalf: '½',
  51. oneThird: '⅓',
  52. oneQuarter: '¼',
  53. oneFifth: '⅕',
  54. oneSixth: '⅙',
  55. oneEighth: '⅛',
  56. twoThirds: '⅔',
  57. twoFifths: '⅖',
  58. threeQuarters: '¾',
  59. threeFifths: '⅗',
  60. threeEighths: '⅜',
  61. fourFifths: '⅘',
  62. fiveSixths: '⅚',
  63. fiveEighths: '⅝',
  64. sevenEighths: '⅞',
  65. line: '─',
  66. lineBold: '━',
  67. lineDouble: '═',
  68. lineDashed0: '┄',
  69. lineDashed1: '┅',
  70. lineDashed2: '┈',
  71. lineDashed3: '┉',
  72. lineDashed4: '╌',
  73. lineDashed5: '╍',
  74. lineDashed6: '╴',
  75. lineDashed7: '╶',
  76. lineDashed8: '╸',
  77. lineDashed9: '╺',
  78. lineDashed10: '╼',
  79. lineDashed11: '╾',
  80. lineDashed12: '−',
  81. lineDashed13: '–',
  82. lineDashed14: '‐',
  83. lineDashed15: '⁃',
  84. lineVertical: '│',
  85. lineVerticalBold: '┃',
  86. lineVerticalDouble: '║',
  87. lineVerticalDashed0: '┆',
  88. lineVerticalDashed1: '┇',
  89. lineVerticalDashed2: '┊',
  90. lineVerticalDashed3: '┋',
  91. lineVerticalDashed4: '╎',
  92. lineVerticalDashed5: '╏',
  93. lineVerticalDashed6: '╵',
  94. lineVerticalDashed7: '╷',
  95. lineVerticalDashed8: '╹',
  96. lineVerticalDashed9: '╻',
  97. lineVerticalDashed10: '╽',
  98. lineVerticalDashed11: '╿',
  99. lineDownLeft: '┐',
  100. lineDownLeftArc: '╮',
  101. lineDownBoldLeftBold: '┓',
  102. lineDownBoldLeft: '┒',
  103. lineDownLeftBold: '┑',
  104. lineDownDoubleLeftDouble: '╗',
  105. lineDownDoubleLeft: '╖',
  106. lineDownLeftDouble: '╕',
  107. lineDownRight: '┌',
  108. lineDownRightArc: '╭',
  109. lineDownBoldRightBold: '┏',
  110. lineDownBoldRight: '┎',
  111. lineDownRightBold: '┍',
  112. lineDownDoubleRightDouble: '╔',
  113. lineDownDoubleRight: '╓',
  114. lineDownRightDouble: '╒',
  115. lineUpLeft: '┘',
  116. lineUpLeftArc: '╯',
  117. lineUpBoldLeftBold: '┛',
  118. lineUpBoldLeft: '┚',
  119. lineUpLeftBold: '┙',
  120. lineUpDoubleLeftDouble: '╝',
  121. lineUpDoubleLeft: '╜',
  122. lineUpLeftDouble: '╛',
  123. lineUpRight: '└',
  124. lineUpRightArc: '╰',
  125. lineUpBoldRightBold: '┗',
  126. lineUpBoldRight: '┖',
  127. lineUpRightBold: '┕',
  128. lineUpDoubleRightDouble: '╚',
  129. lineUpDoubleRight: '╙',
  130. lineUpRightDouble: '╘',
  131. lineUpDownLeft: '┤',
  132. lineUpBoldDownBoldLeftBold: '┫',
  133. lineUpBoldDownBoldLeft: '┨',
  134. lineUpDownLeftBold: '┥',
  135. lineUpBoldDownLeftBold: '┩',
  136. lineUpDownBoldLeftBold: '┪',
  137. lineUpDownBoldLeft: '┧',
  138. lineUpBoldDownLeft: '┦',
  139. lineUpDoubleDownDoubleLeftDouble: '╣',
  140. lineUpDoubleDownDoubleLeft: '╢',
  141. lineUpDownLeftDouble: '╡',
  142. lineUpDownRight: '├',
  143. lineUpBoldDownBoldRightBold: '┣',
  144. lineUpBoldDownBoldRight: '┠',
  145. lineUpDownRightBold: '┝',
  146. lineUpBoldDownRightBold: '┡',
  147. lineUpDownBoldRightBold: '┢',
  148. lineUpDownBoldRight: '┟',
  149. lineUpBoldDownRight: '┞',
  150. lineUpDoubleDownDoubleRightDouble: '╠',
  151. lineUpDoubleDownDoubleRight: '╟',
  152. lineUpDownRightDouble: '╞',
  153. lineDownLeftRight: '┬',
  154. lineDownBoldLeftBoldRightBold: '┳',
  155. lineDownLeftBoldRightBold: '┯',
  156. lineDownBoldLeftRight: '┰',
  157. lineDownBoldLeftBoldRight: '┱',
  158. lineDownBoldLeftRightBold: '┲',
  159. lineDownLeftRightBold: '┮',
  160. lineDownLeftBoldRight: '┭',
  161. lineDownDoubleLeftDoubleRightDouble: '╦',
  162. lineDownDoubleLeftRight: '╥',
  163. lineDownLeftDoubleRightDouble: '╤',
  164. lineUpLeftRight: '┴',
  165. lineUpBoldLeftBoldRightBold: '┻',
  166. lineUpLeftBoldRightBold: '┷',
  167. lineUpBoldLeftRight: '┸',
  168. lineUpBoldLeftBoldRight: '┹',
  169. lineUpBoldLeftRightBold: '┺',
  170. lineUpLeftRightBold: '┶',
  171. lineUpLeftBoldRight: '┵',
  172. lineUpDoubleLeftDoubleRightDouble: '╩',
  173. lineUpDoubleLeftRight: '╨',
  174. lineUpLeftDoubleRightDouble: '╧',
  175. lineUpDownLeftRight: '┼',
  176. lineUpBoldDownBoldLeftBoldRightBold: '╋',
  177. lineUpDownBoldLeftBoldRightBold: '╈',
  178. lineUpBoldDownLeftBoldRightBold: '╇',
  179. lineUpBoldDownBoldLeftRightBold: '╊',
  180. lineUpBoldDownBoldLeftBoldRight: '╉',
  181. lineUpBoldDownLeftRight: '╀',
  182. lineUpDownBoldLeftRight: '╁',
  183. lineUpDownLeftBoldRight: '┽',
  184. lineUpDownLeftRightBold: '┾',
  185. lineUpBoldDownBoldLeftRight: '╂',
  186. lineUpDownLeftBoldRightBold: '┿',
  187. lineUpBoldDownLeftBoldRight: '╃',
  188. lineUpBoldDownLeftRightBold: '╄',
  189. lineUpDownBoldLeftBoldRight: '╅',
  190. lineUpDownBoldLeftRightBold: '╆',
  191. lineUpDoubleDownDoubleLeftDoubleRightDouble: '╬',
  192. lineUpDoubleDownDoubleLeftRight: '╫',
  193. lineUpDownLeftDoubleRightDouble: '╪',
  194. lineCross: '╳',
  195. lineBackslash: '╲',
  196. lineSlash: '╱',
  197. };
  198. const specialMainSymbols = {
  199. tick: '✔',
  200. info: 'ℹ',
  201. warning: '⚠',
  202. cross: '✘',
  203. squareSmall: '◻',
  204. squareSmallFilled: '◼',
  205. circle: '◯',
  206. circleFilled: '◉',
  207. circleDotted: '◌',
  208. circleDouble: '◎',
  209. circleCircle: 'ⓞ',
  210. circleCross: 'ⓧ',
  211. circlePipe: 'Ⓘ',
  212. radioOn: '◉',
  213. radioOff: '◯',
  214. checkboxOn: '☒',
  215. checkboxOff: '☐',
  216. checkboxCircleOn: 'ⓧ',
  217. checkboxCircleOff: 'Ⓘ',
  218. pointer: '❯',
  219. triangleUpOutline: '△',
  220. triangleLeft: '◀',
  221. triangleRight: '▶',
  222. lozenge: '◆',
  223. lozengeOutline: '◇',
  224. hamburger: '☰',
  225. smiley: '㋡',
  226. mustache: '෴',
  227. star: '★',
  228. play: '▶',
  229. nodejs: '⬢',
  230. oneSeventh: '⅐',
  231. oneNinth: '⅑',
  232. oneTenth: '⅒',
  233. };
  234. const specialFallbackSymbols = {
  235. tick: '√',
  236. info: 'i',
  237. warning: '‼',
  238. cross: '×',
  239. squareSmall: '□',
  240. squareSmallFilled: '■',
  241. circle: '( )',
  242. circleFilled: '(*)',
  243. circleDotted: '( )',
  244. circleDouble: '( )',
  245. circleCircle: '(○)',
  246. circleCross: '(×)',
  247. circlePipe: '(│)',
  248. radioOn: '(*)',
  249. radioOff: '( )',
  250. checkboxOn: '[×]',
  251. checkboxOff: '[ ]',
  252. checkboxCircleOn: '(×)',
  253. checkboxCircleOff: '( )',
  254. pointer: '>',
  255. triangleUpOutline: '∆',
  256. triangleLeft: '◄',
  257. triangleRight: '►',
  258. lozenge: '♦',
  259. lozengeOutline: '◊',
  260. hamburger: '≡',
  261. smiley: '☺',
  262. mustache: '┌─┐',
  263. star: '✶',
  264. play: '►',
  265. nodejs: '♦',
  266. oneSeventh: '1/7',
  267. oneNinth: '1/9',
  268. oneTenth: '1/10',
  269. };
  270. export const mainSymbols = {...common, ...specialMainSymbols};
  271. export const fallbackSymbols = {...common, ...specialFallbackSymbols};
  272. const shouldUseMain = isUnicodeSupported();
  273. const figures = shouldUseMain ? mainSymbols : fallbackSymbols;
  274. export default figures;
  275. const replacements = Object.entries(specialMainSymbols);
  276. // On terminals which do not support Unicode symbols, substitute them to other symbols
  277. export const replaceSymbols = (string, {useFallback = !shouldUseMain} = {}) => {
  278. if (useFallback) {
  279. for (const [key, mainSymbol] of replacements) {
  280. string = string.replaceAll(mainSymbol, fallbackSymbols[key]);
  281. }
  282. }
  283. return string;
  284. };