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 | if (i < 2) {
|
13 | return str;
|
14 | }
|
15 | while (isSeparator(str, i)) {
|
16 | i--;
|
17 | }
|
18 | return str.substr(0, i + 1);
|
19 | }
|
20 |
|
21 | function isSeparator(str, i) {
|
22 | var char = str[i];
|
23 | return i > 0 && (char === '/' || isWin && char === '\\');
|
24 | }
|
25 |
|
26 | function normalizePath(str, stripTrailing) {
|
27 | if (typeof str !== 'string') {
|
28 | throw new TypeError('expected a string');
|
29 | }
|
30 | str = str.replace(/[\\\/]+/g, '/');
|
31 | if (stripTrailing !== false) {
|
32 | str = removeTrailingSeparator(str);
|
33 | }
|
34 | return str;
|
35 | }
|
36 |
|
37 | function unixify(filepath) {
|
38 | var stripTrailing = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
39 |
|
40 | if (isWin) {
|
41 | filepath = normalizePath(filepath, stripTrailing);
|
42 | return filepath.replace(/^([a-zA-Z]+:|\.\/)/, '');
|
43 | }
|
44 | return filepath;
|
45 | }
|
46 |
|
47 | function correctPath(filepath) {
|
48 | return unixify(filepath.replace(/^\\\\\?\\.:\\/, '\\'));
|
49 | } |
\ | No newline at end of file |