Config
Handles a configuration dictionary.
Type parameters
CfgA type of the configuration dictionary.
Properties
_config : Record<string, any>privatereadonlymodule:utils/config~Config#_configStore for the whole configuration.
Methods
constructor( [ configurations ], [ defaultConfigurations ] )module:utils/config~Config#constructorCreates an instance of the
Configclass.Type parameters
Cfg
Parameters
[ configurations ] : Partial<Cfg>The initial configurations to be set. Usually, provided by the user.
[ defaultConfigurations ] : Partial<Cfg>The default configurations. Usually, provided by the system.
define( config ) → voidmodule:utils/config~Config#define:CONFIG_OBJECTDoes exactly the same as
setwith one exception – passed configuration extends existing one, but does not overwrite already defined values.This method is supposed to be called by plugin developers to setup plugin's configurations. It would be rarely used for other needs.
Parameters
config : Partial<Cfg>The configuration object from which take properties as configuration entries. Configuration names are case-sensitive.
Returns
void
define( name, value ) → voidmodule:utils/config~Config#define:KEY_VALUEDoes exactly the same as
setwith one exception – passed configuration extends existing one, but does not overwrite already defined values.This method is supposed to be called by plugin developers to setup plugin's configurations. It would be rarely used for other needs.
Type parameters
K : extends string
Parameters
name : KThe configuration name. Configuration names are case-sensitive.
value : GetSubConfig<Cfg, K>The configuration value.
Returns
void
get( name ) → undefined | GetSubConfig<Cfg, K>module:utils/config~Config#getGets the value for a configuration entry.
config.get( 'name' );Copy codeDeep configurations can be retrieved by separating each part with a dot.
config.get( 'toolbar.collapsed' );Copy codeType parameters
K : extends string
Parameters
name : KThe configuration name. Configuration names are case-sensitive.
Returns
undefined | GetSubConfig<Cfg, K>The configuration value or
undefinedif the configuration entry was not found.
names() → Iterable<string>module:utils/config~Config#namesIterates over all top level configuration names.
Returns
Iterable<string>
set( config ) → voidmodule:utils/config~Config#set:CONFIG_OBJECTSet configuration values.
It accepts an object, which properties and values will be used to set configurations.
config.set( { width: 500 toolbar: { collapsed: true } } ); // Equivalent to: config.set( 'width', 500 ); config.set( 'toolbar.collapsed', true );Copy codePassing an object as the value will amend the configuration, not replace it.
config.set( 'toolbar', { collapsed: true, } ); config.set( 'toolbar', { color: 'red', } ); config.get( 'toolbar.collapsed' ); // true config.get( 'toolbar.color' ); // 'red'Copy codeIt accepts both a name/value pair or an object, which properties and values will be used to set configurations. See
set.Parameters
config : Partial<Cfg>The configuration object from which take properties as configuration entries. Configuration names are case-sensitive.
Returns
void
set( name, value ) → voidmodule:utils/config~Config#set:KEY_VALUESet configuration values.
It also accepts setting a "deep configuration" by using dots in the name. For example,
'resize.width'sets the value for thewidthconfiguration in theresizesubset.config.set( 'resize.width', 500 );Copy codeIt accepts both a name/value pair or an object, which properties and values will be used to set configurations. See
set.Type parameters
K : extends string
Parameters
name : KThe configuration name. Configuration names are case-sensitive.
value : GetSubConfig<Cfg, K>The configuration value.
Returns
void
_getFromSource( source, name ) → anyprivatemodule:utils/config~Config#_getFromSourceGet specified configuration from specified source (nested object).
Parameters
source : anylevel of nested object.
name : stringThe configuration name. Configuration names are case-sensitive.
Returns
anyThe configuration value or
undefinedif the configuration entry was not found.
_setObjectToTarget( target, configuration, [ isDefine ] ) → voidprivatemodule:utils/config~Config#_setObjectToTargetIterates through passed object and calls
_setToTargetmethod with object key and value for each property.Parameters
target : anyNested config object.
configuration : anyConfiguration data set
[ isDefine ] : booleanDefines if passed configuration is default configuration or not.
Returns
void
_setToTarget( target, name, value, isDefine ) → voidprivatemodule:utils/config~Config#_setToTargetSaves passed configuration to the specified target (nested object).
Parameters
target : anyNested config object.
name : anyThe configuration name or an object from which take properties as configuration entries. Configuration names are case-sensitive.
value : anyThe configuration value. Used if a name is passed.
isDefine : booleanDefine if passed configuration should overwrite existing one.
Defaults to
false
Returns
void