UNPKG

@authduo/authduo

Version:

Free User-sovereign Authentication for the World

29 lines 741 B
import { ev, pubsub } from "@benev/slate"; export class JsonStorage { key; storage; onChangeFromOutside = pubsub(); dispose; constructor(key, storage = window.localStorage) { this.key = key; this.storage = storage; this.dispose = ev(window, { storage: () => this.onChangeFromOutside.publish(this.get()), }); } set(data) { this.storage.setItem(this.key, JSON.stringify(data)); } get() { const string = this.storage.getItem(this.key); try { return (string) ? JSON.parse(string) : null; } catch { return null; } } } //# sourceMappingURL=json-storage.js.map