Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
strip-absolute-path.js25 linesDownload Raw Back to esm
1// unix absolute paths are also absolute on win32, so we use this for both
2import { win32 } from 'node:path';
3const { isAbsolute, parse } = win32;
4// returns [root, stripped]
5// Note that windows will think that //x/y/z/a has a "root" of //x/y, and in
6// those cases, we want to sanitize it to x/y/z/a, not z/a, so we strip /
7// explicitly if it's the first character.
8// drive-specific relative paths on Windows get their root stripped off even
9// though they are not absolute, so `c:../foo` becomes ['c:', '../foo']
10export const stripAbsolutePath = (path) => {
11    let r = '';
12    let parsed = parse(path);
13    while (isAbsolute(path) || parsed.root) {
14        // windows will think that //x/y/z has a "root" of //x/y/
15        // but strip the //?/C:/ off of //?/C:/path
16        const root = path.charAt(0) === '/' && path.slice(0, 4) !== '//?/' ?
17            '/'
18            : parsed.root;
19        path = path.slice(root.length);
20        r += root;
21        parsed = parse(path);
22    }
23    return [r, path];
24};
25//# sourceMappingURL=strip-absolute-path.js.map
codekingpro/portable-devtools · Team Ai