Electron-Settings
User settings manager for Electron, adapted from Atom/config.
Options
Key | Type | Description | Default |
---|
shouldSave | boolean | Whether we should save changes to disk. | true |
Methods
set(keyPath, value[, options])
Sets the value of a configuration setting at the given key-path.
Parameters
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 |
Examples
- Simple example with basic key-path.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
settings.set('foo', 'bar');
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());
- 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());
- Overwrite settings without defining a key-path.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
settings.set({
foo: 'bar'
});
console.log(settings.get());
get(keyPath):Object
Gets the value of a configuration setting at the given key-path. Returns an Object
.
Parameters
Parameter | Type | Description | Required | Default |
---|
keyPath | string | The key-path. | | |
Examples
- Simple example with basic key-path.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
settings.set('foo', 'bar');
console.log(settings.get('foo'));
- 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'));
- Get all settings.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
settings.set('foo.bar.baz', 'qux');
console.log(settings.get());
unset(keyPath[, options])
Unsets a configuration setting at the given key-path.
Parameters
Parameter | Type | Description | Required | Default |
---|
keyPath | string | The key-path. | ✓ | |
options | Object | ElectronSettings options. | | See options |
Examples
- Simple example with basic key-path.
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
settings.set('foo', 'bar');
console.log(settings.get());
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());
settings.unset('foo.bar');
console.log(settings.get());
getUserConfigPath():string
Gets the string path to the config file being used. Returns a string
.
Example
let ElectronSettings = require('electron-settings');
let settings = new ElectronSettings();
console.log(settings.getUserConfigPath());
Todo
observe
method to watch when a particular key-path has changed.- Allow default setting handling and merging with pre-existing settings.
- Write tests.
Authors
License
ISC