# node-lstorage

> Simple storage library with temp file options for [node.js](https://www.npmjs.org)

Latest version **1.0.7** (published 2020-05-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install node-lstorage
pnpm add node-lstorage
yarn add node-lstorage
bun add node-lstorage
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2020-05-27 |
| First published | 2020-05-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tusso4 |
| Maintainers | tusso4 |
| Keywords | temp, tmp, storage, storage system, settings system |

## Links

- npm: https://www.npmjs.com/package/node-lstorage
- npm.io page: https://npm.io/package/node-lstorage

## Dependencies (1)

- [tmp](https://npm.io/package/tmp.md) ^0.2.1

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.7 (latest) — 2020-05-27
- 1.0.6 — 2020-05-27
- 1.0.5 — 2020-05-27
- 1.0.4 — 2020-05-27
- 1.0.3 — 2020-05-27
- 1.0.2 — 2020-05-27
- 1.0.1 — 2020-05-27
- 1.0.0 — 2020-05-27

## README

# LocalStorage

Simple storage library with temp file options for [node.js](https://www.npmjs.org)

[![npm Package](https://img.shields.io/npm/v/node-lstorage.svg)](https://www.npmjs.org/package/node-lstorage)
[![downloads per month](http://img.shields.io/npm/dm/node-lstorage.svg)](https://www.npmjs.org/package/node-lstorage)
[![Known Vulnerabilities](https://snyk.io/test/npm/node-lstorage/badge.svg)](https://snyk.io/test/npm/node-lstorage)

---
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:

```js
const storage = require('node-lstorage'); // I recommend use `storage` name for var.
```

#### Simple
```js
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
```js
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
```js
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
```js
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
---------
| Property              | Description                                                               |
|:---                   |:---                                                                       |
|`data`                 | JSON file data as object.    |
|`lFile`               | Used JSON file path.   |

---
Methods
---------
| Property              | Description                     | Params        |
|:---                   |:---                             |:---         |
|`get`                 | JSON file data as object.        |*`String` Property|
|`set`               | Set JSON property value.           |*(`String`) Property, *(`Any`) Value *OR* (`Object`) Values |
|`has`               | Verify JSON property exists.       |*(`String`\|`Array`) Property |
|`load`               | Load JSON file data.              |(`String`) JSON File Path|
|`empty`               | Empty JSON file.   |             |
|`tmp`               | Instance temp file system subclass.|        |

---
TMP Subclass methods
---------
| Property              | Description                     | Params        |
|:---                   |:---                             |:---         |
|`get`                 | Temp JSON file data as object.        |*`String` Property|
|`set`               | Set temp JSON property value.           |*(`String`) Property, *(`Any`) Value *OR* (`Object`) Values|
|`has`               | Verify temp JSON property exists.       |*(`String`\|`Array`) Property |
|`delete`               | Delete temp JSON file.   |             |

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