async-web-storage
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Async wrapper for web storage

npm install async-web-storage

Example

import { asyncLocalStorage, asyncSessionStorage } from 'async-web-storage';

async function saveLocally() {
  await asyncLocalStorage.setItem('foo', 'bar');
  const foo = await asyncLocalStorage.getItem('foo'); // bar

  const person = {
    name: 'mcha',
  };
  await asyncLocalStorage.setItem('user_1', person);
  const user = await asyncLocalStorage.getItem('user_1'); // {name: "mcha"}
}

All values are stored as JSON.stringifyed objects {[key]: value, createAt: Date.now()}

For example, the above values would exisit in local storage like this:

Key Value
foo "{\"foo\":\"bar\",\"createdAt\":1600516661351}"
user_1 "{\"name\":\"mcha\",\"createdAt\":1600516591899}"

To have access to the raw stored objects pass an option object {raw: true} as a 2nd argument .getItem

const rawStoredUser1 = await asyncLocalStorage.getItem('user_1', {raw: true});

console.log(rawStoredUser1); // {name: "mcha", createdAt: 1600516591899}

Package Sidebar

Install

npm i async-web-storage

Weekly Downloads

240

Version

1.0.3

License

ISC

Unpacked Size

8.35 kB

Total Files

6

Last publish

Collaborators

  • mcha