minimatch-fast 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +950 -0
  3. package/dist/cjs/brace-expand.d.ts +42 -0
  4. package/dist/cjs/brace-expand.d.ts.map +1 -0
  5. package/dist/cjs/brace-expand.js +172 -0
  6. package/dist/cjs/brace-expand.js.map +1 -0
  7. package/dist/cjs/cache.d.ts +36 -0
  8. package/dist/cjs/cache.d.ts.map +1 -0
  9. package/dist/cjs/cache.js +91 -0
  10. package/dist/cjs/cache.js.map +1 -0
  11. package/dist/cjs/escape.d.ts +40 -0
  12. package/dist/cjs/escape.d.ts.map +1 -0
  13. package/dist/cjs/escape.js +52 -0
  14. package/dist/cjs/escape.js.map +1 -0
  15. package/dist/cjs/fast-paths.d.ts +54 -0
  16. package/dist/cjs/fast-paths.d.ts.map +1 -0
  17. package/dist/cjs/fast-paths.js +213 -0
  18. package/dist/cjs/fast-paths.js.map +1 -0
  19. package/dist/cjs/index.d.ts +150 -0
  20. package/dist/cjs/index.d.ts.map +1 -0
  21. package/dist/cjs/index.js +250 -0
  22. package/dist/cjs/index.js.map +1 -0
  23. package/dist/cjs/minimatch-class.d.ts +153 -0
  24. package/dist/cjs/minimatch-class.d.ts.map +1 -0
  25. package/dist/cjs/minimatch-class.js +618 -0
  26. package/dist/cjs/minimatch-class.js.map +1 -0
  27. package/dist/cjs/options.d.ts +31 -0
  28. package/dist/cjs/options.d.ts.map +1 -0
  29. package/dist/cjs/options.js +67 -0
  30. package/dist/cjs/options.js.map +1 -0
  31. package/dist/cjs/package.json +3 -0
  32. package/dist/cjs/types.d.ts +194 -0
  33. package/dist/cjs/types.d.ts.map +1 -0
  34. package/dist/cjs/types.js +19 -0
  35. package/dist/cjs/types.js.map +1 -0
  36. package/dist/cjs/unescape.d.ts +36 -0
  37. package/dist/cjs/unescape.d.ts.map +1 -0
  38. package/dist/cjs/unescape.js +49 -0
  39. package/dist/cjs/unescape.js.map +1 -0
  40. package/dist/cjs/utils.d.ts +62 -0
  41. package/dist/cjs/utils.d.ts.map +1 -0
  42. package/dist/cjs/utils.js +126 -0
  43. package/dist/cjs/utils.js.map +1 -0
  44. package/dist/esm/brace-expand.d.ts +42 -0
  45. package/dist/esm/brace-expand.d.ts.map +1 -0
  46. package/dist/esm/brace-expand.js +165 -0
  47. package/dist/esm/brace-expand.js.map +1 -0
  48. package/dist/esm/cache.d.ts +36 -0
  49. package/dist/esm/cache.d.ts.map +1 -0
  50. package/dist/esm/cache.js +86 -0
  51. package/dist/esm/cache.js.map +1 -0
  52. package/dist/esm/escape.d.ts +40 -0
  53. package/dist/esm/escape.d.ts.map +1 -0
  54. package/dist/esm/escape.js +49 -0
  55. package/dist/esm/escape.js.map +1 -0
  56. package/dist/esm/fast-paths.d.ts +54 -0
  57. package/dist/esm/fast-paths.d.ts.map +1 -0
  58. package/dist/esm/fast-paths.js +209 -0
  59. package/dist/esm/fast-paths.js.map +1 -0
  60. package/dist/esm/index.d.ts +150 -0
  61. package/dist/esm/index.d.ts.map +1 -0
  62. package/dist/esm/index.js +240 -0
  63. package/dist/esm/index.js.map +1 -0
  64. package/dist/esm/minimatch-class.d.ts +153 -0
  65. package/dist/esm/minimatch-class.d.ts.map +1 -0
  66. package/dist/esm/minimatch-class.js +611 -0
  67. package/dist/esm/minimatch-class.js.map +1 -0
  68. package/dist/esm/options.d.ts +31 -0
  69. package/dist/esm/options.d.ts.map +1 -0
  70. package/dist/esm/options.js +63 -0
  71. package/dist/esm/options.js.map +1 -0
  72. package/dist/esm/package.json +3 -0
  73. package/dist/esm/types.d.ts +194 -0
  74. package/dist/esm/types.d.ts.map +1 -0
  75. package/dist/esm/types.js +16 -0
  76. package/dist/esm/types.js.map +1 -0
  77. package/dist/esm/unescape.d.ts +36 -0
  78. package/dist/esm/unescape.d.ts.map +1 -0
  79. package/dist/esm/unescape.js +46 -0
  80. package/dist/esm/unescape.js.map +1 -0
  81. package/dist/esm/utils.d.ts +62 -0
  82. package/dist/esm/utils.d.ts.map +1 -0
  83. package/dist/esm/utils.js +116 -0
  84. package/dist/esm/utils.js.map +1 -0
  85. package/package.json +83 -0
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @fileoverview Brace expansion using the 'braces' package
3
+ *
4
+ * This module is critical because picomatch does NOT perform full brace expansion.
5
+ * picomatch only does brace matching, meaning {a,b} will match 'a' or 'b'
6
+ * but won't expand the pattern into ['a', 'b'].
7
+ *
8
+ * minimatch uses brace-expansion to fully expand patterns like:
9
+ * - {a,b,c} -> ['a', 'b', 'c']
10
+ * - {1..3} -> ['1', '2', '3']
11
+ * - {a..c} -> ['a', 'b', 'c']
12
+ * - a{b,c}d -> ['abd', 'acd']
13
+ *
14
+ * We use 'braces' package which is maintained by the same author as picomatch
15
+ * and is what micromatch uses internally.
16
+ *
17
+ * Security considerations:
18
+ * - Maximum expansion length is limited to prevent DoS attacks
19
+ * - Range expansion is limited (e.g., {1..1000000} is restricted)
20
+ *
21
+ * @author 686f6c61
22
+ * @see https://github.com/686f6c61/minimatch-fast
23
+ * @license MIT
24
+ */
25
+ import type { MinimatchOptions } from './types.js';
26
+ /**
27
+ * Expand brace patterns like {a,b,c} and {1..3}
28
+ *
29
+ * Optimized with:
30
+ * 1. Cache for repeated patterns
31
+ * 2. Fast path for simple {a,b,c} patterns
32
+ *
33
+ * @param pattern - The glob pattern to expand
34
+ * @param options - Minimatch options
35
+ * @returns Array of expanded patterns
36
+ */
37
+ export declare function braceExpand(pattern: string, options?: MinimatchOptions): string[];
38
+ /**
39
+ * Check if a pattern contains brace expansion syntax
40
+ */
41
+ export declare function hasBraces(pattern: string): boolean;
42
+ //# sourceMappingURL=brace-expand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brace-expand.d.ts","sourceRoot":"","sources":["../../src/brace-expand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAyCnD;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,gBAAqB,GAC7B,MAAM,EAAE,CAsEV;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CA8BlD"}
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Brace expansion using the 'braces' package
4
+ *
5
+ * This module is critical because picomatch does NOT perform full brace expansion.
6
+ * picomatch only does brace matching, meaning {a,b} will match 'a' or 'b'
7
+ * but won't expand the pattern into ['a', 'b'].
8
+ *
9
+ * minimatch uses brace-expansion to fully expand patterns like:
10
+ * - {a,b,c} -> ['a', 'b', 'c']
11
+ * - {1..3} -> ['1', '2', '3']
12
+ * - {a..c} -> ['a', 'b', 'c']
13
+ * - a{b,c}d -> ['abd', 'acd']
14
+ *
15
+ * We use 'braces' package which is maintained by the same author as picomatch
16
+ * and is what micromatch uses internally.
17
+ *
18
+ * Security considerations:
19
+ * - Maximum expansion length is limited to prevent DoS attacks
20
+ * - Range expansion is limited (e.g., {1..1000000} is restricted)
21
+ *
22
+ * @author 686f6c61
23
+ * @see https://github.com/686f6c61/minimatch-fast
24
+ * @license MIT
25
+ */
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.braceExpand = braceExpand;
31
+ exports.hasBraces = hasBraces;
32
+ const braces_1 = __importDefault(require("braces"));
33
+ /**
34
+ * Maximum number of patterns that can be generated from brace expansion
35
+ * This prevents DoS attacks from patterns like {1..1000000}
36
+ */
37
+ const MAX_EXPANSION_LENGTH = 10000;
38
+ /**
39
+ * Cache for brace expansion results.
40
+ * Key is the pattern, value is the expanded array.
41
+ * Limited to prevent memory issues.
42
+ */
43
+ const BRACE_CACHE_SIZE = 200;
44
+ const braceCache = new Map();
45
+ /**
46
+ * Simple brace pattern regex: prefix{a,b,c}suffix
47
+ * Matches patterns with a single brace group containing comma-separated values
48
+ * without nesting or ranges.
49
+ */
50
+ const SIMPLE_BRACE_RE = /^([^{]*)\{([^{}]+)\}([^{]*)$/;
51
+ /**
52
+ * Try fast path for simple brace patterns like prefix{a,b,c}suffix
53
+ * Returns null if pattern is not a simple brace pattern.
54
+ */
55
+ function trySimpleBraceExpand(pattern) {
56
+ const m = pattern.match(SIMPLE_BRACE_RE);
57
+ if (!m)
58
+ return null;
59
+ const [, prefix, content, suffix] = m;
60
+ // Check if it's a range pattern (contains ..)
61
+ if (content.includes('..'))
62
+ return null;
63
+ // Split by comma and expand
64
+ const items = content.split(',');
65
+ return items.map(item => prefix + item + suffix);
66
+ }
67
+ /**
68
+ * Expand brace patterns like {a,b,c} and {1..3}
69
+ *
70
+ * Optimized with:
71
+ * 1. Cache for repeated patterns
72
+ * 2. Fast path for simple {a,b,c} patterns
73
+ *
74
+ * @param pattern - The glob pattern to expand
75
+ * @param options - Minimatch options
76
+ * @returns Array of expanded patterns
77
+ */
78
+ function braceExpand(pattern, options = {}) {
79
+ // If nobrace is set, return pattern unchanged
80
+ if (options.nobrace) {
81
+ return [pattern];
82
+ }
83
+ // Quick check: pattern must contain both { and }
84
+ const braceIdx = pattern.indexOf('{');
85
+ if (braceIdx === -1 || pattern.indexOf('}', braceIdx) === -1) {
86
+ return [pattern];
87
+ }
88
+ // Check cache first
89
+ const cached = braceCache.get(pattern);
90
+ if (cached) {
91
+ // Return a copy to prevent mutation
92
+ return [...cached];
93
+ }
94
+ // Try fast path for simple brace patterns
95
+ const fastResult = trySimpleBraceExpand(pattern);
96
+ if (fastResult !== null) {
97
+ // Cache and return
98
+ if (braceCache.size >= BRACE_CACHE_SIZE) {
99
+ const firstKey = braceCache.keys().next().value;
100
+ if (firstKey !== undefined) {
101
+ braceCache.delete(firstKey);
102
+ }
103
+ }
104
+ braceCache.set(pattern, fastResult);
105
+ return [...fastResult];
106
+ }
107
+ try {
108
+ // Use braces with expand: true for full bash-like expansion
109
+ const expanded = (0, braces_1.default)(pattern, {
110
+ expand: true,
111
+ // Limit range expansion to prevent DoS
112
+ // e.g., {1..10000} will be limited
113
+ rangeLimit: 1000,
114
+ });
115
+ // Check if expansion is too large (additional safety)
116
+ if (expanded.length > MAX_EXPANSION_LENGTH) {
117
+ // Return original pattern if expansion is too large
118
+ console.warn(`Brace expansion for "${pattern}" produced ${expanded.length} patterns, limiting to original pattern`);
119
+ return [pattern];
120
+ }
121
+ // Remove duplicates using Set (faster than manual loop for larger arrays)
122
+ const unique = [...new Set(expanded)];
123
+ const result = unique.length > 0 ? unique : [pattern];
124
+ // Cache the result
125
+ if (braceCache.size >= BRACE_CACHE_SIZE) {
126
+ const firstKey = braceCache.keys().next().value;
127
+ if (firstKey !== undefined) {
128
+ braceCache.delete(firstKey);
129
+ }
130
+ }
131
+ braceCache.set(pattern, result);
132
+ return [...result];
133
+ }
134
+ catch (e) {
135
+ // If expansion fails for any reason, return original pattern
136
+ // This matches minimatch's behavior of being lenient with invalid patterns
137
+ return [pattern];
138
+ }
139
+ }
140
+ /**
141
+ * Check if a pattern contains brace expansion syntax
142
+ */
143
+ function hasBraces(pattern) {
144
+ // Simple check for balanced braces with content
145
+ let depth = 0;
146
+ let hasContent = false;
147
+ for (let i = 0; i < pattern.length; i++) {
148
+ const char = pattern[i];
149
+ const prevChar = i > 0 ? pattern[i - 1] : '';
150
+ // Skip escaped braces
151
+ if (prevChar === '\\') {
152
+ continue;
153
+ }
154
+ if (char === '{') {
155
+ depth++;
156
+ }
157
+ else if (char === '}') {
158
+ if (depth > 0) {
159
+ depth--;
160
+ if (depth === 0 && hasContent) {
161
+ return true;
162
+ }
163
+ }
164
+ }
165
+ else if (depth > 0 && (char === ',' || char === '.')) {
166
+ // Has content (comma for list, dots for range)
167
+ hasContent = true;
168
+ }
169
+ }
170
+ return false;
171
+ }
172
+ //# source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GAAG,EAAE,CAAC;YACjB,KAAK,EAAE,CAAC;QACV,CAAC;aAAM,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACxB,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;gBACd,KAAK,EAAE,CAAC;gBACR,IAAI,KAAK,KAAK,CAAC,IAAI,UAAU,EAAE,CAAC;oBAC9B,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;aAAM,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACvD,+CAA+C;YAC/C,UAAU,GAAG,IAAI,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @fileoverview LRU Cache for compiled Minimatch patterns
3
+ *
4
+ * This module provides a simple LRU (Least Recently Used) cache for Minimatch
5
+ * instances. Caching compiled patterns significantly improves performance
6
+ * when the same pattern is used multiple times with the minimatch() function.
7
+ *
8
+ * The cache stores compiled Minimatch instances keyed by a combination of
9
+ * the pattern string and relevant options that affect compilation.
10
+ *
11
+ * @author 686f6c61
12
+ * @see https://github.com/686f6c61/minimatch-fast
13
+ * @license MIT
14
+ */
15
+ import type { MinimatchOptions } from './types.js';
16
+ import { Minimatch } from './minimatch-class.js';
17
+ /**
18
+ * Get a cached Minimatch instance or create a new one.
19
+ * Implements LRU eviction when cache is full.
20
+ *
21
+ * @param pattern - The glob pattern
22
+ * @param options - Minimatch options
23
+ * @returns A Minimatch instance (cached or new)
24
+ */
25
+ export declare function getOrCreateMatcher(pattern: string, options: MinimatchOptions): Minimatch;
26
+ /**
27
+ * Clear the pattern cache.
28
+ * Useful for testing or when memory pressure is high.
29
+ */
30
+ export declare function clearCache(): void;
31
+ /**
32
+ * Get the current cache size.
33
+ * Useful for monitoring and testing.
34
+ */
35
+ export declare function getCacheSize(): number;
36
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AA4CjD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,GACxB,SAAS,CA4BX;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAEjC;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview LRU Cache for compiled Minimatch patterns
4
+ *
5
+ * This module provides a simple LRU (Least Recently Used) cache for Minimatch
6
+ * instances. Caching compiled patterns significantly improves performance
7
+ * when the same pattern is used multiple times with the minimatch() function.
8
+ *
9
+ * The cache stores compiled Minimatch instances keyed by a combination of
10
+ * the pattern string and relevant options that affect compilation.
11
+ *
12
+ * @author 686f6c61
13
+ * @see https://github.com/686f6c61/minimatch-fast
14
+ * @license MIT
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.getOrCreateMatcher = getOrCreateMatcher;
18
+ exports.clearCache = clearCache;
19
+ exports.getCacheSize = getCacheSize;
20
+ const minimatch_class_js_1 = require("./minimatch-class.js");
21
+ /**
22
+ * Maximum number of patterns to cache.
23
+ * This prevents unbounded memory growth while still providing
24
+ * good cache hit rates for typical usage patterns.
25
+ */
26
+ const CACHE_SIZE = 500;
27
+ /**
28
+ * LRU cache for compiled Minimatch instances.
29
+ * Uses Map which maintains insertion order, making it easy
30
+ * to implement LRU eviction by deleting the oldest entry.
31
+ */
32
+ const patternCache = new Map();
33
+ /**
34
+ * Generate a cache key from pattern and options.
35
+ * Only includes options that affect pattern compilation.
36
+ *
37
+ * @param pattern - The glob pattern
38
+ * @param options - Minimatch options
39
+ * @returns A unique cache key string
40
+ */
41
+ function getCacheKey(pattern, options) {
42
+ // Use null byte as separator (cannot appear in patterns)
43
+ // Include all options that affect compilation
44
+ return `${pattern}\0${options.nocase ? '1' : '0'}${options.dot ? '1' : '0'}${options.noglobstar ? '1' : '0'}${options.nobrace ? '1' : '0'}${options.noext ? '1' : '0'}${options.nonegate ? '1' : '0'}${options.nocomment ? '1' : '0'}${options.matchBase ? '1' : '0'}${options.flipNegate ? '1' : '0'}${options.windowsPathsNoEscape ? '1' : '0'}${options.preserveMultipleSlashes ? '1' : '0'}${options.partial ? '1' : '0'}${options.platform ?? ''}`;
45
+ }
46
+ /**
47
+ * Get a cached Minimatch instance or create a new one.
48
+ * Implements LRU eviction when cache is full.
49
+ *
50
+ * @param pattern - The glob pattern
51
+ * @param options - Minimatch options
52
+ * @returns A Minimatch instance (cached or new)
53
+ */
54
+ function getOrCreateMatcher(pattern, options) {
55
+ const key = getCacheKey(pattern, options);
56
+ // Check cache first
57
+ let mm = patternCache.get(key);
58
+ if (mm) {
59
+ // Move to end (most recently used) by re-inserting
60
+ patternCache.delete(key);
61
+ patternCache.set(key, mm);
62
+ return mm;
63
+ }
64
+ // Create new Minimatch instance
65
+ mm = new minimatch_class_js_1.Minimatch(pattern, options);
66
+ // Evict oldest entry if cache is full
67
+ if (patternCache.size >= CACHE_SIZE) {
68
+ const firstKey = patternCache.keys().next().value;
69
+ if (firstKey !== undefined) {
70
+ patternCache.delete(firstKey);
71
+ }
72
+ }
73
+ // Add to cache
74
+ patternCache.set(key, mm);
75
+ return mm;
76
+ }
77
+ /**
78
+ * Clear the pattern cache.
79
+ * Useful for testing or when memory pressure is high.
80
+ */
81
+ function clearCache() {
82
+ patternCache.clear();
83
+ }
84
+ /**
85
+ * Get the current cache size.
86
+ * Useful for monitoring and testing.
87
+ */
88
+ function getCacheSize() {
89
+ return patternCache.size;
90
+ }
91
+ //# sourceMappingURL=c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,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAC5B,OAAO,CAAC,QAAQ,IAAI,EACtB,EAAE,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAChC,OAAe,EACf,OAAyB;IAEzB,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE1C,oBAAoB;IACpB,IAAI,EAAE,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAE/B,IAAI,EAAE,EAAE,CAAC;QACP,mDAAmD;QACnD,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC1B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,gCAAgC;IAChC,EAAE,GAAG,IAAI,8BAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAErC,sCAAsC;IACtC,IAAI,YAAY,CAAC,IAAI,IAAI,UAAU,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;QAClD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED,eAAe;IACf,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAE1B,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;GAGG;AACH,SAAgB,UAAU;IACxB,YAAY,CAAC,KAAK,EAAE,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,SAAgB,YAAY;IAC1B,OAAO,YAAY,CAAC,IAAI,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @fileoverview Escape glob magic characters
3
+ *
4
+ * This module provides functionality to escape special glob characters in strings,
5
+ * making them match literally instead of being interpreted as patterns.
6
+ *
7
+ * Escape modes:
8
+ * - Default mode: Uses backslash escaping (\* \? etc.)
9
+ * - Windows mode: Uses character class escaping ([*] [?] etc.)
10
+ *
11
+ * This is useful when you need to match file paths that contain glob
12
+ * special characters like *, ?, [], {}, etc.
13
+ *
14
+ * @example
15
+ * escape('*.js') // Returns '\\*.js'
16
+ * escape('[test].js') // Returns '\\[test\\].js'
17
+ * escape('*.js', { windowsPathsNoEscape: true }) // Returns '[*].js'
18
+ *
19
+ * @author 686f6c61
20
+ * @see https://github.com/686f6c61/minimatch-fast
21
+ * @license MIT
22
+ */
23
+ import type { MinimatchOptions } from './types.js';
24
+ /**
25
+ * Escape all magic characters in a glob pattern so it matches literally.
26
+ *
27
+ * If windowsPathsNoEscape is true, characters are escaped by wrapping in [],
28
+ * because a magic character wrapped in a character class can only be satisfied
29
+ * by that exact character. Backslash is NOT escaped in this mode because it
30
+ * is treated as a path separator.
31
+ *
32
+ * If windowsPathsNoEscape is false (default), characters are escaped with
33
+ * backslash.
34
+ *
35
+ * @param str - The string to escape
36
+ * @param options - Options controlling escape behavior
37
+ * @returns Escaped string
38
+ */
39
+ export declare function escape(str: string, options?: Pick<MinimatchOptions, 'windowsPathsNoEscape'>): string;
40
+ //# sourceMappingURL=escape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"escape.d.ts","sourceRoot":"","sources":["../../src/escape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CACpB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,sBAAsB,CAAM,GAC3D,MAAM,CAYR"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Escape glob magic characters
4
+ *
5
+ * This module provides functionality to escape special glob characters in strings,
6
+ * making them match literally instead of being interpreted as patterns.
7
+ *
8
+ * Escape modes:
9
+ * - Default mode: Uses backslash escaping (\* \? etc.)
10
+ * - Windows mode: Uses character class escaping ([*] [?] etc.)
11
+ *
12
+ * This is useful when you need to match file paths that contain glob
13
+ * special characters like *, ?, [], {}, etc.
14
+ *
15
+ * @example
16
+ * escape('*.js') // Returns '\\*.js'
17
+ * escape('[test].js') // Returns '\\[test\\].js'
18
+ * escape('*.js', { windowsPathsNoEscape: true }) // Returns '[*].js'
19
+ *
20
+ * @author 686f6c61
21
+ * @see https://github.com/686f6c61/minimatch-fast
22
+ * @license MIT
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.escape = escape;
26
+ /**
27
+ * Escape all magic characters in a glob pattern so it matches literally.
28
+ *
29
+ * If windowsPathsNoEscape is true, characters are escaped by wrapping in [],
30
+ * because a magic character wrapped in a character class can only be satisfied
31
+ * by that exact character. Backslash is NOT escaped in this mode because it
32
+ * is treated as a path separator.
33
+ *
34
+ * If windowsPathsNoEscape is false (default), characters are escaped with
35
+ * backslash.
36
+ *
37
+ * @param str - The string to escape
38
+ * @param options - Options controlling escape behavior
39
+ * @returns Escaped string
40
+ */
41
+ function escape(str, options = {}) {
42
+ const { windowsPathsNoEscape = false } = options;
43
+ if (windowsPathsNoEscape) {
44
+ // Escape by wrapping in character class []
45
+ // Don't escape backslash since it's a path separator in this mode
46
+ return str.replace(/[?*()[\]{}]/g, '[$&]');
47
+ }
48
+ // Default: escape with backslash
49
+ // Include backslash in the escape set
50
+ return str.replace(/[?*()[\]{}\\]/g, '\\$&');
51
+ }
52
+ //# sourceMappingURL=escape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"escape.js","sourceRoot":"","sources":["../../src/escape.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;AAmBH,wBAeC;AA9BD;;;;;;;;;;;;;;GAcG;AACH,SAAgB,MAAM,CACpB,GAAW,EACX,UAA0D,EAAE;IAE5D,MAAM,EAAE,oBAAoB,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAEjD,IAAI,oBAAoB,EAAE,CAAC;QACzB,2CAA2C;QAC3C,kEAAkE;QAClE,OAAO,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED,iCAAiC;IACjC,sCAAsC;IACtC,OAAO,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @fileoverview Fast path handlers for common glob patterns
3
+ *
4
+ * This module provides optimized matching for the most common glob patterns,
5
+ * avoiding the overhead of full regex compilation. These fast paths use
6
+ * simple string operations like startsWith(), endsWith(), and includes()
7
+ * which are significantly faster than regex matching.
8
+ *
9
+ * Supported fast path patterns:
10
+ * - `*` - Match any single path segment (except dotfiles by default)
11
+ * - `*.ext` - Match files with specific extension (e.g., `*.js`, `*.ts`)
12
+ * - `*.*` - Match files with any extension
13
+ * - `.*` - Match hidden files (dotfiles)
14
+ * - `???` - Match files with exact length (question mark patterns)
15
+ *
16
+ * When a pattern doesn't match any fast path, null is returned and the
17
+ * caller should fall back to full pattern matching.
18
+ *
19
+ * @author 686f6c61
20
+ * @see https://github.com/686f6c61/minimatch-fast
21
+ * @license MIT
22
+ */
23
+ import type { MinimatchOptions } from './types.js';
24
+ /**
25
+ * Try to match a path against a pattern using a fast path.
26
+ *
27
+ * This function attempts to use optimized string operations for common
28
+ * glob patterns instead of full regex compilation. If the pattern is not
29
+ * a simple pattern that can be handled by a fast path, null is returned.
30
+ *
31
+ * @param path - The path to match (should be a filename without directory)
32
+ * @param pattern - The glob pattern to match against
33
+ * @param options - Minimatch options (dot, nocase are relevant)
34
+ * @returns true if matches, false if doesn't match, null if no fast path available
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * tryFastPath('foo.js', '*.js', {}); // true
39
+ * tryFastPath('foo.txt', '*.js', {}); // false
40
+ * tryFastPath('.hidden', '*', {}); // false
41
+ * tryFastPath('.hidden', '*', { dot: true }); // true
42
+ * tryFastPath('foo.js', '**\/*.js', {}); // null (has /, need full matching)
43
+ * ```
44
+ */
45
+ export declare function tryFastPath(path: string, pattern: string, options: MinimatchOptions): boolean | null;
46
+ /**
47
+ * Check if a pattern might be eligible for fast path.
48
+ * This is a quick pre-check to avoid expensive regex tests.
49
+ *
50
+ * @param pattern - The glob pattern
51
+ * @returns true if pattern might use fast path
52
+ */
53
+ export declare function mightUseFastPath(pattern: string): boolean;
54
+ //# sourceMappingURL=fast-paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fast-paths.d.ts","sourceRoot":"","sources":["../../src/fast-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA4CnD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,GACxB,OAAO,GAAG,IAAI,CAmHhB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAYzD"}