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.

49 lines
576 B

4 years ago
  1. "use strict";
  2. function joinPath(pathArray)
  3. {
  4. if (pathArray.length > 0)
  5. {
  6. return pathArray.join("/") + "/";
  7. }
  8. else
  9. {
  10. return "";
  11. }
  12. }
  13. function resolveDotSegments(pathArray)
  14. {
  15. var pathAbsolute = [];
  16. pathArray.forEach( function(dir)
  17. {
  18. if (dir !== "..")
  19. {
  20. if (dir !== ".")
  21. {
  22. pathAbsolute.push(dir);
  23. }
  24. }
  25. else
  26. {
  27. // Remove parent
  28. if (pathAbsolute.length > 0)
  29. {
  30. pathAbsolute.splice(pathAbsolute.length-1, 1);
  31. }
  32. }
  33. });
  34. return pathAbsolute;
  35. }
  36. module.exports =
  37. {
  38. join: joinPath,
  39. resolveDotSegments: resolveDotSegments
  40. };