# async-web-storage

> async wrapper for web (local|session) storage

Latest version **1.0.3** (published 2020-09-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install async-web-storage
pnpm add async-web-storage
yarn add async-web-storage
bun add async-web-storage
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-09-20 |
| First published | 2020-09-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | mcha |
| Maintainers | mustafawm |
| Keywords | async, WebStroage, localStorage, sessionStorage |

## Links

- npm: https://www.npmjs.com/package/async-web-storage
- Repository: https://github.com/mustafawm/async-web-storage
- Homepage: https://github.com/mustafawm/async-web-storage#readme
- Issues: https://github.com/mustafawm/async-web-storage/issues
- npm.io page: https://npm.io/package/async-web-storage

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2020-09-20
- 1.0.2 — 2020-09-20
- 1.0.1 — 2020-09-20
- 1.0.0 — 2020-09-20
- 0.0.1 — 2020-09-20

## README

## Async wrapper for web storage

```sh
npm install async-web-storage
```

### Example
```js
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.stringify`ed 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`

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

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

---
_Source: https://npm.io/package/async-web-storage · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
