Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ConfigParams

Contains a key-value map with configuration parameters. All values stored as strings and can be serialized as JSON or string forms. When retrieved the values can be automatically converted on read using GetAsXXX methods.

The keys are case-sensitive, so it is recommended to use consistent C-style as: "my_param"

Configuration parameters can be broken into sections and subsections using dot notation as: "section1.subsection1.param1". Using GetSection method all parameters from specified section can be extracted from a ConfigMap.

The ConfigParams supports serialization from/to plain strings as: "key1=123;key2=ABC;key3=2016-09-16T00:00:00.00Z"

ConfigParams are used to pass configurations to IConfigurable objects. They also serve as a basis for more concrete configurations such as ConnectionParams or CredentialParams (in the Pip.Services components package).

see

IConfigurable

see

StringValueMap

Example

let config = ConfigParams.fromTuples(
    "section1.key1", "AAA",
    "section1.key2", 123,
    "section2.key1", true
);

config.getAsString("section1.key1"); // Result: AAA
config.getAsInteger("section1.key1"); // Result: 0

section1 = config.getSection("section1");
section1.toString(); // Result: key1=AAA;key2=123

Hierarchy

Index

Constructors

constructor

Methods

addSection

  • addSection(section: string, sectionParams: ConfigParams): void
  • Adds parameters into this ConfigParams under specified section. Keys for the new parameters are appended with section dot prefix.

    Parameters

    • section: string

      name of the section where add new parameters

    • sectionParams: ConfigParams

      new parameters to be added.

    Returns void

append

  • append(map: any): void

clear

  • clear(): any

clone

  • clone(): any

get

  • get(key: string): string
  • Gets a map element specified by its key.

    Parameters

    • key: string

      a key of the element to get.

    Returns string

    the value of the map element.

getAsArray

getAsArrayWithDefault

getAsBoolean

  • getAsBoolean(key: string): boolean

getAsBooleanWithDefault

  • getAsBooleanWithDefault(key: string, defaultValue: boolean): boolean

getAsDateTime

  • getAsDateTime(key: string): Date

getAsDateTimeWithDefault

  • getAsDateTimeWithDefault(key: string, defaultValue: Date): Date

getAsDouble

  • getAsDouble(key: string): number

getAsDoubleWithDefault

  • getAsDoubleWithDefault(key: string, defaultValue: number): number

getAsFloat

  • getAsFloat(key: string): number

getAsFloatWithDefault

  • getAsFloatWithDefault(key: string, defaultValue: number): number

getAsInteger

  • getAsInteger(key: string): number

getAsIntegerWithDefault

  • getAsIntegerWithDefault(key: string, defaultValue: number): number

getAsLong

  • getAsLong(key: string): number

getAsLongWithDefault

  • getAsLongWithDefault(key: string, defaultValue: number): number

getAsMap

  • Converts map element into an AnyValueMap or returns empty AnyValueMap if conversion is not possible.

    see

    fromValue

    Parameters

    • key: string

      a key of element to get.

    Returns AnyValueMap

    AnyValueMap value of the element or empty AnyValueMap if conversion is not supported.

getAsMapWithDefault

getAsNullableArray

getAsNullableBoolean

  • getAsNullableBoolean(key: string): boolean

getAsNullableDateTime

  • getAsNullableDateTime(key: string): Date

getAsNullableDouble

  • getAsNullableDouble(key: string): number

getAsNullableFloat

  • getAsNullableFloat(key: string): number

getAsNullableInteger

  • getAsNullableInteger(key: string): number

getAsNullableLong

  • getAsNullableLong(key: string): number

getAsNullableMap

getAsNullableString

  • getAsNullableString(key: string): string

getAsNullableType

  • getAsNullableType<T>(type: TypeCode, key: string): T

getAsObject

  • getAsObject(key?: string): any
  • Gets the value stored in map element without any conversions. When element key is not defined it returns the entire map value.

    Parameters

    • Default value key: string = undefined

      (optional) a key of the element to get

    Returns any

    the element value or value of the map when index is not defined.

getAsString

  • getAsString(key: string): string

getAsStringWithDefault

  • getAsStringWithDefault(key: string, defaultValue: string): string

getAsType

  • getAsType<T>(type: TypeCode, key: string): T
  • Converts map element into a value defined by specied typecode. If conversion is not possible it returns default value for the specified type.

    see

    getAsTypeWithDefault

    Type parameters

    • T

    Parameters

    • type: TypeCode

      the TypeCode that defined the type of the result

    • key: string

      a key of element to get.

    Returns T

    element value defined by the typecode or default if conversion is not supported.

getAsTypeWithDefault

  • getAsTypeWithDefault<T>(type: TypeCode, key: string, defaultValue: T): T
  • Converts map element into a value defined by specied typecode. If conversion is not possible it returns default value.

    see

    TypeConverter.toTypeWithDefault

    Type parameters

    • T

    Parameters

    • type: TypeCode

      the TypeCode that defined the type of the result

    • key: string

      a key of element to get.

    • defaultValue: T

      the default value

    Returns T

    element value defined by the typecode or default value if conversion is not supported.

getAsValue

getKeys

  • getKeys(): string[]

getSection

  • Gets parameters from specific section stored in this ConfigMap. The section name is removed from parameter keys.

    Parameters

    • section: string

      name of the section to retrieve configuration parameters from.

    Returns ConfigParams

    all configuration parameters that belong to the section named 'section'.

getSectionNames

  • getSectionNames(): string[]
  • Gets a list with all 1st level section names.

    Returns string[]

    a list of section names stored in this ConfigMap.

length

  • length(): number

override

put

  • put(key: string, value: any): any
  • Puts a new value into map element specified by its key.

    Parameters

    • key: string

      a key of the element to put.

    • value: any

      a new value for map element.

    Returns any

remove

  • remove(key: string): void

setAsObject

  • setAsObject(key: any, value?: any): void
  • Sets a new value to map element specified by its index. When the index is not defined, it resets the entire map value. This method has double purpose because method overrides are not supported in JavaScript.

    see

    MapConverter.toMap

    Parameters

    • key: any

      (optional) a key of the element to set

    • Default value value: any = undefined

      a new element or map value.

    Returns void

setDefaults

toString

  • toString(): string
  • Gets a string representation of the object. The result is a semicolon-separated list of key-value pairs as "key1=value1;key2=value2;key=value3"

    Returns string

    a string representation of the object.

Static fromMaps

  • Creates a new AnyValueMap by merging two or more maps. Maps defined later in the list override values from previously defined maps.

    Parameters

    • Rest ...maps: any[]

      an array of maps to be merged

    Returns StringValueMap

    a newly created AnyValueMap.

Static fromString

Static fromTuples

Static fromTuplesArray

  • Creates a new StringValueMap from a list of key-value pairs called tuples. The method is similar to fromTuples but tuples are passed as array instead of parameters.

    Parameters

    • tuples: any[]

      a list of values where odd elements are keys and the following even elements are values

    Returns StringValueMap

    a newly created StringValueMap.

Static fromValue

Static mergeConfigs

Generated using TypeDoc