path.js 576 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. };