MCPcopy Create free account
hub / github.com/Monogatari/Monogatari / interpolate

Method interpolate

src/lib/FancyError.ts:88–96  ·  view source on GitHub ↗

* Interpolate placeholders in a string with context values. * Placeholders use the format: {{key}}

(text: string, context: ErrorContext)

Source from the content-addressed store, hash-verified

86 * Placeholders use the format: {{key}}
87 */
88 private static interpolate (text: string, context: ErrorContext): string {
89 return text.replace(/\{\{(\w+)\}\}/g, (match, key) => {
90 const value = context[key];
91 if (value === undefined) {
92 return match; // Keep placeholder if no value provided
93 }
94 return String(value);
95 });
96 }
97
98 /**
99 * Deep interpolate an object, replacing all string placeholders with context values.

Callers 2

interpolatePropsMethod · 0.80
showMethod · 0.80

Calls 1

replaceMethod · 0.80

Tested by

no test coverage detected