Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

electron-settings

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-settings

User settings manager for Electron

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.6K
decreased by-12.94%
Maintainers
1
Weekly downloads
 
Created
Source

Electron-Settings

User settings manager for Electron, adapted from Atom/config.


Options

KeyTypeDescriptionDefault
shouldSavebooleanWhether 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
ParameterTypeDescriptionRequiredDefault
keyPathstringThe key-path.
value*The value to set the given key-path.
optionsObjectElectronSettings options.See options
Examples
  1. 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' }
  1. 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' } } }
  1. 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' } } }
  1. 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' }

get(keyPath):Object

Gets the value of a configuration setting at the given key-path. Returns an Object.

Parameters
ParameterTypeDescriptionRequiredDefault
keyPathstringThe key-path.
Examples
  1. 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'
  1. 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' }
  1. 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' } } }

unset(keyPath[, options])

Unsets a configuration setting at the given key-path.

Parameters
ParameterTypeDescriptionRequiredDefault
keyPathstringThe key-path.
optionsObjectElectronSettings options.See options
Examples
  1. 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());
// => {}
  1. 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 }

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());
// => /Users/Nathan/Library/Application Support/Electron/config/settings.json

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

Keywords

FAQs

Package last updated on 14 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc