File size: 1,764 Bytes
4e1096a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | // localStorage mock
if (typeof window !== 'undefined' && !window.localStorage) {
const storage: Record<string, string> = {};
window.localStorage = {
getItem: (key: string) => storage[key] || null,
setItem: (key: string, value: string) => {
storage[key] = value;
},
removeItem: (key: string) => {
delete storage[key];
},
clear: () => {
Object.keys(storage).forEach((key) => delete storage[key]);
},
get length() {
return Object.keys(storage).length;
},
key: (index: number) => {
const keys = Object.keys(storage);
return keys[index] || null;
},
} as Storage;
} else if (typeof window !== 'undefined' && window.localStorage && !window.localStorage.getItem) {
// If localStorage exists but getItem is not a function, replace it
const storage: Record<string, string> = {};
window.localStorage = {
getItem: (key: string) => storage[key] || null,
setItem: (key: string, value: string) => {
storage[key] = value;
},
removeItem: (key: string) => {
delete storage[key];
},
clear: () => {
Object.keys(storage).forEach((key) => delete storage[key]);
},
get length() {
return Object.keys(storage).length;
},
key: (index: number) => {
const keys = Object.keys(storage);
return keys[index] || null;
},
} as Storage;
}
// matchMedia mock
if (typeof window !== 'undefined' && !window.matchMedia) {
window.matchMedia = (query: string) =>
({
matches: false,
media: query,
onchange: null,
addEventListener: () => {},
removeEventListener: () => {},
addListener: () => {},
removeListener: () => {},
dispatchEvent: () => false,
}) as MediaQueryList;
}
|