# feathers-localstorage

> A client side service based on feathers-memory that persists to LocalStorage

Latest version **5.2.1** (published 2022-05-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install feathers-localstorage
pnpm add feathers-localstorage
yarn add feathers-localstorage
bun add feathers-localstorage
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.2.1 |
| Published | 2022-05-20 |
| First published | 2016-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 6 |
| Dependencies | 2 |
| Unpacked size | 335.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 38 |
| Author | Feathers contributors |
| Maintainers | daffl, ekryski |
| Keywords | feathers, feathers-plugin |

## Links

- npm: https://www.npmjs.com/package/feathers-localstorage
- Repository: https://github.com/feathersjs-ecosystem/feathers-localstorage
- Issues: https://github.com/feathersjs-ecosystem/feathers-localstorage/issues
- npm.io page: https://npm.io/package/feathers-localstorage

## Dependencies (2)

- [debug](https://npm.io/package/debug.md) ^4.1.1
- [feathers-memory](https://npm.io/package/feathers-memory.md) ^4.1.0

## Alternatives

- [@fortawesome/react-fontawesome](https://npm.io/package/@fortawesome/react-fontawesome.md) — 2.2M weekly downloads
- [roboto-fontface](https://npm.io/package/roboto-fontface.md) — 196.0K weekly downloads
- [@react-native-vector-icons/common](https://npm.io/package/@react-native-vector-icons/common.md) — 150.4K weekly downloads
- [stockfish](https://npm.io/package/stockfish.md) — 27.0K weekly downloads
- [@procore/core-icons](https://npm.io/package/@procore/core-icons.md) — 4.6K weekly downloads

## Recent versions

- 5.2.1 (latest) — 2022-05-20
- 5.2.0 — 2020-12-09
- 5.1.1 — 2020-03-27
- 5.1.0 — 2019-10-07
- 5.0.0 — 2019-07-05
- 4.0.0 — 2018-12-17
- 3.0.0 — 2018-09-21
- 2.0.2 — 2018-04-13
- 2.0.1 — 2018-03-07
- 2.0.0 — 2017-12-03
- 1.1.0 — 2017-09-23
- 1.0.1 — 2017-09-06
- 1.0.0 — 2016-11-11
- 0.5.0 — 2016-09-09
- 0.4.1 — 2016-06-17
- … 8 more at https://npm.io/package/feathers-localstorage/versions

## README

# feathers-localstorage

[![Greenkeeper badge](https://badges.greenkeeper.io/feathersjs-ecosystem/feathers-localstorage.svg)](https://greenkeeper.io/)

[![Build Status](https://travis-ci.org/feathersjs-ecosystem/feathers-localstorage.png?branch=master)](https://travis-ci.org/feathersjs-ecosystem/feathers-localstorage)
[![Dependency Status](https://img.shields.io/david/feathersjs-ecosystem/feathers-localstorage.svg?style=flat-square)](https://david-dm.org/feathersjs-ecosystem/feathers-localstorage)
[![Download Status](https://img.shields.io/npm/dm/feathers-localstorage.svg?style=flat-square)](https://www.npmjs.com/package/feathers-localstorage)

[feathers-localstorage](https://github.com/feathersjs-ecosystem/feathers-localstorage/) is a database service adapter that extends [feathers-memory](./memory.md) and stores data in [localStorage](https://developer.mozilla.org/en/docs/Web/API/Window/localStorage) in the browser or [AsyncStorage](https://facebook.github.io/react-native/docs/asyncstorage.html) in React Native.

```bash
$ npm install --save feathers-localstorage
```

> __Important:__ `feathers-localstorage` implements the [Feathers Common database adapter API](https://docs.feathersjs.com/api/databases/common.html) and [querying syntax](https://docs.feathersjs.com/api/databases/querying.html).


## API

### `service(options)`

Returns a new service instance initialized with the given options.

```js
const service = require('feathers-localstorage');

app.use('/messages', service({
  storage: window.localStorage || AsyncStorage
}));
app.use('/messages', service({ storage, id, startId, name, store, paginate }));
```

__Options:__

- `storage` (**required**) - The local storage engine. You can pass in the browsers `window.localStorage`, React Native's `AsyncStorage` or a NodeJS localstorage module.
- `throttle` (*optional*, default `200`) - The minimum time (ms) before in-memory data is written to `storage`. Data is only written if changed since last write.
- `id` (*optional*, default: `'id'`) - The name of the id field property.
- `startId` (*optional*, default: `0`) - An id number to start with that will be incremented for new record.
- `name` (*optional*, default: `'feathers'`) - The key to store data under in local or async storage.
- `store` (*optional*) - An object with id to item assignments to pre-initialize the data store.
- `events` (*optional*) - A list of [custom service events](https://docs.feathersjs.com/api/events.html#custom-events) sent by this service.
- `paginate` (*optional*) - A [pagination object](https://docs.feathersjs.com/api/databases/common.html#pagination) containing a `default` and `max` page size.
- `whitelist` (*optional*) - A list of additional query parameters to allow.
- `multi` (*optional*) - Allow `create` with arrays and `update` and `remove` with `id` `null` to change multiple items. Can be `true` for all methods or an array of allowed methods (e.g. `[ 'remove', 'create' ]`).
- `reuseKeys` (*optional*, default: `false`) Allow duplicate keys i.e. last definition wins. Mostly useful for demonstration and testing purposes.

## Example

See the [clients](https://docs.feathersjs.com/api/client.html) chapter for more information about using Feathers in the browser and React Native.

### Browser

```html
<script type="text/javascript" src="//unpkg.com/@feathersjs/client@^3.0.0/dist/feathers.js"></script>
<script type="text/javascript" src="//unpkg.com/feathers-localstorage@^2.0.2/dist/feathers-localstorage.js"></script>
<script type="text/javascript">
  var service = feathers.localstorage({
    storage: window.localStorage
  });
  var app = feathers().use('/messages', service);

  var messages = app.service('messages');

  messages.on('created', function(message) {
    console.log('Someone created a message', message);
  });

  messages.create({
    text: 'Message created in browser'
  });
</script>
```

### React Native

```bash
$ npm install @feathersjs/feathers feathers-localstorage --save
```

```js
import React from 'react-native';
import feathers from '@feathersjs/feathers';
import localstorage from 'feathers-localstorage';

const { AsyncStorage } = React;

const app = feathers()
  .use('/messages', localstorage({ storage: AsyncStorage }));

const messages = app.service('messages');

messages.on('created', function(message) {
  console.log('Someone created a message', message);
});

messages.create({
  text: 'Message from React Native'
});
```

## License

Copyright (c) 2017

Licensed under the [MIT license](LICENSE).

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