-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.js
More file actions
42 lines (42 loc) · 1.1 KB
/
convert.js
File metadata and controls
42 lines (42 loc) · 1.1 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
/// <reference path="./typings/index.d.ts" />
"use strict";
var path = require('path');
var os = require('os');
function getPathInput(path) {
if (os.platform() == 'win32') {
return pathToWindows(path);
}
else {
return pathToPosix(path);
}
}
exports.getPathInput = getPathInput;
/**
* Converts given path string to POSIX type path string
* it will replace the windows file path seperator to unix file path seperator
*
* @param pathInput input path
* @returns string
*/
function pathToPosix(pathInput) {
var p = path.normalize(pathInput);
var path_regex = /\/\//;
p = p.replace(/\\/g, "/");
while (p.match(path_regex)) {
p = p.replace(path_regex, "/");
}
return p;
}
exports.pathToPosix = pathToPosix;
/**
* Converts given path string to Windows type path string
* it will replace the Posix file path seperator to Windows file path seperator
*
* @param pathInput input path
* @returns string
*/
function pathToWindows(pathInput) {
var p = pathToPosix(pathInput);
return p.replace(/\//g, "\\");
}
exports.pathToWindows = pathToWindows;