Function
Static Public Summary | ||
public |
Provides a configuration object based on a given config object and a json file loaded from the filesystem. |
|
public |
loadConfigFile(file: string): object 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:
Name | Type | Attribute | Description |
baseConfig | object | The default configuration before runtime config values are added. |
|
options | object |
|
An object with additional options |
options.file | string |
|
Absolute path to a json file that will be loaded at runtime. |
options.freeze | boolean |
|
Whether to freeze the returned config (and make it read-only) |
options.resolve | string | array |
|
One or more special keys to resolve. |
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`
});
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:
Name | Type | Attribute | Description |
file | string | Absolute path to the file, including filename and extension |
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
.