2024-09-27 14:56:46 +02:00
|
|
|
// getLocalStorageData.ts
|
|
|
|
|
2024-10-11 10:18:33 +02:00
|
|
|
// Function to retrieve all items from localStorage
|
2024-09-27 14:56:46 +02:00
|
|
|
export const getAllLocalStorageItems = (): Record<string, string | null> => {
|
2024-10-11 10:18:33 +02:00
|
|
|
const allData: Record<string, string | null> = {}; // Object to hold key-value pairs from localStorage
|
|
|
|
|
|
|
|
// Check if localStorage is available
|
2024-10-07 11:16:51 +02:00
|
|
|
if (typeof localStorage !== 'undefined') {
|
2024-10-11 10:18:33 +02:00
|
|
|
// Iterate through all localStorage keys
|
|
|
|
for (let i = 0; i < localStorage.length; i++) {
|
|
|
|
const key = localStorage.key(i); // Get the key at the current index
|
|
|
|
if (key) {
|
|
|
|
const value = localStorage.getItem(key); // Retrieve the value associated with the key
|
|
|
|
allData[key] = value; // Store the key-value pair in the allData object
|
|
|
|
}
|
2024-09-27 14:56:46 +02:00
|
|
|
}
|
2024-10-07 11:16:51 +02:00
|
|
|
}
|
2024-10-11 10:18:33 +02:00
|
|
|
return allData; // Return the object containing all localStorage items
|
|
|
|
};
|