var _ = require("./misc");
var URIjs = require("URIjs");

function _joinUrl(baseUri, part) {
  if (part.length === 0)
    return baseUri;

  var partUri = new URIjs(part);
  if (partUri.is("relative")) {
    return partUri.absoluteTo(baseUri);
  } else {
    return partUri;
  }
}

function resolveURL() {
  var args = _.compact(arguments);
  var len = args.length;
  if (len === 0)
    return "";
  else {
    return URIjs.decode(_.reduce(args, _joinUrl, new URIjs("")));
  }
}

function parseBaseURL(url) {
  return URIjs.commonPath(url, url);
}

module.exports = { resolveURL, parseBaseURL };

@@ -24,36 +24,173 @@
 %22);%0A
+%0A
 var 
-URIjs = require(%22URIjs%22)
+schemeRe = /:%5C/%5C//;%0Avar uniqSchemeRe = /:%5C//;%0Avar selfDirRe = /%5C/%5C.%5C//g;%0Avar prevDirRe = /%5C/%5C.%5C.%5C//;%0Avar rmPrevDirRe = /%5B%5E%5C/%5D*%5C/+%5C.%5C.%5C//;%0Avar slashesRe = /%5C/+/g
 ;%0A%0Af
@@ -210,19 +210,16 @@
 Url(base
-Uri
 , part) 
@@ -240,28 +240,24 @@
 ength === 0)
-%0A   
  return base
@@ -260,153 +260,438 @@
 base
-Uri;%0A%0A  var partUri = new URIjs(
+;%0A  if (schemeRe.test(part)) %7B%0A    return part;%0A  %7D else %7B%0A    return base + %22/%22 + 
 part
-)
 ;%0A  
-if (partUri.is(%22
+%7D%0A%7D%0A%0Afunction _normalizeUrl(str) %7B%0A  // remove ./ parts%0A  if (selfDirRe.test(str))%0A    str = str.
 re
+p
 la
-tive%22)) %7B%0A    return partUri.absoluteTo(baseUri
+ce(selfDirRe, %22/%22);%0A%0A  // remove foo/../ parts%0A  while(prevDirRe.test(str))%0A    str = str.replace(rmPrevDirRe, %22/%22
 );%0A
+%0A
   
-%7D else %7B%0A    return partUri;%0A  %7D
+// join multiple / except the scheme one%0A  return str%0A    .replace(slashesRe, %22/%22)%0A    .replace(uniqSchemeRe, %22://%22);
 %0A%7D%0A%0A
@@ -808,26 +808,24 @@
 n %22%22;%0A  else
- %7B
 %0A    return 
@@ -828,20 +828,21 @@
 urn 
-URIjs.decode
+_normalizeUrl
 (_.r
@@ -867,28 +867,13 @@
 rl, 
-new URIjs(%22%22)));%0A  %7D
+%22%22));
 %0A%7D%0A%0A
@@ -907,42 +907,132 @@
 %7B%0A  
-return URIjs.commonPath(url, url);
+var slash = url.lastIndexOf(%22/%22);%0A  if (slash %3E= 0) %7B%0A    return url.substring(0, slash + 1);%0A  %7D else %7B%0A    return url;%0A  %7D
 %0A%7D%0A%0A

Revert "uri: use URIjs for joining and resolving"