# store-memory

> Simplified memory store

Latest version **0.3.2** (published 2018-02-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install store-memory
pnpm add store-memory
yarn add store-memory
bun add store-memory
```

## 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.3.2 |
| Published | 2018-02-24 |
| First published | 2018-02-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 210 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Simon RENOULT |
| Maintainers | simonrenoult |
| Keywords | store, memory |

## Links

- npm: https://www.npmjs.com/package/store-memory
- Repository: https://github.com/simonrenoult/store-memory
- Homepage: https://github.com/simonrenoult/store-memory#readme
- Issues: https://github.com/simonrenoult/store-memory/issues
- npm.io page: https://npm.io/package/store-memory

## Dependencies (1)

- [shortid](https://npm.io/package/shortid.md) ^2.2.8

## Recent versions

- 0.3.2 (latest) — 2018-02-24
- 0.3.1 — 2018-02-24
- 0.3.0 — 2018-02-24
- 0.2.1 — 2018-02-24
- 0.2.0 — 2018-02-24
- 0.1.2 — 2018-02-24
- 0.1.1 — 2018-02-24
- 0.1.0 — 2018-02-24
- 0.0.2 — 2018-02-24
- 0.0.1 — 2018-02-24

## README

# store-memory

> Simplified memory store.

<a href="https://travis-ci.org/simonrenoult/store-memory">
  <img alt="Travis" src="https://img.shields.io/travis/simonrenoult/store-memory.svg?style=flat-square">
</a>
<a href="https://codecov.io/gh/simonrenoult/store-memory">
  <img alt="Codecov" src="https://img.shields.io/codecov/c/github/simonrenoult/store-memory.svg?style=flat-square">
</a>
<a href="https://travis-ci.org/simonrenoult/store-memory">
  <img alt="Travis" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square">
</a>

## Install

```
$ npm install store-memory
```

## Usage

```js
// Create a new store.
const store = []
const memoryStore = require('store-memory')
const productStore = memoryStore(store);

// Add a new product to the store.
const product = {name: "mug"}
const id = productStore.add(product);

// Find all products in the store.
const products = productStore.findAll();

// Find a product by id.
const product = productStore.find(id);

// Remove all products.
productStore.removeAll();

// Remove a product by id.
productStore.remove(id);

// Update a product.
productStore.update(id, {name: "tshirt"});

// Count the products.
productStore.count();

// Handle a product that does not exist.
try {
  productStore.find(42);
  productStore.remove(42);
  productStore.update(42, {});
} catch(e) {
  if (e instanceof memoryStore.NotFoundError) {
    // Do something.
  }
}

// Handle an invalid id.
try {
  productStore.find(null);
  productStore.remove(null);
  productStore.update(null);
} catch(e) {
  if (e instanceof ReferenceError) {
    // Do something.
  }
}

// Handle invalid data.
try {
  productStore.add(null);
  productStore.update(1, null);
} catch(e) {
  if (e instanceof ReferenceError) {
    // Do something.
  }
}
```

## License

MIT

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