Caplin Trader 5.1.0

Class: module:ct-core/validator/MapConfigUtility

module:ct-core/validator/MapConfigUtility()

new module:ct-core/validator/MapConfigUtility()

Utility class with static method for checking validity of map config object.

Methods

(static) checkConfig(config, value:)

Check validity of given map config object.

Parameters:
Name Type Description
config object

configuration object specifying the allowed/required keys and values in a map.

Properties
Name Type Description
anyAllowed boolean

If true, any field or value is allowed, and an optional fields property may be provided to specify if fields are required or have conditions on their values. If false, then a fields property must be provided, which must be a map of field names. Only these field names will be allowed.

fields Object

The map of field names

Properties
Name Type Description
type String

The field's value must have the given type (possible types: var, number, string, flag).

required boolean

The field must be present in the map being validated.

minimum Number

The field's value must be at least the given minimum (only for numbers).

maximum: Number

The field's value must be at most the given maximum (only for numbers).

value: *

The field's value must match the given value exactly.

Example config objects:

This is the simplest possible config object; it allows any field. { anyAllowed: true }
This config object allows any field, and requires that width be present, and have value type number at least 100.
{
anyAllowed: true,
fields: {
width: { required: true, type: 'number', minimum: 100 } }
}
}