-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb0x.js
More file actions
34 lines (28 loc) · 1.14 KB
/
b0x.js
File metadata and controls
34 lines (28 loc) · 1.14 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
function box(string) {
// split and append new line esc char
const maxChar = Math.floor(Math.random() * (120 - 40 + 1) + 40)
let stringMod = string.trim().split(' ')
let wordsPerLine = Math.floor(Math.random() * ((maxChar / 10) - 4 + 1) + 4);
for (let x = 0; x != stringMod.length; x++) {
if (x % wordsPerLine == 0 && x != 0) { stringMod[x] += '\n' }
else if (stringMod[x].length > 60) { stringMod[x] = stringMod[x].slice(0, 60) }
}
stringMod = stringMod.join(' ')
// split and pad
const content = stringMod.split('\n')
const arr = []
for (let x = 0; x != content.length; x++) {
arr.push(content[x].padStart((maxChar + content[x].length) / 2).padEnd(maxChar))
}
arr.unshift(' '.repeat(maxChar))
arr.push(' '.repeat(maxChar))
// make box
let [hline, vline, tlcorner, trcorner, blcorner, brcorner] = /*['═', '║', '╔', '╗', '╚', '╝'] ||*/ ['-', '|', '+', '+', '+', '+']
for (let x = 0; x != arr.length; x++) {
arr[x] = vline + arr[x] + vline + ' \n'
}
arr.unshift(' ' + tlcorner + hline.repeat(maxChar) + trcorner + ' \n')
arr.push(blcorner + hline.repeat(maxChar) + brcorner + ' \n')
return arr.join(' ')
}
export { box }