-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
41 lines (36 loc) · 1.1 KB
/
utils.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
const TYPES = {
real: 'REAL',
blue: 'BLUE',
}
const convert = (val) => val.toFixed(2)
const calculateOffset = (a, b) => ({
buy: convert(a.value_buy).length < convert(b.value_buy).length,
sell: convert(a.value_sell).length < convert(b.value_sell).length,
avg: convert(a.value_avg).length < convert(b.value_avg).length,
})
const printTable = (
val,
type,
offset = { buy: false, sell: false, avg: false },
) => {
console.log(`|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|`)
console.log(`| ${type}\t\t |`)
console.log(`| ----------------- |`)
console.log(
`| Buy:\t ${offset.buy ? ' ' : ''}$ ${convert(val.value_buy)} |`,
)
console.log(
`| Sell:\t ${offset.sell ? ' ' : ''}$ ${convert(val.value_sell)} |`,
)
console.log(`| ----------------- |`)
console.log(
`| Avg:\t ${offset.avg ? ' ' : ''}$ ${convert(val.value_avg)} |`,
)
console.log(`|___________________|`)
}
const print = (oficial, blue) => {
printTable(oficial, TYPES.real, calculateOffset(oficial, blue))
console.log()
printTable(blue, TYPES.blue, calculateOffset(blue, oficial))
}
module.exports = { print }