Code Monkey home page Code Monkey logo

electron-settings's Introduction

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

  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

Parameter Type Description Required Default
keyPath string The 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

Parameter Type Description Required Default
keyPath string The key-path.
options Object ElectronSettings 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

electron-settings's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.