# local-storage-helper

> It helps you to work with LocalStorage

Latest version **1.2.5** (published 2022-01-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install local-storage-helper
pnpm add local-storage-helper
yarn add local-storage-helper
bun add local-storage-helper
```

## 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.2.5 |
| Published | 2022-01-10 |
| First published | 2019-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | michael-kravchuk |
| Keywords | local storage |

## Links

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

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) ^4.4.3

## 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.2.5 (latest) — 2022-01-10
- 1.2.4 — 2021-09-29
- 1.2.3 — 2021-09-29
- 1.2.2 — 2020-09-17
- 1.2.1 — 2020-01-22
- 1.2.0 — 2020-01-13
- 1.1.9 — 2019-11-25
- 1.1.8 — 2019-11-25
- 1.1.7 — 2019-11-25
- 1.1.6 — 2019-11-19
- 0.1.5 — 2019-11-19
- 0.1.4 — 2019-11-19
- 0.1.3 — 2019-11-19
- 0.1.1 — 2019-11-19

## README

# Local Storage Helper

It helps you to work with LocalStorage 

[![npm version](https://badge.fury.io/js/local-storage-helper.svg)](http://badge.fury.io/js/local-storage-helper)
[![GitHub issues](https://img.shields.io/github/issues/MichaelKravchuk/local-storage-helper.svg)](https://github.com/MichaelKravchuk/local-storage-helper/issues)
[![GitHub stars](https://img.shields.io/github/stars/MichaelKravchuk/local-storage-helper.svg)](https://github.com/MichaelKravchuk/local-storage-helper/stargazers)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/MichaelKravchuk/local-storage-helper/master/LICENSE)


## Usage

**Step 1:** Install local-storage-helper

```sh
npm install local-storage-helper --save
```

**Step 2:** Set up application prefix

```ts
import { LocalStorageHelper } from 'local-storage-helper';

LocalStorageHelper.setAppPrefix('yourPrefix');
```

**Step 3:** Start using

```ts
   const account = new LocalStorageHelper('account');
   account.save(someData);
```

## Methods

| Method         | Type   | Description
|----------------|--------|------------
| save | (new (options: any) => T &#124; any) => void | This method save data to LocalStorage
| restoreAs | (Type?: new (options: any) => T) => T &#124; any | This method get data from LocalStorage, and can automatically convert to Class instance

## Static Methods

| Method      | Type   | Description
|----------------|--------|------------
| setAppPrefix | (value: string) => void | This method will set a prefix to your keys in LocalStorage

## Example with RxJs

```ts

class Account {
    ...
}

class AccountService {
  private readonly subAccount: BehaviorSubject<Account>;
  private readonly accountStorage: LocalStorageHelper<Account> = new LocalStorageHelper<Account>('account');

  constructor() {
    this.subAccount = new BehaviorSubject(this.accountStorage.restoreAs(Account));
    this.subAccount.subscribe((account => this.accountStorage.save(account)));
  }

  public get account(): Account {
    return this.subAccount.getValue();
  }

  public set account(value: Account) {
    this.subAccount.next(value);
  }

  public clear(): void {
    this.account = null;
  }
}

```




## License
[MIT](https://choosealicense.com/licenses/mit/)

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