| | |
| | | const GLOBSTAR = '**'; |
| | | const ESCAPE_SYMBOL = '\\'; |
| | | const COMMON_GLOB_SYMBOLS_RE = /[*?]|^!/; |
| | | const REGEX_CHARACTER_CLASS_SYMBOLS_RE = /\[.*]/; |
| | | const REGEX_GROUP_SYMBOLS_RE = /(?:^|[^!*+?@])\(.*\|.*\)/; |
| | | const GLOB_EXTENSION_SYMBOLS_RE = /[!*+?@]\(.*\)/; |
| | | const BRACE_EXPANSIONS_SYMBOLS_RE = /{.*(?:,|\.\.).*}/; |
| | | const REGEX_CHARACTER_CLASS_SYMBOLS_RE = /\[[^[]*]/; |
| | | const REGEX_GROUP_SYMBOLS_RE = /(?:^|[^!*+?@])\([^(]*\|[^|]*\)/; |
| | | const GLOB_EXTENSION_SYMBOLS_RE = /[!*+?@]\([^(]*\)/; |
| | | const BRACE_EXPANSION_SEPARATORS_RE = /,|\.\./; |
| | | function isStaticPattern(pattern, options = {}) { |
| | | return !isDynamicPattern(pattern, options); |
| | | } |
| | |
| | | if (options.extglob !== false && GLOB_EXTENSION_SYMBOLS_RE.test(pattern)) { |
| | | return true; |
| | | } |
| | | if (options.braceExpansion !== false && BRACE_EXPANSIONS_SYMBOLS_RE.test(pattern)) { |
| | | if (options.braceExpansion !== false && hasBraceExpansion(pattern)) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | exports.isDynamicPattern = isDynamicPattern; |
| | | function hasBraceExpansion(pattern) { |
| | | const openingBraceIndex = pattern.indexOf('{'); |
| | | if (openingBraceIndex === -1) { |
| | | return false; |
| | | } |
| | | const closingBraceIndex = pattern.indexOf('}', openingBraceIndex + 1); |
| | | if (closingBraceIndex === -1) { |
| | | return false; |
| | | } |
| | | const braceContent = pattern.slice(openingBraceIndex, closingBraceIndex); |
| | | return BRACE_EXPANSION_SEPARATORS_RE.test(braceContent); |
| | | } |
| | | function convertToPositivePattern(pattern) { |
| | | return isNegativePattern(pattern) ? pattern.slice(1) : pattern; |
| | | } |