Config Class

Helper class that manages all configuration settings for an iModel.js application.

The static Config.App is used by many parts of the iModel.js library to retrieve configuration settings.

The initial use of Config.App gathers configuration variables from 3 different locations:

  1. Sets 'imjs_env_is_browser' based on if the window is defined.
  2. Performs a GET request for a "config.json". If found merges the files contents into the Config.
  3. Appends any environment variable that are prefixed with "imjs".

The order listed above is important because if there is any overlap, the last one to contain the variable will win.

After the initial use of Config.App, all additional updates to the configuration must be performed using Config.App.add or Config.App.merge.

Expanding variables is supported using ${} syntax. If the variable is of type string and contains a ${}, the rest of the configuration variables are searched to populate the place of the variable. i.e. If the variable appName='TestApp', a variable with a value of 'https://${appName}' will be expanded to https://TestApp.

Does not recursively expand variables such as, appName=${appName}.

Methods

Name Description
get(varName: string, defaultVal?: boolean | string | number): any Attempts to retrieve a variable, the search is case-insensitive.  
getBoolean(name: string, defaultVal?: false | true): boolean Attempt to get a boolean type variable value.  
getContainer(): any Return clone of the internal property container object.  
getNumber(name: string, defaultVal?: number): number Attempt to get a number type variable value.  
getString(name: string, defaultVal?: string): string Attempt to get a string type variable value.  
getVars(): string[] Return a list of variable names present in the config.  
has(varName: string): boolean Checks, case-insensitive, if a variable exists.  
merge(source: any): void Merges the provided object into the config.  
query(varName: string): any Retrieves a variable if it exists, otherwise returns undefined.  
remove(varName: string): void Remove a variable from the config.  
set(varName: string, value: boolean | string | number): void Set a new property if it does not exist or updates a property to new value.  

Properties

Name Type Description
App Accessor StaticReadOnly Config Provide singleton object for application  

Defined in

Last Updated: 13 June, 2024