MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / globToRegex

Function globToRegex

src/tools/filesystem/glob.ts:17–43  ·  view source on GitHub ↗
(pattern: string)

Source from the content-addressed store, hash-verified

15]);
16
17function globToRegex(pattern: string): RegExp {
18 let re = '';
19 let i = 0;
20 while (i < pattern.length) {
21 const c = pattern[i]!;
22 if (c === '*') {
23 if (pattern[i + 1] === '*') {
24 re += '.*';
25 i += 2;
26 if (pattern[i] === '/') i++; // **/ matches zero or more dirs
27 } else {
28 re += '[^/]*';
29 i++;
30 }
31 } else if (c === '?') {
32 re += '[^/]';
33 i++;
34 } else if (c === '.' || c === '(' || c === ')' || c === '+' || c === '|' || c === '^' || c === '$' || c === '{' || c === '}' || c === '[' || c === ']') {
35 re += '\\' + c;
36 i++;
37 } else {
38 re += c;
39 i++;
40 }
41 }
42 return new RegExp('^' + re + '$');
43}
44
45export class GlobTool extends Tool<z.infer<typeof ArgsSchema>> {
46 name = 'glob';

Callers 1

executeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected