src/localStorage.js
export default class LocalStorageMock {
constructor() {
this.store = {};
}
clear() {
this.store = {};
}
getItem(key) {
return this.store[key] || null;
}
removeItem(key) {
delete this.store[key];
}
setItem(key, value) {
if (value) {
this.store[key] = value.toString();
}
}
key(index) {
return Object.keys(this.store)[index];
}
get length() {
return Object.keys(this.store).length;
}
}