@thefarce/ripple-browser-storage
v0.4.0
Published
A browser storage persistence layer for @thefarce/ripple
Downloads
8
Maintainers
Readme
@thefarce/ripple-browser-storage
A browser storage persistence layer for @thefarce/ripple
, providing an easy interface to interact with localStorage
and sessionStorage
.
Features
- Seamless integration with
localStorage
andsessionStorage
. - Easy-to-use API for storing and retrieving data.
- Customizable storage options.
- Lightweight and no external dependencies.
Installation
Install the package using npm:
npm install @thefarce/ripple-browser-storage
Or using yarn:
yarn add @thefarce/ripple-browser-storage
Usage
Here's how to use @thefarce/ripple-browser-storage
in your project.
Basic Usage
import { storeInBrowser } from '@thefarce/ripple-browser-storage';
// Store data in sessionStorage (default)
storeInBrowser({
namespace: 'myApp',
key: 'userData',
data: { name: 'John Doe', age: 30 }
});
// Retrieve data
const userData = sessionStorage.getItem('myApp::userData');
console.log(JSON.parse(userData)); // Outputs: { name: 'John Doe', age: 30 }
Storing Data in localStorage
// Store data in localStorage
storeInBrowser({
namespace: 'myApp',
key: 'settings',
data: { theme: 'dark', notifications: true },
metadata: { storageType: 'local' }
});
// Retrieve data
const settings = localStorage.getItem('myApp::settings');
console.log(JSON.parse(settings)); // Outputs: { theme: 'dark', notifications: true }
Advanced Usage
Here are some advanced scenarios for using @thefarce/ripple-browser-storage
:
// Example 1: Clearing data from a specific namespace
storeInBrowser.clearNamespace('myApp');
// Example 2: Using async/await for storing data
async function storeUserData() {
await storeInBrowser({
namespace: 'myApp',
key: 'asyncData',
data: { message: 'Hello World' }
});
}
storeUserData();
API Reference
storeInBrowser(options)
: Function to store data in browser storage.Options:
namespace
: A unique identifier for your app/module.key
: The key under which to store the data.data
: The data to be stored.metadata
: (Optional) Additional configuration, such asstorageType
.
Contributing
Contributions to @thefarce/ripple-browser-storage
are welcome!
- Fork the repository.
- Create a new branch for each feature or improvement.
- Send a pull request from each feature branch to the main branch.
Contributing
We welcome contributions to @thefarce/ripple
!
Contribution guidelines: Commit clean code with full, good tests. Comment your code as needed.
License
This project is licensed under the Gratitude License - see the LICENSE.txt file for details.