join.js 655 B

1234567891011121314
  1. var normalize = require("./normalize");
  2. var absoluteWinRegExp = /^[A-Z]:([\\\/]|$)/i;
  3. var absoluteNixRegExp = /^\//i;
  4. module.exports = function join(path, request) {
  5. if(!request) return normalize(path);
  6. if(absoluteWinRegExp.test(request)) return normalize(request.replace(/\//g, "\\"));
  7. if(absoluteNixRegExp.test(request)) return normalize(request);
  8. if(path == "/") return normalize(path + request);
  9. if(absoluteWinRegExp.test(path)) return normalize(path.replace(/\//g, "\\") + "\\" + request.replace(/\//g, "\\"));
  10. if(absoluteNixRegExp.test(path)) return normalize(path + "/" + request);
  11. return normalize(path + "/" + request);
  12. };