Ohm-Management - Projektarbeit B-ME
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.

path-is-inside.js 858B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. var path = require("path");
  3. module.exports = function (thePath, potentialParent) {
  4. // For inside-directory checking, we want to allow trailing slashes, so normalize.
  5. thePath = stripTrailingSep(thePath);
  6. potentialParent = stripTrailingSep(potentialParent);
  7. // Node treats only Windows as case-insensitive in its path module; we follow those conventions.
  8. if (process.platform === "win32") {
  9. thePath = thePath.toLowerCase();
  10. potentialParent = potentialParent.toLowerCase();
  11. }
  12. return thePath.lastIndexOf(potentialParent, 0) === 0 &&
  13. (
  14. thePath[potentialParent.length] === path.sep ||
  15. thePath[potentialParent.length] === undefined
  16. );
  17. };
  18. function stripTrailingSep(thePath) {
  19. if (thePath[thePath.length - 1] === path.sep) {
  20. return thePath.slice(0, -1);
  21. }
  22. return thePath;
  23. }