UNPKG

walletlink-e

Version:
36 lines (35 loc) 1.16 kB
"use strict"; // Copyright (c) 2018-2020 WalletLink.org <https://www.walletlink.org/> // Copyright (c) 2018-2020 Coinbase, Inc. <https://www.coinbase.com/> // Licensed under the Apache License, version 2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.ScopedLocalStorage = void 0; class ScopedLocalStorage { constructor(scope) { this.scope = scope; } setItem(key, value) { localStorage.setItem(this.scopedKey(key), value); } getItem(key) { return localStorage.getItem(this.scopedKey(key)); } removeItem(key) { localStorage.removeItem(this.scopedKey(key)); } clear() { const prefix = this.scopedKey(""); const keysToRemove = []; for (let i = 0; i < localStorage.length; i++) { const key = localStorage.key(i); if (typeof key === "string" && key.startsWith(prefix)) { keysToRemove.push(key); } } keysToRemove.forEach(key => localStorage.removeItem(key)); } scopedKey(key) { return `${this.scope}:${key}`; } } exports.ScopedLocalStorage = ScopedLocalStorage;