forked from TimRudy/ice-chips-verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfs-helper.js
39 lines (32 loc) · 1.13 KB
/
fs-helper.js
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
// fs-helper.js
//
// - filesystem path utility functions
//
// © 2019 Tim Rudy
class FsHelper {
getTargetDirectoryOrDefault(userArgDirectory, defaultDirectory) {
let targetDirectory;
if (userArgDirectory) {
targetDirectory = userArgDirectory;
// if the input is not of absolute or relative form (relative to the current working
// directory), then is relative to defaultDirectory
if (!(targetDirectory.startsWith('.') ||
targetDirectory.startsWith('/') || targetDirectory.startsWith('\\') ||
targetDirectory.indexOf(':/') === 1 || targetDirectory.indexOf(':\\') === 1)) {
targetDirectory = defaultDirectory + targetDirectory;
}
// put in canonical form of a directory (it will act as a prefix)
if (!(targetDirectory.endsWith('/') || targetDirectory.endsWith('\\'))) {
targetDirectory = targetDirectory + '/';
}
} else {
targetDirectory = defaultDirectory;
}
return targetDirectory;
}
getBasePathFromDirectoryPath(directory) {
// remove slash at the end (no longer the canonical form of a directory)
return directory.substr(0, directory.length - 1);
}
}
module.exports = new FsHelper();