Sign up (with export icon)

Config

Api-class icon class

Handles a configuration dictionary.

Type parameters

  • Chevron-right icon

    Cfg

    A type of the configuration dictionary.

Properties

Methods

  • Chevron-right icon

    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.

  • Chevron-right icon

    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
  • Chevron-right icon

    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
  • Chevron-right icon

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

    Gets the value for a configuration entry.

    config.get( 'name' );
    
    Copy code

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

    config.get( 'toolbar.collapsed' );
    
    Copy code

    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.

  • Chevron-right icon

    names() → Iterable<string>

    Iterates over all top level configuration names.

    Returns

    Iterable<string>
  • Chevron-right icon

    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 );
    
    Copy code

    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'
    
    Copy code

    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
  • Chevron-right icon

    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 );
    
    Copy code

    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
  • Chevron-right icon

    _getFromSource( source, name ) → any
    Lock icon private

    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.

  • Chevron-right icon

    _setObjectToTarget( target, configuration, [ isDefine ] ) → void
    Lock icon private

    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
  • Chevron-right icon

    _setToTarget( target, name, value, isDefine ) → void
    Lock icon private

    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