Created
July 10, 2022 23:23
-
-
Save pfftdammitchris/43de51b02a6b0399381da6202d688f0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LocalStorage { | |
#data = {} | |
static _instance = null | |
static getInstance(options) { | |
if (!LocalStorage._instance) { | |
LocalStorage._instance = new LocalStorage(options) | |
} | |
return LocalStorage._instance | |
} | |
constructor(options) { | |
this.options = options || {} | |
} | |
get(key) { | |
return this.#data[key] | |
} | |
set(key, value) { | |
this.#data[key] = value | |
} | |
remove(key) { | |
delete this.#data[key] | |
} | |
clear() { | |
this.#data = {} | |
} | |
} | |
const localStorage = new LocalStorage() | |
Object.freeze(localStorage) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment