https://github.com/codewell/state-persistor
Write, read or purge localstorage based on key
https://github.com/codewell/state-persistor
Last synced: 3 days ago
JSON representation
Write, read or purge localstorage based on key
- Host: GitHub
- URL: https://github.com/codewell/state-persistor
- Owner: codewell
- License: mit
- Created: 2019-09-13T08:05:49.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T07:48:46.000Z (over 3 years ago)
- Last Synced: 2025-10-06T14:56:54.276Z (9 months ago)
- Language: JavaScript
- Size: 472 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @codewell/state-persistor
Minimalistic state persistor for front end applications with localstorage.
## Installation
```bash
npm install @codewell/state-persistor
```
## Basic usage
```JavaScript
import { saveState, loadState, purgeState } from '@codewell/state-persistor';
const state = {}; // Some state
const STORAGE_KEY = 'myCoolUniqueApplicationStorageKey'; // Unique key to store the state in localstorage
// Persist the state
saveState(state, STORAGE_KEY);
// Get the persisted state
const loadedState = loadState(STORAGE_KEY);
// Clear any saved state
purgeState(STORAGE_KEY);
```