yahoo-exchange
Advanced tools
Comparing version 2.0.3 to 2.1.0
18
index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const request = require("request"); | ||
const requestPromise = require("request-promise"); | ||
const arrayLen24 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
@@ -151,2 +152,19 @@ const remove = (str, remove) => { | ||
exports.getExchangeDataArray = getExchangeDataArray; | ||
/** | ||
* This function returns exchange data via Promise. | ||
* @param pair ex) USDKRW, JPYKRW. etc... | ||
*/ | ||
function getExchangeData(pair) { | ||
const pairArray = typeof pair === 'string' ? [pair] : (Array.isArray(pair)) ? pair : null; | ||
return new Promise((resolve, reject) => !!pairArray ? | ||
Promise.all(pairArray.map(pair => new Promise((resolve, reject) => requestPromise({ | ||
url: `https://query2.finance.yahoo.com/v10/finance/quoteSummary/${pair}=X?modules=price`, json: true | ||
}) | ||
.then(data => resolve(parseHTML(data))) | ||
.catch(err => reject([err, pair]))))) | ||
.then((v) => resolve(v)) | ||
.catch(v => resolve(v)) | ||
: reject('A pair must be "string" or "array".')); | ||
} | ||
exports.getExchangeData = getExchangeData; | ||
function getPairArray(currency, base) { | ||
@@ -153,0 +171,0 @@ let list = []; |
22
index.ts
import request = require('request'); | ||
import requestPromise = require('request-promise'); | ||
@@ -125,3 +126,3 @@ const arrayLen24 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
export function getExchangeDataArray(pair: any, callback: (data: Array<number>, pair?: string) => any, errorHandler: (error: Error, pair?: String) => any = err => console.log(err)): void { | ||
export function getExchangeDataArray(pair: any, callback: (data: number[], pair?: string) => any, errorHandler: (error: Error, pair?: String) => any = err => console.log(err)): void { | ||
try { | ||
@@ -136,2 +137,21 @@ if (typeof pair === 'string') req(pair, errorHandler, callback); | ||
/** | ||
* This function returns exchange data via Promise. | ||
* @param pair ex) USDKRW, JPYKRW. etc... | ||
*/ | ||
export function getExchangeData(pair: string | Array<string>): Promise<Array<[number[], string]>> { | ||
const pairArray = typeof pair === 'string' ? [pair] : (Array.isArray(pair)) ? pair : null; | ||
return new Promise((resolve, reject) => !!pairArray ? | ||
Promise.all(pairArray.map(pair => | ||
new Promise((resolve, reject) => | ||
requestPromise({ | ||
url: `https://query2.finance.yahoo.com/v10/finance/quoteSummary/${pair}=X?modules=price`, json: true | ||
}) | ||
.then(data => resolve(parseHTML(data))) | ||
.catch(err => reject([err, pair]))))) | ||
.then((v: [number[], string][]) => resolve(v)) | ||
.catch(v => resolve(v)) | ||
: reject('A pair must be "string" or "array".')); | ||
} | ||
export function getPairArray(currency: Array<string>, base: Array<string>): Array<string> { | ||
@@ -138,0 +158,0 @@ let list: Array<string> = []; |
@@ -14,6 +14,7 @@ { | ||
"main": "index.js", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"license": "MIT", | ||
"dependencies": { | ||
"request": "2.88.0" | ||
"request": "2.88.0", | ||
"request-promise": "latest" | ||
}, | ||
@@ -25,4 +26,4 @@ "repository": { | ||
"devDependencies": { | ||
"@types/node": "10.7.1" | ||
"@types/node": "10.9.4" | ||
} | ||
} |
@@ -10,9 +10,11 @@ # yahoo-exchange 疎開 | ||
[![npm](https://img.shields.io/badge/Readme-日本語-orange.svg?style=flat-square)](https://github.com/Shin-JaeHeon/yahoo-exchange/blob/master/README-JP.md) | ||
> 従来のParserの問題点を解決したバージョンであるyahoo-exchange 2.0.0が発売されました。 | ||
## getExchangeData(pair): Promise<Array<[number[], string]>> | ||
* pair : string または Array\<string\> | ||
* number[] : [Now, Changes, Changes percent, Previous Close, Open, Day's Range Min, Day's Range Max] | ||
* string[] : pair | ||
> 以前のバージョンと互換されません。 | ||
`getExchangeDataArray`と違ってすべての要請が完了するまで待った後Promiseに返還します。 | ||
> deprecatedされたメソッドが除去されました。 | ||
このメソッドは、2018.09.02(KST)に作成されました。 | ||
> Warning : getExchangeDataLowTrafficとgetExchangeDataLowTrafficPがいつもエラーを返還します。 今は使用しないでください。 | ||
## getExchangeDataArray(pair, callback, errorHandler): void | ||
@@ -25,3 +27,3 @@ * pair : string または Array\<string\> | ||
Array\<number\>Kは次のような項目が含まれます。 [Now, Changes, Changes percent, Previous Close, Open, Bid, Ask, Day's Range Min, Day's Range Max, 52 Week Range Min, 52 Week Range Max] | ||
Array\<number\>Kは次のような項目が含まれます。 [Now, Changes, Changes percent, Previous Close, Open, Bid, Ask, Day's Range Min, Day's Range Max] | ||
### 警告 | ||
@@ -72,18 +74,2 @@ getExchangeDataArrayは全体データをコールバック関数で返却しません。 | ||
通貨の記号($など)を返還してくれます。 二つ以上の通貨を付けた場合には3文字ずつ分離して配列に返還します。 | ||
## test.js | ||
* ``` javascript | ||
const yahooExchange = require('yahoo-exchange'); | ||
yahooExchange.getFxYahooJapan(v => console.log(v)); | ||
yahooExchange.getExchangeDataLowTraffic(v => console.log(v)); | ||
yahooExchange.getExchangeDataLowTrafficP().then(v => console.log(v)); | ||
yahooExchange.getExchangeDataArray(['USDKRW', 'JPYKRW'], data => console.log(data)); | ||
yahooExchange.getExchangeDataArray('USDKRW', (data, pair) => console.log(data, pair)); | ||
yahooExchange.getExchangeDataArray(['USDKRW', 'JPYKRW'], (data, pair) => console.log(data, pair)); | ||
yahooExchange.getExchangeDataArray('USDKRW', (data, pair) => console.log(data, pair), (error, pair) => console.log(`[Error] ${pair}\n${error}`)); | ||
yahooExchange.getExchangeDataArray(['USDKRW', 'JPYKRW'], (data, pair) => console.log(data, pair), (error, pair) => console.log(`[Error] ${pair}\n${error}`)); | ||
yahooExchange.getUnit('KRW'); | ||
yahooExchange.getUnit('USDKRWJPYEUR'); | ||
yahooExchange.getPairArray(['USD'], ['KRW', 'JPY']); | ||
``` | ||
### 翻訳の誤りはイッシューに登録してください。 | ||
@@ -90,0 +76,0 @@ ## 使用されたライブラリに対する著作権告知事項 |
@@ -10,9 +10,13 @@ # yahoo-exchange | ||
[![npm](https://img.shields.io/badge/Readme-日本語-orange.svg?style=flat-square)](https://github.com/Shin-JaeHeon/yahoo-exchange/blob/master/README-JP.md) | ||
> 기존 파서의 문제점을 해결한 버전인 yahoo-exchange 2.0.0이 출시되었습니다. | ||
> 이전버전과 호환되지 않습니다. | ||
> deprecated된 메소드가 제거되었습니다. | ||
## getExchangeData(pair): Promise<Array<[number[], string]>> | ||
* pair : string 또는 Array\<string\> | ||
* number[] : [Now, Changes, Changes percent, Previous Close, Open, Day's Range Min, Day's Range Max] | ||
* string[] : pair | ||
> 경고 : getExchangeDataLowTraffic 와 getExchangeDataLowTrafficP가 항상 에러를 반환합니다. 지금은 사용하지 마십시오. | ||
`getExchangeDataArray`와 다르게 모든 요청이 완료될 때까지 기다린 후 Promise로 반환합니다. | ||
이 메소드는 2018년 9월 2일(KST)에 제작되었습니다. | ||
## getExchangeDataArray(pair, callback, errorHandler): void | ||
@@ -25,3 +29,3 @@ > ### v2.0.0 안내 | ||
Array\<number\>는 다음과 같은 항목이 포함됩니다. [Now, Changes, Changes percent, Previous Close, Open, Bid, Ask, Day's Range Min, Day's Range Max, 52 Week Range Min, 52 Week Range Max] | ||
Array\<number\>는 다음과 같은 항목이 포함됩니다. [Now, Changes, Changes percent, Previous Close, Open, Day's Range Min, Day's Range Max] | ||
### 경고 | ||
@@ -68,21 +72,8 @@ getExchangeDataArray는 Callback에 전체 데이터를 넘겨주지 않습니다. | ||
페어 목록을 생성해 줍니다. | ||
## getUnit(currency:string):string | ||
통화의 기호($ 등)을 반환합니다. 두개이상의 통화를 넣을 경우 3글자씩 분리되어 배열로 반환합니다. | ||
## test.js | ||
* ``` javascript | ||
const yahooExchange = require('yahoo-exchange'); | ||
yahooExchange.getFxYahooJapan(v => console.log(v)); | ||
yahooExchange.getExchangeDataLowTraffic(v => console.log(v)); | ||
yahooExchange.getExchangeDataLowTrafficP().then(v => console.log(v)); | ||
yahooExchange.getExchangeDataArray(['USDKRW', 'JPYKRW'], data => console.log(data)); | ||
yahooExchange.getExchangeDataArray('USDKRW', (data, pair) => console.log(data, pair)); | ||
yahooExchange.getExchangeDataArray(['USDKRW', 'JPYKRW'], (data, pair) => console.log(data, pair)); | ||
yahooExchange.getExchangeDataArray('USDKRW', (data, pair) => console.log(data, pair), (error, pair) => console.log(`[Error] ${pair}\n${error}`)); | ||
yahooExchange.getExchangeDataArray(['USDKRW', 'JPYKRW'], (data, pair) => console.log(data, pair), (error, pair) => console.log(`[Error] ${pair}\n${error}`)); | ||
yahooExchange.getUnit('KRW'); | ||
yahooExchange.getUnit('USDKRWJPYEUR'); | ||
yahooExchange.getPairArray(['USD'], ['KRW', 'JPY']); | ||
``` | ||
## 사용된 라이브러리에 대한 저작권 고지 | ||
아래의 라이브러리의 일부 코드가 이 프로젝트에 포함되었습니다. | ||
* [currency-symbol-map](https://github.com/bengourley/currency-symbol-map) |
# yahoo-exchange | ||
[![npm](https://img.shields.io/npm/v/yahoo-exchange.svg?style=flat-square)](https://www.npmjs.com/package/yahoo-exchange) | ||
@@ -10,13 +9,20 @@ [![npm](https://img.shields.io/npm/dt/yahoo-exchange.svg?style=flat-square)](https://www.npmjs.com/package/yahoo-exchange) | ||
[![npm](https://img.shields.io/badge/Readme-日本語-orange.svg?style=flat-square)](https://github.com/Shin-JaeHeon/yahoo-exchange/blob/master/README-JP.md) | ||
> yahoo-exchange 2.0.0, a version that solves the problem of existing parser, has been released. | ||
> Warning : getExchangeDataLowTraffic and getExchangeDataLowTrafficP returns error. Don't use now. | ||
## getExchangeData(pair): Promise<Array<[number[], string]>> | ||
* pair : string or Array\<string\> | ||
* number[] : [Now, Changes, Changes percent, Previous Close, Open, Day's Range Min, Day's Range Max] | ||
* string[] : pair | ||
Unlike `getExchangeDataArray`, it waits for all requests to complete before returning to `Promise`. | ||
This method was created on 2018.09.02(KST) | ||
## getExchangeDataArray(pair, callback, errorHandler): void | ||
* pair : string or Array\<string\> | ||
* callback : (Array\<number\>, pair) => any | ||
* errorHandler : options (A default method is ```console.log(error)```) | ||
* errorHandler : options (A default method is ```console.log(error)```) | ||
> ### Introduction to v2.0.0 | ||
> 52 Week Range Min, 52 Week Range Max, Bid, Ask have been removed from the returned items. | ||
Array\<number\> : [Now, Changes, Changes percent, Previous Close, Open, Bid, Ask, Day's Range Min, Day's Range Max, 52 Week Range Min, 52 Week Range Max] | ||
Array\<number\> : [Now, Changes, Changes percent, Previous Close, Open, Day's Range Min, Day's Range Max] | ||
@@ -64,19 +70,4 @@ ### Warning | ||
It Returns a currency sign or a list of currency sign. | ||
## test.js | ||
* ``` javascript | ||
const yahooExchange = require('yahoo-exchange'); | ||
yahooExchange.getFxYahooJapan(v => console.log(v)); | ||
yahooExchange.getExchangeDataLowTraffic(v => console.log(v)); | ||
yahooExchange.getExchangeDataLowTrafficP().then(v => console.log(v)); | ||
yahooExchange.getExchangeDataArray(['USDKRW', 'JPYKRW'], data => console.log(data)); | ||
yahooExchange.getExchangeDataArray('USDKRW', (data, pair) => console.log(data, pair)); | ||
yahooExchange.getExchangeDataArray(['USDKRW', 'JPYKRW'], (data, pair) => console.log(data, pair)); | ||
yahooExchange.getExchangeDataArray('USDKRW', (data, pair) => console.log(data, pair), (error, pair) => console.log(`[Error] ${pair}\n${error}`)); | ||
yahooExchange.getExchangeDataArray(['USDKRW', 'JPYKRW'], (data, pair) => console.log(data, pair), (error, pair) => console.log(`[Error] ${pair}\n${error}`)); | ||
yahooExchange.getUnit('KRW'); | ||
yahooExchange.getUnit('USDKRWJPYEUR'); | ||
yahooExchange.getPairArray(['USD'], ['KRW', 'JPY']); | ||
``` | ||
## A copyright notice on the library used | ||
Some of the code from the library below has been included in this project. | ||
* [currency-symbol-map](https://github.com/bengourley/currency-symbol-map) |
const index = require('../index'); | ||
index.getFxYahooJapan(v => console.log(v)); | ||
index.getExchangeDataLowTraffic(v => console.log(v)); | ||
index.getExchangeDataLowTrafficP().then(v => console.log(v)); | ||
index.getExchangeDataArray(['USDKRW', 'JPYKRW'], data => console.log(data)); | ||
index.getExchangeDataArray('USDKRW', (data, pair) => console.log(data, pair)); | ||
index.getExchangeDataArray(['USDKRW', 'JPYKRW'], (data, pair) => console.log(data, pair)); | ||
index.getExchangeData(['USDKRW', 'JPYKRW']).then(data => console.log(data)).catch(err => console.log(err)); | ||
index.getExchangeDataArray('USDKRW', (data, pair) => console.log(data, pair), (error, pair) => console.log(`[Error] ${pair}\n${error}`)); | ||
@@ -10,0 +6,0 @@ index.getExchangeDataArray(['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
1079
57731
2
72
+ Addedrequest-promise@latest
+ Addedbluebird@3.7.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedrequest-promise@4.2.6(transitive)
+ Addedrequest-promise-core@1.1.4(transitive)
+ Addedstealthy-require@1.1.1(transitive)