import { AlloyConstant } from '../config/AlloyConstant';
|
|
export class AlloyStorage {
|
static readonly PREFIX = `${AlloyConstant.NAMESPACE}:`;
|
static getFullKey(key: string) {
|
return `${AlloyStorage.PREFIX}${key}`;
|
}
|
static get(key: string) {
|
const storageValue = localStorage.getItem(AlloyStorage.getFullKey(key));
|
const jsonData = storageValue ? JSON.parse(storageValue) : undefined;
|
return jsonData;
|
}
|
static set(key: string, value: any) {
|
if (typeof value !== 'string') {
|
value = JSON.stringify(value);
|
}
|
localStorage.setItem(AlloyStorage.getFullKey(key), value);
|
}
|
static remove(key: string) {
|
localStorage.removeItem(key);
|
}
|
static clear() {
|
localStorage.clear();
|
}
|
}
|