{"size": 2094, "ext": "js", "max_stars_repo_path": "src/curl.js", "max_stars_repo_name": "elarahq/sense-chrome", "max_stars_repo_stars_event_min_datetime": "2017-11-07T12:09:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:12:50.000Z", "max_issues_repo_path": "src/curl.js", "max_issues_repo_name": "elarahq/sense-chrome", "max_issues_repo_issues_event_min_datetime": "2017-11-15T11:38:33.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-17T03:10:07.000Z", "max_forks_repo_path": "src/curl.js", "max_forks_repo_name": "elarahq/sense-chrome", "max_forks_repo_forks_event_min_datetime": "2017-11-07T17:37:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T07:44:58.000Z"}
{"max_stars_count": 183, "max_issues_count": 11, "max_forks_count": 85, "avg_line_length": 27.5526315789, "max_line_length": 88, "alphanum_fraction": 0.4832855778}
(function () {
   var global = window;
   if (!global.sense)
      global.sense = {};

   function detectCURL(text) {
      // returns true if text matches a curl request
      if (!text) return false;
      return text.match(/^\s*?curl\s+(-X[A-Z]+)?\s*['"]?.*?['"]?(\s*$|\s+?-d\s*?['"])/);

   }

   function parseCURL(text) {
      var matches = text.match(/^\s*?curl\s+(?:-s\s+)?(-X\s*[A-Z]+)?\s*/);
      var ret = {
         method: "",
         server: "",
         endpoint: "",
         data: ""
      };
      if (matches[1]) {
         ret.method = matches[1].substring(2).trim(); // strip -X
      }
      text = text.substring(matches[0].length); // strip everything so far.
      if (text.length == 0) return ret;
      if (text[0] == '"') {
         matches = text.match(/^"([^"]*)"/);
      }
      else if (text[0] == "'") {
         matches = text.match(/^'([^']*)'/);
      }
      else {
         matches = text.match(/^(\S*)/);
      }

      if (!matches) return ret;
      var url = matches[1];

      if (!url.match(/:\/\//)) url = "http://" + url; // inject http as curl does

      var urlAnchor = document.createElement("a");
      urlAnchor.href = url;

      ret.server = (urlAnchor.protocol || "http") + "//" + urlAnchor.hostname;
      if (urlAnchor.port && urlAnchor.port != 0) ret.server += ":" + urlAnchor.port;
      ret.url = (urlAnchor.pathname || "") + (urlAnchor.search || "");

      text = text.substring(matches[0].length);

      // now search for -d
      matches = text.match(/.*-d\s*?'/);
      if (matches) {
         ret.data = text.substring(matches[0].length).replace(/'\s*$/, '');
      }
      else {
         matches = text.match(/.*-d\s*?"/);
         if (matches) {
            ret.data = text.substring(matches[0].length).replace(/"\s*$/, '');
            ret.data = ret.data.replace(/\\(.)/gi, "$1");
         }
      }

      if (ret.data) {
         ret.data = ret.data.trim();
      }

      return ret;
   }


   global.sense.curl = {};
   global.sense.curl.parseCURL = parseCURL;
   global.sense.curl.detectCURL = detectCURL;

})();
