@lukeboyle/local-storage-manager

3.0.1 • Public • Published

Local Storage Manager

Build Status Coverage Status

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 for JSON.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

Contact

Find me on Github, or at my website

Dependents (0)

Package Sidebar

Install

npm i @lukeboyle/local-storage-manager

Weekly Downloads

0

Version

3.0.1

License

MIT

Unpacked Size

244 kB

Total Files

23

Last publish

Collaborators

  • lukeboyle