Determine if a slash has to be added between the parts you're combining. And combine the parts.  Pass an empty string as the last argument if you want the returned URL to end with a slash.
763507
function joinUrlParts(...parts: Array<string>): string {
  let result = '';
  parts.forEach((part, index) => {
    if (index !== 0 && !/\/$/.test(result) && !/^\//.test(part)) {
      result += '/';
    }
    result += part;
  });
  return result;
}
167682
public static String mergeSlashesInUrl(String url) {
        StringBuilder builder = new StringBuilder();
        boolean prevIsColon = false;
        boolean inMerge = false;
        for (int i = 0; i < url.length(); i++) {
            char c = url.charAt(i);
            if (c == ':') {
                prevIsColon = true;
                builder.append(c);
            } else {
                if (c == '/') {
                    if (prevIsColon) {
                        builder.append(c);
                        inMerge = false;
                    } else {
                        if (!inMerge) {
                            builder.append(c);
                        }
                        inMerge = true;
                    }
                } else {
                    inMerge = false;
                    builder.append(c);
                }

                prevIsColon = false;
            }
        }

        return builder.toString();
    }
723405
def concat_url(parts)
      parts.reject!(&:empty?)
      if parts.length > 1
        parts.first + '?' + parts.drop(1).join('&')
      else
        parts.first
      end
    end
1358265
def urljoin(*args):
        
        return "/".join(map(lambda x: str(x).rstrip('/'), args)).rstrip('/')
885818
function addFragmentParam(url, param, value) {
  return url +
      (url.indexOf('#') == -1 ? '#' : '&') +
      encodeURIComponent(param) + '=' + encodeURIComponent(value);
}
356588
private static void joinPath(StringBuilder path, String parent, String child)
    {
        // Add parent piece, with no trailing slash.
        if ( (parent != null) && (parent.length() > 0) )
        {
            if ( !parent.startsWith(PATH_SEPARATOR) )
            {
                path.append(PATH_SEPARATOR);
            }
            if ( parent.endsWith(PATH_SEPARATOR) )
            {
                path.append(parent.substring(0, parent.length() - 1));
            }
            else
            {
                path.append(parent);
            }
        }

        if ( (child == null) || (child.length() == 0) || (child.equals(PATH_SEPARATOR)) )
        {
            // Special case, empty parent and child
            if ( path.length() == 0 )
            {
                path.append(PATH_SEPARATOR);
            }
            return;
        }

        // Now add the separator between parent and child.
        path.append(PATH_SEPARATOR);

        if ( child.startsWith(PATH_SEPARATOR) )
        {
            child = child.substring(1);
        }

        if ( child.endsWith(PATH_SEPARATOR) )
        {
            child = child.substring(0, child.length() - 1);
        }

        // Finally, add the child.
        path.append(child);
    }
114795
function appendQueryStringOptions(requestUrl, queryStringOptions) {
    requestUrl += "?";
    for (var prop in queryStringOptions) {
        if (queryStringOptions.hasOwnProperty(prop)) {
            requestUrl += prop + "=" + queryStringOptions[prop] + "&";
        }
    }

    //Remove the last & from the string
    requestUrl = requestUrl.substr(0, requestUrl.length - 1);
    return requestUrl;
}
1185817
public static String concatenateUrls(String rootUrl, String path) {
        if (rootUrl == null || rootUrl.isEmpty()) {
            return path;
        }

        if (path == null || path.isEmpty()) {
            return rootUrl;
        }

        String finalUrl;

        if (rootUrl.charAt(rootUrl.length() - 1) == '/' && path.charAt(0) == '/') {
            finalUrl = rootUrl.substring(0, rootUrl.length() - 2) + path;
        } else if (rootUrl.charAt(rootUrl.length() - 1) != '/' && path.charAt(0) != '/') {
            finalUrl = rootUrl + "/" + path;
        } else {
            finalUrl = rootUrl + path;
        }

        return finalUrl;
    }
1116009
def append_url(base_url, path):
    
    if base_url[-1] != "/":
        base_url += "/"
    if path[0] == "/":
        path = path[1:]
    return urljoin(base_url, path)
1040111
def add_path_part(url, regex=PATH_PART):
    
    formatter = string.Formatter()
    url_var_template = "(?P<{var_name}>{regex})"

    for part in formatter.parse(url):
        string_part, var_name, _, _ = part
        if string_part:
            yield string_part
        if var_name:
            yield url_var_template.format(var_name=var_name, regex=regex)
707487
public boolean hasToolPathForUrl(String url) {

        List<String> toolPaths = m_urls.getObjectList(url);
        return ((toolPaths != null) && !toolPaths.isEmpty());
    }
395320
private String joinUrl(String url, String... paths) {
		StringBuilder result = new StringBuilder(url);
		for (String path : paths) {
			if (path != null) {
				String p = path.replaceFirst("^(\\/)+", "");
				if (result.lastIndexOf("/") != result.length() - 1) {
					result.append('/');
				}
				result.append(p);
			}
		}
		return result.toString();
	}
903238
function shortenUrl ( url , length ) {

  if( !isBlank( url ) && url.length > length) {
      url = url.substr( 0 , length ) + "...";
  }

  return url;
}
569615
function(parts) {
        var urls = [];
        var start = '';

        // If the first part is empty
        // the original path begins with a slash so we
        // do that, too

        if( _.isEmpty(parts[0]) ) {
            start = '/';
            urls[0] = '/';      // would not be generated in reduce()
        }

        _.reduce(parts, function(acc, value){

            if( ! _.isString(value) || _.isEmpty(value) )
                return acc;

            acc += value;

            // Push w/out trailing slash
            urls.push(acc);

            return acc + '/';
        }, start );

        return urls;
    }
237399
def prepend_http(url):
    
    url = url.lstrip()
    if not urlparse(url).scheme:
        return 'http://' + url
    return url
392368
def urlsplit(url):
    
    p = '((?P<scheme>.*)?.*://)?(?P<host>[^:/ ]+).?(?P<port>[0-9]*).*'
    m = re.search(p, url)
    scheme = m.group('scheme')
    host = m.group('host')
    port = m.group('port')

    _scheme, _netloc, path, query, _fragment = tuple(py_urlsplit(url))

    return scheme, host, port, path, query
633878
function joinURL (urlA, urlB) {
  urlA = urlA || "";
  urlB = urlB || "";

  let endsWithASlash = urlA.substr(-1) === "/" || urlA.substr(-1) === "\\";
  let startsWithASlash = urlB[0] === "/" || urlB[0] === "\\";

  if (endsWithASlash || startsWithASlash) {
    return urlA + urlB;
  }
  else {
    return urlA + "/" + urlB;
  }
}