# storage-factory

> Because using localStorage directly is a bad idea

Latest version **0.2.1** (published 2022-06-17) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2022-06-17 |
| First published | 2018-09-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 64 |
| Author | Michal Zalecki |
| Maintainers | michalzalecki |

## Links

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

## Recent versions

- 0.2.1 (latest) — 2022-06-17
- 0.2.0-beta.2 (beta) — 2020-12-20
- 0.2.0 — 2020-12-20
- 0.2.0-beta.1 — 2020-12-20
- 0.2.0-beta.0 — 2020-12-20
- 0.1.1 — 2020-06-09
- 0.1.0 — 2019-07-29
- 0.0.4 — 2019-01-11
- 0.0.3 — 2018-11-23
- 0.0.2 — 2018-09-27
- 0.0.1 — 2018-09-26

## README

# storage-factory

[![CircleCI](https://circleci.com/gh/MichalZalecki/storage-factory.svg?style=svg)](https://circleci.com/gh/MichalZalecki/storage-factory)

This library is a [tiny](https://bundlephobia.com/result?p=storage-factory) (414B) wrapper for `localStorage` and `sessionStorage` because using Storage directly is a bad idea. Here's the blogpost that explains [why is that](https://michalzalecki.com/why-using-localStorage-directly-is-a-bad-idea/).

**Warning**: object access (e.g. `localStorage.foo`) is not yet implemented 💥

## Usage

Somewhere in your project

```js
// storage.js
import { storageFactory } from "storage-factory";

export const local = storageFactory(() => localStorage);
export const session = storageFactory(() => sessionStorage);
```

When you need to use storage

```js
import * as storage from "./storage";

function login(token) {
  storage.local.setItem("token", token);
  // do your other login things
}
```

## Example

Run the example using [parcel](https://parceljs.org/)

```bash
npx parcel example/index.html
```

## Contribute

Do you want to contribute? Awesome! Please, create an issue first and tell me about it.

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