@bjnstnkvc/stash
v1.0.5
Published
Simple wrapper for JavaScript Local Storage, Session Storage and Cookie API.
Downloads
14
Readme
Stash
A class that provides a wrapper for working with browser's Local and Session storage with a unified API.
Installation & setup
NPM
You can install the package via npm:
npm install @bjnstnkvc/stashand then import it into your project
import { Stash } from '@bjnstnkvc/stash';CDN
You can install the package via jsDelivr CDN:
<script src="https://cdn.jsdelivr.net/npm/@bjnstnkvc/stash/lib/main.min.js"></script>Usage
driver
Creates a new instance of the Stash for the given driver.
Parameters
- driver - String containing the name of the storage driver to be used ('local', 'session' or 'cookie').
Example
const local: typeof LocalStorage = Stash.driver('local');const session: typeof SessionStorage = Stash.driver('session');const cookie: typeof Cookie = Stash.driver('cookie');Note: Driver implementations can be found in local-storage, session-storage and cookie repositories respectively.
local
Creates a new instance of the Local Storage.
Example
const local: typeof LocalStorage = Stash.local();session
Creates a new instance of the Session Storage.
Example
const session: typeof SessionStorage = Stash.session();cookie
Creates a new instance of the Cookie.
Example
const cookie: typeof Cookie = Stash.cookie();