CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/backend/misc/abspath.ts
Views: 687
1
// Any non-absolute path is assumed to be relative to the user's home directory.
2
// This function converts such a path to an absolute path.
3
4
import { join } from "path";
5
6
export default function abspath(path: string): string {
7
if (path.length === 0) {
8
return process.env.HOME ?? "";
9
}
10
if (path.startsWith("/")) {
11
return path; // already an absolute path
12
}
13
// The regexp is to get rid of /./, which is the same as /...
14
return join(process.env.HOME ?? "", path).replace(/\/\.\//g, "/");
15
}
16
17