source: trip-planner-front/node_modules/fast-glob/out/utils/pattern.js@ 76712b2

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

initial commit

  • Property mode set to 100644
File size: 6.3 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.matchAny = exports.convertPatternsToRe = exports.makeRe = exports.getPatternParts = exports.expandBraceExpansion = exports.expandPatternsWithBraceExpansion = exports.isAffectDepthOfReadingPattern = exports.endsWithSlashGlobStar = exports.hasGlobStar = exports.getBaseDirectory = exports.isPatternRelatedToParentDirectory = exports.getPatternsOutsideCurrentDirectory = exports.getPatternsInsideCurrentDirectory = exports.getPositivePatterns = exports.getNegativePatterns = exports.isPositivePattern = exports.isNegativePattern = exports.convertToNegativePattern = exports.convertToPositivePattern = exports.isDynamicPattern = exports.isStaticPattern = void 0;
4const path = require("path");
5const globParent = require("glob-parent");
6const micromatch = require("micromatch");
7const GLOBSTAR = '**';
8const ESCAPE_SYMBOL = '\\';
9const COMMON_GLOB_SYMBOLS_RE = /[*?]|^!/;
10const REGEX_CHARACTER_CLASS_SYMBOLS_RE = /\[.*]/;
11const REGEX_GROUP_SYMBOLS_RE = /(?:^|[^!*+?@])\(.*\|.*\)/;
12const GLOB_EXTENSION_SYMBOLS_RE = /[!*+?@]\(.*\)/;
13const BRACE_EXPANSIONS_SYMBOLS_RE = /{.*(?:,|\.\.).*}/;
14function isStaticPattern(pattern, options = {}) {
15 return !isDynamicPattern(pattern, options);
16}
17exports.isStaticPattern = isStaticPattern;
18function isDynamicPattern(pattern, options = {}) {
19 /**
20 * A special case with an empty string is necessary for matching patterns that start with a forward slash.
21 * An empty string cannot be a dynamic pattern.
22 * For example, the pattern `/lib/*` will be spread into parts: '', 'lib', '*'.
23 */
24 if (pattern === '') {
25 return false;
26 }
27 /**
28 * When the `caseSensitiveMatch` option is disabled, all patterns must be marked as dynamic, because we cannot check
29 * filepath directly (without read directory).
30 */
31 if (options.caseSensitiveMatch === false || pattern.includes(ESCAPE_SYMBOL)) {
32 return true;
33 }
34 if (COMMON_GLOB_SYMBOLS_RE.test(pattern) || REGEX_CHARACTER_CLASS_SYMBOLS_RE.test(pattern) || REGEX_GROUP_SYMBOLS_RE.test(pattern)) {
35 return true;
36 }
37 if (options.extglob !== false && GLOB_EXTENSION_SYMBOLS_RE.test(pattern)) {
38 return true;
39 }
40 if (options.braceExpansion !== false && BRACE_EXPANSIONS_SYMBOLS_RE.test(pattern)) {
41 return true;
42 }
43 return false;
44}
45exports.isDynamicPattern = isDynamicPattern;
46function convertToPositivePattern(pattern) {
47 return isNegativePattern(pattern) ? pattern.slice(1) : pattern;
48}
49exports.convertToPositivePattern = convertToPositivePattern;
50function convertToNegativePattern(pattern) {
51 return '!' + pattern;
52}
53exports.convertToNegativePattern = convertToNegativePattern;
54function isNegativePattern(pattern) {
55 return pattern.startsWith('!') && pattern[1] !== '(';
56}
57exports.isNegativePattern = isNegativePattern;
58function isPositivePattern(pattern) {
59 return !isNegativePattern(pattern);
60}
61exports.isPositivePattern = isPositivePattern;
62function getNegativePatterns(patterns) {
63 return patterns.filter(isNegativePattern);
64}
65exports.getNegativePatterns = getNegativePatterns;
66function getPositivePatterns(patterns) {
67 return patterns.filter(isPositivePattern);
68}
69exports.getPositivePatterns = getPositivePatterns;
70/**
71 * Returns patterns that can be applied inside the current directory.
72 *
73 * @example
74 * // ['./*', '*', 'a/*']
75 * getPatternsInsideCurrentDirectory(['./*', '*', 'a/*', '../*', './../*'])
76 */
77function getPatternsInsideCurrentDirectory(patterns) {
78 return patterns.filter((pattern) => !isPatternRelatedToParentDirectory(pattern));
79}
80exports.getPatternsInsideCurrentDirectory = getPatternsInsideCurrentDirectory;
81/**
82 * Returns patterns to be expanded relative to (outside) the current directory.
83 *
84 * @example
85 * // ['../*', './../*']
86 * getPatternsInsideCurrentDirectory(['./*', '*', 'a/*', '../*', './../*'])
87 */
88function getPatternsOutsideCurrentDirectory(patterns) {
89 return patterns.filter(isPatternRelatedToParentDirectory);
90}
91exports.getPatternsOutsideCurrentDirectory = getPatternsOutsideCurrentDirectory;
92function isPatternRelatedToParentDirectory(pattern) {
93 return pattern.startsWith('..') || pattern.startsWith('./..');
94}
95exports.isPatternRelatedToParentDirectory = isPatternRelatedToParentDirectory;
96function getBaseDirectory(pattern) {
97 return globParent(pattern, { flipBackslashes: false });
98}
99exports.getBaseDirectory = getBaseDirectory;
100function hasGlobStar(pattern) {
101 return pattern.includes(GLOBSTAR);
102}
103exports.hasGlobStar = hasGlobStar;
104function endsWithSlashGlobStar(pattern) {
105 return pattern.endsWith('/' + GLOBSTAR);
106}
107exports.endsWithSlashGlobStar = endsWithSlashGlobStar;
108function isAffectDepthOfReadingPattern(pattern) {
109 const basename = path.basename(pattern);
110 return endsWithSlashGlobStar(pattern) || isStaticPattern(basename);
111}
112exports.isAffectDepthOfReadingPattern = isAffectDepthOfReadingPattern;
113function expandPatternsWithBraceExpansion(patterns) {
114 return patterns.reduce((collection, pattern) => {
115 return collection.concat(expandBraceExpansion(pattern));
116 }, []);
117}
118exports.expandPatternsWithBraceExpansion = expandPatternsWithBraceExpansion;
119function expandBraceExpansion(pattern) {
120 return micromatch.braces(pattern, {
121 expand: true,
122 nodupes: true
123 });
124}
125exports.expandBraceExpansion = expandBraceExpansion;
126function getPatternParts(pattern, options) {
127 let { parts } = micromatch.scan(pattern, Object.assign(Object.assign({}, options), { parts: true }));
128 /**
129 * The scan method returns an empty array in some cases.
130 * See micromatch/picomatch#58 for more details.
131 */
132 if (parts.length === 0) {
133 parts = [pattern];
134 }
135 /**
136 * The scan method does not return an empty part for the pattern with a forward slash.
137 * This is another part of micromatch/picomatch#58.
138 */
139 if (parts[0].startsWith('/')) {
140 parts[0] = parts[0].slice(1);
141 parts.unshift('');
142 }
143 return parts;
144}
145exports.getPatternParts = getPatternParts;
146function makeRe(pattern, options) {
147 return micromatch.makeRe(pattern, options);
148}
149exports.makeRe = makeRe;
150function convertPatternsToRe(patterns, options) {
151 return patterns.map((pattern) => makeRe(pattern, options));
152}
153exports.convertPatternsToRe = convertPatternsToRe;
154function matchAny(entry, patternsRe) {
155 return patternsRe.some((patternRe) => patternRe.test(entry));
156}
157exports.matchAny = matchAny;
Note: See TracBrowser for help on using the repository browser.