Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Use arrow functions
Browse files Browse the repository at this point in the history
  • Loading branch information
renefs committed Feb 23, 2021
1 parent fe4137a commit 55e643b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ Node.js API to scrape stock prices from Yahoo Finance.

[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/bocabitlabs/yahoo-stock-prices-fetch)

This is a fork from [yahoo-stock-prices](https://github.com/darthbatman/yahoo-stock-prices) which includes 2 main differences:
This is a fork from [yahoo-stock-prices](https://github.com/darthbatman/yahoo-stock-prices) which includes 3 main differences:

1. Uses fetch instead of the npm `request` package.
2. Has support for `CORS` (Being the default `no-cors`)
3. It's writen in Typescript

This 2 options together make this module **compatible with React and Electron renderer**.

Expand Down
15 changes: 7 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const baseUrl = "https://finance.yahoo.com/quote/";
*
* @return {Promise<{date: number, open: number, high:number, low:number, close:number, volume:number, adjclose:number}[]>|undefined} Returns a promise if no callback was supplied.
*/
export const getHistoricalPrices = function (
export const getHistoricalPrices = (
startMonth: number,
startDay: number,
startYear: number,
Expand All @@ -24,7 +24,7 @@ export const getHistoricalPrices = function (
frequency: "1d" | "1wk" | "1mo",
callback: Function,
cors: "no-cors" | "cors" | "navigate" | "same-origin" | undefined = "no-cors"
) {
) => {
const startDate = Math.floor(
Date.UTC(startYear, startMonth, startDay, 0, 0, 0) / 1000
);
Expand Down Expand Up @@ -77,10 +77,10 @@ export const getHistoricalPrices = function (
*
* @return {Promise<{price: number, currency: string}>}
*/
export const getCurrentData = function (
export const getCurrentData = (
ticker: string,
cors: "no-cors" | "cors" | "navigate" | "same-origin" | undefined = "no-cors"
) {
) => {
return new Promise((resolve, reject) => {
let requestOptions: RequestInit = {
method: "GET",
Expand All @@ -90,7 +90,6 @@ export const getCurrentData = function (
fetch(`${baseUrl + ticker}/`, requestOptions)
.then((response) => response.text())
.then((result) => {
console.log(result);
let priceText = result
.split(`"${ticker}":{"sourceInterval"`)[1]
.split("regularMarketPrice")[1]
Expand Down Expand Up @@ -122,11 +121,11 @@ export const getCurrentData = function (
*
* @return {Promise<number>|undefined} Returns a promise if no callback was supplied.
*/
export const getCurrentPrice = function (
export const getCurrentPrice = (
ticker: string,
callback: Function,
callback: Function|undefined = undefined,
cors: "no-cors" | "cors" | "navigate" | "same-origin" | undefined = "no-cors"
) {
) => {
if (callback) {
getCurrentData(ticker, cors)
.then((data: any) => callback(null, data.price))
Expand Down

0 comments on commit 55e643b

Please sign in to comment.