User settings manager for Electron, adapted from Atom/config.
Key | Type | Description | Default |
---|---|---|---|
shouldSave |
boolean |
Whether we should save changes to disk. | true |
Sets the value of a configuration setting at the given key-path.
Parameter | Type | Description | Required | Default |
---|---|---|---|---|
keyPath |
string |
The key-path. | ✓ | |
value |
* |
The value to set the given key-path. | ✓ | |
options |
Object |
ElectronSettings options. | See options |
- Simple example with basic key-path.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
settings.set('foo', 'bar');
console.log(settings.get());
// => { foo: 'bar' }
- Advanced example with complex key-path.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
settings.set('foo.bar.baz', 'qux');
console.log(settings.get());
// => { foo: { bar: { baz: 'qux' } } }
- Advanced example with basic key-path and complex value.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
settings.set('foo', {
snap: {
crackle: 'pop'
}
});
console.log(settings.get());
// => { foo: { snap: { crackle: 'pop' } } }
- Overwrite settings without defining a key-path.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
// This will overwrite any pre-existing settings.
settings.set({
foo: 'bar'
});
console.log(settings.get());
// => { foo: 'bar' }
Gets the value of a configuration setting at the given key-path. Returns an Object
.
Parameter | Type | Description | Required | Default |
---|---|---|---|---|
keyPath |
string |
The key-path. |
- Simple example with basic key-path.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
settings.set('foo', 'bar');
console.log(settings.get('foo'));
// => 'bar'
- Advanced example with complex key-path.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
settings.set('foo.bar.baz', 'qux');
console.log(settings.get('foo.bar'));
// => { baz: 'qux' }
- Get all settings.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
settings.set('foo.bar.baz', 'qux');
console.log(settings.get());
// => { foo: { bar: { baz: 'qux' } } }
Unsets a configuration setting at the given key-path.
Parameter | Type | Description | Required | Default |
---|---|---|---|---|
keyPath |
string |
The key-path. | ✓ | |
options |
Object |
ElectronSettings options. | See options |
- Simple example with basic key-path.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
settings.set('foo', 'bar');
console.log(settings.get());
// => { foo: 'bar' }
settings.unset('foo');
console.log(settings.get());
// => {}
- Advanced example with complex key-path.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
settings.set('foo.bar.baz', 'qux');
console.log(settings.get());
// => { foo: { bar: { baz: 'qux' } } }
settings.unset('foo.bar');
console.log(settings.get());
// => { foo: null }
Gets the string path to the config file being used. Returns a string
.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
console.log(settings.getUserConfigPath());
// => /Users/Nathan/Library/Application Support/Electron/config/settings.json
observe
method to watch when a particular key-path has changed.- Allow default setting handling and merging with pre-existing settings.
- Write tests.
ISC