source: frontend/node_modules/fs-monkey/lib/correctPath.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.1 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.correctPath = correctPath;
7exports.unixify = unixify;
8var isWin = process.platform === 'win32';
9function removeTrailingSeparator(str) {
10 var i = str.length - 1;
11 if (i < 2) {
12 return str;
13 }
14 while (isSeparator(str, i)) {
15 i--;
16 }
17 return str.substr(0, i + 1);
18}
19function isSeparator(str, i) {
20 var _char = str[i];
21 return i > 0 && (_char === '/' || isWin && _char === '\\');
22}
23function normalizePath(str, stripTrailing) {
24 if (typeof str !== 'string') {
25 throw new TypeError('expected a string');
26 }
27 str = str.replace(/[\\\/]+/g, '/');
28 if (stripTrailing !== false) {
29 str = removeTrailingSeparator(str);
30 }
31 return str;
32}
33function unixify(filepath) {
34 var stripTrailing = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
35 if (isWin) {
36 filepath = normalizePath(filepath, stripTrailing);
37 return filepath.replace(/^([a-zA-Z]+:|\.\/)/, '');
38 }
39 return filepath;
40}
41function correctPath(filepath) {
42 return unixify(filepath.replace(/^\\\\\?\\.:\\/, '\\'));
43}
Note: See TracBrowser for help on using the repository browser.