yahoo-exchange
Advanced tools
Comparing version 1.7.1 to 1.7.2
44
index.js
@@ -12,7 +12,9 @@ "use strict"; | ||
const parseHTML = html => parseR(html.toString())(36); | ||
const getJSON = data => name => data[name]; | ||
const parseHTML2 = (html) => { | ||
const list = []; | ||
html = html['quoteSummary'].result[0]; | ||
const previousClose = html['summaryDetail']['previousClose'].raw; | ||
const open = html['summaryDetail']['open'].raw; | ||
const sd = getJSON(getJSON(html)('summaryDetail')); | ||
const previousClose = sd('previousClose').raw; | ||
const open = sd('open').raw; | ||
list.push((previousClose + open) / 2); | ||
@@ -23,8 +25,8 @@ list.push(html['price']['regularMarketChange'].raw); | ||
list.push(open); | ||
list.push(html['summaryDetail']['bid'].raw); | ||
list.push(html['summaryDetail']['ask'].raw); | ||
list.push(html['summaryDetail']['dayLow'].raw); | ||
list.push(html['summaryDetail']['dayHigh'].raw); | ||
list.push(html['summaryDetail']['fiftyTwoWeekLow'].raw); | ||
list.push(html['summaryDetail']['fiftyTwoWeekHigh'].raw); | ||
list.push(sd('bid').raw); | ||
list.push(sd('ask').raw); | ||
list.push(sd('dayLow').raw); | ||
list.push(sd('dayHigh').raw); | ||
list.push(sd('fiftyTwoWeekLow').raw); | ||
list.push(sd('fiftyTwoWeekHigh').raw); | ||
return list; | ||
@@ -204,5 +206,4 @@ }; | ||
exports.getPairArray = getPairArray; | ||
function getUnit(currency) { | ||
currency = currency.trim(); | ||
if (currency.length === 3) { | ||
const whatCurrency = currency => { | ||
{ | ||
switch (currency) { | ||
@@ -556,8 +557,23 @@ case 'AED': | ||
default: | ||
return null; | ||
return undefined; | ||
} | ||
} | ||
else | ||
return undefined; | ||
}; | ||
function getUnit(currency) { | ||
currency = currency.trim().toUpperCase(); | ||
if (currency.length === 3) | ||
return whatCurrency(currency); | ||
else { | ||
let temp = ""; | ||
let list = []; | ||
for (let a of currency) { | ||
temp += a; | ||
if (temp.length === 3) { | ||
list.push(whatCurrency(temp)); | ||
temp = ""; | ||
} | ||
} | ||
return list; | ||
} | ||
} | ||
exports.getUnit = getUnit; |
44
index.ts
@@ -10,7 +10,9 @@ import request = require('request'); | ||
const parseHTML = html => parseR(html.toString())(36); | ||
const getJSON = data => name => data[name]; | ||
const parseHTML2 = (html: Object) => { | ||
const list = []; | ||
html = html['quoteSummary'].result[0]; | ||
const previousClose = html['summaryDetail']['previousClose'].raw; | ||
const open = html['summaryDetail']['open'].raw; | ||
const sd = getJSON(getJSON(html)('summaryDetail')); | ||
const previousClose = sd('previousClose').raw; | ||
const open = sd('open').raw; | ||
list.push((previousClose + open) / 2); | ||
@@ -21,8 +23,8 @@ list.push(html['price']['regularMarketChange'].raw); | ||
list.push(open); | ||
list.push(html['summaryDetail']['bid'].raw); | ||
list.push(html['summaryDetail']['ask'].raw); | ||
list.push(html['summaryDetail']['dayLow'].raw); | ||
list.push(html['summaryDetail']['dayHigh'].raw); | ||
list.push(html['summaryDetail']['fiftyTwoWeekLow'].raw); | ||
list.push(html['summaryDetail']['fiftyTwoWeekHigh'].raw); | ||
list.push(sd('bid').raw); | ||
list.push(sd('ask').raw); | ||
list.push(sd('dayLow').raw); | ||
list.push(sd('dayHigh').raw); | ||
list.push(sd('fiftyTwoWeekLow').raw); | ||
list.push(sd('fiftyTwoWeekHigh').raw); | ||
return list; | ||
@@ -49,3 +51,2 @@ }; | ||
export function getExchangeDataLowTrafficP(): Promise<Array<Array<any>>> { | ||
return new Promise<Array<Array<any>>>(((resolve, reject) => request({ | ||
@@ -188,5 +189,4 @@ url: 'https://finance.yahoo.com/currencies', | ||
export function getUnit(currency: string): string { | ||
currency = currency.trim(); | ||
if (currency.length === 3) { | ||
const whatCurrency = currency => { | ||
{ | ||
switch (currency) { | ||
@@ -540,6 +540,22 @@ case 'AED': | ||
default: | ||
return null; | ||
return undefined; | ||
} | ||
} else return undefined; | ||
} | ||
}; | ||
export function getUnit(currency: string): any { | ||
currency = currency.trim().toUpperCase(); | ||
if (currency.length === 3) return whatCurrency(currency); | ||
else { | ||
let temp = ""; | ||
let list = []; | ||
for (let a of currency) { | ||
temp += a; | ||
if (temp.length === 3) { | ||
list.push(whatCurrency(temp)); | ||
temp = ""; | ||
} | ||
} | ||
return list; | ||
} | ||
} |
@@ -14,3 +14,3 @@ { | ||
"main": "index.js", | ||
"version": "1.7.1", | ||
"version": "1.7.2", | ||
"license": "MIT", | ||
@@ -25,4 +25,4 @@ "dependencies": { | ||
"devDependencies": { | ||
"@types/node": "^9.4.7" | ||
"@types/node": "^10.0.8" | ||
} | ||
} |
@@ -149,8 +149,11 @@ # yahoo-exchange 疎開 | ||
## getUnit(currency:string):string | ||
通貨の記号($など)を返還してくれます。 | ||
通貨の記号($など)を返還してくれます。 二つ以上の通貨を付けた場合には3文字ずつ分離して配列に返還します。 | ||
### Example | ||
* ``` javascript | ||
const currency = 'USD'; | ||
const currency2 = 'USDKRW'; | ||
getUnit(currency); | ||
// '$'; | ||
getUnit(currency2); | ||
// '$' | ||
// [ '$', '₩' ] | ||
``` | ||
@@ -157,0 +160,0 @@ |
@@ -149,8 +149,11 @@ # yahoo-exchange 소개 | ||
## getUnit(currency:string):string | ||
통화의 기호($ 등)을 반환합니다. | ||
통화의 기호($ 등)을 반환합니다. 두개이상의 통화를 넣을 경우 3글자씩 분리되어 배열로 반환합니다. | ||
### Example | ||
* ``` javascript | ||
const currency = 'USD'; | ||
const currency2 = 'USDKRW'; | ||
getUnit(currency); | ||
// '$'; | ||
getUnit(currency2); | ||
// '$' | ||
// [ '$', '₩' ] | ||
@@ -157,0 +160,0 @@ ## getData(pair, callback, errorHandler): void @deprecated |
@@ -138,3 +138,3 @@ # yahoo-exchange | ||
## getPairArray(currency: Array<string>, base: Array<string>): Array<string> | ||
It Returns a pair array. | ||
It returns a pair array. | ||
### Example | ||
@@ -147,9 +147,12 @@ * ``` javascript | ||
``` | ||
## getUnit(currency:string):string | ||
It Returns a symbol of currency | ||
## getUnit(currency:string):string or Array<string> | ||
It Returns a currency sign or a list of currency sign | ||
### Example | ||
* ``` javascript | ||
const currency = 'USD'; | ||
const currency2 = 'USDKRW'; | ||
getUnit(currency); | ||
getUnit(currency2); | ||
// '$'; | ||
// [ '$', '₩' ] | ||
``` | ||
@@ -156,0 +159,0 @@ |
@@ -12,2 +12,3 @@ const index = require('../index'); | ||
index.getUnit('KRW'); | ||
index.getUnit('USDKRWJPYEUR'); | ||
index.getPairArray(['USD'], ['KRW', 'JPY']); |
Sorry, the diff of this file is not supported yet
78371
1140
178