is-inside-another-path.js 723 B

12345678910111213141516171819202122
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.isInsideAnotherPath = void 0;
  4. const path_1 = require("path");
  5. function isInsideAnotherPath(parent, directory) {
  6. const relativePart = (0, path_1.relative)(parent, directory);
  7. // Tested folder is above parent.
  8. if (relativePart.startsWith('..')) {
  9. return false;
  10. }
  11. // Tested folder is the same as parent.
  12. if (relativePart.length === 0) {
  13. return false;
  14. }
  15. // Tested directory has nothing in common with parent.
  16. if ((0, path_1.isAbsolute)(relativePart)) {
  17. return false;
  18. }
  19. // Last option, must be subfolder.
  20. return true;
  21. }
  22. exports.isInsideAnotherPath = isInsideAnotherPath;