# ember-cli-storagekit

> A thin layer on top of the HTML5 localStorage and sessionStorage services

Latest version **0.4.2** (published 2016-06-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install ember-cli-storagekit
pnpm add ember-cli-storagekit
yarn add ember-cli-storagekit
bun add ember-cli-storagekit
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.2 |
| Published | 2016-06-10 |
| First published | 2015-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Maintainers | kdbuck |
| Keywords | ember-addon |

## Links

- npm: https://www.npmjs.com/package/ember-cli-storagekit
- Repository: https://github.com/kennethdavidbuck/ember-cli-storagekit
- Issues: https://github.com/kennethdavidbuck/ember-cli-storagekit/issues
- npm.io page: https://npm.io/package/ember-cli-storagekit

## Dependencies (1)

- [ember-cli-babel](https://npm.io/package/ember-cli-babel.md) ^5.1.5

## Recent versions

- 0.4.2 (latest) — 2016-06-10
- 0.4.1 — 2016-03-31
- 0.4.0 — 2016-03-30
- 0.3.2 — 2015-12-03
- 0.3.1 — 2015-10-24
- 0.3.0 — 2015-10-18
- 0.2.9 — 2015-10-03
- 0.2.8 — 2015-09-27
- 0.2.7 — 2015-09-27
- 0.2.6 — 2015-09-26
- 0.2.5 — 2015-09-24
- 0.2.4 — 2015-09-21
- 0.2.3 — 2015-09-20
- 0.2.0 — 2015-09-20

## README

## ember-cli-storagekit 
[![npm version](https://badge.fury.io/js/ember-cli-storagekit.svg)](http://badge.fury.io/js/ember-cli-storagekit) [![Build Status](https://travis-ci.org/kennethdavidbuck/ember-cli-storagekit.svg?branch=develop)](https://travis-ci.org/kennethdavidbuck/ember-cli-storagekit) [![Ember Observer Score](http://emberobserver.com/badges/ember-cli-storagekit.svg)](http://emberobserver.com/addons/ember-cli-storagekit) [![Code Climate](https://codeclimate.com/github/kennethdavidbuck/ember-cli-storagekit/badges/gpa.svg)](https://codeclimate.com/github/kennethdavidbuck/ember-cli-storagekit/badges) [![Dependencies](https://david-dm.org/kennethdavidbuck/ember-cli-storagekit.svg)](https://david-dm.org/kennethdavidbuck/ember-cli-storagekit) [![Dev Dependencies](https://david-dm.org/kennethdavidbuck/ember-cli-storagekit/dev-status.svg)](https://david-dm.org/kennethdavidbuck/ember-cli-storagekit#info=devDependencies&view=table) 

A thin layer on top of the HTML5 localStorage and sessionStorage services. It also has a third type of storage called 
instanceStorage which is used as a failover when localStorage or sessionStorage are not available (such as when a user intentionally disables them).

This addon does not assume your application uses ember data. That being said it would serve well as part of a custom local, session, instance storage adapter.

## Installation

```
ember install ember-cli-storagekit
```

## Basic Usage
Storagekit takes care of ```JSON.stringify()``` and ```JSON.parse()``` for you, and supports the following methods:

* setItem
* getItem
* removeItem
* clear
* length
* key

Storagekit makes no assumptions about where you would like to make the service available. As such you need to specify your own injections.

### initializer
```javascript
  export function initialize(registry, application) {
    // inject the storage service, which contains each storage type.
    application.inject('route', 'storage', 'storagekit/service:storage');
    
    // you can also inject each service individually if that is your thing.
    application.inject('route', 'localStorage', 'storagekit/service:local-storage');
    application.inject('route', 'sessionStorage', 'storagekit/service:session-storage');
    application.inject('route', 'instanceStorage', 'storagekit/service:instance-storage');
  }

  export default {
    name: 'inject-storage-service',
    after: 'inject-storagekit',
    initialize: initialize
  };
```

### Local
```javascript
  // A controller...or route
  // ...snip...
  actions: {
    savePreferences(preferences) {
      // with storage
      this.get('storage.local').setItem('preferences', preferences);
      
      // with localStorage
      this.get('localStorage').setItem('preferences', preferences);
    }
  }
  // ...snip...
```

### Session
```javascript
  // A controller...or route
  // ...snip...
  actions: {
    saveSession(session) {
      // with storage
      this.get('storage.session').setItem('session', session);
    
      // with sessionStorage
      this.get('sessionStorage').setItem('session', session);
    }
  }
  // ...snip...
```

### Instance
```javascript
  // A controller...or route
  // ...snip...
  actions: {
    storeTemporarily(temporaryData) {
      // with storage
      this.get('storage.instance').setItem('temporaryData', temporaryData);
    
      // with instanceStorage
      this.get('instanceStorage').setItem('temporaryData', temporaryData);
    }
  }
  // ...snip...
```

## Namespacing
The storagekit env config provides a means for namespacing your application keys. This is how it works:

```javascript
  // ...snip...
  APP: {
    storagekit: {
      namespace: 'storagekit'
    }
  }
  // ...snip...
```

Now your incoming keys will be stored like this:

```
'storagekit:mykey'
```

**IMPORTANT**: The namespace defines the storage "world" for all operations, and will give a result based solely on keys that are namespaced within it. Such methods include: ```#clear```, ```#keys```, ```#length```, and ```#key```. 

Why is this useful? Because it allows you to change your namespace based on the current environment. For example, you can define a different namespace for your test environment and keep yourself shielded from any setup and teardown methods that modify your browsers local or session storage.

If you do not specify a namespace, then your keys will be stored in the same form that they are received. If you 
specify a key directly in one of the adapters it will supercede the namespace in the env config.


## Generating the Docs
This addon has yuidoc annotations, and uses [ember-cli-yuidoc](https://github.com/cibernox/ember-cli-yuidoc) in order to generate and serve them.

## Running Tests

* `ember test`
* `ember test --server`

For more information on using ember-cli, visit [http://www.ember-cli.com/](http://www.ember-cli.com/).

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