lib/helpers/routeHelper.js
function compileStringRouteExpression (routeExpression) {
  var routeUri = new URI(routeExpression);
  routeUri.path = module.exports.removeEndSlash(routeUri.path);
  if (!routeUri) {
    return null;
  }

  // escape regular expression characters
  var escaped = routeUri.path.replace(
    EXPRESSION_ESCAPE_REG_EXP, '\\$&'
  );

  // get all occurrences of routing parameters in URI path
  var regExpSource = '^' + escaped.replace(PARAMETER_REG_EXP, URI_PATH_REPLACEMENT_REG_EXP_SOURCE) + '$';
  var expression = new RegExp(regExpSource, 'i');
  var pathParameterMatches = escaped.match(PARAMETER_REG_EXP);
  var pathParameters = pathParameterMatches ? pathParameterMatches.map(getParameterDescriptor) : null;

  var pathMapper = pathParameters ? createUriPathMapper(expression, pathParameters) : null;
  var queryMapper = routeUri.query ? createUriQueryMapper(routeUri.query) : null;

  return {
    expression: expression,
    map: uri => {
      var args = Object.create(null);

      if (pathMapper) {
        pathMapper(uri.path, args);
      }

      if (queryMapper && uri.query) {
        queryMapper(uri.query.values, args);
      }

      return args;
    }
  };
}
function compileStringRouteExpression (routeExpression) {
  var routeUri = new URI(routeExpression);
  routeUri.path = module.exports.removeEndSlash(routeUri.path);
  if (!routeUri) {
    return null;
  }

  // escape regular expression characters
  var escaped = routeUri.path.replace(
    EXPRESSION_ESCAPE_REG_EXP, '\\$&'
  );

  // get all occurrences of routing parameters in URI path
  var regExpSource = '^' + escaped.replace(PARAMETER_REG_EXP, URI_PATH_REPLACEMENT_REG_EXP_SOURCE) + '$';
  var expression = new RegExp(regExpSource, 'i');
  var pathParameterMatches = escaped.match(PARAMETER_REG_EXP);
  var pathParameters = pathParameterMatches ? pathParameterMatches.map(getParameterDescriptor) : null;

  var pathMapper = pathParameters ? createUriPathMapper(expression, pathParameters) : null;
  var queryMapper = routeUri.query ? createUriQueryMapper(routeUri.query) : null;

  return {
    expression: expression,
    map: uri => {
      var args = Object.create(null);

      if (pathMapper) {
        pathMapper(uri.path, args);
      }

      if (queryMapper && uri.query) {
        queryMapper(uri.query.values, args);
      }

      return args;
    }
  };
}
function compileStringRouteExpression ( routeExpression ) { var routeUri = new URI ( routeExpression ) ; routeUri . path = module . exports . removeEndSlash ( routeUri . path ) ; if ( ! routeUri ) { return null ; } // escape regular expression characters var escaped = routeUri . path . replace ( EXPRESSION_ESCAPE_REG_EXP , '\\$&' ) ; // get all occurrences of routing parameters in URI path var regExpSource = '^' + escaped . replace ( PARAMETER_REG_EXP , URI_PATH_REPLACEMENT_REG_EXP_SOURCE ) + '$' ; var expression = new RegExp ( regExpSource , 'i' ) ; var pathParameterMatches = escaped . match ( PARAMETER_REG_EXP ) ; var pathParameters = pathParameterMatches ? pathParameterMatches . map ( getParameterDescriptor ) : null ; var pathMapper = pathParameters ? createUriPathMapper ( expression , pathParameters ) : null ; var queryMapper = routeUri . query ? createUriQueryMapper ( routeUri . query ) : null ; return { expression : expression , map : uri => { var args = Object . create ( null ) ; if ( pathMapper ) { pathMapper ( uri . path , args ) ; } if ( queryMapper && uri . query ) { queryMapper ( uri . query . values , args ) ; } return args ; } } ; }
Creates a mapper for string route definition
@param {String} routeExpression string route uri definition
@returns {{expression: RegExp, map: Function}|null} URI mapper object.
Creates a mapper for string route definition