This package has been deprecated

Author message:

This package has been deprecated and is no longer maintained. Please use @varasto/fs-storage.

varasto-storage
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i varasto-storage

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

8.39 kB

Total Files

5

Last publish

Collaborators

  • rauli