# handy-storage

> HandyStorage is a simple way to store your data in a JSON file

Latest version **2.1.6** (published 2019-07-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install handy-storage
pnpm add handy-storage
yarn add handy-storage
bun add handy-storage
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.6 |
| Published | 2019-07-29 |
| First published | 2017-10-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 130.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Alireza Sheikholmolouki |
| Maintainers | alireza29675 |
| Keywords | handy, storage, json, easy, filesystem |

## Links

- npm: https://www.npmjs.com/package/handy-storage
- Repository: https://github.com/Alireza29675/handy-storage
- Homepage: https://github.com/Alireza29675/handy-storage#readme
- Issues: https://github.com/Alireza29675/handy-storage/issues
- npm.io page: https://npm.io/package/handy-storage

## Dependencies (1)

- [json-beautify](https://npm.io/package/json-beautify.md) ^1.0.1

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.1.6 (latest) — 2019-07-29
- 2.1.5 — 2019-07-29
- 2.1.4 — 2019-06-29
- 2.1.1 — 2019-05-14
- 2.0.1 — 2018-02-18
- 1.2.1 — 2018-02-18
- 1.0.0 — 2017-10-06

## README

<a name="beginning"></a>

![handy-storage logo](https://user-images.githubusercontent.com/2771377/36355655-d20e813a-14fb-11e8-8c15-4741799c9090.png)

# HandyStorage
**HandyStorage** is a simple way to store your data in a JSON file

<a name="Installation"></a>
## Installation
```bash
npm install --save handy-storage
```

<a name="Usage"></a>
## Example of Usage
```javascript
const HandyStorage = require('handy-storage');

const storage = new HandyStorage({
    beautify: true
});

storage.connect('./information.json');

storage.setState({
    name: 'Alireza',
    lastname: 'Sh',
    friends: [
        'Jane',
        'John'
    ],
    visited: storage.state.visited || 0
})

storage.setState({
    visited: storage.state.visited + 1
})
```

<a name="Refrence"></a>

## Manual Refrence

<a name="HandyStorage"></a>

### HandyStorage
**Kind**: global class

* [HandyStorage](#HandyStorage)
    * [new HandyStorage([path])](#new_HandyStorage_new)
    * [.connect(path)](#HandyStorage+connect)
    * [.state](#HandyStorage+state)
    * [.setState([changes])](#HandyStorage+setState)
    * [.save([options])](#HandyStorage+save) ⇒ <code>Promise</code>

<a name="new_HandyStorage_new"></a>

### new HandyStorage([path], [options])
Represents a "Handy" storage



| Param | Type | Description |
| --- | --- | --- |
| [path] | <code>string</code> | Path of JSON file |
| [options] | <code>Object</code> | Additional Configurations |
| [options.beautify] | <code>boolean</code> | Should storage beautify JSON before storing? _(Default: **false**)_ |
| [options.autoSave] | <code>boolean</code> | Should storage auto save when you use **.setState()** method? _(Default: **true**)_ |


<a name="HandyStorage+connect"></a>

### handyStorage.connect(path)
Connects storage to a JSON file

**Kind**: instance method of [<code>HandyStorage</code>](#HandyStorage)

| Param | Type | Description |
| --- | --- | --- |
| path | <code>string</code> | Path of JSON file |

<a name="HandyStorage+state"></a>

### handyStorage.state
State object of storage, including all stored data

**Kind**: instance property of [<code>HandyStorage</code>](#HandyStorage)

> **Tip 1**: you can change this object and call [.save()](#HandyStorage+save) to store it into JSON file.

> **Tip 2**: try to use [.setState()](#HandyStorage+setState) method instead of changing **.state** directly! it's much safer, also it supports **autoSave** mode.

<a name="HandyStorage+setState"></a>

### handyStorage.setState(changes) ⇒ <code>Promise</code>
Sets some changes on "state" object then saves it into the file

**Kind**: instance method of [<code>HandyStorage</code>](#HandyStorage)

| Param | Type | Description |
| --- | --- | --- |
| changes | <code>Object</code> | State changes |

**Returns**: <code>Promise</code> - State change callback promise


<a name="HandyStorage+save"></a>

### handyStorage.save([options]) ⇒ <code>Promise</code>
Saves current state into the connected JSON file

**Kind**: instance method of [<code>HandyStorage</code>](#HandyStorage)

| Param | Type | Description |
| --- | --- | --- |
| [options] | <code>Object</code> | Additional save configurations |
| [options.sync] | <code>boolean</code> | Should save synchronous? _(Default: **false**)_ |

**Returns**: <code>Promise</code> - Saving state callback promise

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