-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (67 loc) · 2.35 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
import chalk from 'chalk';
import gradientString from 'gradient-string';
import balancedLineSplit from 'balanced-line-split';
function jumper(message, options = {}) {
const { buildingStyle, personStyle, messageStyle, extraFloors, compact, gradient } = {
buildingStyle: 'gray',
personStyle: 'white',
messageStyle: 'bold.white',
extraFloors: 0,
compact: false,
gradient: false,
...options
};
// Limit to 60 characters per line so we don’t go past 80 total.
// The building and space accounts for 14 characters.
let wrapped = balancedLineSplit(message, 3, 60);
// Unless we’re in compact mode, insert padding between each word.
// Easier to insert an extra space here than to mutate the array later.
if (!compact) {
wrapped = wrapped.replace(/\n/g, '\n \n');
}
// Apply a multiline gradient to the whole message.
if (gradient) {
const gradientName = gradient in gradientString ? gradient : 'pastel';
wrapped = gradientString[gradientName].multiline(wrapped);
}
const lines = wrapped.split('\n').map((line) => {
if (gradient) {
return line;
}
return chalk`{${messageStyle} ${line}}`;
});
const output = [
chalk`{${buildingStyle} ┓┏┓┏┓┃}`,
chalk`{${buildingStyle} ┛┗┛┗┛┃} {${personStyle} ⟍ ○⟋}`,
chalk`{${buildingStyle} ┓┏┓┏┓┃} {${personStyle} ∕} ${lines[0]}`,
chalk`{${buildingStyle} ┛┗┛┗┛┃} {${personStyle} ノ)} ${lines[1]}`,
chalk`{${buildingStyle} ┓┏┓┏┓┃} ${lines[2]}`
];
if (lines.length > 3) {
const additionalLines = lines.slice(3);
// If the array length is odd, add one to make it even.
// Since each floor is two lines, we need to add two at a time.
// This makes the loop a little clearner.
if (additionalLines.length % 2 !== 0) {
additionalLines.push(' ');
}
for (let i = 0; i < additionalLines.length; i += 2) {
output.push(
chalk`{${buildingStyle} ┛┗┛┗┛┃} ${additionalLines[i]}`,
chalk`{${buildingStyle} ┓┏┓┏┓┃} ${additionalLines[i + 1]}`
);
}
}
for (let i = 0; i < extraFloors; i++) {
output.push(
chalk`{${buildingStyle} ┛┗┛┗┛┃}`,
chalk`{${buildingStyle} ┓┏┓┏┓┃}`
);
}
output.push(
chalk`{${buildingStyle} ┃┃┃┃┃┃}`,
chalk`{${buildingStyle} ┻┻┻┻┻┻}`
);
return output.join('\n');
}
export default jumper;