| 15 | ]); |
| 16 | |
| 17 | function 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 | |
| 45 | export class GlobTool extends Tool<z.infer<typeof ArgsSchema>> { |
| 46 | name = 'glob'; |