# simple-storage

> Simple localStorage / sessionStorage supporting objects and arrays

Latest version **6.0.2** (published 2023-03-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple-storage
pnpm add simple-storage
yarn add simple-storage
bun add simple-storage
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.0.2 |
| Published | 2023-03-14 |
| First published | 2013-09-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Derek Petersen |
| Maintainers | tuxracer |

## Links

- npm: https://www.npmjs.com/package/simple-storage
- Repository: https://codeberg.org/tuxracer/simple-storage
- Homepage: https://git.fedi.ai/tuxracer/simple-storage
- Issues: https://git.fedi.ai/tuxracer/simple-storage/issues
- npm.io page: https://npm.io/package/simple-storage

## Recent versions

- 6.0.2 (latest) — 2023-03-14
- 6.0.1 — 2022-12-20
- 6.0.0 — 2022-08-29
- 4.0.4 — 2022-08-29
- 4.0.2 — 2018-03-27
- 4.0.1 — 2017-11-20
- 4.0.0 — 2017-11-20
- 3.2.0 — 2017-11-19
- 3.1.0 — 2017-11-19
- 3.0.0 — 2017-11-18
- 2.2.0 — 2014-02-04
- 2.1.5 — 2013-12-06
- 2.1.4 — 2013-10-31
- 2.1.3 — 2013-10-23
- 2.1.2 — 2013-10-23
- … 3 more at https://npm.io/package/simple-storage/versions

## README

# simple-storage

Store strings and objects to local or session storage. Falls back to storing data in memory if run on platforms where the [Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Storage) is unavailable (such as node).

## sessionStorage

Store items for current session

```javascript
import { simpleSessionStorage } from "simple-storage";

// set item
simpleSessionStorage.setItem("pets", {
  dogs: 3,
  cats: 1,
});

// get item
const pets = simpleSessionStorage.getItem("pets");
console.log(pets); // { dogs: 3, cats: 1 }

// get all items
const items = simpleSessionStorage.getAllItems();
console.log(items); // [ [ "pets", {dogs: 3, cats: 1} ] ]

// get all items async
const i = await simpleSessionStorage.getAllItemsAsync();
console.log(i); // [ [ "pets", {dogs: 3, cats: 1} ] ]

// remove item
simpleSessionStorage.removeItem("pets");

// remove all items
simpleSessionStorage.clear();
```

## localStorage

Store items for longer than current session when possible

```javascript
import { simpleLocalStorage } from "simple-storage";

// set item
simpleLocalStorage.setItem("pets", {
  dogs: 3,
  cats: 1,
});

// get item
const pets = simpleLocalStorage.getItem("pets");
console.log(pets); // { dogs: 3, cats: 1 }

// get all items
const items = simpleLocalStorage.getAllItems();
console.log(items); // [ [ "pets", {dogs: 3, cats: 1} ] ]

// get all items async
const i = await simpleLocalStorage.getAllItemsAsync();
console.log(i); // [ [ "pets", {dogs: 3, cats: 1} ] ]

// remove item
simpleLocalStorage.removeItem("pets");

// remove all items
simpleLocalStorage.clear();
```

<https://git.fedi.ai/tuxracer/simple-storage>

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