@sebgroup/frontend-tools
Version:
A set of frontend tools
57 lines (54 loc) • 1.43 kB
JavaScript
import { CookieStorage } from '../CookieStorage/CookieStorage.js';
class StorageManagement {
constructor(type = "LOCAL") {
switch (type) {
case "LOCAL":
this.handler = localStorage;
break;
case "SESSION":
this.handler = sessionStorage;
break;
case "COOKIE":
this.handler = new CookieStorage();
break;
default:
this.handler = localStorage;
}
}
get length() {
return this.keys().length;
}
setItem(key, value) {
this.handler.setItem(key, value);
}
getItem(key) {
return this.handler.getItem(key);
}
removeItem(key) {
if (this.handler.getItem(key)) {
this.handler.removeItem(key);
return true;
}
return false;
}
clear() {
this.handler.clear();
}
/**
* Retrieves the list of keys in the stored storage
* @returns The list of keys in the stored storage
*/
keys() {
if (this.handler.keys) {
return this.handler.keys();
}
else {
return Object.keys(this.handler);
}
}
key(index) {
return this.keys()[index];
}
}
export { StorageManagement };
//# sourceMappingURL=StorageManagement.js.map