join.js 662 B

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