# type-storage

> A tool to store multiple types of data in Cookie or Web Storage.

Latest version **0.1.6** (published 2017-09-02) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2017-09-02 |
| First published | 2017-08-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ayon Lee |
| Maintainers | hyurl |
| Keywords | storage, cookie, localStorage, sessionStorage |

## Links

- npm: https://www.npmjs.com/package/type-storage
- Repository: https://github.com/hyurl/type-storage
- Homepage: https://github.com/hyurl/type-storage#readme
- Issues: https://github.com/hyurl/type-storage/issues
- npm.io page: https://npm.io/package/type-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.1.6 (latest) — 2017-09-02
- 0.1.5 — 2017-08-30
- 0.1.4 — 2017-08-30
- 0.1.3 — 2017-08-28
- 0.1.2 — 2017-08-24
- 0.1.1 — 2017-08-24
- 0.1.0 — 2017-08-18
- 0.0.1 — 2017-08-18

## README

# Type-Storage

**We know that Cookie and Web Storage (Session Storage and Local Storage) can only store strings, this simple module let you handle Object, Array and other types to be stored in and retrieved from them.**

# Install

```sh
npm install type-storage
```

# Example

```html
<script src="storage.js"></script>

<sciprt>
storage("a", {A: "Hello", B: "World"}); //Object
storage("b", ["Hello", "World"]); //Array

//Or use cookie

cookie("c", storage("a")); //storage("a") returns the Object.
cookie("d", storage("b")); //storage("b") returns the Array.
</sciprt>
```

Or in WebPack

```javascript
import {storage, cookie} from "storage";

storage("a", {A: "Hello", B: "World"}); //Object
storage("b", ["Hello", "World"]); //Array

//Or use cookie

cookie("c", storage("a")); //storage("a") returns the Object.
cookie("d", storage("b")); //storage("b") returns the Array.

console.log(storage()); //Print out all data in Storage.
console.log(cookie());  //Print out all data in Cookie.

console.log(storage().length); //Prints length of Storages.
console.log(cookie().length);  //Prints length of Cookies.

storage("a", undefined); //Removes a.
cookie("c", undefined);  //Removes c.
```

## storage()

**Sets and retrieves Storage data, supports String, Number, Object, Array, Boolean and Function.**

**params:**

- `key` The storage name.
- `value` The storage data, if an `undefined` is passed, remove the previous data.
- `local` Store in localStorage instead of sessionStorage, default is `false`.

**return:**

If both `key` and `value` are passed, always returns the value;
if only `key` is passed, returns the data it represents, or undefined.

## cookie()

**This function is similar to `storage()`, only it stores data in cookies, and if the third argument passes a `true`, it stores data only in one year.**

## References

Sometimes, there reference methods are useful:

- `storage.session()` The Session Storage.
- `storage.local()` The Local Storage.
- `storage.storage()` The storage() itself.
- `storage.cookie()` The cookie() function.

You can do:

```javascript
//Import storage and/or storage() all at once.
import storage from 'type-storage';

//Or import each of them seperaterly.
import {session, local, cookie} from 'type-storage';
```

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