UNPKG

web-shared-preferences

Version:

An simple class to manage the loacal storage, including React like useString, useJSON and more!

35 lines 994 B
/** * Used for debugging purposes only. */ export class TempLocalStorage { constructor() { this.valuesMap = new Map(); } getItem(key) { const stringKey = String(key); if (this.valuesMap.has(key)) { return String(this.valuesMap.get(stringKey)); } return null; } setItem(key, val) { this.valuesMap.set(String(key), String(val)); } removeItem(key) { this.valuesMap.delete(key); } clear() { this.valuesMap.clear(); } key(i) { if (arguments.length === 0) { throw new TypeError("Failed to execute 'key' on 'Storage': 1 argument required, but only 0 present."); // this is a TypeError implemented on Chrome, Firefox throws Not enough arguments to Storage.key. } var arr = Array.from(this.valuesMap.keys()); return arr[i]; } get length() { return this.valuesMap.size; } } //# sourceMappingURL=TempLocalStorage.js.map