currency-converter-lt
Advanced tools
Comparing version
25
index.js
@@ -164,2 +164,3 @@ const cheerio = require("cheerio") | ||
this.convertedValue = 0 | ||
this.isDecimalComma = false | ||
@@ -175,2 +176,5 @@ if(params != undefined){ | ||
this.amount(params["amount"]) | ||
if(params["isDecimalComma"] !== undefined) | ||
this.setDecimalComma(params["isDecimalComma"]) | ||
} | ||
@@ -210,2 +214,10 @@ | ||
setDecimalComma (isDecimalComma){ | ||
if(typeof isDecimalComma !== "boolean") | ||
throw new TypeError("isDecimalComma should be a boolean") | ||
this.isDecimalComma = isDecimalComma | ||
return this | ||
} | ||
rates(){ | ||
@@ -227,4 +239,13 @@ if(this.currencyFrom === this.currencyTo) | ||
.then((rates) => { | ||
if(rates.includes(",")) | ||
rates = rates.replaceAll(",", "") | ||
if(this.isDecimalComma){ | ||
if(rates.includes(".")) | ||
rates = rates.replaceAll(".", "") | ||
if(rates.includes(",")) | ||
rates = rates.replaceAll(",", ".") | ||
} | ||
else{ | ||
if(rates.includes(",")) | ||
rates = rates.replaceAll(",", "") | ||
} | ||
return parseFloat(rates) | ||
@@ -231,0 +252,0 @@ }) |
{ | ||
"name": "currency-converter-lt", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "A nodejs currency converter library that doesn't require subscribing to any API calls.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -26,2 +26,7 @@ const chai = require("chai") | ||
it("should instantiate an object with json object as a parameter with isDecimalComma", () => { | ||
let CC_ = new CC({from:"GBP", to:"CAD", amount: 100, isDecimalComma: true}) | ||
assert.equal(CC_.currencyFrom, "GBP") | ||
}) | ||
it("should instantiate an object with json object with partial parameters", () => { | ||
@@ -102,2 +107,13 @@ let CC_ = new CC({from:"GBP", amount: 100}) | ||
describe("setDecimalComma", () => { | ||
it("should be true", () => { | ||
currencyConverter.setDecimalComma(true) | ||
assert.equal(currencyConverter.isDecimalComma, true) | ||
}) | ||
it("should throw TypeError", () => { | ||
expect(() => currencyConverter.isDecimalComma("10")).to.throw(TypeError); | ||
}) | ||
}) | ||
describe("rates", () => { | ||
@@ -108,2 +124,7 @@ it("should not return undefined values", () => { | ||
}) | ||
it("should not return undefined values when isDecimalComma is true", () => { | ||
currencyConverter.from("USD").to("JPY").setDecimalComma(true) | ||
return expect(currencyConverter.rates()).to.eventually.not.equal(undefined) | ||
}) | ||
}) | ||
@@ -110,0 +131,0 @@ |
23377
7.38%397
9.37%