source: frontend/node_modules/fast-glob/out/utils/path.js

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

Fix frontend appearance

  • Property mode set to 100644
File size: 2.9 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.convertPosixPathToPattern = exports.convertWindowsPathToPattern = exports.convertPathToPattern = exports.escapePosixPath = exports.escapeWindowsPath = exports.escape = exports.removeLeadingDotSegment = exports.makeAbsolute = exports.unixify = void 0;
4const os = require("os");
5const path = require("path");
6const IS_WINDOWS_PLATFORM = os.platform() === 'win32';
7const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
8/**
9 * All non-escaped special characters.
10 * Posix: ()*?[]{|}, !+@ before (, ! at the beginning, \\ before non-special characters.
11 * Windows: (){}[], !+@ before (, ! at the beginning.
12 */
13const POSIX_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\()|\\(?![!()*+?@[\]{|}]))/g;
14const WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()[\]{}]|^!|[!+@](?=\())/g;
15/**
16 * The device path (\\.\ or \\?\).
17 * https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#dos-device-paths
18 */
19const DOS_DEVICE_PATH_RE = /^\\\\([.?])/;
20/**
21 * All backslashes except those escaping special characters.
22 * Windows: !()+@{}
23 * https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
24 */
25const WINDOWS_BACKSLASHES_RE = /\\(?![!()+@[\]{}])/g;
26/**
27 * Designed to work only with simple paths: `dir\\file`.
28 */
29function unixify(filepath) {
30 return filepath.replace(/\\/g, '/');
31}
32exports.unixify = unixify;
33function makeAbsolute(cwd, filepath) {
34 return path.resolve(cwd, filepath);
35}
36exports.makeAbsolute = makeAbsolute;
37function removeLeadingDotSegment(entry) {
38 // We do not use `startsWith` because this is 10x slower than current implementation for some cases.
39 // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
40 if (entry.charAt(0) === '.') {
41 const secondCharactery = entry.charAt(1);
42 if (secondCharactery === '/' || secondCharactery === '\\') {
43 return entry.slice(LEADING_DOT_SEGMENT_CHARACTERS_COUNT);
44 }
45 }
46 return entry;
47}
48exports.removeLeadingDotSegment = removeLeadingDotSegment;
49exports.escape = IS_WINDOWS_PLATFORM ? escapeWindowsPath : escapePosixPath;
50function escapeWindowsPath(pattern) {
51 return pattern.replace(WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE, '\\$2');
52}
53exports.escapeWindowsPath = escapeWindowsPath;
54function escapePosixPath(pattern) {
55 return pattern.replace(POSIX_UNESCAPED_GLOB_SYMBOLS_RE, '\\$2');
56}
57exports.escapePosixPath = escapePosixPath;
58exports.convertPathToPattern = IS_WINDOWS_PLATFORM ? convertWindowsPathToPattern : convertPosixPathToPattern;
59function convertWindowsPathToPattern(filepath) {
60 return escapeWindowsPath(filepath)
61 .replace(DOS_DEVICE_PATH_RE, '//$1')
62 .replace(WINDOWS_BACKSLASHES_RE, '/');
63}
64exports.convertWindowsPathToPattern = convertWindowsPathToPattern;
65function convertPosixPathToPattern(filepath) {
66 return escapePosixPath(filepath);
67}
68exports.convertPosixPathToPattern = convertPosixPathToPattern;
Note: See TracBrowser for help on using the repository browser.