15 lines
584 B
JavaScript
15 lines
584 B
JavaScript
"use strict";
|
|
/**
|
|
* expandTemplate: simple variable substitution in {{key}} placeholders.
|
|
* @param {string} template - The template string with {{key}} tokens.
|
|
* @param {object} context - Mapping of key -> replacement value.
|
|
* @returns {string} - The template with keys replaced by context values.
|
|
*/
|
|
export function expandTemplate(template, context) {
|
|
if (typeof template !== 'string') return '';
|
|
return template.replace(/\{\{\s*(\w+)\s*\}\}/g, (_match, key) => {
|
|
return Object.prototype.hasOwnProperty.call(context, key)
|
|
? String(context[key])
|
|
: '';
|
|
});
|
|
} |