Skip to content

Commit 47f22cc

Browse files
committed
Use ES6 & add 'use strict'
1 parent c5a5fb1 commit 47f22cc

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
'use strict'
12
/* global fetch */
23

3-
var baseUrl = 'https://www.cryptocompare.com/api/data/'
4+
const baseUrl = 'https://www.cryptocompare.com/api/data/'
45

56
function fetchJSON (url) {
67
return fetch(url)
@@ -13,22 +14,20 @@ function fetchJSON (url) {
1314
}
1415

1516
function coinList () {
16-
var url = baseUrl + 'coinlist/'
17+
let url = `${baseUrl}coinlist/`
1718
return fetchJSON(url)
1819
}
1920

2021
function price (fsym, tsyms, useBtc) {
21-
if (!Array.isArray(tsyms)) tsyms = [tsyms]
22-
var url = baseUrl + 'price?fsym=' + fsym + '&tsyms=' + tsyms.join(',')
22+
let url = `${baseUrl}price?fsym=${fsym}&tsyms=${tsyms}`
2323
if (useBtc) url += 'usebtc=true'
2424
return fetchJSON(url)
2525
}
2626

2727
function priceHistorical (fsym, tsyms, time) {
28-
if (!Array.isArray(tsyms)) tsyms = [tsyms]
2928
if (!(time instanceof Date)) throw new Error('time parameter must be an instance of Date.')
3029
time = Math.floor(time.getTime() / 1000)
31-
var url = baseUrl + 'pricehistorical?fsym=' + fsym + '&tsyms=' + tsyms.join(',') + '&ts=' + time
30+
let url = `${baseUrl}pricehistorical?fsym=${fsym}&tsyms=${tsyms}&ts=${time}`
3231
return fetchJSON(url)
3332
}
3433

test/cryptocompare.test.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
var test = require('tape')
1+
'use strict'
2+
const test = require('tape')
23

34
// set to global
45
global.fetch = require('node-fetch')
5-
var cc = require('../')
6+
const cc = require('../')
67

7-
test('coinList()', function (t) {
8+
test('coinList()', t => {
89
t.plan(1)
910
cc.coinList().then(coinList => {
1011
t.strictEqual(coinList.BTC.CoinName, 'Bitcoin', 'CoinName field should be Bitcoin')
1112
}).catch(t.end)
1213
})
1314

14-
test('price()', function (t) {
15+
test('price()', t => {
1516
t.plan(4)
1617
cc.price('BTC', ['USD', 'CNY']).then(prices => {
1718
t.strictEqual(prices[0].Symbol, 'USD', 'prices[0].Symbol === USD')
@@ -22,10 +23,10 @@ test('price()', function (t) {
2223
}).catch(t.end)
2324
})
2425

25-
test('priceHistorical()', function (t) {
26+
test('priceHistorical()', t => {
2627
t.plan(5)
2728
// Arbitrary timestamp; historical values are hard-coded into this test
28-
var timestamp = new Date(1456149600 * 1000)
29+
const timestamp = new Date(1456149600 * 1000)
2930
cc.priceHistorical('BTC', ['USD', 'CNY'], timestamp).then(prices => {
3031
t.strictEqual(prices[0].Symbol, 'USD', 'prices[0].Symbol === USD')
3132
t.strictEqual(typeof prices[0].Price, 'number', 'prices[0].Price is a number')

0 commit comments

Comments
 (0)