GithubHelp home page GithubHelp logo

chimpanzees / electron-config Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sindresorhus/electron-store

1.0 2.0 0.0 10 KB

Simple config handling for your Electron app or module

License: MIT License

JavaScript 100.00%

electron-config's Introduction

electron-config Build Status: Linux and macOS Build status: Windows

Simple config handling for your Electron app or module

Electron doesn't have a built-in way to persist user settings and other data. This module handles that for you, so you can focus on building your app. Config is saved in a JSON file in app.getPath('userData').

You can use this module directly in both the main and renderer process.

Install

$ npm install --save electron-config

Usage

const Config = require('electron-config');
const config = new Config();

config.set('unicorn', 'πŸ¦„');
console.log(config.get('unicorn'));
//=> 'πŸ¦„'

// use dot-notation to access nested properties
config.set('foo.bar', true);
console.log(config.get('foo'));
//=> {bar: true}

config.delete('unicorn');
console.log(config.get('unicorn'));
//=> undefined

API

Config([options])

Returns a new instance.

options

defaults

Type: Object

Default config.

name

Type: string
Default: config

Name of the config file (without extension).

This is useful if you want multiple config files for your app. Or if you're making a reusable Electron module that persists some config, in which case you should not use the name config.

Instance

You can use dot-notation in a key to access nested properties.

The instance is iterable so you can use it directly in a for…of loop.

.set(key, value)

Set an item.

.set(object)

Set multiple items at once.

.get(key)

Get an item.

.has(key)

Check if an item exists.

.delete(key)

Delete an item.

.clear()

Delete all items.

.size

Get the item count.

.store

Get all the config as an object or replace the current config with an object:

conf.store = {
	hello: 'world'
};

.path

Get the path to the config file.

Related

License

MIT Β© Sindre Sorhus

electron-config's People

Contributors

sindresorhus avatar

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.