source: trip-planner-front/node_modules/fs-monkey/lib/correctPath.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.unixify = unixify;
7exports.correctPath = correctPath;
8var isWin = process.platform === 'win32';
9
10function 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
24function isSeparator(str, i) {
25 var _char = str[i];
26 return i > 0 && (_char === '/' || isWin && _char === '\\');
27}
28
29function 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
43function 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
54function correctPath(filepath) {
55 return unixify(filepath.replace(/^\\\\\?\\.:\\/, '\\'));
56}
Note: See TracBrowser for help on using the repository browser.