MCPcopy Create free account
hub / github.com/SethGammon/Citadel / matchPattern

Function matchPattern

hooks_src/protect-files.js:331–352  ·  view source on GitHub ↗

* Match a file path against a glob pattern. * * Supports: * - Exact path match * - dir/* — files directly in a directory (single level) * - dir/ — all files under a directory prefix (trailing slash) * - src/** — recursive glob (any depth under src/) * - **\/*.ts — any .ts file at

(filePath, pattern)

Source from the content-addressed store, hash-verified

329 * - dir/* — files directly in a directory (single level)
330 * - dir/ — all files under a directory prefix (trailing slash)
331 * - src/** — recursive glob (any depth under src/)
332 * - **\/*.ts — any .ts file at any depth
333 *
334 * @param {string} filePath - Relative file path, forward-slash separated
335 * @param {string} pattern - Glob pattern to match against
336 * @returns {boolean}
337 */
338function matchPattern(filePath, pattern) {
339 // Exact match
340 if (filePath === pattern) return true;
341
342 // Recursive glob: pattern contains **
343 if (pattern.includes('**')) {
344 return matchGlobStar(filePath, pattern);
345 }
346
347 // Single-level wildcard: pattern ends with /*
348 if (pattern.endsWith('/*')) {
349 const dir = pattern.slice(0, -2);
350 return filePath.startsWith(dir + '/') && !filePath.slice(dir.length + 1).includes('/');
351 }
352
353 // Directory prefix: pattern ends with /
354 if (pattern.endsWith('/')) {
355 return filePath.startsWith(pattern);

Callers 3

runFunction · 0.85
checkCampaignScopeFunction · 0.85
matchScopeEntryFunction · 0.85

Calls 1

matchGlobStarFunction · 0.85

Tested by

no test coverage detected