/* jshint ignore:end http://stackoverflow.com/questions/1714786/querystring-encoding-of-a-javascript-object
971628
function objectToQueryString(obj) {
        var str = [];
        for (var p in obj) {
            if (obj.hasOwnProperty(p)) {
                str.push(p + '=' + obj[p]);
            }
        }
        return str.join('&');
    }
1242858
public static void parseQueryString( String str, Map res, String encoding )
    {

        // "Within the query string, the plus sign is reserved as
        // shorthand notation for a space. Therefore, real plus signs must
        // be encoded. This method was used to make query URIs easier to
        // pass in systems which did not allow spaces." -- RFC 1630
        int i = str.indexOf( '#' );
        if ( i > 0 )
        {
            str = str.substring( 0, i );
        }
        StringTokenizer st = new StringTokenizer( str.replace( '+', ' ' ), "&" );

        while ( st.hasMoreTokens() )
        {
            String qp = st.nextToken();
            String[] pair = qp.split( "=" );  // was String[] pair = StringUtils.split(qp, '=');
            //String s = unescape(pair[1], encoding);
            res.put( unescape( pair[0], encoding ), unescape( pair[1], encoding ) );
        }
    }
541335
function objectToQueryString(urlParams) {
  var queryString = '';
      
  if (urlParams) {
    Object.keys(urlParams).forEach(function (key) {
      if (queryString.length === 0) {
        queryString = '?';
      }
      else {
        queryString += '&';
      }
      
      queryString += key + '=' + encodeURIComponent(urlParams[key] || '');
    });
  }
  
  return queryString;
}
288854
function parseQueryString(s) {
    var data = {};

    s.split('&').forEach(function(item) {
      var pair = item.split('=');
      data[decodeURIComponent(pair[0])] =
        pair[1] ? decodeURIComponent(pair[1]) : true;
    });

    return data;
  }
354766
function(query) {
        var queryObj = {q: ''};
        if(!query) {
            return queryObj;
        }

        var qArray = query.split('&');
        var qObj = qs.parse(query);
        for(var i = 0, len = qArray.length; i < len; i++) {
            var queryItem = decodeURIComponent(qArray[i]).replace('=', '');
            if(/^\?/g.test(queryItem)) {
                debug('matched query: %s', queryItem) ;
                queryObj.q = queryItem;
                break;
            }
        }

        queryObj.m = qObj._mcss == 'true' || qObj._mcss == 'y';
        return queryObj;
    }
596502
function(obj) {
  var str = "";

  for (var i in obj) {
    if (obj.hasOwnProperty(i)) {
      if (str.length) str += "&";
      str += encodeURIComponent(i) + "=" + encodeURIComponent(obj[i]);
    }
  }

  return str;
}
1144408
function parseQueryStr(url) {
      if (!contains(url, '?')) return {};
      var queryStr = url.substring(url.lastIndexOf('?') + 1);
      if (queryStr === '') return {};
      var querys = queryStr.split('&'), params = {}, i = -1;
      while (++i < querys.length) {
        var kw = querys[i].split('=')
          , decode = decodeURIComponent;
        params[decode(kw[0])] = decode(kw[1] || '');
      }
      return params;
    }
955232
function encodeQueryAsString(query = {}) {
  const params = Object.keys(query).map((name) =>
    [encodeURIComponent(name), encodeURIComponent(query[name])].join('=')
  );
  return params.length ? `?${params.join('&')}` : '';
}
676241
function encodeRfc3986(urlEncodedString) {
  return urlEncodedString.replace(/[!'()*]/g, function(c) {
    return '%' + c.charCodeAt(0).toString(16).toUpperCase()
  })
}
629130
function encodeEntities(value) {
        return value.
            replace(/&/g, '&amp;').
            replace(surrogatePairRegexp, function(value) {
                var hi = value.charCodeAt(0),
                    low = value.charCodeAt(1);
                return '&#' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';';
            }).
            replace(nonAlphanumericRegexp, function(value) {
                return '&#' + value.charCodeAt(0) + ';';
            }).
            replace(/</g, '&lt;').
            replace(/>/g, '&gt;');
    }
24110
function toQueryParams(object){
	return Object.keys(object)
		.filter(key => !!object[key])
		.map(key => key + "=" + encodeURIComponent(object[key]))
		.join("&")
}
1230971
function getData(queryString, obj) {
  return queryString.split('.').reduce(function(prev, curr) {
    return prev ? prev[curr] : undefined
  }, obj);
}
529105
function utf8Encode(str) {
  var bytes = [], offset = 0, length, char;

  str = encodeURI(str);
  length = str.length;

  while (offset < length) {
    char = str.charAt(offset);
    offset += 1;

    if (char !== '%') {
      bytes.push(char.charCodeAt(0));
    } else {
      char = str.charAt(offset) + str.charAt(offset + 1);
      bytes.push(parseInt(char, 16));
      offset += 2;
    }
  }

  return bytes;
}
816168
String getQueryString(Map<String, String> params) {
		StringBuilder builder = new StringBuilder();
		try {
			boolean first = true;
			for (Map.Entry<String,String> entry : params.entrySet()) {
				if (first) {
					first = false;
				} else {
					builder.append("&");
				}
				builder.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
				builder.append("=");
				builder.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
			}
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(
					"Your Java version does not support UTF-8 encoding.");
		}

		return builder.toString();
	}
1004696
function objectToQueryString (obj) {
    let qs = reduce(obj, (result, value, key) => {
        if (!isNull(value) && !isUndefined(value)) {
            if (isArray(value)) {
                result += reduce(value, (result1, value1) => {
                    if (!isNull(value1) && !isUndefined(value1)) {
                        result1 += key + '=' + value1 + '&';
                        return result1
                    } else {
                        return result1;
                    }
                }, '')
            } else {
                result += key + '=' + value + '&';
            }
            return result;
        } else {
            return result
        }
    }, '').slice(0, -1);
    return qs;
}
69798
function encodeQueryData(obj, prefix) {
          var str = [];
          for (var p in obj) {
            if (obj.hasOwnProperty(p)) {
              var k = prefix ? prefix + '[' + p + ']' : p, v = obj[p];
              str.push(typeof v === 'object' ? encodeQueryData(v, k) : encodeURIComponent(k) + '=' + encodeURIComponent(v));
            }
          }
          return str.join('&');
        }
662903
function toQueryString(params, id) {
    var paramsString = '';
    for (var key in params) {
      if (params.hasOwnProperty(key)) {
        paramsString += '&' + key + '=' + encodeURIComponent(params[key]);
      }
    }
    return 'zws-id=' + id + paramsString;
  }