cookie-consent/src/storage.js
Pdn Technology 48cabcf293 first commit
2026-06-20 08:47:21 +03:00

31 lines
698 B
JavaScript

import { getStorageKey } from "./config.js";
import { parseUserConsent, serializeUserConsent } from "./preferences.js";
export function readStoredConsent() {
if (typeof window === "undefined") return null;
try {
const raw = window.localStorage.getItem(getStorageKey());
if (!raw) return null;
try {
return parseUserConsent(JSON.parse(raw));
} catch {
return parseUserConsent(raw);
}
} catch {
return null;
}
}
export function writeStoredConsent(consent) {
if (typeof window === "undefined") return false;
try {
window.localStorage.setItem(getStorageKey(), serializeUserConsent(consent));
return true;
} catch {
return false;
}
}