parse a url to a structured object
@param {String} str url string
@param {Boolean} [parseQueryString] whether parse query string to structured object
@return {Object}
503778
function (str, parseQueryString) {
                var m = str.match(URI_SPLIT_REG) || [], ret = {};    // old ie 7:  return "" for unmatched regexp ...
                // old ie 7:  return "" for unmatched regexp ...
                for (var part in REG_INFO) {
                    ret[part] = m[REG_INFO[part]];
                }
                if (ret.protocol) {
                    ret.protocol = ret.protocol.toLowerCase();
                }
                if (ret.hostname) {
                    ret.hostname = ret.hostname.toLowerCase();
                }
                var protocol = ret.protocol;
                if (protocol) {
                    ret.slashes = str.lastIndexOf(protocol + '//') !== -1;
                }    // mailto: yiminghe@gmail.com
                // mailto: yiminghe@gmail.com
                if (protocol && !needDoubleSlash(protocol.slice(0, -1))) {
                    if (!ret.slashes) {
                        str = str.slice(0, protocol.length) + '//' + str.slice(protocol.length);
                        ret = url.parse(str, parseQueryString);
                        ret.slashes = null;
                        return ret;
                    }
                } else {
                    // http://www.g.cn
                    // pathname => /
                    if (ret.hostname && !ret.pathname) {
                        ret.pathname = '/';
                    }
                }
                ret.path = ret.pathname;
                if (ret.search) {
                    ret.path += ret.search;
                }
                ret.host = ret.hostname;
                if (ret.port) {
                    ret.host = ret.hostname + ':' + ret.port;
                }
                if (ret.search) {
                    ret.query = ret.search.substring(1);
                }
                if (parseQueryString && ret.query) {
                    ret.query = querystring.parse(ret.query);
                }
                ret.href = url.format(ret);
                return ret;
            }
243319
function parse(arg)
{
  try{
    var url = urllib.parse(arg, true);
  }catch(E){
    return false;
  }

  // paths is always an array
  if(!url.query.paths) url.query.paths = [];
  if(!Array.isArray(url.query.paths)) url.query.paths = [url.query.paths];
  
  // parse any paths
  url.paths = [];
  url.query.paths.forEach(function(epath){
    try{
      var path = JSON.parse(hashname.base32.decode(epath));
      if(typeof path == 'object' && typeof path.type == 'string') url.paths.push(path);
    }catch(E){};
  });

  // parse any csid keys
  url.keys = {};
  Object.keys(url.query).forEach(function(id){
    if(id.length != 4 || id.substr(0,2) != 'cs') return;
    url.keys[id.substr(2)] = url.query[id];
  });
  
  // parse any fragment
  if(url.hash) url.fragment = hashname.base32.decode(url.hash.substr(1));
  
  // add formatting wrapper
  url.encode = function()
  {
    // delete these to force lib to make new
    delete url.search;
    delete url.href;
    if(url.query.paths.length == 0) delete url.query.paths; // dumb node bug
    return urllib.format(url);
  }
  
  return url;
}
613578
public Object parse(URL url, Map params, String charset) {
        return parseURL(url, params, charset);
    }
1041769
function parseCookie(str) {
  var obj = {},
    pairs = str.split(/[;,] */);

  for (var pair,eqlIndex,key,val,i=0; i < pairs.length; i++) {
    pair = pairs[i];
    eqlIndex = pair.indexOf('=');
    key = pair.substr(0, eqlIndex).trim().toLowerCase();
    val = pair.substr(++eqlIndex, pair.length).trim();
    if ('"' === val[0]) val = val.slice(1, -1);
    if (obj[key] === undefined) {
      val = val.replace(/\+/g, ' ');
      try {
        obj[key] = decodeURIComponent(val);
      } catch (err) {
        if (err instanceof URIError) {
          obj[key] = val;
        } else {
          throw err;
        }
      }
    }
  }
  return obj;
}
962529
function queryStringToJSON(url) {
  if (url === '') {
    return '';
  }
  var pairs = (url).slice(0).split('&'), result = {};
  for (var idx in pairs) {
    var pair = pairs[idx].split('=');
    if (!!pair[0]) {
      result[pair[0].toLowerCase()] = decodeURIComponent(pair[1] || '');
    }
  }
  return result;
}
921548
function parseURL(url) {

	const endpoint = {};

	const purl = urlParser.parse(url, true);

	if (purl.protocol && purl.protocol.startsWith('http')) {
		endpoint.protocol = purl.protocol.slice(0, -1);
		if (purl.hostname) {
			endpoint.hostname = purl.hostname;

			if (purl.port) {
				endpoint.port = parseInt(purl.port);
			}

		} else {
			throw new Error('InvalidURL: missing hostname.');
		}

	} else {
		throw new Error('InvalidURL: url must start with http or https.');
	}

	return endpoint;
}
1282001
def from_raw_query(cls, query_string):
        
        try:
            node_tree = grammar.parse(query_string)
        except IncompleteParseError:
            query_string = cls.fix_quotes(query_string)
            node_tree = grammar.parse(query_string)

        structured_query = DictFormater().visit(node_tree)

        return cls([t for t in structured_query
                    if t[1].lower() not in STOPWORDS])
363476
function parse(str) {

  // find the prefix expressions and the main value
  var stringMatches = str.match(stringRegex)
  var allExpString = stringMatches[1] || ''
  var value = stringMatches[2]

  // parse each prefix expression
  var expressions = execAll(allExpressionsRegex, allExpString)
    // grab the expression content inside the braces
    .map(function (match) { return match[1] })
    .map(parseExpression)

  return {
    original:   str,
    value:      value,
    expressions: expressions
  }
}
477691
function parse (str, options) {
  if (typeof str !== 'string') throw new TypeError('str is required!');

  var splitData = split(str);
  var raw = splitData.data;

  if (!raw) return { _content: str };

  var data;

  data = parseYAML(raw, options);

  if (!data) return { _content: str };

  data._content = splitData.content;

  return data;
}
304289
function trimUrlQuery(url: string): string {
  const length = url.length;
  const q1 = url.indexOf("?");
  const q2 = url.indexOf("&");
  const q3 = url.indexOf("#");
  const q = Math.min(
    q1 != -1 ? q1 : length,
    q2 != -1 ? q2 : length,
    q3 != -1 ? q3 : length
  );

  return url.slice(0, q);
}
882791
function parseUrl (url) {
  const regex = /(https?).*\/(.+)\/thread\/(\d+)/g
  let protocol
  let board
  let threadNo

  try {
    [, protocol, board, threadNo] = regex.exec(url)
  } catch (err) {
    throw new Error('Invalid 4chan URL!')
  }

  return {
    protocol,
    board,
    threadNo: Number.parseInt(threadNo)
  }
}
84677
function parse(str, options) {
  if (typeof str !== 'string') {
    throw new TypeError('argument str must be a string');
  }

  var obj = {}
  var opt = options || {};
  var pairs = str.split(pairSplitRegExp);
  var dec = opt.decode || decode;

  for (var i = 0; i < pairs.length; i++) {
    var pair = pairs[i];
    var eq_idx = pair.indexOf('=');

    // skip things that don't look like key=value
    if (eq_idx < 0) {
      continue;
    }

    var key = pair.substr(0, eq_idx).trim()
    var val = pair.substr(++eq_idx, pair.length).trim();

    // quoted values
    if ('"' == val[0]) {
      val = val.slice(1, -1);
    }

    // only assign once
    if (undefined == obj[key]) {
      obj[key] = tryDecode(val, dec);
    }
  }

  return obj;
}
323022
function parse(string) {
  if (!string) {
    throw new TypeError('argument string is required')
  }

  if (typeof string === 'object') {
    // support req/res-like objects as argument
    string = getcontenttype(string)

    if (typeof string !== 'string') {
      throw new TypeError('content-type header is missing from object');
    }
  }

  if (typeof string !== 'string') {
    throw new TypeError('argument string is required to be a string')
  }

  var index = string.indexOf(';')
  var type = index !== -1
    ? string.substr(0, index).trim()
    : string.trim()

  if (!typeRegExp.test(type)) {
    throw new TypeError('invalid media type')
  }

  var key
  var match
  var obj = new ContentType(type.toLowerCase())
  var value

  paramRegExp.lastIndex = index

  while (match = paramRegExp.exec(string)) {
    if (match.index !== index) {
      throw new TypeError('invalid parameter format')
    }

    index += match[0].length
    key = match[1].toLowerCase()
    value = match[2]

    if (value[0] === '"') {
      // remove quotes and escapes
      value = value
        .substr(1, value.length - 2)
        .replace(qescRegExp, '$1')
    }

    obj.parameters[key] = value
  }

  if (index !== -1 && index !== string.length) {
    throw new TypeError('invalid parameter format')
  }

  return obj
}
649524
function(url){
    // this creates json object from url with querystring
    if((typeof url) == 'string'){
        var curURL = url;
        var queryStringIndex = curURL.indexOf("?");
        var qsString = curURL.substr(queryStringIndex + 1, curURL.length);
        return queryString.parse(qsString);
    }else if((typeof url)== 'object'){
        return url;
    }else{
        return {};
    }
}
933070
function appendQueryString(url, params){
        var key;
        url = url || '';
        if(params){
            if(url.indexOf('?') === -1){
                url += '?';
            }
            if(typeof params === 'string'){
                url += params;
            } else if (typeof params === 'object'){
                for(key in params){
                    if(!/[?&]$/.test(url)){
                        url += '&';
                    }
                    url += encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
                }
            }
        }

        return url;
    }
547468
function parseSearchString(str) {

    str = tia.cU.replaceXTypesInTeq(str);

    var re = /&(\w|\d|_|-)+/g;

    var searchData = [];
    var prevLastIndex = 0;
    var query;

    while (true) {
      var reResult = re.exec(str);

      if (reResult === null) {
        // Only query string.
        query = str.slice(prevLastIndex).trim();
        if (query) {
          searchData.push({
            query: query,
          });
        }
        return searchData;
      }

      query = str.slice(prevLastIndex, reResult.index).trim();
      var reference = str.slice(reResult.index + 1, re.lastIndex).trim();
      prevLastIndex = re.lastIndex;

      if (query) {
        searchData.push({
          query: query,
        });
      }

      searchData.push({
        reference: reference,
      });

    }
  }
938392
def parse_querystring(querystring):
    
    if querystring is None or len(querystring) == 0:
        return {}

    qs_dict = parse.parse_qs(querystring, keep_blank_values=True)
    for key in qs_dict:
        if len(qs_dict[key]) != 1:
            continue
        qs_dict[key] = qs_dict[key][0]
        if qs_dict[key] == '':
            qs_dict[key] = True

    return dict((key, qs_dict[key]) for key in qs_dict if len(key) != 0)