1.0.7 • Published 4 years ago

node-lstorage v1.0.7

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

LocalStorage

Simple storage library with temp file options for node.js

npm Package downloads per month Known Vulnerabilities


Why?

I so many times needed a simple local storage or temp storage and it simplify all the process.


Installation

npm install node-lstorage


Usage

It's so easy to use.

First you need to define it:

const storage = require('node-lstorage'); // I recommend use `storage` name for var.

Simple

let notifications = false;

(function main() {
    storage.load();
    if(storage.has('notifications')) {
        notifications = storage.get("notifications");
    } else {
    	storage.set("notifications", notifications);
    }

	console.log(notifications);
})();

Change File Name

let notifications = false;

(function main() {
    storage.load("json_files/change_file");
    if(storage.has('notifications')) {
        notifications = storage.get("notifications");
    } else {
    	storage.set("notifications", notifications);
    }

	console.log(notifications);
})();

Save Multiple Data

let notifications = false;
let normal_width = 800;
let normal_height = 1024;

(function main() {
    storage.load("json_files/save_multiple_data");

	if(!storage.has([ 'notifications', 'normal_width', 'normal_height' ])) {
		console.log("All variables setted.");

		storage.set({
			notifications: notifications,
			normal_width: normal_width,
			normal_height: normal_height
		});
	}

    if(storage.has('notifications')) {
        notifications = storage.get("notifications");
    } else {
    	storage.set("notifications", notifications);
    }

    if(storage.has('normal_width')) {
        normal_width = storage.get("normal_width");
    } else {
    	storage.set("normal_width", normal_width);
    }

    if(storage.has('normal_height')) {
        normal_height = storage.get("normal_height");
    } else {
    	storage.set("normal_height", normal_height);
    }

	console.log({
		notifications: notifications,
		normal_width: normal_width,
		normal_height: normal_height
	});
})();

Temp file system

let notifications = false;

(function main() {
    storage.tmp(); // Initialize temp storage system

    if(storage.tmp.has('notifications')) {
        notifications = storage.get("notifications");
    } else {
    	storage.tmp.set("notifications", notifications);
    }

	console.log("\r\n");
	console.log("FileName:", storage.tmp.fileName);
	console.log("StorageData:", JSON.stringify(storage.tmp.data));

	storage.tmp.delete(); // Delete temp file
	console.log("TMP File deleted.");
})();

Properties

PropertyDescription
dataJSON file data as object.
lFileUsed JSON file path.

Methods

PropertyDescriptionParams
getJSON file data as object.*String Property
setSet JSON property value.(String) Property, (Any) Value OR (Object) Values
hasVerify JSON property exists.*(String|Array) Property
loadLoad JSON file data.(String) JSON File Path
emptyEmpty JSON file.
tmpInstance temp file system subclass.

TMP Subclass methods

PropertyDescriptionParams
getTemp JSON file data as object.*String Property
setSet temp JSON property value.(String) Property, (Any) Value OR (Object) Values
hasVerify temp JSON property exists.*(String|Array) Property
deleteDelete temp JSON file.
1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago