{"size": 1198, "ext": "js", "max_stars_repo_path": "src/shortcuts/language/commands/utils/urlContentRetriever.js", "max_stars_repo_name": "farleigh/keyboardshortcuts", "max_stars_repo_stars_event_min_datetime": "2015-03-21T14:47:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-15T08:01:55.000Z", "max_issues_repo_path": "src/shortcuts/language/commands/utils/urlContentRetriever.js", "max_issues_repo_name": "farleigh/keyboardshortcuts", "max_issues_repo_issues_event_min_datetime": "2015-04-23T13:27:38.000Z", "max_issues_repo_issues_event_max_datetime": "2016-04-05T13:04:09.000Z", "max_forks_repo_path": "src/shortcuts/language/commands/utils/urlContentRetriever.js", "max_forks_repo_name": "farleigh/keyboardshortcuts", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 7, "max_issues_count": 9, "max_forks_count": null, "avg_line_length": 27.2272727273, "max_line_length": 79, "alphanum_fraction": 0.5934891486}
define("urlContentRetriever", function() {

  // Url expression format: url(/regex/flags), or url, or url()
  var urlRegex = /^\s*url(?:\s*\((?:\s*\/(.*)\/(.*))?\s*\))?\s*$/i;

  function getItemSafely (matches, position) {
    return matches && matches.length > position ? matches[position] : "";
  }

  function buildRegex (regex, flags) {
    if(!regex) {
      // match everything on default
      return new RegExp(".*");
    }
    if(flags) {
      return new RegExp(regex, flags);
    }
    return new RegExp(regex);
  }

  // Attempt to get content from the URL of matching regex.
  function getContent (jq, query, context) {
    var matches, regexp, value;
    matches = urlRegex.exec(query);
    if(!matches) {
      return { match: false };
    }
    var win = context && context.window;
    if(!win || !win.location || !win.location.href) {
      return { match: true, content: "" };
    }
    regexp = buildRegex( getItemSafely(matches, 1), getItemSafely(matches, 2));
    value = decodeURI(win.location.href).match(regexp);
    if(value && value.length) {
      value = value[0];
    }
    return { match: true, content: value };
  }

  return {
      getContent: getContent
  };
});
