template
@guoba-ai/utils / string / template
Function: template()
function template(str, data): string;Defined in: string.ts:77
Simple template string replacement. Replaces {key} placeholders
with values from the data object.
Parameters
str
string
The template string with {key} placeholders
data
Record<string, string>
Object with replacement values
Returns
string
The string with placeholders replaced
Example
template('Hello {name}!', { name: 'World' }) // 'Hello World!'
template('{a} + {b} = {c}', { a: '1', b: '2', c: '3' }) // '1 + 2 = 3'
template('Hello {name}!', {}) // 'Hello {name}!'Warning
Only {word} placeholders are replaced. Keys containing dots or hyphens are left unchanged.