# @jaysalvat/super-storage

> Cookie, localStorage and sessionStorage javascript helpers

Latest version **1.1.6** (published 2021-10-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install @jaysalvat/super-storage
pnpm add @jaysalvat/super-storage
yarn add @jaysalvat/super-storage
bun add @jaysalvat/super-storage
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.6 |
| Published | 2021-10-11 |
| First published | 2021-02-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 35.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Jay Salvat |
| Maintainers | jaysalvat |
| Keywords | javascript, local, session, storage, cookie |

## Links

- npm: https://www.npmjs.com/package/@jaysalvat/super-storage
- Repository: https://github.com/jaysalvat/super-storage
- Homepage: https://github.com/jaysalvat/super-storage#readme
- Issues: https://github.com/jaysalvat/super-storage/issues
- npm.io page: https://npm.io/package/@jaysalvat/super-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

- 1.1.6 (latest) — 2021-10-11
- 1.1.5 — 2021-10-11
- 1.1.4 — 2021-02-17
- 1.1.3 — 2021-02-17
- 1.1.2 — 2021-02-17
- 1.1.1 — 2021-02-17
- 1.1.0 — 2021-02-17
- 1.0.0 — 2021-02-17

## README

[![npm version](https://badge.fury.io/js/%40jaysalvat%2Fsuper-storage.svg)](https://badge.fury.io/js/%40jaysalvat%2Fsuper-storage)

Super Storage 
=============

Super Storage provides some helpers over cookie, localStorage and sessionStorage.

- [x] 1Kb gzipped
- [x] Store all type of values (objects and arrays)
- [x] Default value when empty
- [x] Prefix key
- [x] Session kept between tabs

## Install

Install npm package

```sh
npm install @jaysalvat/super-storage
```

## Usage

### Module

```javascript
import { SuperCookie, SuperLocalStorage, SuperSessionStorage } from '@jaysalvat/super-storage'

const settings = {
  storagePrefix: 'myApp'
}

const superCookie = new SuperCookie(settings)
const superLocalStorage = new SuperLocalStorage(settings)
const superSessionStorage = new SuperSessionStorage(settings)
```

### CDN

```html
<script src="https://unpkg.com/@jaysalvat/super-storage@latest/build/super-storage.umd.min.js"></script>
<script>
  const settings = {
    storagePrefix: 'myApp'
  }

  const superCookie = new superStorage.SuperCookie(settings)
  const superLocalStorage = new superStorage.SuperLocalStorage(settings)
  const superSessionStorage = new superStorage.SuperSessionStorage(settings)
</script>

```


## Settings

Default settings.

```javascript
{
  storagePrefix: '',
  sessionCookieName: '__superStorageSession',
  sessionNative: false,
  sessionPrefix: 'session',
  cookiePrefix: '',
  cookieOptions: {
    domain: null,
    path: null,
    maxAge: null,
    expires: null,
    secure: null
  }
}
```

## SuperLocalStorage

### setItem

Set a value

```javascript
superLocalStorage.setItem('key', 'data')
```

### getItem

Get a value

```javascript
superLocalStorage.getItem('key')
superLocalStorage.getItem('key', 'default value')
```

### removeItem

Remove a value

```javascript
superLocalStorage.removeItem('key')
```

### clear

Remove all value

```javascript
superLocalStorage.clear()
```



## SuperSessionStorage

Note: If `sessionNative` set to false (default) in the settings, `SuperSessionStorage`
will use the native `localStorage` to store values and a cookie in order to watch the 
browser session. This trick allows `SuperSessionStorage` to be kept between tabs and 
windows (unlike native `sessionStorage`)

### setItem

Set a value

```javascript
superSessionStorage.setItem('key', 'data')
```

### getItem

Get a value

```javascript
superSessionStorage.getItem('key')
superSessionStorage.getItem('key', 'default value')
```

### removeItem

Remove a value

```javascript
superSessionStorage.removeItem('key')
```

### clear

Remove all value

```javascript
superSessionStorage.clear()
```



## SuperCookie

### setItem

Set a value. 
Options can be passed (merged with global settings `cookieOptions`)

```javascript
  const options = {
    domain: null,
    path: null,
    maxAge: null,
    expires: null,
    secure: null
  }
```

See [Cookie specs](https://developer.mozilla.org/fr/docs/Web/HTTP/Cookies).

```javascript
superCookie.setItem('key', 'data', [options]))
```

### getItem

Get a value

```javascript
superCookie.getItem('key')
superCookie.getItem('key', 'default value')
```

### removeItem

Remove a value. Options `path` and `domain` can be passed.

```javascript
 const options = {
    domain: 'mydomain.com',
    path: '/',
  }
```

```javascript
superCookie.removeItem('key', [options])
```


## Dev

Dev mode

```sh
npm run dev
```

Build

```sh
npm run build
```

Lint

```sh
npm run lint
```

Fix lint errors

```sh
npm run lint:fix
```

Bump version and publish to NPM

```sh
npm run release
npm run release:patch
npm run release:minor
npm run release:major
```

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