# observable-storage

> A simplified implementation to subscribe to localStorage or sessionStorage changes

Latest version **0.1.1** (published 2023-02-21) · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2023-02-21 |
| First published | 2023-02-21 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | qsalatiel |

## Links

- npm: https://www.npmjs.com/package/observable-storage
- Homepage: https://github.com/qsalatiel/observable-storage
- npm.io page: https://npm.io/package/observable-storage

## Recent versions

- 0.1.1 (latest) — 2023-02-21
- 0.1.0 — 2023-02-21

## README

# ObservableStorage

A simplified implementation to subscribe to localStorage or sessionStorage changes

## Installation

Install using `npm`, `yarn` or `pnpm`

```bash
pnpm i observable-storage
```

## Usage

```typescript
import { ObservableStorage } from "./observable-storage";

// Create a instance providing storage adapter
// Adapter can be localStorage, sessionStorage or custom that implements the same API
const ls = new ObservableStorage(localStorage);

ls.setItem("example", "old-value");

// subscribe to changes passing the storage key
ls.subscribe("example", (newValue) => {
  // After 2sec newValue will log as 'new-value'
  console.log("storage has changed:", newValue);
});

setTimeout(() => {
  ls.setItem("example", "new-value");
}, 2000);

// removes all listeners to that storage key
ls.unsubscribe("example");

// will no longer log
ls.setItem("example", "old-value");
```

## Contributing

Pull requests are welcome. For major changes, please open an issue first
to discuss what you would like to change.

Please make sure to update tests as appropriate.

## License

[MIT](https://choosealicense.com/licenses/mit/)

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