packages/optimizely-sdk/lib/core/project_config/index.js
function(variableValue, variableType, logger) {
    var castValue;

    switch (variableType) {
      case FEATURE_VARIABLE_TYPES.BOOLEAN:
        if (variableValue !== 'true' && variableValue !== 'false') {
          logger.log(LOG_LEVEL.ERROR, sprintf(ERROR_MESSAGES.UNABLE_TO_CAST_VALUE, MODULE_NAME, variableValue, variableType));
          castValue = null;
        } else {
          castValue = variableValue === 'true';
        }
        break;

      case FEATURE_VARIABLE_TYPES.INTEGER:
        castValue = parseInt(variableValue, 10);
        if (isNaN(castValue)) {
          logger.log(LOG_LEVEL.ERROR, sprintf(ERROR_MESSAGES.UNABLE_TO_CAST_VALUE, MODULE_NAME, variableValue, variableType));
          castValue = null;
        }
        break;

      case FEATURE_VARIABLE_TYPES.DOUBLE:
        castValue = parseFloat(variableValue);
        if (isNaN(castValue)) {
          logger.log(LOG_LEVEL.ERROR, sprintf(ERROR_MESSAGES.UNABLE_TO_CAST_VALUE, MODULE_NAME, variableValue, variableType));
          castValue = null;
        }
        break;

      default: // type is STRING
        castValue = variableValue;
        break;
    }

    return castValue;
  }
function(variableValue, variableType, logger) {
    var castValue;

    switch (variableType) {
      case FEATURE_VARIABLE_TYPES.BOOLEAN:
        if (variableValue !== 'true' && variableValue !== 'false') {
          logger.log(LOG_LEVEL.ERROR, sprintf(ERROR_MESSAGES.UNABLE_TO_CAST_VALUE, MODULE_NAME, variableValue, variableType));
          castValue = null;
        } else {
          castValue = variableValue === 'true';
        }
        break;

      case FEATURE_VARIABLE_TYPES.INTEGER:
        castValue = parseInt(variableValue, 10);
        if (isNaN(castValue)) {
          logger.log(LOG_LEVEL.ERROR, sprintf(ERROR_MESSAGES.UNABLE_TO_CAST_VALUE, MODULE_NAME, variableValue, variableType));
          castValue = null;
        }
        break;

      case FEATURE_VARIABLE_TYPES.DOUBLE:
        castValue = parseFloat(variableValue);
        if (isNaN(castValue)) {
          logger.log(LOG_LEVEL.ERROR, sprintf(ERROR_MESSAGES.UNABLE_TO_CAST_VALUE, MODULE_NAME, variableValue, variableType));
          castValue = null;
        }
        break;

      default: // type is STRING
        castValue = variableValue;
        break;
    }

    return castValue;
  }
function ( variableValue , variableType , logger ) { var castValue ; switch ( variableType ) { case FEATURE_VARIABLE_TYPES . BOOLEAN : if ( variableValue !== 'true' && variableValue !== 'false' ) { logger . log ( LOG_LEVEL . ERROR , sprintf ( ERROR_MESSAGES . UNABLE_TO_CAST_VALUE , MODULE_NAME , variableValue , variableType ) ) ; castValue = null ; } else { castValue = variableValue === 'true' ; } break ; case FEATURE_VARIABLE_TYPES . INTEGER : castValue = parseInt ( variableValue , 10 ) ; if ( isNaN ( castValue ) ) { logger . log ( LOG_LEVEL . ERROR , sprintf ( ERROR_MESSAGES . UNABLE_TO_CAST_VALUE , MODULE_NAME , variableValue , variableType ) ) ; castValue = null ; } break ; case FEATURE_VARIABLE_TYPES . DOUBLE : castValue = parseFloat ( variableValue ) ; if ( isNaN ( castValue ) ) { logger . log ( LOG_LEVEL . ERROR , sprintf ( ERROR_MESSAGES . UNABLE_TO_CAST_VALUE , MODULE_NAME , variableValue , variableType ) ) ; castValue = null ; } break ; default : // type is STRING castValue = variableValue ; break ; } return castValue ; }
Given a variable value in string form, try to cast it to the argument type.
If the type cast succeeds, return the type casted value, otherwise log an
error and return null.
@param {string} variableValue  Variable value in string form
@param {string} variableType   Type of the variable whose value was passed
in the first argument. Must be one of
FEATURE_VARIABLE_TYPES in
lib/utils/enums/index.js. The return value's
type is determined by this argument (boolean
for BOOLEAN, number for INTEGER or DOUBLE,
and string for STRING).
@param {Object} logger         Logger instance
@returns {*}                   Variable value of the appropriate type, or
null if the type cast failed
Given a variable value in string form try to cast it to the argument type . If the type cast succeeds return the type casted value otherwise log an error and return null .