From 47f22cc0cbb4b1a6aab9df8f00f1e73580504633 Mon Sep 17 00:00:00 2001 From: RyanZim Date: Tue, 21 Feb 2017 09:52:44 -0500 Subject: [PATCH] Use ES6 & add 'use strict' --- index.js | 11 +++++------ test/cryptocompare.test.js | 13 +++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index fc8887e..9643e48 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ +'use strict' /* global fetch */ -var baseUrl = 'https://www.cryptocompare.com/api/data/' +const baseUrl = 'https://www.cryptocompare.com/api/data/' function fetchJSON (url) { return fetch(url) @@ -13,22 +14,20 @@ function fetchJSON (url) { } function coinList () { - var url = baseUrl + 'coinlist/' + let url = `${baseUrl}coinlist/` return fetchJSON(url) } function price (fsym, tsyms, useBtc) { - if (!Array.isArray(tsyms)) tsyms = [tsyms] - var url = baseUrl + 'price?fsym=' + fsym + '&tsyms=' + tsyms.join(',') + let url = `${baseUrl}price?fsym=${fsym}&tsyms=${tsyms}` if (useBtc) url += 'usebtc=true' return fetchJSON(url) } function priceHistorical (fsym, tsyms, time) { - if (!Array.isArray(tsyms)) tsyms = [tsyms] if (!(time instanceof Date)) throw new Error('time parameter must be an instance of Date.') time = Math.floor(time.getTime() / 1000) - var url = baseUrl + 'pricehistorical?fsym=' + fsym + '&tsyms=' + tsyms.join(',') + '&ts=' + time + let url = `${baseUrl}pricehistorical?fsym=${fsym}&tsyms=${tsyms}&ts=${time}` return fetchJSON(url) } diff --git a/test/cryptocompare.test.js b/test/cryptocompare.test.js index bc40b69..2e8ba5e 100644 --- a/test/cryptocompare.test.js +++ b/test/cryptocompare.test.js @@ -1,17 +1,18 @@ -var test = require('tape') +'use strict' +const test = require('tape') // set to global global.fetch = require('node-fetch') -var cc = require('../') +const cc = require('../') -test('coinList()', function (t) { +test('coinList()', t => { t.plan(1) cc.coinList().then(coinList => { t.strictEqual(coinList.BTC.CoinName, 'Bitcoin', 'CoinName field should be Bitcoin') }).catch(t.end) }) -test('price()', function (t) { +test('price()', t => { t.plan(4) cc.price('BTC', ['USD', 'CNY']).then(prices => { t.strictEqual(prices[0].Symbol, 'USD', 'prices[0].Symbol === USD') @@ -22,10 +23,10 @@ test('price()', function (t) { }).catch(t.end) }) -test('priceHistorical()', function (t) { +test('priceHistorical()', t => { t.plan(5) // Arbitrary timestamp; historical values are hard-coded into this test - var timestamp = new Date(1456149600 * 1000) + const timestamp = new Date(1456149600 * 1000) cc.priceHistorical('BTC', ['USD', 'CNY'], timestamp).then(prices => { t.strictEqual(prices[0].Symbol, 'USD', 'prices[0].Symbol === USD') t.strictEqual(typeof prices[0].Price, 'number', 'prices[0].Price is a number')