google-stocks-watch
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -18,12 +18,12 @@ 'use strict'; | ||
var GoogleStocksWatch = (function () { | ||
function GoogleStocksWatch(_x, callback) { | ||
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
function GoogleStocksWatch(options, callback) { | ||
if (options === undefined) options = {}; | ||
var _ref$stocks = _ref.stocks; | ||
var stocks = _ref$stocks === undefined ? {} : _ref$stocks; | ||
var _ref$timerInterval = _ref.timerInterval; | ||
var timerInterval = _ref$timerInterval === undefined ? 10000 : _ref$timerInterval; | ||
_classCallCheck(this, GoogleStocksWatch); | ||
var _options$stocks = options.stocks; | ||
var stocks = _options$stocks === undefined ? {} : _options$stocks; | ||
var _options$timerInterval = options.timerInterval; | ||
var timerInterval = _options$timerInterval === undefined ? 10000 : _options$timerInterval; | ||
if (!callback) { | ||
@@ -57,3 +57,3 @@ throw 'google-stocks-watch: callback is not passed'; | ||
data.forEach(function (dataObj) { | ||
result.push(_this._onParse(dataObj)); | ||
return result.push(_this._onParse(dataObj)); | ||
}); | ||
@@ -68,3 +68,3 @@ | ||
_googleStocks2['default'].get(this._stockCodes, function (error, data) { | ||
(0, _googleStocks2['default'])(this._stockCodes, function (error, data) { | ||
if (error) { | ||
@@ -74,5 +74,3 @@ return _this2._callback(error); | ||
data = _this2._process(data); | ||
_this2._callback(undefined, data); | ||
_this2._callback(undefined, _this2._process(data)); | ||
}); | ||
@@ -83,12 +81,12 @@ } | ||
value: function _onParse() { | ||
var _ref2 = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var code = options.t; | ||
var currentPrice = options.l; | ||
var current_time = options.lt; | ||
var stockCode = _ref2.t; | ||
var currentPrice = _ref2.l; | ||
var currentTime = _ref2.lt; | ||
var _ref = this._stocks[code] || {}; | ||
var _ref3 = this._stocks[stockCode] || {}; | ||
var stockAmount = _ref.amount; | ||
var initialPrice = _ref.price; | ||
var stockAmount = _ref3.amount; | ||
var initialPrice = _ref3.price; | ||
var currentTotalPrice = currentPrice * stockAmount; | ||
@@ -98,6 +96,8 @@ var purchasedTotalPrice = stockAmount * initialPrice; | ||
var percentage = (difference / purchasedTotalPrice * 100).toFixed(2); | ||
return { | ||
code: stockCode, | ||
code: code, | ||
amount: stockAmount, | ||
current_time: currentTime, | ||
current_time: current_time, | ||
current_price: currentPrice, | ||
@@ -108,3 +108,3 @@ current_total_price: currentTotalPrice.toFixed(2), | ||
diff: difference.toFixed(2), | ||
percentage: (difference / purchasedTotalPrice * 100).toFixed(2) + '%' | ||
percentage: percentage + '%' | ||
}; | ||
@@ -142,3 +142,2 @@ } | ||
exports['default'] = GoogleStocksWatch; | ||
; | ||
module.exports = exports['default']; |
{ | ||
"name": "google-stocks-watch", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"author": "anvk", | ||
@@ -14,3 +14,9 @@ "main": "dist/google-stocks-watch.js", | ||
"scripts": { | ||
"test": "node node_modules/mocha/bin/mocha --reporter spec test/*" | ||
"lint": "eslint src", | ||
"build:source": "rimraf dist/ && babel src/ --out-dir dist/", | ||
"build:tests": "rimraf test-dist/ && babel test/ --out-dir test-dist/", | ||
"clean": "rimraf dist/ && rimraf test-dist/", | ||
"build": "npm run build:source && npm run build:tests", | ||
"test": "node node_modules/mocha/bin/mocha --reporter spec test-dist/*", | ||
"example": "node example.js" | ||
}, | ||
@@ -31,12 +37,13 @@ "directories": { | ||
"dependencies": { | ||
"google-stocks": "0.1.4" | ||
"google-stocks": "0.2.0" | ||
}, | ||
"devDependencies": { | ||
"clear": "0.0.1", | ||
"babel": "5.6.5", | ||
"babel-eslint": "5.0.0", | ||
"chai": "3.0.0", | ||
"gulp": "3.9.0", | ||
"gulp-babel": "5.1.0", | ||
"gulp-mocha": "2.1.2", | ||
"mocha": "2.2.5" | ||
"clear": "0.0.1", | ||
"eslint": "2.2.0", | ||
"eslint-config-airbnb": "6.0.2", | ||
"mocha": "2.2.5", | ||
"rimraf": "2.5.2" | ||
}, | ||
@@ -43,0 +50,0 @@ "engine": "node >= 0.10.x", |
@@ -93,3 +93,3 @@ # google-stocks-watch [![Build Status](https://travis-ci.org/anvk/google-stocks-watch.svg?branch=master)](https://travis-ci.org/anvk/google-stocks-watch) | ||
``` | ||
node example.js | ||
npm run example | ||
``` | ||
@@ -100,3 +100,1 @@ | ||
MIT license; see [LICENSE](./LICENSE). | ||
(c) 2015 by Alexey Novak |
@@ -1,3 +0,1 @@ | ||
'use strict'; | ||
import googleStocks from 'google-stocks'; | ||
@@ -7,3 +5,8 @@ | ||
constructor({stocks = {}, timerInterval = 10000} = {}, callback) { | ||
constructor(options = {}, callback) { | ||
const { | ||
stocks = {}, | ||
timerInterval = 10000 | ||
} = options; | ||
if (!callback) { | ||
@@ -30,5 +33,3 @@ throw 'google-stocks-watch: callback is not passed'; | ||
// cannot use for...of loop since it is supported only in Node > 0.12 | ||
data.forEach(dataObj => { | ||
result.push(this._onParse(dataObj)); | ||
}); | ||
data.forEach(dataObj => result.push(this._onParse(dataObj))); | ||
@@ -39,3 +40,3 @@ return result; | ||
_tick() { | ||
googleStocks.get(this._stockCodes, (error, data) => { | ||
googleStocks(this._stockCodes, (error, data) => { | ||
if (error) { | ||
@@ -45,18 +46,28 @@ return this._callback(error); | ||
data = this._process(data); | ||
this._callback(undefined, data); | ||
this._callback(undefined, this._process(data)); | ||
}); | ||
} | ||
_onParse({t: stockCode, l: currentPrice, lt: currentTime} = {}) { | ||
let {amount: stockAmount, price: initialPrice} = this._stocks[stockCode] || {}, | ||
currentTotalPrice = currentPrice * stockAmount, | ||
purchasedTotalPrice = stockAmount * initialPrice, | ||
difference = currentTotalPrice - purchasedTotalPrice; | ||
_onParse(options = {}) { | ||
const { | ||
t: code, | ||
l: currentPrice, | ||
lt: current_time | ||
} = options; | ||
const { | ||
amount: stockAmount, | ||
price: initialPrice | ||
} = this._stocks[code] || {}; | ||
const currentTotalPrice = currentPrice * stockAmount; | ||
const purchasedTotalPrice = stockAmount * initialPrice; | ||
const difference = currentTotalPrice - purchasedTotalPrice; | ||
const percentage = ((difference / purchasedTotalPrice) * 100).toFixed(2); | ||
return { | ||
code: stockCode, | ||
code, | ||
amount: stockAmount, | ||
current_time: currentTime, | ||
current_time, | ||
current_price: currentPrice, | ||
@@ -67,3 +78,3 @@ current_total_price: currentTotalPrice.toFixed(2), | ||
diff: difference.toFixed(2), | ||
percentage: ((difference / purchasedTotalPrice) * 100).toFixed(2) + '%' | ||
percentage: `${percentage}%` | ||
}; | ||
@@ -92,2 +103,2 @@ } | ||
} | ||
}; | ||
} |
@@ -1,13 +0,5 @@ | ||
/* global it, describe, require */ | ||
import { expect } from 'chai'; | ||
var chai = require('chai'), | ||
expect = chai.expect, | ||
utils = require('../dist/google-stocks-watch.js'); | ||
describe('utils tests', function() { | ||
it('meh', function() { | ||
expect(true).to.be.true; | ||
}); | ||
describe('utils tests', () => { | ||
it('Need to write proper tests', () => expect(true).to.be.true); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13729
11
8
221
99
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedasap@2.0.6(transitive)
+ Addedasn1@0.1.11(transitive)
+ Addedassert-plus@0.1.5(transitive)
+ Addedasync@0.9.2(transitive)
+ Addedaws-sign2@0.5.0(transitive)
+ Addedbl@0.9.5(transitive)
+ Addedbluebird@2.11.0(transitive)
+ Addedboom@2.10.1(transitive)
+ Addedcaseless@0.9.0(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcombined-stream@0.0.7(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcryptiles@2.0.5(transitive)
+ Addedctype@0.5.3(transitive)
+ Addeddelayed-stream@0.0.5(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedform-data@0.2.0(transitive)
+ Addedgenerate-function@2.3.1(transitive)
+ Addedgenerate-object-property@1.2.0(transitive)
+ Addedgoogle-stocks@0.2.0(transitive)
+ Addedhar-validator@1.8.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhawk@2.3.1(transitive)
+ Addedhoek@2.16.3(transitive)
+ Addedhttp-signature@0.10.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-my-ip-valid@1.0.1(transitive)
+ Addedis-my-json-valid@2.20.6(transitive)
+ Addedis-property@1.0.2(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedjsonpointer@5.0.1(transitive)
+ Addedmime-db@1.12.0(transitive)
+ Addedmime-types@2.0.14(transitive)
+ Addednode-uuid@1.4.8(transitive)
+ Addedoauth-sign@0.6.0(transitive)
+ Addedpromise@7.1.1(transitive)
+ Addedqs@2.4.2(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedrequest@2.55.0(transitive)
+ Addedsntp@1.0.9(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedstringstream@0.0.6(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedtldts@6.1.64(transitive)
+ Addedtldts-core@6.1.64(transitive)
+ Addedtough-cookie@5.0.0(transitive)
+ Addedtunnel-agent@0.4.3(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedgoogle-stocks@0.1.4(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.13.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
Updatedgoogle-stocks@0.2.0