stock-info
Advanced tools
Comparing version 1.0.3 to 1.1.0
43
index.js
@@ -1,2 +0,2 @@ | ||
const http = require('http'); | ||
const axios = require('axios'); | ||
@@ -12,30 +12,19 @@ const getSingleStockInfo = stock => | ||
const options = { | ||
hostname: 'query1.finance.yahoo.com', | ||
path: `/v7/finance/quote?symbols=${stock}`, | ||
}; | ||
const url = `https://query1.finance.yahoo.com/v7/finance/quote?symbols=${stock}`; | ||
return http.get(options, (res) => { | ||
let data = ''; | ||
res.setEncoding('utf-8'); | ||
res.on('data', (chunk) => { | ||
data += chunk; | ||
}); | ||
res.on('end', () => { | ||
try { | ||
data = JSON.parse(data); | ||
if ( | ||
!data || | ||
!data.quoteResponse || | ||
!data.quoteResponse.result || | ||
data.quoteResponse.result.length === 0 | ||
) { | ||
return reject(new Error(`Error retrieving info for symbol ${stock}`)); | ||
} | ||
return resolve(data.quoteResponse.result[0]); | ||
} catch (err) { | ||
return reject(err); | ||
return axios | ||
.get(url) | ||
.then((res) => { | ||
const { data } = res; | ||
if ( | ||
!data || | ||
!data.quoteResponse || | ||
!data.quoteResponse.result || | ||
data.quoteResponse.result.length === 0 | ||
) { | ||
return reject(new Error(`Error retrieving info for symbol ${stock}`)); | ||
} | ||
}); | ||
}); | ||
return resolve(data.quoteResponse.result[0]); | ||
}) | ||
.catch(err => reject(err)); | ||
}); | ||
@@ -42,0 +31,0 @@ |
{ | ||
"name": "stock-info", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Node.js module to retrieve stock information from Yahoo Finance API", | ||
@@ -9,3 +9,8 @@ "main": "index.js", | ||
}, | ||
"keywords": ["stock", "price", "value", "information"], | ||
"keywords": [ | ||
"stock", | ||
"price", | ||
"value", | ||
"information" | ||
], | ||
"repository": "luizjr92/stock-value", | ||
@@ -23,3 +28,6 @@ "author": { | ||
"mocha": "^5.2.0" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.18.0" | ||
} | ||
} |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
0
6589
1
70
+ Addedaxios@^0.18.0
+ Addedaxios@0.18.1(transitive)
+ Addedfollow-redirects@1.5.10(transitive)
+ Addedis-buffer@2.0.5(transitive)