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/util/misc-path.ts
Views: 687
1
// lower case extension of the path
2
export function getExtension(path: string): string {
3
const v = path.split(".");
4
return (v.length <= 1 ? "" : v.pop() ?? "").toLowerCase();
5
}
6
7
export function containingPath(path: string): string {
8
const i = path.lastIndexOf("/");
9
if (i != -1) {
10
return path.slice(0, i);
11
} else {
12
return "";
13
}
14
}
15
16
export function splitFirst(
17
path: string,
18
symbol: string = "/"
19
): [string, string] {
20
const i = path.indexOf(symbol);
21
if (i == -1) {
22
return [path, ""];
23
}
24
return [path.slice(0, i), path.slice(i + 1)];
25
}
26
27
export function splitLast(
28
path: string,
29
symbol: string = "/"
30
): [string, string] {
31
const i = path.lastIndexOf(symbol);
32
if (i == -1) {
33
return [path, ""];
34
}
35
return [path.slice(0, i), path.slice(i + 1)];
36
}
37
38
39
40