(text: string, toolNames: readonly string[])
| 37 | * `codegraph explore` command never match. |
| 38 | */ |
| 39 | export function withOpenCodeToolNames(text: string, toolNames: readonly string[]): string { |
| 40 | if (toolNames.length === 0) return text; |
| 41 | const alternatives = [...toolNames] |
| 42 | .sort((a, b) => b.length - a.length) |
| 43 | .map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')) |
| 44 | .join('|'); |
| 45 | const wholeName = new RegExp(`(?<![A-Za-z0-9_])(?:${alternatives})(?![A-Za-z0-9_])`, 'g'); |
| 46 | return text.replace(wholeName, (name) => openCodeToolName(name)); |
| 47 | } |
no test coverage detected