1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.unixify = unixify;
|
---|
7 | exports.correctPath = correctPath;
|
---|
8 | var isWin = process.platform === 'win32';
|
---|
9 |
|
---|
10 | function removeTrailingSeparator(str) {
|
---|
11 | var i = str.length - 1;
|
---|
12 |
|
---|
13 | if (i < 2) {
|
---|
14 | return str;
|
---|
15 | }
|
---|
16 |
|
---|
17 | while (isSeparator(str, i)) {
|
---|
18 | i--;
|
---|
19 | }
|
---|
20 |
|
---|
21 | return str.substr(0, i + 1);
|
---|
22 | }
|
---|
23 |
|
---|
24 | function isSeparator(str, i) {
|
---|
25 | var _char = str[i];
|
---|
26 | return i > 0 && (_char === '/' || isWin && _char === '\\');
|
---|
27 | }
|
---|
28 |
|
---|
29 | function normalizePath(str, stripTrailing) {
|
---|
30 | if (typeof str !== 'string') {
|
---|
31 | throw new TypeError('expected a string');
|
---|
32 | }
|
---|
33 |
|
---|
34 | str = str.replace(/[\\\/]+/g, '/');
|
---|
35 |
|
---|
36 | if (stripTrailing !== false) {
|
---|
37 | str = removeTrailingSeparator(str);
|
---|
38 | }
|
---|
39 |
|
---|
40 | return str;
|
---|
41 | }
|
---|
42 |
|
---|
43 | function unixify(filepath) {
|
---|
44 | var stripTrailing = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
---|
45 |
|
---|
46 | if (isWin) {
|
---|
47 | filepath = normalizePath(filepath, stripTrailing);
|
---|
48 | return filepath.replace(/^([a-zA-Z]+:|\.\/)/, '');
|
---|
49 | }
|
---|
50 |
|
---|
51 | return filepath;
|
---|
52 | }
|
---|
53 |
|
---|
54 | function correctPath(filepath) {
|
---|
55 | return unixify(filepath.replace(/^\\\\\?\\.:\\/, '\\'));
|
---|
56 | } |
---|