@mug3n96/asynclocalstorage

0.2.9 • Public • Published

AsyncLocalStorage

DESCRIPTION:

This is a lightweight promised based async wrapper for localStorage.

INSTALLATION:

npm i @mug3n96/asynclocalstorage --save

USE:

require module

const asyncLocalStorage = require('@mug3n96/asynclocalstorage');

set item

// you can pass a none stringified object, the methode will stringify it automatically
// (there is no Promise rejection )
asyncLocalStorage.setItem('key', {test: 'test'})
  .then(value => console.log(value));

get item

// if there is no saved item, promise will reject
asyncLocalStorage.getItem('key')
  .then(value => console.log(value))
  .catch(e => console.log('CANNOT GET THE ITEM'));

remove item

// if there is no item with the key 'key' promise will
// reject
asyncLocalStorage.removeItem('key')
  .then(data => console.log(data.value, 'of', data.key, 'has been removed'))
  .catch(e => console.log(e));

clear

// will clear all items of your local storage
asyncLocalStorage.clear()
  .then(() => {
    console.log('do maybe smth after you cleared all items');
  });

Package Sidebar

Install

npm i @mug3n96/asynclocalstorage

Weekly Downloads

1

Version

0.2.9

License

ISC

Unpacked Size

2.29 kB

Total Files

3

Last publish

Collaborators

  • mug3n96