yahoo-exchange
Advanced tools
Comparing version 0.1.3 to 1.0.0-alpha
@@ -10,5 +10,5 @@ "use strict"; | ||
if (err) | ||
errorHandler(err); | ||
errorHandler(err, pair); | ||
else | ||
callback(parseFloat(html.toString().split('react-text: 36 -->')[1].split('<')[0].replace(',', ''))); | ||
callback(parseFloat(html.toString().split('react-text: 36 -->')[1].split('<')[0].replace(',', '')), pair); | ||
}); | ||
@@ -23,5 +23,5 @@ } | ||
if (err) | ||
errorHandler(err); | ||
errorHandler(err, v); | ||
else | ||
callback(parseFloat(html.toString().split('react-text: 36 -->')[1].split('<')[0].replace(',', ''))); | ||
callback(parseFloat(html.toString().split('react-text: 36 -->')[1].split('<')[0].replace(',', '')), v); | ||
})); | ||
@@ -28,0 +28,0 @@ } |
32
index.ts
import request = require("request"); | ||
export function getData(pair: string, callback: (data: number) => any, errorHandler: (error: Error) => any = err => console.log(err)): void { | ||
request({ | ||
url: `https://finance.yahoo.com/quote/${pair}=X?p=${pair}=X`, | ||
encoding: null, | ||
}, (err, response, html) => { | ||
if (err) errorHandler(err); | ||
else callback(parseFloat(html.toString().split('react-text: 36 -->')[1].split('<')[0].replace(',', ''))); | ||
}); | ||
export function getData(pair: string, callback: (data: number, pair?: string) => any, errorHandler: (error: Error, pair?: String) => any = err => console.log(err)): void { | ||
request({ | ||
url: `https://finance.yahoo.com/quote/${pair}=X?p=${pair}=X`, | ||
encoding: null, | ||
}, (err, response, html) => { | ||
if (err) errorHandler(err, pair); | ||
else callback(parseFloat(html.toString().split('react-text: 36 -->')[1].split('<')[0].replace(',', '')), pair); | ||
}); | ||
} | ||
export function getDataArray(pair: Array<string>, callback: (data: number) => any, errorHandler: (error: Error) => any = err => console.log(err)): void { | ||
pair.map( v=>request({ | ||
url: `https://finance.yahoo.com/quote/${v}=X?p=${v}=X`, | ||
encoding: null, | ||
}, (err, response, html) => { | ||
if (err) errorHandler(err); | ||
else callback(parseFloat(html.toString().split('react-text: 36 -->')[1].split('<')[0].replace(',', ''))); | ||
})); | ||
export function getDataArray(pair: Array<string>, callback: (data: number, pair?: string) => any, errorHandler: (error: Error, pair?: String) => any = err => console.log(err)): void { | ||
pair.map(v => request({ | ||
url: `https://finance.yahoo.com/quote/${v}=X?p=${v}=X`, | ||
encoding: null, | ||
}, (err, response, html) => { | ||
if (err) errorHandler(err, v); | ||
else callback(parseFloat(html.toString().split('react-text: 36 -->')[1].split('<')[0].replace(',', '')), v); | ||
})); | ||
} |
@@ -14,3 +14,3 @@ { | ||
"main": "index.js", | ||
"version": "0.1.3", | ||
"version": "1.0.0-alpha", | ||
"license": "MIT", | ||
@@ -17,0 +17,0 @@ "dependencies": { |
@@ -5,12 +5,20 @@ # yahoo-exchange | ||
* ``` javascript | ||
getData('USDKRW', data=>console.log(data)); // 1070 | ||
getData('USDKRW', data => console.log(data)); // 1070 | ||
``` | ||
* ``` javascript | ||
getData('USDKRW', data=>console.log(data), error=>console.log('[Error]' + error)); | ||
getData('USDKRW', data => console.log(data), error => console.log('[Error]' + error)); | ||
// 1070 or [Error] error message | ||
``` | ||
* ``` javascript | ||
getData('USDKRW', (data,pair) => console.log(data,pair), error => console.log('[Error]' + error)); | ||
// 1070 USDRKW or [Error] error message | ||
``` | ||
* ``` javascript | ||
getData('USDKRW', (data,pair) => console.log(data,pair), (error,pair) => console.log(`[Error:${pair}]${error}`)); | ||
// 1070 USDKRW or [Error:USDKRW] error message | ||
``` | ||
## getDataArray(pair, callback, errorHandler): void | ||
### Example | ||
* ``` javascript | ||
getDataArray(['USDKRW', 'JPYKRW'], data=>console.log(data)); | ||
getDataArray(['USDKRW', 'JPYKRW'], dat a=> console.log(data)); | ||
// 1070 | ||
@@ -20,6 +28,16 @@ // 970 | ||
* ``` javascript | ||
getDataArray(['USDKRW', 'JPYKRW'], data=>console.log(data),error=>console.log('[Error]' + error)); | ||
getDataArray(['USDKRW', 'JPYKRW'], data => console.log(data), error => console.log('[Error]' + error)); | ||
// 1070 or [Error] error message | ||
// 970 or [Error] error message | ||
``` | ||
* ``` javascript | ||
getDataArray(['USDKRW', 'JPYKRW'], (data,pair)=>console.log(data, pair)), error => console.log('[Error]' + error)); | ||
// 1070 USDKRW or [Error] error message | ||
// 970 JPYKRW or [Error] error message | ||
``` | ||
* ``` javascript | ||
getDataArray(['USDKRW', 'JPYKRW'], (data,pair)=>console.log(data, pair)), (error,pair) => console.log(`[Error:${pair}]${error}`)); | ||
// 1070 USDKRW or [Error:USDKRW] error message | ||
// 970 JPYKRW or [Error:JPYKRW] error message | ||
``` | ||
### Warning | ||
@@ -30,5 +48,7 @@ getDataArray does not return Array to Callback. | ||
const yahooExchange = require('yahoo-exchange'); | ||
yahooExchange.getData('USDKRW', data => console.log(data)); | ||
yahooExchange.getDataArray(['USDKRW', 'JPYKRW'], data =>console.log(data)); | ||
yahooExchange.getData('USDKRW', (data, pair) => console.log(data, pair)); | ||
yahooExchange.getDataArray(['USDKRW', 'JPYKRW'], (data, pair) => console.log(data, pair)); | ||
``` |
const index = require('../index'); | ||
index.getData('USDKRW', data => { | ||
console.log(data); | ||
}); | ||
index.getDataArray(['USDKRW', 'JPYKRW'], data =>console.log(data)); | ||
index.getData('USDKRW', data => console.log(data)); | ||
index.getDataArray(['USDKRW', 'JPYKRW'], data => console.log(data)); | ||
index.getData('USDKRW', (data, pair) => console.log(data, pair)); | ||
index.getDataArray(['USDKRW', 'JPYKRW'], (data, pair) => console.log(data, pair)); | ||
index.getData('USDKRW', (data, pair) => console.log(data, pair), (error,pair) => console.log(`[Error] ${pair}\n${error}`)); | ||
index.getDataArray(['USDKRW', 'JPYKRW'], (data, pair) => console.log(data, pair), (error,pair) => console.log(`[Error] ${pair}\n${error}`)); |
Sorry, the diff of this file is not supported yet
17110
61
52