All checks were successful
ci/woodpecker/push/ci Pipeline was successful
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
24 lines
613 B
TypeScript
24 lines
613 B
TypeScript
export interface TemplateVars {
|
|
[key: string]: string;
|
|
}
|
|
|
|
/**
|
|
* Replaces {{PLACEHOLDER}} tokens with provided values.
|
|
* Does NOT expand ${ENV_VAR} syntax — those pass through for shell resolution.
|
|
*/
|
|
export function renderTemplate(
|
|
template: string,
|
|
vars: TemplateVars,
|
|
options: { strict?: boolean } = {},
|
|
): string {
|
|
return template.replace(/\{\{([A-Z_][A-Z0-9_]*)\}\}/g, (match, varName: string) => {
|
|
if (varName in vars) {
|
|
return vars[varName] ?? '';
|
|
}
|
|
if (options.strict) {
|
|
throw new Error(`Template variable not provided: {{${varName}}}`);
|
|
}
|
|
return '';
|
|
});
|
|
}
|