tar
Version:
tar for JavaScript
26 lines • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.stripAbsolutePath = void 0;
const win32_path_js_1 = require("./win32-path.js");
/**
* Remove each root from the start of a path. Returns the roots and
* the rest of the path.
*
* A POSIX absolute path is also absolute on Windows, so the rules of
* Windows are used on each platform. A path that is relative to a
* drive loses the drive: `c:../foo` gives `['c:', '../foo']`.
*/
const stripAbsolutePath = (path) => {
let roots = '';
for (let root; (root = (0, win32_path_js_1.win32Root)(path));) {
// Windows reads `//x/y/` as the root of `//x/y/z`. Remove only the
// first slash, but remove all of `//?/c:/`.
if (path.charAt(0) === '/' && path.slice(0, 4) !== '//?/')
root = '/';
path = path.slice(root.length);
roots += root;
}
return [roots, path];
};
exports.stripAbsolutePath = stripAbsolutePath;
//# sourceMappingURL=strip-absolute-path.js.map