# with-storage

> auto bind object properties to store and retrieve values using local storage easily

Latest version **0.0.2** (published 2020-08-12) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2020-08-12 |
| First published | 2020-02-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jeffrey Mendez |
| Maintainers | jeffmendez |
| Keywords | local-storage, auto-storage, with-storage, auto-bind-to-local-storage |

## Links

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

## 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

- 0.0.2 (latest) — 2020-08-12
- 0.0.1 — 2020-02-19

## README

## with-storage

A package that auto binds object or class properties to local-storage for persistance and easy manipulation.

## Installation Instructions

```bash
$ yarn add with-storage
```

## Example

```typescript
import { withStorage } from "with-storage";

const user = withStorage({
  isLoggedIn: false,
  email: "",
  sports: ["football"],
  health: { height: "6ft", eyeColor: "blue" },
  updateName: () => {}, // <-- funcs are ignored
});

user.email = "somemail@gmail.com"; // <-- cookie created

console.log(user.email); //  <-- 'somemail@gmail.com'
// RESTART application and remove setting your email above - try logging the same property
console.log(user.email); // <-- 'somemail@gmail.com' is still there

// DESTROY cookie simply just re-assign the value to "", undefined, or delete obj.key.
// setting value to undefined reverts to static defaults upon reload
user.email = "";
```

class example

```typescript
import { withStorage, getStorageItem } from "with-cookie";

@withStorage
class User {
  isLoggedIn: false,
  email: "",
};

const user =  new User()

user.email = "somemail@gmail.com";

// check to see if cookie exist with cookie util.
// cookies are stored formatted `${constructor.name || config.name}_{$key}`
console.log(getStorageItem("User_email")); // <-- 'somemail@gmail.com'
```

## Available Configuration

| param | default          | type   | description                                                 |
| ----- | ---------------- | ------ | ----------------------------------------------------------- |
| name  | constructor.name | string | Optional: A keyname for cookie storage if anonymous object. |

Example adjusting configuration. Simply pass in the object as the second param.

```typescript
const User = {
  isLoggedIn: false,
  email: "",
  card: {
    number: "",
    exp: "",
    cvc: "",
  },
};

const user = withStorage(User, { noStorage: ["card"] });
```

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