Skip to content

Commit

Permalink
removed whitespace changes
Browse files Browse the repository at this point in the history
  • Loading branch information
marneborn committed Oct 11, 2022
1 parent 36ed428 commit 6b56f68
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class CurrencyConverter {

if(params["to"] !== undefined)
this.to(params["to"])

if(params["amount"] !== undefined)
this.amount(params["amount"])

Expand All @@ -179,7 +179,7 @@ class CurrencyConverter {
from (currencyFrom) {
if(typeof currencyFrom !== "string")
throw new TypeError("currency code should be a string")

if(!this.currencyCode.includes(currencyFrom.toUpperCase()))
throw new Error(`${currencyFrom} is not a valid currency code`)

Expand All @@ -202,15 +202,15 @@ class CurrencyConverter {

if(currencyAmount <= 0)
throw new Error("amount should be a positive number")

this.currencyAmount = currencyAmount
return this
}

setDecimalComma (isDecimalComma){
if(typeof isDecimalComma !== "boolean")
throw new TypeError("isDecimalComma should be a boolean")

this.isDecimalComma = isDecimalComma
return this
}
Expand All @@ -231,13 +231,12 @@ class CurrencyConverter {
rates(){
if(this.currencyFrom === this.currencyTo)
return new Promise((resolve, _) => {resolve(this.currencyAmount) })
else
else
return got(`https://www.google.co.in/search?q=${this.currencyAmount}+${this.currencyFrom}+to+${this.currencyTo}+&hl=en`)
.then((html) => {
return cheerio.load(html.body)})
.then(($) => {return $(".iBp4i").text().split(" ")[0]})
.then((rates) => {
console.log('b', rates);
.then((rates) => {
if(this.isDecimalComma){
if(rates.includes("."))
rates = this.replaceAll(rates, ".", "")
Expand Down Expand Up @@ -268,21 +267,20 @@ class CurrencyConverter {
throw new Error("currency amount should be a positive value")

return this.rates().then((rates) =>{
console.log('a', rates);
// this.convertedValue = rates * this.currencyAmount

// as the google result now sends the exact converted
// currency, multiplying the rates with currencyAmount
// makes it redundant.
this.convertedValue = rates * 1
// as the google result now sends the exact converted
// currency, multiplying the rates with currencyAmount
// makes it redundant.
this.convertedValue = rates * 1
return this.convertedValue
})
}

currencyName(currencyCode_){
if(typeof currencyCode_ != "string")
throw new TypeError("currency code should be a string")

if(!this.currencyCode.includes(currencyCode_.toUpperCase()))
throw new Error(`${currencyCode_} is not a valid currency code`)

Expand Down

0 comments on commit 6b56f68

Please sign in to comment.