packages/optimizely-sdk/lib/core/custom_attribute_condition_evaluator/index.js
function evaluate(condition, userAttributes, logger) {
  if (condition.type !== CUSTOM_ATTRIBUTE_CONDITION_TYPE) {
    logger.log(LOG_LEVEL.WARNING, sprintf(LOG_MESSAGES.UNKNOWN_CONDITION_TYPE, MODULE_NAME, JSON.stringify(condition)));
    return null;
  }

  var conditionMatch = condition.match;
  if (typeof conditionMatch !== 'undefined' && MATCH_TYPES.indexOf(conditionMatch) === -1) {
    logger.log(LOG_LEVEL.WARNING, sprintf(LOG_MESSAGES.UNKNOWN_MATCH_TYPE, MODULE_NAME, JSON.stringify(condition)));
    return null;
  }

  var attributeKey = condition.name;
  if (!userAttributes.hasOwnProperty(attributeKey) && conditionMatch != EXISTS_MATCH_TYPE) {
    logger.log(LOG_LEVEL.DEBUG, sprintf(LOG_MESSAGES.MISSING_ATTRIBUTE_VALUE, MODULE_NAME, JSON.stringify(condition), attributeKey));
    return null;
  }

  var evaluatorForMatch = EVALUATORS_BY_MATCH_TYPE[conditionMatch] || exactEvaluator;
  return evaluatorForMatch(condition, userAttributes, logger);
}
function evaluate(condition, userAttributes, logger) {
  if (condition.type !== CUSTOM_ATTRIBUTE_CONDITION_TYPE) {
    logger.log(LOG_LEVEL.WARNING, sprintf(LOG_MESSAGES.UNKNOWN_CONDITION_TYPE, MODULE_NAME, JSON.stringify(condition)));
    return null;
  }

  var conditionMatch = condition.match;
  if (typeof conditionMatch !== 'undefined' && MATCH_TYPES.indexOf(conditionMatch) === -1) {
    logger.log(LOG_LEVEL.WARNING, sprintf(LOG_MESSAGES.UNKNOWN_MATCH_TYPE, MODULE_NAME, JSON.stringify(condition)));
    return null;
  }

  var attributeKey = condition.name;
  if (!userAttributes.hasOwnProperty(attributeKey) && conditionMatch != EXISTS_MATCH_TYPE) {
    logger.log(LOG_LEVEL.DEBUG, sprintf(LOG_MESSAGES.MISSING_ATTRIBUTE_VALUE, MODULE_NAME, JSON.stringify(condition), attributeKey));
    return null;
  }

  var evaluatorForMatch = EVALUATORS_BY_MATCH_TYPE[conditionMatch] || exactEvaluator;
  return evaluatorForMatch(condition, userAttributes, logger);
}
function evaluate ( condition , userAttributes , logger ) { if ( condition . type !== CUSTOM_ATTRIBUTE_CONDITION_TYPE ) { logger . log ( LOG_LEVEL . WARNING , sprintf ( LOG_MESSAGES . UNKNOWN_CONDITION_TYPE , MODULE_NAME , JSON . stringify ( condition ) ) ) ; return null ; } var conditionMatch = condition . match ; if ( typeof conditionMatch !== 'undefined' && MATCH_TYPES . indexOf ( conditionMatch ) === - 1 ) { logger . log ( LOG_LEVEL . WARNING , sprintf ( LOG_MESSAGES . UNKNOWN_MATCH_TYPE , MODULE_NAME , JSON . stringify ( condition ) ) ) ; return null ; } var attributeKey = condition . name ; if ( ! userAttributes . hasOwnProperty ( attributeKey ) && conditionMatch != EXISTS_MATCH_TYPE ) { logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . MISSING_ATTRIBUTE_VALUE , MODULE_NAME , JSON . stringify ( condition ) , attributeKey ) ) ; return null ; } var evaluatorForMatch = EVALUATORS_BY_MATCH_TYPE [ conditionMatch ] || exactEvaluator ; return evaluatorForMatch ( condition , userAttributes , logger ) ; }
Given a custom attribute audience condition and user attributes, evaluate the
condition against the attributes.
@param  {Object}     condition
@param  {Object}     userAttributes
@param  {Object}     logger
@return {?Boolean}   true/false if the given user attributes match/don't match the given condition,
null if the given user attributes and condition can't be evaluated
Given a custom attribute audience condition and user attributes evaluate the condition against the attributes .