1.2.0 • Published 5 years ago
electron-json-storage-sync v1.2.0
electron-json-storage-sync
Synchronously write and read user settings in Electron apps
This is a synchronous version of electron-json-storage. Credits to jviotti for writing the original async version. Version 1.1.0 implements methods get, set, has, keys, remove and clear.
Installation
Install electron-json-storage-sync by running:
$ npm install --save electron-json-storage-syncYou can require this module from either the main or renderer process (with and without remote).
Documentation
Storage module
const storage = require('electron-json-storage-sync');.get(key)
const result = storage.get('foo');
if (result.status) {
// do something with result.data
} else {
// handle result.error
}.set(key, data)
const result = storage.set('foo', {bar:'baz'});
if (result.status) {
// data has been stored
} else {
// handle result.error
}.has()
const result = storage.has('foo');
if (result.status && result.data) {
// key in storage
} else if (result.status && !result.data){
// key not in storage
} else {
// handle result.error
}.keys()
const result = storage.keys();
if (result.status) {
// do something with array result.data
} else {
// handle result.error
}.remove(key)
const result = storage.remove();
if (result.status) {
// the storage record has been removed
} else {
// handle result.error
}.clear()
const result = storage.clear();
if (result.status) {
// storage has been cleared
} else {
// handle result.error
}