# rumblejs

> Reactive Data Storage in the browser.

Latest version **1.0.8** (published 2022-04-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install rumblejs
pnpm add rumblejs
yarn add rumblejs
bun add rumblejs
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2022-04-23 |
| First published | 2022-04-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Maximilien COMLAN |
| Maintainers | themx05 |

## Links

- npm: https://www.npmjs.com/package/rumblejs
- Repository: https://github.com/themx05/rumblejs
- Homepage: https://github.com/themx05/rumblejs#readme
- Issues: https://github.com/themx05/rumblejs
- npm.io page: https://npm.io/package/rumblejs

## Recent versions

- 1.0.8 (latest) — 2022-04-23
- 1.0.7 — 2022-04-23
- 1.0.6 — 2022-04-23
- 1.0.5 — 2022-04-23
- 1.0.4 — 2022-04-23
- 1.0.3 — 2022-04-23
- 1.0.2 — 2022-04-23
- 1.0.1 — 2022-04-23
- 1.0.0 — 2022-04-23

## README

# RumbleJS

Reactive Storage wrapped around either localStorage or sessionStorage, in the browser. you chooose which engine fits your needs.

It works like this:

```javascript 
import SetupStorage from "rumblejs";

const rls = SetupStorage(localStorage);

const readSubscriber = rls.onRead("user", (event) => {
    console.log("User readed", event.value);
});

const writeSubscriber = rls.onWrite("user", (event) => {
    console.log(event.previous, event.value);
});

const removeSubscriber = rls.onRemove("user", (event) => {
    console.log("User removed. Need to signin again");
});

const clearSubscriber = rls.onClear(() => {
    console.log("Storage has been cleared");
});

rls.setItem("user", "Paul Logan");
rls.getItem("user");
rls.removeItem("user");

readSubscriber.cancel();
writeSubscriber.cancel();
removeSubscriber.cancel();
clearSubscriber.cancel();
/// same for other subscribers

```

How it works: 

*RumbleJS* encapsulates either `localStorage` or `sessionStorage` to provide the same functionality as `localStorage` or `sessionStorage`, but is able to react to changes applied to the keys stored by it, on demand. Events are passed through the sender associated with the document, to allow function calls without latency or __promise__.


## Available functions and attributes

### readonly length: number
Returns the total number of keys available in the storage


### clear(): void
Clears the storage, and triggers the `clear` event. Interceptable with `onClear`.


### getItem(key: string): string | null
Returns the current value associated with the given key, or null if the given key does not exist

### getString(key: string): string | null
Returns the current value associated with the given key, or null if the given key does not exist

### getObject(key: string): any | null
Returns the current value associated with the given key with automatic conversion to Javascript Object with `JSON.parse`, or null if the given key does not exist
    
### getNumber(key: string): number | null
Returns the current value associated with the given key with automatic parsing to number with `parseFloat`, or null if the given key does not exist

### getBoolean(key: string): boolean
Returns the current value associated with the given key with automatic parsing to boolean by checking if the value is equal to `true` or `1`, or false if the given key does not exist


### getMatches(pattern: string | RegExp): { key: string, value: string | null }[]
Returns every key value pair where the key match the given pattern. if each key-pair, the value might be null


### getNonNullMatches(pattern: string | RegExp): { key: string, value: string }[]
Returns every key value pair where the key match the given pattern. if each key-pair, but skip keys with null values.

### key(index: number): string | null
Return the key at the specified index

### removeItem(key: string): void
Remove the specified key from the storage.

### setItem(key: string, value: string): void
Append the given key value to storage.

### onRead(key: SubscribeParams['key'], listener: SubscribeParams['listener']): Subscription


### onWrite(key: SubscribeParams['key'], listener: SubscribeParams['listener']): Subscription


### onRemove(key: SubscribeParams['key'], listener: SubscribeParams['listener']): Subscription


### onClear(listener: SubscribeParams['listener']): Subscription


### on(params: SubscribeParams): Subscription;

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