All Projects → de-luca → electron-json-config

de-luca / electron-json-config

Licence: BSD-2-Clause license
Simply set and get configuration from a json file for your Electron app

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to electron-json-config

scheriff
Schema Sheriff: yet another Kubernetes manifests validation tool
Stars: ✭ 15 (-40%)
Mutual labels:  config
superconfig
Access environment variables. Also includes presence validation, type coercion and default values.
Stars: ✭ 33 (+32%)
Mutual labels:  config
ApexConfigs
Apex Legends configs for a competitve player
Stars: ✭ 52 (+108%)
Mutual labels:  config
qtile-config
My qtile config
Stars: ✭ 47 (+88%)
Mutual labels:  config
lightning-hydra-template
PyTorch Lightning + Hydra. A very user-friendly template for rapid and reproducible ML experimentation with best practices. ⚡🔥⚡
Stars: ✭ 1,905 (+7520%)
Mutual labels:  config
d-l-l
Simplified DLL config creator & handler
Stars: ✭ 27 (+8%)
Mutual labels:  config
parse-git-config
Parse `.git/config` into a JavaScript object. sync or async.
Stars: ✭ 55 (+120%)
Mutual labels:  config
nvim
❤️ A neovim config repo.
Stars: ✭ 33 (+32%)
Mutual labels:  config
DYNAMICMORTAL
Config files for my GitHub profile.
Stars: ✭ 19 (-24%)
Mutual labels:  config
Tieba-Birthday-Spider
百度贴吧生日爬虫,可抓取贴吧内吧友生日,并且在对应日期自动发送祝福
Stars: ✭ 28 (+12%)
Mutual labels:  config
lime
Simple standalone Zsh theme
Stars: ✭ 15 (-40%)
Mutual labels:  config
Enderfga
Undergraduate period academic garbage
Stars: ✭ 49 (+96%)
Mutual labels:  config
unconfig
A universal solution for loading configurations.
Stars: ✭ 415 (+1560%)
Mutual labels:  config
AbbasAtaei
Config files for my GitHub profile.
Stars: ✭ 47 (+88%)
Mutual labels:  config
uconfig
Lightweight, zero-dependency, and extendable configuration management library for Go
Stars: ✭ 53 (+112%)
Mutual labels:  config
eslint-config-trybe
ESLint shared config packages used be Trybe
Stars: ✭ 55 (+120%)
Mutual labels:  config
stumpwm-config
My configuration files for StumpWM
Stars: ✭ 62 (+148%)
Mutual labels:  config
kerrigan
基于Tornado实现的一套配置中心,可基于分项目、环境管理配置,语法高亮、对比历史版本、快速回滚等,并提供Restful风格的API
Stars: ✭ 57 (+128%)
Mutual labels:  config
php-nacos
阿里巴巴nacos配置中心-PHP客户端
Stars: ✭ 167 (+568%)
Mutual labels:  config
redconf
sync config from redis or others storage while the config values changed
Stars: ✭ 12 (-52%)
Mutual labels:  config

electron-json-config

npm codecov

Simply set and get configuration from a json file for your Electron app

This is the 2.x.x tree.
For 1.x.x code and documentation please refer to the 1.x.x tree.
See UPGRADE.md for an upgrade guide.

This package can only be used from the main process.

Installation

NPM

npm install --save electron-json-config@beta

yarn

yarn add electron-json-config@beta

Usage

CommonJS

const config = require('electron-json-config').factory();

config.set('foo', 'bar');
console.log(config.get('foo')); // bar

ES Modules

import { factory } from 'electron-json-config';

const config = factory();

config.set('foo', 'bar');
console.log(config.get('foo')); // bar

Documentation

Key

type Key = string | Array<string>;

A key can be :

  • a classic string key
    eg: 'foo'
  • a dotted string multi level key
    eg: 'foo.bar'
  • an array of string representing a multi level key
    eg: ['foo', 'bar']

Storable

interface Storable {
  [key: string]: Storable | any;
}

factory(file?: string, key?: string): Conf

Description:
Create an instance of Config and returns it.
If an instance with the same key exist, returns this instance instead.

If file is specified, the configuration will be saved to that file instead of the default app.getPath('userData') + '/config.json'.

If key is specified, the requested instance will be saved under une given key instead of the default userData.

Examples:

// file: app.getPath('userData') + '/config.json'
// key: 'userData'
factory();

// file: '/data/test.json'
// key: '/data/test.json'
factory('/data/test.json');

// file: '/data/test.json'
// key: 'test'
factory('/data/test.json', 'test');

// file: app.getPath('userData') + '/config.json'
// key: 'test'
factory(undefined, 'test');

Parameters:

Name Type Default
file? string app.getPath('userData') + '/config.json'
key? string `key

Returns: void

Config

The config class is a set of wrappers and helpers providing access to configuration and file synchronization.

new Config(file: string, data: Storable): Config

Parameters:

Name Type
file string
data Storable

Returns: Config

get file(): string

Description: Returns the name of the file the config is stored in.

Returns: string

all(): Storable

Description: Returns all the data currently saved.

Returns: Storable

delete(key: Key): void

Description: Removes the key and its value from the config file.

Parameters:

Name Type
key Key

Returns: void

deleteBulk(keys: Array<Key>): void

Description: Removes all the keys specified and theirs value from the config file.

Parameters:

Name Type
keys Array<Key>

Returns: void

get<T>(key: Key, defaultValue?: T): T | undefined

Description: Returns the value associated with the key, undefined otherwise. You can specify a default value returned in case the key does not exists.

Parameters:

Name Type
key Key
defaultValue? T

Returns: T | undefined

has(key: Key): boolean

Description: Checks if a key exists.

Parameters:

Name Type
key Key

Returns: boolean

keys(key?: Key): Array<string>

Description: If key is omitted, returns an array containing all keys in the config file.
If key is provided, returns an array containing all sub keys in the key object.

Parameters:

Name Type
key? Key

Returns: Array<string>

purge(): void

Description: Removes all data from the config file.

Returns: void

set<T>(key: Key, value: Storable | T): void

Description: Sets a key with the specified value. Overwrites the value, if the key already exists.

Parameters:

Name Type
key Key
value Storable | T

Returns: void

setBulk<T>(items: { [key:string]: Storable | T }): void

Description: Like .set() but sets multiple keys in a single call.

Parameters:

Name Type
items { [key: string]: Storable | T }

Returns: void

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].