-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
index.js
157 lines (144 loc) · 3.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
'use strict';
const escapeStringRegexp = require('escape-string-regexp');
const {platform} = process;
const common = {
bullet: '●',
dot: '․',
line: '─',
ellipsis: '…',
pointerSmall: '›',
heart: '♥',
arrowUp: '↑',
arrowDown: '↓',
arrowLeft: '←',
arrowRight: '→',
arrowLeftRight: '↔',
arrowUpDown: '↕',
subscriptZero: '₀',
subscriptOne: '₁',
subscriptTwo: '₂',
subscriptThree: '₃',
subscriptFour: '₄',
subscriptFive: '₅',
subscriptSix: '₆',
subscriptSeven: '₇',
subscriptEight: '₈',
subscriptNine: '₉',
oneHalf: '½',
oneThird: '⅓',
oneQuarter: '¼',
oneFifth: '⅕',
oneSixth: '⅙',
oneEighth: '⅛',
twoThirds: '⅔',
twoFifths: '⅖',
threeQuarters: '¾',
threeFifths: '⅗',
threeEighths: '⅜',
fourFifths: '⅘',
fiveSixths: '⅚',
fiveEighths: '⅝',
sevenEighths: '⅞'
};
const main = {
...common,
tick: '✔',
cross: '✖',
star: '★',
square: '▇',
squareSmall: '◻',
squareSmallFilled: '◼',
play: '▶',
circle: '◯',
circleFilled: '◉',
circleDotted: '◌',
circleDouble: '◎',
circleCircle: 'ⓞ',
circleCross: 'ⓧ',
circlePipe: 'Ⓘ',
circleQuestionMark: '?⃝',
pointer: '❯',
info: 'ℹ',
warning: '⚠',
hamburger: '☰',
smiley: '㋡',
mustache: '෴',
nodejs: '⬢',
radioOn: '◉',
radioOff: '◯',
checkboxOn: '☒',
checkboxOff: '☐',
checkboxCircleOn: 'ⓧ',
checkboxCircleOff: 'Ⓘ',
questionMarkPrefix: '?⃝',
oneSeventh: '⅐',
oneNinth: '⅑',
oneTenth: '⅒'
};
const fallback = {
...common,
tick: '√',
cross: '×',
star: '✶',
square: '█',
squareSmall: '□',
squareSmallFilled: '■',
play: '►',
circle: '( )',
circleFilled: '(*)',
circleDotted: '( )',
circleDouble: '( )',
circleCircle: '(○)',
circleCross: '(×)',
circlePipe: '(│)',
circleQuestionMark: '(?)',
pointer: '>',
info: 'i',
warning: '‼',
hamburger: '≡',
smiley: '☺',
mustache: '┌─┐',
nodejs: '♦',
radioOn: '(*)',
radioOff: '( )',
checkboxOn: '[×]',
checkboxOff: '[ ]',
checkboxCircleOn: '(×)',
checkboxCircleOff: '( )',
questionMarkPrefix: '?',
oneSeventh: '1/7',
oneNinth: '1/9',
oneTenth: '1/10'
};
if (platform === 'linux') {
// The main one doesn't look that good on Ubuntu.
main.circleQuestionMark = '?';
main.questionMarkPrefix = '?';
}
// TODO: Use https://github.com/sindresorhus/is-unicode-supported when targeting Node.js 10.
const figures = platform === 'win32' ? fallback : main;
const isFallbackFigure = ([key, mainValue]) => figures[key] !== mainValue;
const getFigureRegExp = ([key, mainValue]) => [new RegExp(escapeStringRegexp(mainValue), 'g'), figures[key]];
let replacements = [];
const getReplacements = () => {
if (replacements.length !== 0) {
return replacements;
}
replacements = Object.entries(main)
.filter(isFallbackFigure)
.map(getFigureRegExp);
return replacements;
};
// On Windows, substitute non-fallback to fallback figures
const replaceCharsToFallback = string => {
if (figures === main) {
return string;
}
for (const [mainRegExp, fallbackValue] of getReplacements()) {
string = string.replace(mainRegExp, fallbackValue);
}
return string;
};
module.exports = Object.assign(replaceCharsToFallback, figures);
module.exports.main = main;
module.exports.windows = fallback;