You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.1 KiB

4 years ago
  1. "use strict";
  2. var hrefInfo = require("./hrefInfo");
  3. var parseHost = require("./host");
  4. var parsePath = require("./path");
  5. var parsePort = require("./port");
  6. var parseQuery = require("./query");
  7. var parseUrlString = require("./urlstring");
  8. var pathUtils = require("../util/path");
  9. function parseFromUrl(url, options, fallback)
  10. {
  11. if (url)
  12. {
  13. var urlObj = parseUrl(url, options);
  14. // Because the following occurs in the relate stage for "to" URLs,
  15. // such had to be mostly duplicated here
  16. var pathArray = pathUtils.resolveDotSegments(urlObj.path.absolute.array);
  17. urlObj.path.absolute.array = pathArray;
  18. urlObj.path.absolute.string = "/" + pathUtils.join(pathArray);
  19. return urlObj;
  20. }
  21. else
  22. {
  23. return fallback;
  24. }
  25. }
  26. function parseUrl(url, options)
  27. {
  28. var urlObj = parseUrlString(url, options);
  29. if (urlObj.valid===false) return urlObj;
  30. parseHost(urlObj, options);
  31. parsePort(urlObj, options);
  32. parsePath(urlObj, options);
  33. parseQuery(urlObj, options);
  34. hrefInfo(urlObj);
  35. return urlObj;
  36. }
  37. module.exports =
  38. {
  39. from: parseFromUrl,
  40. to: parseUrl
  41. };