forked from React-Group/interstellar_ai
Commented getLocalStorage
This commit is contained in:
parent
9e762191c7
commit
157e838b01
1 changed files with 13 additions and 10 deletions
|
@ -1,16 +1,19 @@
|
||||||
// getLocalStorageData.ts
|
// getLocalStorageData.ts
|
||||||
|
|
||||||
|
// Function to retrieve all items from localStorage
|
||||||
export const getAllLocalStorageItems = (): Record<string, string | null> => {
|
export const getAllLocalStorageItems = (): Record<string, string | null> => {
|
||||||
const allData: Record<string, string | null> = {};
|
const allData: Record<string, string | null> = {}; // Object to hold key-value pairs from localStorage
|
||||||
|
|
||||||
|
// Check if localStorage is available
|
||||||
if (typeof localStorage !== 'undefined') {
|
if (typeof localStorage !== 'undefined') {
|
||||||
for (let i = 0; i < localStorage.length; i++) {
|
// Iterate through all localStorage keys
|
||||||
const key = localStorage.key(i);
|
for (let i = 0; i < localStorage.length; i++) {
|
||||||
if (key) {
|
const key = localStorage.key(i); // Get the key at the current index
|
||||||
const value = localStorage.getItem(key);
|
if (key) {
|
||||||
allData[key] = value;
|
const value = localStorage.getItem(key); // Retrieve the value associated with the key
|
||||||
|
allData[key] = value; // Store the key-value pair in the allData object
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return allData;
|
return allData; // Return the object containing all localStorage items
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue