Class: Validate

new Validate
(console)

common/validate.js, line 22

Constructor for Finsemble argment validator.

Validatation logic is ONLY RAN when SystemSettings diagnotics level is set to debug (i.e. 4 or above)
A failed validation will generate a warning message, but nothing more; however application logic can check the validation results.

Name Type Description
console string

Finsemble console object used to display messages and check diagnotic level

Methods

args
(param1, paramType1, param2, paramType2){boolean}

common/validate.js, line 68

Confirm parameters are valid. A variable number of parameter pairs are supported.

Name Type Description
param1 any

is arg to validate

paramType1 string

is required type for parameter (if '=' suffix then parameter is optional). "any" represents any type (but not "undefined").

param2 any optional

is next arg to validate

paramType2 string optional

os required type for next arg

Returns:
Type Description
boolean returns turn if parameter list is valid; otherwise, false.
Example
var validate = new Validate(console); 
validate.args(name, "string", age, "number")

validate.args(topic, "string", initialState, "object="); // with optional paramter (represented by "=")

validate.args(topic, "string", initialState, "any"); // with "any" type

validate.args(subscribeIDStruct, "object") && validate.args(subscribeIDStruct.subscribeID, "string"); // only do second varidate if first test successful

validate.args(subscribeIDStruct, "object", subscribeIDStruct.subscribeID, "string"); // only check second parm if first validated successful

validate.args(topic, "any", initialState, "object=", params, "object="); // depending on logic, can break into seperate validations
params = params || {}; 
validate.args(params.subscribeCallback, "function=", params.publishCallback, "function=", params.unsubscribeCallback, "function=");

args2
(paramName1, param1, paramType1, paramName2, param2, paramType2){boolean}

common/validate.js, line 122

Confirm parameters are valid. args2() has the same functionality as args() except a third "parameter description" is passed in for each argument varified
Typically this for passing in a properties name for better diagnostic messages when varifying object properties.
A variable number of parameter "triples"" are supported.

Name Type Description
paramName1 string

is descriptive name of param1 (for diagnostic message)

param1 any

is arg to validate

paramType1 string

is required type for parameter (if '=' suffix then parameter is optional). "any" represents any type (but not "undefined").

paramName2 string

is descriptive name of param1 (for diagnostic message)

param2 any

is arg to validate

paramType2 string

is required type for parameter (if '=' suffix then parameter is optional). "any" represents any type (but not "undefined").

Returns:
Type Description
boolean returns turn if parameter list is valid; otherwise, false.
Example
var validate = new Utils.Validate(console); 
validate.args2("record.name", record.name, "string", "record.age", age, "number")

// common case using args() and args2() together
validate.args(topic, "any", initialState, "object=", params, "object=") &&
  validate.args2("params.subscribeCallback", params.subscribeCallback, "function=", "params.publishCallback", params.publishCallback, "function=") &&
  validate.args2("params.unsubscribeCallback", params.unsubscribeCallback, "function=");