init crater

This commit is contained in:
Mohit Panjwani
2019-11-11 12:16:00 +05:30
commit bdf2ba51d6
668 changed files with 158503 additions and 0 deletions

View File

@ -0,0 +1,34 @@
class ExpiringStorage {
get (key) {
const cached = JSON.parse(
localStorage.getItem(key)
)
if (!cached) {
return null
}
const expires = new Date(cached.expires)
if (expires < new Date()) {
localStorage.removeItem(key)
return null
}
return cached.value
}
has (key) {
return this.get(key) !== null
}
set (key, value, lifeTimeInMinutes) {
const currentTime = new Date().getTime()
const expires = new Date(currentTime + lifeTimeInMinutes * 60000)
localStorage.setItem(key, JSON.stringify({ value, expires }))
}
}
export default new ExpiringStorage()