|
|
|
@ -12,8 +12,22 @@ export const Cache = {
|
|
|
|
|
_generateKey: function (key) { |
|
|
|
|
return Cache._getKeyPrefix() + (key || ""); |
|
|
|
|
}, |
|
|
|
|
getItem: function (key) { |
|
|
|
|
return localStorage.getItem(Cache._generateKey(key)); |
|
|
|
|
getItem: function (key, opt = {}) { |
|
|
|
|
const { defaultValue, typeConversion } = opt; |
|
|
|
|
const storageKey = Cache._generateKey(key); |
|
|
|
|
let value = localStorage.getItem(storageKey); |
|
|
|
|
|
|
|
|
|
if (value !== null && typeConversion) { |
|
|
|
|
if (value === "true") { |
|
|
|
|
value = true; |
|
|
|
|
} else if (value === "false") { |
|
|
|
|
value = false; |
|
|
|
|
} else if (Number.isNaN(Number(value))) { |
|
|
|
|
value = Number(value); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return value !== null ? value : defaultValue; |
|
|
|
|
}, |
|
|
|
|
setItem: function (key, value) { |
|
|
|
|
localStorage.setItem(Cache._generateKey(key), value); |
|
|
|
|