-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCStorage.js
More file actions
29 lines (29 loc) · 749 Bytes
/
CStorage.js
File metadata and controls
29 lines (29 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class CStorage {
static #storage = {}
static #identifer = document.location.href
static init() {
if (localStorage.getItem(this.#identifer) === null) {
this.#update()
} else {
this.#storage = JSON.parse(localStorage.getItem(this.#identifer))
}
}
static clear() {
this.#storage = {}
this.#update()
}
static setItem(key, value) {
this.#storage[key] = value
this.#update()
}
static removeItem(key) {
delete this.#storage[key]
this.#update()
}
static getItem(key) {
return this.#storage[key]
}
static #update() {
localStorage.setItem(this.#identifer, JSON.stringify(this.#storage))
}
}