1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | exports.center = (center, left, right, leftLen = 17) => {
|
11 | const REPLACER = '...';
|
12 |
|
13 | if (leftLen < REPLACER.length) {
|
14 | return `${REPLACER} ${center} ${right}`;
|
15 | }
|
16 |
|
17 |
|
18 | if (left.length > leftLen) {
|
19 | left.length = leftLen;
|
20 | left = left.split('').slice(0, leftLen - REPLACER.length).concat(REPLACER).join('');
|
21 | }
|
22 |
|
23 |
|
24 | let delta = leftLen - left.length;
|
25 | let addon = '';
|
26 | while (delta--) {
|
27 | addon += ' ';
|
28 | }
|
29 |
|
30 | return `${addon}${left} ${center} ${right}`;
|
31 | };
|