mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-13 20:44:16 +00:00
31 lines
774 B
JavaScript
31 lines
774 B
JavaScript
import jscookies from "js-cookie"
|
|
|
|
class InternalStorage {
|
|
#storage = {}
|
|
|
|
get(key) {
|
|
// get value from storage
|
|
return this.#storage[key]
|
|
}
|
|
|
|
set(key, value) {
|
|
// storage securely in memory
|
|
return this.#storage[key] = value
|
|
}
|
|
}
|
|
|
|
export default class Storage {
|
|
static get engine() {
|
|
// check if is running in browser, if is import js-cookie
|
|
// else use in-memory safe storage
|
|
if (typeof window !== "undefined") {
|
|
return jscookies
|
|
}
|
|
|
|
if (!globalThis.__comty_shared_state["_internal_storage"]) {
|
|
globalThis.__comty_shared_state["_internal_storage"] = new InternalStorage()
|
|
}
|
|
|
|
return globalThis.__comty_shared_state["_internal_storage"]
|
|
}
|
|
} |