https://github.com/alireza29675/handy-storage
🗃️ Handy Storage is a simple way to store your data in a JSON file
https://github.com/alireza29675/handy-storage
database json storage
Last synced: 11 months ago
JSON representation
🗃️ Handy Storage is a simple way to store your data in a JSON file
- Host: GitHub
- URL: https://github.com/alireza29675/handy-storage
- Owner: Alireza29675
- License: mit
- Created: 2017-07-28T20:25:41.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-01-12T09:03:55.000Z (over 3 years ago)
- Last Synced: 2025-03-17T13:15:58.200Z (over 1 year ago)
- Topics: database, json, storage
- Language: JavaScript
- Homepage:
- Size: 536 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# HandyStorage
**HandyStorage** is a simple way to store your data in a JSON file
## Installation
```bash
npm install --save handy-storage
```
## 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
})
```
## Manual Refrence
### 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) ⇒ Promise
### new HandyStorage([path], [options])
Represents a "Handy" storage
| Param | Type | Description |
| --- | --- | --- |
| [path] | string | Path of JSON file |
| [options] | Object | Additional Configurations |
| [options.beautify] | boolean | Should storage beautify JSON before storing? _(Default: **false**)_ |
| [options.autoSave] | boolean | Should storage auto save when you use **.setState()** method? _(Default: **true**)_ |
### handyStorage.connect(path)
Connects storage to a JSON file
**Kind**: instance method of [HandyStorage](#HandyStorage)
| Param | Type | Description |
| --- | --- | --- |
| path | string | Path of JSON file |
### handyStorage.state
State object of storage, including all stored data
**Kind**: instance property of [HandyStorage](#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.
### handyStorage.setState(changes) ⇒ Promise
Sets some changes on "state" object then saves it into the file
**Kind**: instance method of [HandyStorage](#HandyStorage)
| Param | Type | Description |
| --- | --- | --- |
| changes | Object | State changes |
**Returns**: Promise - State change callback promise
### handyStorage.save([options]) ⇒ Promise
Saves current state into the connected JSON file
**Kind**: instance method of [HandyStorage](#HandyStorage)
| Param | Type | Description |
| --- | --- | --- |
| [options] | Object | Additional save configurations |
| [options.sync] | boolean | Should save synchronous? _(Default: **false**)_ |
**Returns**: Promise - Saving state callback promise