@depay/local-currency
Advanced tools
Comparing version 3.6.1 to 3.7.0
@@ -439,2 +439,10 @@ var timezoneToCurrency = { | ||
static getCacheKey(currency) { | ||
const now = new Date(); | ||
const year = now.getUTCFullYear(); | ||
const month = now.getUTCMonth(); | ||
const day = now.getUTCDate(); | ||
return `@depay/local-currency/v3.6.1/rates/${currency}/${year}-${month}-${day}` | ||
} | ||
static async rate({ from, to }) { | ||
@@ -452,9 +460,20 @@ if(to == undefined) { to = Currency.getCode(); } | ||
let currency = new Currency({ amount, code, timeZone }); | ||
let rate = await fetch('https://public.depay.com/currencies/' + currency.code) | ||
const cacheKey = Currency.getCacheKey(currency.code); | ||
let cachedValue = localStorage.getItem(cacheKey); | ||
let rate; | ||
if(cachedValue) { | ||
rate = cachedValue; | ||
} else { | ||
rate = await fetch('https://public.depay.com/currencies/' + currency.code) | ||
.then((response) => response.json()) | ||
.then((data) => parseFloat(data)) | ||
.catch(()=>{ | ||
.then((data) => { | ||
let value = parseFloat(data); | ||
localStorage.setItem(cacheKey, value); | ||
return value | ||
}) | ||
.catch((e)=>{ | ||
currency.code = "USD"; | ||
return 1 | ||
}); | ||
} | ||
currency.amount = currency.amount * rate; | ||
@@ -461,0 +480,0 @@ return currency |
@@ -445,2 +445,10 @@ (function (global, factory) { | ||
static getCacheKey(currency) { | ||
const now = new Date(); | ||
const year = now.getUTCFullYear(); | ||
const month = now.getUTCMonth(); | ||
const day = now.getUTCDate(); | ||
return `@depay/local-currency/v3.6.1/rates/${currency}/${year}-${month}-${day}` | ||
} | ||
static async rate({ from, to }) { | ||
@@ -458,9 +466,20 @@ if(to == undefined) { to = Currency.getCode(); } | ||
let currency = new Currency({ amount, code, timeZone }); | ||
let rate = await fetch('https://public.depay.com/currencies/' + currency.code) | ||
const cacheKey = Currency.getCacheKey(currency.code); | ||
let cachedValue = localStorage.getItem(cacheKey); | ||
let rate; | ||
if(cachedValue) { | ||
rate = cachedValue; | ||
} else { | ||
rate = await fetch('https://public.depay.com/currencies/' + currency.code) | ||
.then((response) => response.json()) | ||
.then((data) => parseFloat(data)) | ||
.catch(()=>{ | ||
.then((data) => { | ||
let value = parseFloat(data); | ||
localStorage.setItem(cacheKey, value); | ||
return value | ||
}) | ||
.catch((e)=>{ | ||
currency.code = "USD"; | ||
return 1 | ||
}); | ||
} | ||
currency.amount = currency.amount * rate; | ||
@@ -467,0 +486,0 @@ return currency |
{ | ||
"name": "@depay/local-currency", | ||
"moduleName": "LocalCurrency", | ||
"version": "3.6.1", | ||
"version": "3.7.0", | ||
"description": "JavaScript library that detects user's local currency and provides functionalities to convert between multiple currencies.", | ||
@@ -6,0 +6,0 @@ "main": "dist/umd/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34790
987