# varasto-storage

> Persistent JSON key-value store

Latest version **1.0.0** (published 2021-02-11) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install varasto-storage
pnpm add varasto-storage
yarn add varasto-storage
bun add varasto-storage
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-02-11 |
| First published | 2019-06-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12.0 |
| Dependencies | 2 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Rauli Laine |
| Maintainers | rauli |

## Links

- npm: https://www.npmjs.com/package/varasto-storage
- Repository: https://github.com/RauliL/varasto
- Issues: https://github.com/RauliL/varasto/issues
- npm.io page: https://npm.io/package/varasto-storage

## Dependencies (2)

- [mkdirp](https://npm.io/package/mkdirp.md) ^1.0.4
- [type-fest](https://npm.io/package/type-fest.md) ^0.20.2

## Recent versions

- 1.0.0 (latest) — 2021-02-11
- 0.3.0 — 2021-02-11
- 0.2.0 — 2019-06-13

## README

# varasto-storage

Low level API for the Varasto JSON key-value store.

## Installation

```bash
$ npm install --save varasto-storage
```

## Usage

The package provides class called `Storage`, which provides an API very similar
to [Web Storage API].

Basic usage of storage looks like this:

```TypeScript
import { createStorage } from 'varasto-storage';

const storage = createStorage({ dir: './data' });
```

The function takes an optional configuration object, which supports these
settings:

| Property   | Default value | Description                                                    |
| ---------- | ------------- | -------------------------------------------------------------- |
| `dir`      | `./data`      | Directory where the items will be persisted into.              |
| `encoding` | `utf-8`       | Character encoding to use when items are stored onto the disk. |

If `dir` does not exist, it will be created when an item is stored into the
storage.

### Storing items

```TypeScript
setItem(key: string, value: JsonObject): Promise<void>
```

Attempts to store an item identified by `key`. Returned promise will fail if an
I/O error occurs while storing the item.

### Retrieving items

```TypeScript
getItem(key: string): Promise<JsonObject|undefined>
```

Attempts to retrieve an item identified by `key`. Returned promise will either
resolve into the value, or `undefined` if item with the given identifier does
not exist. The promise will fail if an I/O error occurs while retrieving the
item.

### Removing items

```TypeScript
removeItem(key: string): Promise<boolean>
```

Attempts to remove an item identified by `key`. Returned promise will resolve
into a boolean value which tells whether an value with the given identifier
existed or not. The promise will fail if an I/O error occurs while removing the
item.

[web storage api]: https://developer.mozilla.org/en-US/docs/Web/API/Storage

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