@lukeboyle/local-storage-manager
v3.0.1
Published
A module to easily manage data in local storage.
Downloads
3
Maintainers
Readme
Local Storage Manager
A simple package used for creating, storing and deleting data from local storage.
Current features:
- Enter key and data into local storage
- Get the data for a given key
- Remove all data for a given key
Installation
npm install @lukeboyle/local-storage-manager --save
Usage
- When setting data, put your namespace as the third argument and all data will be stored under that key
- You can then get keys from under that namespace, or just get that key and dump all your namespace data
const localStorageManager = require('@lukeboyle/local-storage-manager'); // OR
import * as localStorageManager from '@lukeboyle/local-storage-manager'; // OR
import {getItem, setItem, removeItem} from '@lukeboyle/local-storage-manager';
// Creating a key and entering a string into local storage
setItem('string1', 'data');
setItem('some/path', 'some string');
setItem(['other', 'path'], 'some string');
// Second argument of setItem is any type that can be JSON.stringified
// Getting data bound to a key
getItem('string1'); // => 'data'
getItem('some/path'); // => 'some string'
getItem(['other', 'path']); // => 'some string'
// Removing a key and all data bound to it
removeItem('string1');
removeItem('some/path');
removeItem(['other', 'path']);
API
setItem
Arguments
- path -
string | Array<string>
e.g.'noPath'
,'short/path'
,['array', 'path']
(array and slash separated paths can not be combined) - data -
any
- Any data valid forJSON.stringify
getItem
Arguments
- path -
string | Array<string>
e.g.'noPath'
,'short/path'
,['array', 'path']
(array and slash separated paths can not be combined) - defaultValue -
any
- If key doesn't exist in Storage, this will be returned instead
removeItem
Arguments
- path -
string | Array<string>
e.g.'noPath'
,'short/path'
,['array', 'path']
(array and slash separated paths can not be combined)
Running the Tests
run npm test