2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2018-04-03 14:16:57 +00:00
|
|
|
export default {
|
|
|
|
getItem(key) {
|
2022-06-02 20:19:57 +00:00
|
|
|
var item = window.localStorage.getItem(key);
|
2018-04-03 14:16:57 +00:00
|
|
|
return item && JSON.parse(item);
|
|
|
|
},
|
|
|
|
|
|
|
|
setItem(key, val) {
|
2022-06-02 20:19:57 +00:00
|
|
|
window.localStorage.setItem(key, JSON.stringify(val));
|
2018-04-03 14:16:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
removeItem(key) {
|
2022-06-02 20:19:57 +00:00
|
|
|
return window.localStorage.removeItem(key);
|
2018-04-03 14:16:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
keys() {
|
2022-06-02 20:19:57 +00:00
|
|
|
return Object.keys(window.localStorage);
|
2018-04-03 14:16:57 +00:00
|
|
|
},
|
2023-02-14 17:00:24 +00:00
|
|
|
|
2023-06-09 18:03:58 +00:00
|
|
|
cleanupStorage(string, keyToKeep) {
|
2023-02-14 17:00:24 +00:00
|
|
|
if (!string) return;
|
|
|
|
const relevantKeys = this.keys().filter((str) => str.startsWith(string));
|
|
|
|
relevantKeys?.forEach((key) => {
|
|
|
|
if (key !== keyToKeep) {
|
|
|
|
localStorage.removeItem(key);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2018-04-03 14:16:57 +00:00
|
|
|
};
|