> For the complete documentation index, see [llms.txt](https://jscula.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jscula.gitbook.io/docs/storage/localstorage.md).

# localStorage

Enhanced local Storage

Provides automatic JSON handling for `localStorage`.

* `setLocalItem(key, value)`: Stores a value (automatically stringifies objects).
* `getLocalItem(key)`: Retrieves a value (automatically parses JSON if applicable).

You can now store and retrieve objects in the local storage without needing to parse or stringify them.

#### Usage

```javascript
setLocalItem('user', { name: 'John', age: 30 });
const user = getLocalItem('user');
console.log(user.name); // John
```

```javascript
// Storing an array
seLocaltItem('items', [1, 2, 3, 4]);
const items = getLocalItem('items');
console.log(items); // [1, 2, 3, 4]
```

```javascript
// Storing a nested object
setLocalItem('settings', { theme: 'dark', notifications: { email: true, sms: false } });
const settings = getLocalItem('settings');
console.log(settings.theme);// dark
console.log(settings.notifications.email);// true
```

```javascript
setLocalItem('theme','light');
const preferredTheme = getLocalItem('theme');
console.log(preferredTheme);
```

Clearing or removing items:

```javascript
clearLocalItems();//Clears all local storage items for the current site. 

removeLocalItem('settings');//Removes one local storage item.
```
