MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / homeRelativePath

Function homeRelativePath

src/shared/utils/fs.ts:85–95  ·  view source on GitHub ↗
(p: string | undefined)

Source from the content-addressed store, hash-verified

83/// Shortens a path to use ~ if it's inside the home directory and always
84// uses forward slashes in that case.
85export function homeRelativePath(p: string | undefined) {
86 if (!p) return undefined;
87 const homedir = os.homedir();
88 if (isWithinPath(p, homedir)) {
89 if (isWin)
90 return path.join("~", path.relative(homedir, p)).replace(/\\/g, "/");
91 else
92 return path.join("~", path.relative(homedir, p));
93 }
94 return p;
95}
96
97export function isWithinPath(file: string, folder: string) {
98 const relative = path.relative(folder.toLowerCase(), file.toLowerCase());

Callers 4

util.test.tsFile · 0.90
showPackagePickerFunction · 0.90
showFolderMultiPickerFunction · 0.90
promptForSdkFunction · 0.90

Calls 1

isWithinPathFunction · 0.85

Tested by

no test coverage detected