Class

Config (utils)

@ckeditor/ckeditor5-utils/src/config

class

Handles a configuration dictionary.

Filtering

Type parameters

  • Cfg

    A type of the configuration dictionary.

Properties

  • private readonly

    _config : Record<string, any>

    Store for the whole configuration.

Methods

  • constructor( [ configurations ], [ defaultConfigurations ] )

    Creates an instance of the Config class.

    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 ) → void

    Does exactly the same as set with 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 ) → void

    Does exactly the same as set with 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 : K

    The configuration name. Configuration names are case-sensitive.

    value : GetSubConfig<Cfg, K>

    The configuration value.

    Returns

    void
  • get( name ) → undefined | GetSubConfig<Cfg, K>

    Gets the value for a configuration entry.

    config.get( 'name' );
    

    Deep configurations can be retrieved by separating each part with a dot.

    config.get( 'toolbar.collapsed' );
    

    Type parameters

    K : extends string

    Parameters

    name : K

    The configuration name. Configuration names are case-sensitive.

    Returns

    undefined | GetSubConfig<Cfg, K>

    The configuration value or undefined if the configuration entry was not found.

  • names() → Iterable<string>

    Iterates over all top level configuration names.

    Returns

    Iterable<string>
  • set( config ) → void

    Set 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 );
    

    Passing 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'
    

    It 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 ) → void

    Set configuration values.

    It also accepts setting a "deep configuration" by using dots in the name. For example, 'resize.width' sets the value for the width configuration in the resize subset.

    config.set( 'resize.width', 500 );
    

    It 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 : K

    The configuration name. Configuration names are case-sensitive.

    value : GetSubConfig<Cfg, K>

    The configuration value.

    Returns

    void
  • private

    _getFromSource( source, name ) → any

    Get specified configuration from specified source (nested object).

    Parameters

    source : any

    level of nested object.

    name : string

    The configuration name. Configuration names are case-sensitive.

    Returns

    any

    The configuration value or undefined if the configuration entry was not found.

  • private

    _setObjectToTarget( target, configuration, [ isDefine ] ) → void

    Iterates through passed object and calls _setToTarget method with object key and value for each property.

    Parameters

    target : any

    Nested config object.

    configuration : any

    Configuration data set

    [ isDefine ] : boolean

    Defines if passed configuration is default configuration or not.

    Returns

    void
  • private

    _setToTarget( target, name, value, isDefine ) → void

    Saves passed configuration to the specified target (nested object).

    Parameters

    target : any

    Nested config object.

    name : any

    The configuration name or an object from which take properties as configuration entries. Configuration names are case-sensitive.

    value : any

    The configuration value. Used if a name is passed.

    isDefine : boolean

    Define if passed configuration should overwrite existing one.

    Defaults to false

    Returns

    void