-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpaths-utility.js
38 lines (34 loc) · 968 Bytes
/
paths-utility.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
const path = require("path");
const {URI} = require("vscode-uri");
/**
*
* @param {string} fileName
* @param replacement
* @return {*}
*/
function makeServerPath(fileName, replacement) {
if (fileName.startsWith("file:")) {
return fileName;
}
const serverPath = formatPath(__dirname + path.sep + "temp" + path.sep + fileName);
if (replacement){
return serverPath.replace(replacement.from, replacement.to);
}
return serverPath;
}
function makeClientPath(filePath, replacement) {
if (/^(file|https?):/.test(filePath)) {
return filePath;
}
const clientPath = filePath.split(/[/\\]/).pop();
if (replacement){
return clientPath.replace(replacement.from, replacement.to);
}
return clientPath;
}
function formatPath(filePath) {
return URI.file(filePath).toString();
}
exports.makeServerPath = makeServerPath;
exports.makeClientPath = makeClientPath;
exports.formatPath = formatPath;