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

Function substituteVariables

src/services/MagicDocs/prompts.ts:81–93  ·  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

79 * Substitute variables in the prompt template using {{variable}} syntax
80 */
81function 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

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected