* Substitute variables in the prompt template using {{variable}} syntax
( template: string, variables: Record<string, string>, )
| 79 | * Substitute variables in the prompt template using {{variable}} syntax |
| 80 | */ |
| 81 | function substituteVariables( |
| 82 | template: string, |
| 83 | variables: Record<string, string>, |
| 84 | ): string { |
| 85 | // Single-pass replacement avoids two bugs: (1) $ backreference corruption |
| 86 | // (replacer fn treats $ literally), and (2) double-substitution when user |
| 87 | // content happens to contain {{varName}} matching a later variable. |
| 88 | return template.replace(/\{\{(\w+)\}\}/g, (match, key: string) => |
| 89 | Object.prototype.hasOwnProperty.call(variables, key) |
| 90 | ? variables[key]! |
| 91 | : match, |
| 92 | ) |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Build the Magic Docs update prompt with variable substitution |
no outgoing calls
no test coverage detected