Skip to content

Commit e38de3f

Browse files
committed
reduce dependencies
1 parent 98a7ba4 commit e38de3f

File tree

9 files changed

+150
-451
lines changed

9 files changed

+150
-451
lines changed

index.js

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import args from "./src/arguments.js"
44
import asciichart from "asciichart"
5-
import moment from "moment"
6-
import lodash from "lodash/fp.js"
75
import { CryptoCompareAPI } from "./src/CryptoCompareAPI.js"
86
import { print, normalize, time, interpolate } from "./src/utils.js"
97
import { printTopList } from "./src/toplist.js"
@@ -13,14 +11,13 @@ import {
1311
getTechIndicatorColors,
1412
} from "./src/technical-indicator.js"
1513

16-
const { map, flow, sortBy, toLower, trim, pad, max, min } = lodash
17-
18-
const printCoins = async () =>
19-
flow(
20-
map(trim),
21-
sortBy(toLower),
22-
map(print)
23-
)(await CryptoCompareAPI.fetchCoinList())
14+
const printCoins = async () => {
15+
const coins = await CryptoCompareAPI.fetchCoinList()
16+
coins
17+
.map(coin => coin.trim())
18+
.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
19+
.forEach(coin => print(coin))
20+
}
2421

2522
const getMinRange = (max, min) => {
2623
if (max - min > args.minRange) return []
@@ -29,11 +26,29 @@ const getMinRange = (max, min) => {
2926
return [max + range, min - range]
3027
}
3128

29+
const formatDate = (date) => {
30+
const year = date.getFullYear()
31+
const month = String(date.getMonth() + 1).padStart(2, '0')
32+
const day = String(date.getDate()).padStart(2, '0')
33+
let hours = date.getHours()
34+
const minutes = String(date.getMinutes()).padStart(2, '0')
35+
const ampm = hours >= 12 ? 'pm' : 'am'
36+
hours = hours % 12 || 12
37+
hours = String(hours).padStart(2, '0')
38+
return `${year}-${month}-${day} ${hours}:${minutes} ${ampm}`
39+
}
40+
3241
const main = async () => {
3342
const [timePast, timeName, timeApi] = time()
34-
const past = moment()
35-
.subtract(timePast, timeName)
36-
.format("YYYY-MM-DD hh:mm a")
43+
const pastDate = new Date()
44+
if (timeName === 'minutes') {
45+
pastDate.setMinutes(pastDate.getMinutes() - timePast)
46+
} else if (timeName === 'hours') {
47+
pastDate.setHours(pastDate.getHours() - timePast)
48+
} else if (timeName === 'days') {
49+
pastDate.setDate(pastDate.getDate() - timePast)
50+
}
51+
const past = formatDate(pastDate)
3752

3853
const fullHistroy = await CryptoCompareAPI.fetchCoinHistory(
3954
timeApi,
@@ -50,10 +65,10 @@ const main = async () => {
5065
const legend = baseLegend + ` since ${past}` + now
5166
const smallLegend = baseLegend + now
5267

53-
const fixed = normalize(max(history))
54-
const fixedHist = map((x) => x.toFixed(fixed))(history).map(Number)
55-
const padding = pad(2 + max(fixedHist).toString().length)("")
56-
const [maxH, minH] = getMinRange(max(fixedHist), min(fixedHist))
68+
const fixed = normalize(Math.max(...history))
69+
const fixedHist = history.map((x) => Number(x.toFixed(fixed)))
70+
const padding = " ".repeat(2 + Math.max(...fixedHist).toString().length)
71+
const [maxH, minH] = getMinRange(Math.max(...fixedHist), Math.min(...fixedHist))
5772
const chart = getTechIndicator(fullHistroy).concat([fixedHist])
5873
try {
5974
print(

0 commit comments

Comments
 (0)