# ember-cordova-storage

> Read and write data as persistent as possible (localStorage/nativeStorage)

Latest version **1.1.3** (published 2016-12-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install ember-cordova-storage
pnpm add ember-cordova-storage
yarn add ember-cordova-storage
bun add ember-cordova-storage
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2016-12-08 |
| First published | 2016-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10.0 |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | suven |
| Keywords | ember-addon |

## Links

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

## Dependencies (5)

- [rsvp](https://npm.io/package/rsvp.md) ^3.2.1
- [chalk](https://npm.io/package/chalk.md) ^1.1.1
- [lodash](https://npm.io/package/lodash.md) ^4.6.1
- [ember-cli-babel](https://npm.io/package/ember-cli-babel.md) ^5.1.6
- [ember-cli-version-checker](https://npm.io/package/ember-cli-version-checker.md) ^1.1.6

## Recent versions

- 1.1.3 (latest) — 2016-12-08
- 1.1.2 — 2016-11-30
- 1.1.1 — 2016-11-25
- 1.1.0 — 2016-11-24
- 1.0.0 — 2016-11-23
- 0.1.0-beta.4 — 2016-11-23
- 0.1.0-beta.3 — 2016-11-23
- 0.1.0-beta.2 — 2016-11-23
- 0.1.0-beta.1 — 2016-11-22

## README

# ember-cordova-storage

Reads and writes appSettings with the most persistent and secure available
option in a promise-based manner.

In cordova-application it uses `cordova-plugin-nativestorage` to save data in
the platform-offered setting key/value-stores. In the browser it just stores
data in localStorage.

## Things you need to be aware of

Do **NOT** use this if you wish to store huge amounts of data. Querying data isn't
supported. This service is particulary targeted against user-settings you wish
to carry over restarts/updates and not caching in general.

Also make sure you are **not** using the service before `deviceReady`, or else
you will end up using localStorage only (since that is the only thing available)
before `deviceReady`.

## Prerequisite

Although this does not rely on cordova at runtime and works fine in the browser,
the add-on assumes you are building your application with
[ember-cordova](https://github.com/isleofcode/ember-cordova).

## Installation

* `ember install ember-cordova-storage`

## Usage

Just inject the service and you are ready to start:

```
export default Ember.Route.extend({
  storage: Ember.inject.service('cordova/storage'),

  setupController() {
    this.get('storage')
      .write('pogchamp', Date.now())
      .then(() => this.get('storage').read('pogchamp'))
      .then((val) => Ember.debug(`Read ${val} for key pogchamp. That was ${Date.now() - val}ms ago`))
      .catch(console.log);
  }
});
```

#### write(key, value)

Writes a given `value` to a `key` and returns the written value as soon as writing
finished via a `Promise`.

You are free to store strings, ints, objects, booleans, arrays and so on. But be
aware that some object-attributes might get missing as the actually stored value
will `JSON.strinfify`ed.

#### read(key, legacy = false)

Reads a given `key` (always a string) and returns its value inside a `Promise`.

With `legacy` you can toggle if you always wish to use localStorage, even if
nativeStorage would be available.

If `legacy` is set, the value will also be returned as is and not tried to be
`JSON.parse`ed. This is because we can not safely make the assumption that legacy
values were `JSON.strinfify`ed in the first place.

If a key did not yet exist, this will return `null`.

#### clear()

Removes all keys from the storage. Like.. all of them.. Forever.. No turning back.

#### remove(key, legacy = false)

Removes the given `key` from the storage.

With `legacy` you can toggle if you always wish to clear in localStorage, even if
nativeStorage would be available.

## Thanks

Some parts of this plugin do use code from [ember-cordova-keyboard](https://github.com/isleofcode/ember-cordova-keyboard).

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