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.
Install electron-json-storage-sync
by running:
$ npm install --save electron-json-storage-sync
You can require this module from either the main or renderer process (with and without remote
).
const storage = require('electron-json-storage-sync');
const result = storage.get('foo');
if (result.status) {
// do something with result.data
} else {
// handle result.error
}
const result = storage.set('foo', {bar:'baz'});
if (result.status) {
// data has been stored
} else {
// handle result.error
}
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
}
const result = storage.keys();
if (result.status) {
// do something with array result.data
} else {
// handle result.error
}
const result = storage.remove();
if (result.status) {
// the storage record has been removed
} else {
// handle result.error
}
const result = storage.clear();
if (result.status) {
// storage has been cleared
} else {
// handle result.error
}