MCPcopy Create free account
hub / github.com/codeaashu/claude-code / substituteVariables

Function substituteVariables

src/services/SessionMemory/prompts.ts:201–213  ·  view source on GitHub ↗

* Substitute variables in the prompt template using {{variable}} syntax

(
  template: string,
  variables: Record<string, string>,
)

Source from the content-addressed store, hash-verified

199 * Substitute variables in the prompt template using {{variable}} syntax
200 */
201function substituteVariables(
202 template: string,
203 variables: Record<string, string>,
204): string {
205 // Single-pass replacement avoids two bugs: (1) $ backreference corruption
206 // (replacer fn treats $ literally), and (2) double-substitution when user
207 // content happens to contain {{varName}} matching a later variable.
208 return template.replace(/\{\{(\w+)\}\}/g, (match, key: string) =>
209 Object.prototype.hasOwnProperty.call(variables, key)
210 ? variables[key]!
211 : match,
212 )
213}
214
215/**
216 * Check if the session memory content is essentially empty (matches the template).

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected