varasto-storagedeprecated

Persistent JSON key-value store

Usage no npm install needed!

<script type="module">
  import varastoStorage from 'https://cdn.skypack.dev/varasto-storage';
</script>

README

varasto-storage

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

Installation

$ 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:

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

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

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

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.