2025-05-08 01:52:12 +00:00
|
|
|
'use strict';
|
2025-05-06 19:21:55 +00:00
|
|
|
/**
|
|
|
|
|
* 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) {
|
2025-05-08 01:52:12 +00:00
|
|
|
if (typeof template !== 'string') return '';
|
|
|
|
|
return template.replace(/\{\{\s*(\w+)\s*\}\}/g, (_match, key) => {
|
|
|
|
|
return Object.prototype.hasOwnProperty.call(context, key)
|
|
|
|
|
? String(context[key])
|
|
|
|
|
: '';
|
|
|
|
|
});
|
|
|
|
|
}
|