0.1.3 • Published 3 years ago

kvps v0.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

KVPS

kvps is "key-value pair storage".

key-value pair

A key-value pair consists of two related data elements:

  • Key, which is a constant that defines the data set (e.g., name, age, gender).
  • Value, which is a variable that belongs to the set (e.g., steve, 20, male).

Storage

This key-value pair will be saved in a json file. When restarting, the data will be called.

Usage

There are two ways of usage, kvp and kvps.

kvp usage

const KVPS = require("kvps");

const kvp = new KVPS();

kvps usage

const KVPS = require("kvps");

const kvps = new KVPS("path/to/file");

Methods

get

Used to get the value of a key, example:

var age = kvp.get("age");

set

Used to set the value of a key, example:

var age = kvp.set("age", 20);

clear

Used to unset the values, example:

clear all values

kvp.clear();

clear a key value

kvp.clear("age");

save

Used to save the kvp to the json file, example:

kvps.save().then(() => {
  console.log("Saved the kvp.");
}).catch(err => {
  console.error(err);
});

Notes

  • KVP & KVPS do the same job.
  • Diffrence between KVP & KVPS is that KVPS is savable while KVP is not.
  • save method return a promise.