-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringUtils.js
More file actions
88 lines (78 loc) · 3.04 KB
/
Copy pathstringUtils.js
File metadata and controls
88 lines (78 loc) · 3.04 KB
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
const chalk = require("chalk");
const gradient = require("gradient-string");
function createColorString(string, color, style) {
if (style === "bold") return chalk.bold.hex(color)(string);
else return chalk.hex(color)(string);
}
function createGradString(string, grad) {
return chalk.bold(grad(string));
}
function createColorInfoStrings(colorThemes) {
let colorInfoStrings = [];
for (const color in colorThemes) {
// Create Grads
const newGrad = createGrad(colorThemes[color]);
// Insert spaces before Grads to align them
const spaces = " "; // "16 spaces"
const numSpacesCut = spaces.length - color.length;
const newSpaces = spaces.slice(0, numSpacesCut);
const colorInfo = color + newSpaces;
const coloredColorInfo = createColorString(colorInfo, colorThemes[color], "bold");
const coloredDash = createColorString("- ", colorThemes[color], "bold");
const colorInfoString = coloredColorInfo + coloredDash + newGrad("██████████");
const coloredColorInfoString = createColorString(colorInfoString, color, "bold");
colorInfoStrings.push(coloredColorInfoString);
}
return colorInfoStrings;
}
function createBorderInfoStrings(borderThemes, color) {
const borderStrings = [];
for (const border in borderThemes) {
// Insert spaces before Grads to align them
const spaces = " ";
const numSpacesCut = spaces.length - border.length;
const newSpaces = spaces.slice(0, numSpacesCut);
const borderSlice = borderThemes[border][0].slice(0, 16);
const borderString = border + newSpaces + "- " + borderSlice;
const coloredBorderString = createColorString(borderString, color, "bold");
borderStrings.push(coloredBorderString);
// console.log(borderString);
}
return borderStrings;
}
// Adds spaces to the beginning of a string to center it within an area
function centerString(string, areaLength) {
let spaces = "";
const numInsertSpaces = Math.ceil(areaLength - string.length) / 2;
for (let i = 0; i < numInsertSpaces; i++) {
spaces += " ";
}
return spaces + string;
}
// Loops through colors array and creates a new Grad with looping colors
function createGrad(colors = colorThemes.love, loops = 2) {
let colorsRepeat = [];
let length = colors.length;
for (let i = 0; i < loops * 2; i++) {
for (let j = 0; j < length; j++) {
if (i % 2 == 0) {
// Outer iterator is even
// Loop forwards from beginning of colors array
colorsRepeat.push(colors[j]);
} else {
// Outer iterator is odd
// Loop backwards from end of colors array
colorsRepeat.push(colors[length - j - 1]);
}
}
}
return gradient(colorsRepeat);
}
module.exports = {
createGrad,
centerString,
createColorInfoStrings,
createColorString,
createGradString,
createBorderInfoStrings,
};