Initial CMPP frontend prototype
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
const STORAGE_PREFIX = 'cmpp-platform-v2';
|
||||
|
||||
export function readLocalData<T>(key: string, fallback: T): T {
|
||||
if (typeof window === 'undefined') {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
const rawValue = window.localStorage.getItem(`${STORAGE_PREFIX}:${key}`);
|
||||
|
||||
if (!rawValue) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(rawValue) as T;
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
export function writeLocalData<T>(key: string, value: T) {
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
window.localStorage.setItem(`${STORAGE_PREFIX}:${key}`, JSON.stringify(value));
|
||||
}
|
||||
|
||||
export function resetLocalData(key: string) {
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
window.localStorage.removeItem(`${STORAGE_PREFIX}:${key}`);
|
||||
}
|
||||
Reference in New Issue
Block a user