-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPath.js
More file actions
62 lines (47 loc) · 1.43 KB
/
Path.js
File metadata and controls
62 lines (47 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { storage } from "@nucleoidjs/webstorage";
const isUsed = (paths, prefix, suffix, value) => {
if (value === "" && paths.includes(prefix.charAt(0, prefix.length - 1)))
return true;
if (suffix === value) return false;
if (value === "" || value === null) return true;
if (prefix.charAt(prefix.length - 1) !== "/") prefix += "/";
if (paths.includes(prefix + value)) return true;
return false;
};
const split = (path) => {
const pathArray = path.split("/");
const suffix = pathArray.pop();
const prefix = pathArray.length <= 1 ? "/" : pathArray.join("/");
return { prefix, suffix };
};
const addSlashMark = (path) => {
return path?.substring(path.length - 1) !== "/" ? "/" : "";
};
const getRecentProject = () => {
const recentProject = storage.get("ide", "selected", "project");
if (recentProject) {
return recentProject;
}
return null;
};
const getMode = () => {
const urlParts = window.location.pathname.split("/");
const uuidPattern =
/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
const validUuid = urlParts.some((part) => uuidPattern.test(part));
const urlParams = new URLSearchParams(window.location.search);
const queryMode = urlParams.get("mode");
if (validUuid) {
return queryMode ? queryMode : "cloud";
} else {
return null;
}
};
const Path = {
isUsed,
split,
addSlashMark,
getMode,
getRecentProject,
};
export default Path;