Reviewed-on: https://git.ayo.run/ayo/cozy-games/pulls/1 Co-authored-by: Ayo <ayo@ayco.io> Co-committed-by: Ayo <ayo@ayco.io>
23 lines
487 B
JavaScript
23 lines
487 B
JavaScript
export class StorageService {
|
|
|
|
constructor() {
|
|
}
|
|
|
|
saveToLocal(key, value) {
|
|
localStorage.setItem(key, JSON.stringify(value))
|
|
}
|
|
|
|
saveToSession(key, value) {
|
|
sessionStorage.setItem(key, JSON.stringify(value))
|
|
}
|
|
|
|
getFromLocal(key) {
|
|
const data = localStorage.getItem(key)
|
|
if (data !== 'undefined') return JSON.parse(data)
|
|
}
|
|
|
|
getFromSession(key) {
|
|
const data = sessionStorage.getItem(key)
|
|
if (data !== 'undefined') return JSON.parse(data)
|
|
}
|
|
}
|