Home Reference Source

Function

Static Public Summary
public

getConfig(baseConfig: object, options: object): object

Provides a configuration object based on a given config object and a json file loaded from the filesystem.

public

Loads JSON configuration from a file on the filesystem.

public

resolveProperties(target: object, property: string | array): Object

Resolves special non-primitive values in an object.

Static Public

public getConfig(baseConfig: object, options: object): object source

import getConfig from '@xailabs/app-config/src/getConfig.js'

Provides a configuration object based on a given config object and a json file loaded from the filesystem.

Params:

NameTypeAttributeDescription
baseConfig object

The default configuration before runtime config values are added.

options object
  • optional

An object with additional options

options.file string
  • optional

Absolute path to a json file that will be loaded at runtime.

options.freeze boolean
  • optional
  • default: false

Whether to freeze the returned config (and make it read-only)

options.resolve string | array
  • optional
  • default: []

One or more special keys to resolve.

Return:

object

A read-only object containing all resolved values from baseConfig and `

Example:

// config.js
import { getConfig } from '@xailabs/electron-config';
import myConfig from './myConfig.js';
import {app} from 'electron';

export default getConfig(myConfig, {
    file: `${app.getPath('appData')/my-config.json`
});

See:

public loadConfigFile(file: string): object source

import loadConfigFile from '@xailabs/app-config/src/loadConfigFile.js'

Loads JSON configuration from a file on the filesystem. Returns the parsed data as a plain object. Adds a __file property with the full path to the loaded file to the result.

Params:

NameTypeAttributeDescription
file string

Absolute path to the file, including filename and extension

Return:

object

An object containing the json data or undefined if something went wrong

public resolveProperties(target: object, property: string | array): Object source

import resolveProperties from '@xailabs/app-config/src/resolveProperties.js'

Resolves special non-primitive values in an object.

Parses the object recursively and returns a new object where all values that contained a property matching the provided property are resolved to the actual value of that property.

For example, {foo: {development: 'foo', production: 'bar'}} will result in {foo: 'foo'} when called with property=development, but it will result in {foo: 'bar'} when called with property=production.

Params:

NameTypeAttributeDescription
target object

The target object.

property string | array

The name of the property to resolve the value from. Can be array of multiple properties.

Return:

Object

A new object with all values of target, but with resolved values