Skip to content
n2geoffPublic

About

Little Browser Storage Wrapper

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Storage Helper

storage.js is object store build against the browsers storage engines localStorage and sessionStorage. It provides a simplified API to set, get, update, remove, and clear stored objects.

NOTE: Browser-Only library

Installation

To use storage.js, you can include it in your project using ES6 module import syntax. If you are using Node.js, you might need to transpile the code with Babel or a similar tool since some browsers do not support ES6 modules natively.

import Storage from './storage.js';

Storage or {Storage}

Usage

Constructor

The Storage class constructor takes an optional parameter to specify the type of storage (local or session). default local

import {Storage} from './storage.js';

// Initialize with localStorage (default)
const local = new Storage();

// Initialize with sessionStorage
const session = new Storage('session');

API / Methods

Method Description Notes
constructor(type) Initializes the storage type. Defaults to 'local' if not specified. Accepts 'session' for sessionStorage.
get(key) Retrieves a value from the storage by key. Returns null if the key does not exist.
set(key, value) Sets a value in the storage by key. The value is automatically stringified using JSON.stringify().
update(key, json) Updates an existing item with new data. If the key does not exist, it creates a new item.
remove(key) Removes an item from the storage by key. Does nothing if the key does not exist.
clear() Clears all items from the storage.

Test

Browser tests are always a pain, but this will launch a browser, and run the tests there.

bun run test

This will run your tests and provide feedback on whether they pass or fail.

License

MIT License file for details.

About

Little Browser Storage Wrapper

Resources

Stars

0 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages