Skip to content

brianaraby/local-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

A fully-featured, safe, and extensible wrapper around the browser's localStorage API. This class makes working with localStorage as intuitive as working with arrays or objects in JavaScript — with familiar methods like .map(), .filter(), .find(), .reduce(), .keys(), and more.

🚀 Features

  • ✅ Safe JSON parsing
  • .set(), .get(), .delete(), .clear() – standard CRUD operations
  • ✅ Array-like methods: map, filter, reduce, find, forEach, some, every, etc.
  • ✅ Utility helpers: includes, includesKey, includesValue, entries, length, print
  • ✅ Handles invalid JSON gracefully
  • ✅ Fully documented with JSDoc annotations

📦 Installation

Clone this repository

git clone https://github.com/brianaraby/LocalStorage.git

🧠 Usage

const iStorage = new LocalStorage();
iStorage.clear();
iStorage.set('KeyOne', 'ValueOne');
iStorage.set('WAAuthToken', '388ad1c312a488ee9e12998fe097f2258fa8d5ee');
iStorage.print();

iStorage.map((key, value) => console.log(`${key}${value}`));

const Filter = iStorage.filter((key, value) => key.startsWith('KeyOne'));
console.log(Filter);

const Found = iStorage.find((key, value) => value === 1);
console.log(Found)

HTML Example

<script src="LocalStorage.js"></script>
<script>
    const iStorage = new LocalStorage();
    iStorage.clear();
    iStorage.set('KeyOne', 'ValueOne');
    iStorage.set('WAAuthToken', '388ad1c312a488ee9e12998fe097f2258fa8d5ee');
    iStorage.print();

    iStorage.forEach((key, value) => console.log(`${key}${value}`))
</script>

API Reference

Function Description
set(key, value) Save a value.
get(key) Get a parsed value.
delete(key) Remove a key.
has(key) Check if key exists.
clear() Remove all keys.
length Get total count of keys.
keys() Get all keys.
values() Get all values.
entries() Get all key/value pairs.
map(callback) Map over entries and return a new array.
filter(callback) Filter entries based on a callback.
reduce(callback, initial) Reduce entries to a single value.
forEach(callback) Execute callback for each entry.
some(callback) Check if some entries pass the test.
every(callback) Check if every entry passes the test.
find(callback) Find the first matching value.
findIndex(callback) Find index of the first matching entry.
findLast(callback) Find the last matching value.
findLastIndex(callback) Find index of the last matching entry.
includes(value) Check if a value exists.
includesKey(key) Check if a key exists.
includesValue(value) Check if a value exists.
print() Output all key/value pairs in a table.

📄 License

MIT License © 2025 Araby

About

A lightweight wrapper for localStorage with extra helper methods and debugging tools.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published