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.

35 lines
910 B

4 years ago
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. module.exports = function getPaths(path) {
  7. const parts = path.split(/(.*?[\\/]+)/);
  8. const paths = [path];
  9. const seqments = [parts[parts.length - 1]];
  10. let part = parts[parts.length - 1];
  11. path = path.substr(0, path.length - part.length - 1);
  12. for (let i = parts.length - 2; i > 2; i -= 2) {
  13. paths.push(path);
  14. part = parts[i];
  15. path = path.substr(0, path.length - part.length) || "/";
  16. seqments.push(part.substr(0, part.length - 1));
  17. }
  18. part = parts[1];
  19. seqments.push(part);
  20. paths.push(part);
  21. return {
  22. paths: paths,
  23. seqments: seqments
  24. };
  25. };
  26. module.exports.basename = function basename(path) {
  27. const i = path.lastIndexOf("/"),
  28. j = path.lastIndexOf("\\");
  29. const p = i < 0 ? j : j < 0 ? i : i < j ? j : i;
  30. if (p < 0) return null;
  31. const s = path.substr(p + 1);
  32. return s;
  33. };