-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
executable file
·30 lines (24 loc) · 1002 Bytes
/
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
#!/usr/bin/env node
const { Command } = require('commander');
const { version } = require("./package.json");
const { first } = require("lodash/fp");
const axios = require("axios");
const print = (string) => process.stdout.write(string + "\n");
const program = new Command();
program
.version(version)
.option("-a, --amount <n>", "number of coins")
.option("-f, --from <string>", "specify the coin to convert from e.g. ETH")
.option("-t, --to <string>", "specify the coin to convert to e.g. BTC")
.parse(process.argv);
const param = program.opts();
const from = param.from ? param.from : "BTC";
const to = param.to ? param.to : "USD";
const api = `https://min-api.cryptocompare.com/data/price?fsym=${from}&tsyms=${to}`;
const main = async () => {
const result = (await axios.get(api)).data;
const val = first(Object.values(result));
const currency = first(Object.keys(result));
return print(val * (param.amount ? param.amount : 1) + " " + currency);
};
main();