New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

currency-converter-lt

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

currency-converter-lt - npm Package Compare versions

Comparing version

to
1.3.0

33

index.js
const cheerio = require("cheerio")
const got = require("got")
// FIXME: round upto 2 decimal places
// TODO: Add doc for other functions
class CurrencyConverter {

@@ -179,3 +177,2 @@ currencies = {

}
}

@@ -221,2 +218,15 @@ from (currencyFrom) {

replaceAll(text, queryString, replaceString) {
let text_ = ""
for (let i = 0; i < text.length; i++) {
if (text[i] === queryString){
text_ += replaceString
}
else{
text_ += text[i]
}
}
return text_
}
rates(){

@@ -226,12 +236,5 @@ if(this.currencyFrom === this.currencyTo)

else
return got(`https://www.google.co.in/search?q=${this.currencyAmount}+${this.currencyFrom}+to+${this.currencyTo}`)
return got(`https://www.google.co.in/search?q=${this.currencyAmount}+${this.currencyFrom}+to+${this.currencyTo}+&hl=en`)
.then((html) => {
// const fs = require('fs');
// fs.writeFile("a.html", html.body, function(err) {
// if(err) {
// return console.log(err);
// }
// console.log("The file was saved!")})
return cheerio.load(html.body)})
return cheerio.load(html.body)})
.then(($) => {return $(".iBp4i").text().split(" ")[0]})

@@ -241,9 +244,9 @@ .then((rates) => {

if(rates.includes("."))
rates = rates.replaceAll(".", "")
rates = this.replaceAll(rates, ".", "")
if(rates.includes(","))
rates = rates.replaceAll(",", ".")
rates = this.replaceAll(rates, ",", ".")
}
else{
if(rates.includes(","))
rates = rates.replaceAll(",", "")
rates = this.replaceAll(rates, ",", "")
}

@@ -250,0 +253,0 @@

{
"name": "currency-converter-lt",
"version": "1.2.4",
"version": "1.3.0",
"description": "A nodejs currency converter library that doesn't require subscribing to any API calls.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -47,2 +47,9 @@ <div align="center">

#### <p style='color:magenta'>!!! Note: if you get incorrect conversion described in this [issue](https://github.com/paul-shuvo/nodejs-currency-converter/issues/20) then make sure you pass `isDecimalComma: true` to the constructor as following:</p>
```javascript
let currencyConverter = new CC({from:"USD", to:"JPY", amount:100, isDecimalComma:true})
```
The convert method will return the conversion based on the last conversion rate and can be used as a promise.

@@ -49,0 +56,0 @@

@@ -117,2 +117,16 @@ const chai = require("chai")

describe("replaceAll", () => {
it("should replace all the , with empty space", () => {
assert.equal(currencyConverter.replaceAll("123,456,789.50", ",", ""), "123456789.50")
})
it("should replace all the , with empty .", () => {
assert.equal(currencyConverter.replaceAll("123456789,50", ",", "."), "123456789.50")
})
it("should replace all the . with empty space", () => {
assert.equal(currencyConverter.replaceAll("123.456.789", ".", ""), "123456789")
})
})
describe("rates", () => {

@@ -119,0 +133,0 @@ it("should not return undefined values", () => {